21 printf(
"transition\n");
26 p += expf(-transition[s0*N_STATES+s1]);
28 printf(
"%4.2f,", transition[s0*N_STATES+s1]);
30 printf(
"%01.2f,", expf(-transition[s0*N_STATES+s1]));
32 printf(
"] sum=%4.2f\n", p);
45 p += expf(-emission[s*N_TOKENS+o]);
47 printf(
"%4.2f,", emission[s*N_TOKENS+o]);
49 printf(
"%01.2f,", expf(-emission[s*N_TOKENS+o]));
51 printf(
"] sum=%4.2f\n", p);
61 printf(
"%4.2f,",
init[s]);
63 printf(
"%01.2f,", expf(-
init[s]));
71 for(t=0; t<
N_OBS; t++) {
72 printf(
"%d,",path[t]);
80 for(t=0; t<
N_OBS; t++) {
86 int main(
int argc,
char **argv) {
95 #if !defined(DETERMINISTIC_TRANSITION) || !defined(DETERMINISTIC_EMISSION) 98 #if defined(DETERMINISTIC_TRANSITION) || defined(DETERMINISTIC_TRANSITION) 113 #ifndef DETERMINISTIC_TRANSITION 122 data.
transition[s0*N_STATES+s1] = -1*logf(P[s1]/sum);
138 data.
emission[s0*N_TOKENS+o] = -1*logf(Q[o]/sum);
153 data.
init[s0] = -1*logf(P[s0]/sum);
167 #ifndef DETERMINISTIC_TRANSITION 169 s[0]=0;
do{r-=expf(-data.
init[s[0]]);}
while(r>0&&(++s[0]));
174 if(data.
init[s0]<min) {
181 #ifndef DETERMINISTIC_EMISSION 182 r = ((double)
prng_rand(&state)/(double)PRNG_RAND_MAX);
190 if(data.
emission[s[0]*N_TOKENS+o]<min) {
198 for(t=1; t<
N_OBS; t++) {
200 #ifndef DETERMINISTIC_TRANSITION 201 r = ((double)
prng_rand(&state)/(double)PRNG_RAND_MAX);
202 s[t]=0;
do{r-=expf(-data.
transition[s[t-1]*N_STATES+s[t]]);}
while(r>0&&++s[t]);
214 #ifndef DETERMINISTIC_EMISSION 215 r = ((double)
prng_rand(&state)/(double)PRNG_RAND_MAX);
216 o=0;
do{ r-=expf(-data.
emission[s[t]*N_TOKENS+o]); }
while(r>0 && ++o);
222 if(data.
emission[s[t]*N_TOKENS+o]<min) {
237 fd = open(
"input.data", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
238 assert( fd>0 &&
"Couldn't open input data file" );
static uint64_t prng_rand(struct prng_rand_t *state)
void dump_init(prob_t init[N_STATES], int log)
void data_to_input(int fd, void *vdata)
void dump_obs(tok_t obs[N_OBS])
void dump_emission(prob_t emission[N_STATES *N_TOKENS], int log)
prob_t transition[N_STATES *N_STATES]
prob_t emission[N_STATES *N_TOKENS]
void dump_path(state_t path[N_OBS])
void dump_transition(prob_t transition[N_STATES *N_STATES], int log)
void init(int bucket[BUCKETSIZE])
int main(int argc, char **argv)
static void prng_srand(uint64_t seed, struct prng_rand_t *state)