47 static void init_paths_array(
EST_VTPoint *n,
int num_states);
55 if (paths != 0)
delete paths;
58 for (i=0; i<num_states; i++)
63 if (cands != 0)
delete cands;
64 if (next != 0)
delete next;
68 : vit_a_big_number(1.0e10)
77 overall_path_pruning_envelope_width = -1;
78 candidate_pruning_envelope_width = -1;
95 overall_path_pruning_envelope_width = -1;
96 candidate_pruning_envelope_width = -1;
118 for (i=p->
head(); i != 0; i=i->
next())
123 init_paths_array(n,num_states);
133 init_paths_array(n,num_states);
138 if (num_states == -1)
139 init_paths_array(timeline,1);
147 static void init_paths_array(
EST_VTPoint *n,
int num_states)
154 for (j=0;j<num_states;j++)
158 int EST_Viterbi_Decoder::betterthan(
const float a,
const float b)
const 179 for (i=0, c=cands; c != 0; c=c->
next,i++)
181 init_paths_array(p,i);
191 overall_path_pruning_envelope_width = beam;
192 candidate_pruning_envelope_width = ob_beam;
215 double best_score=0.0,score_cutoff=0.0;
216 double best_candidate_score=0.0,candidate_cutoff=0;
218 int cand_count=0, cands_considered=0;
220 for (p=timeline; p->
next != 0; p=p->
next)
223 p->
cands = (*user_clist)(p->
s,
f);
225 prune_initialize(p,best_score,best_candidate_score,
226 score_cutoff,candidate_cutoff,
230 if (num_states == -1)
237 if (((p == timeline) && i==0) || (p->
st_paths[i] != 0))
243 betterthan(c->
score,candidate_cutoff))
248 if (debug) debug_output_1(p,c,np,i);
249 if (do_pruning && betterthan(np->
score,best_score))
251 best_score = np->
score;
253 score_cutoff = best_score
254 - overall_path_pruning_envelope_width;
256 score_cutoff = best_score
257 + overall_path_pruning_envelope_width;
263 if(!do_pruning||betterthan(np->
score,score_cutoff))
264 vit_add_paths(p->
next,np);
275 best_score - overall_path_pruning_envelope_width;
278 best_score + overall_path_pruning_envelope_width;
281 cerr <<
"Considered " << cands_considered <<
" of ";
282 cerr << cand_count*p->
num_states <<
" candidate paths" << endl;
283 cerr <<
"FRAME: best score " << best_score;
284 cerr <<
" score cutoff " << score_cutoff << endl;
285 cerr <<
" best candidate score " << best_candidate_score;
286 cerr <<
" candidate cutoff " << candidate_cutoff << endl;
304 cerr <<
"Pruned " << dcount <<
" of " << pcount;
305 cerr <<
" paths" << endl << endl;
314 np = (*user_npath)(t,c,
f);
315 add_path(p->
next,np);
318 if (debug) fprintf(stdout,
"\n");
323 void EST_Viterbi_Decoder::
325 double &best_score,
double &best_candidate_score,
326 double &score_cutoff,
double &candidate_cutoff,
335 candidate_cutoff = - candidate_pruning_envelope_width;
342 candidate_cutoff = candidate_pruning_envelope_width;
345 for (cand_count=0,c=p->
cands; c; c=c->
next,cand_count++)
346 if (betterthan(c->
score,best_candidate_score))
347 best_candidate_score = c->
score;
348 candidate_cutoff += best_candidate_score;
354 printf(
"%s: ",(
const char *)p->
s->
name());
356 printf(
" %1.3f B %1.3f (%1.3f) st %d s %1.3f ",
359 ((
float)np->
f(
"lscore"))/np->
c->
score),
360 (float)np->
f(
"lscore"),np->
state,
363 cout <<
"(I)" << endl;
373 for (p=np; p != 0; p=next_p)
389 cerr <<
"EST_Viterbi: state too big (" << np->
state <<
")" << endl;
410 if(!betterthan(path_score,score_cutoff))
424 cerr <<
"Viterbi: tried to add path to NULL point\n";
427 if ((beam_width == 0) ||
437 if ((a == 0) || (betterthan(a->
score,np->
score)))
447 if ((beam_width > 0) &&
474 if (allcands ==
NULL)
477 numcands = allcands->
pos;
479 if ((cand_width == 0) ||
480 (numcands < cand_width) ||
486 for (a=newlist; ; a=a->
next)
498 if ((cand_width > 0) &&
499 (numcands > cand_width))
511 newlist->
pos = numcands;
521 if ((timeline == 0) || (timeline->
next == 0))
527 for (; p != 0; p=p->
from)
533 p->
c->
s->
set(n+
"_score",p->
f.
F(
"lscore",0.0));
544 if ((timeline == 0) || (timeline->
next == 0))
547 *bestPathEnd = find_best_end();
549 if (*bestPathEnd == 0)
565 for (; p != 0; p=p->
from)
573 EST_VTPath *EST_Viterbi_Decoder::find_best_end()
const 588 for (i=0,t=timeline; t->
next != 0; t=t->
next,i++)
592 cerr <<
"No paths at frame " << i <<
" " << t->
s->
name() << endl;
610 if (betterthan(p->
score,best))
621 cerr <<
"Failed to find path" << endl;
622 cout <<
"Best score is " << best << endl;
EST_VTPath *(* unpath_f_t)(EST_VTPath *p, EST_VTCandidate *c, EST_Features &f)
const EST_String name() const
void set(const EST_String &name, ssize_t ival)
bool result(const EST_String &n)
void copy_feature(const EST_String &n)
Copy named feature from the best path to related stream item.
bool vit_prune_path(double path_score, double score_cutoff)
EST_VTCandidate *(* uclist_f_t)(EST_Item *s, EST_Features &f)
const double vit_a_big_number
Unfortunately using MAX_DOUBLE doesn't do the right thing (e.g. comparison don't work with MAX_DOUBLE...
void search(void)
Do the the actual search.
void set_pruning_parameters(float beam, float ob_beam)
set beam widths for pruning
void initialise(EST_Relation *r)
Build the initial table from a EST_Relation.
EST_Viterbi_Decoder(uclist_f_t a, unpath_f_t b)
void set_val(const EST_String &name, const EST_Val &sval)
EST_Features f
For holding values to pass to user called functions.
int present(const EST_String &name) const
EST_VTCandidate * add_cand_prune(EST_VTCandidate *newcand, EST_VTCandidate *allcands)
float F(const EST_String &path) const