43#include "EST_viterbi.h"
45static void init_paths_array(
EST_VTPoint *n,
int num_states);
49EST_VTPoint::~EST_VTPoint()
53 if (paths != 0)
delete paths;
56 for (i=0; i<num_states; i++)
61 if (cands != 0)
delete cands;
62 if (next != 0)
delete next;
66 : vit_a_big_number(1.0e10)
75 overall_path_pruning_envelope_width = -1;
76 candidate_pruning_envelope_width = -1;
84 : vit_a_big_number(1.0e10)
92 overall_path_pruning_envelope_width = -1;
93 candidate_pruning_envelope_width = -1;
103EST_Viterbi_Decoder::~EST_Viterbi_Decoder()
114 for (i=p->
head(); i != 0; i=inext(i))
119 init_paths_array(n,num_states);
129 init_paths_array(n,num_states);
134 if (num_states == -1)
135 init_paths_array(timeline,1);
143static void init_paths_array(
EST_VTPoint *n,
int num_states)
148 n->num_states = num_states;
150 for (
j=0;
j<num_states;
j++)
154const int EST_Viterbi_Decoder::betterthan(
const float a,
const float b)
const
175 for (i=0, c=cands; c != 0; c=c->next,i++)
177 init_paths_array(p,i);
187 overall_path_pruning_envelope_width = beam;
188 candidate_pruning_envelope_width = ob_beam;
192void EST_Viterbi_Decoder::turn_on_debug()
197void EST_Viterbi_Decoder::turn_on_trace()
216 for (p=timeline; p->next != 0; p=p->next)
219 p->cands = (*user_clist)(p->s,
f);
226 if (num_states == -1)
227 init_dynamic_states(p->next,p->cands);
230 for (i=0; i<p->num_states; i++)
233 if (((p == timeline) && i==0) || (p->st_paths[i] != 0))
234 for (c=p->cands; c != 0; c=c->next)
243 np = (*user_npath)(p->st_paths[i],c,
f);
244 if (debug) debug_output_1(p,c,
np,i);
250 - overall_path_pruning_envelope_width;
253 + overall_path_pruning_envelope_width;
260 vit_add_paths(p->next,
np);
271 best_score - overall_path_pruning_envelope_width;
274 best_score + overall_path_pruning_envelope_width;
286 for (i=0; i<p->next->num_states; i++)
287 if(p->next->st_paths[i] != 0)
290 if(!betterthan(p->next->st_paths[i]->score,
293 delete p->next->st_paths[i];
294 p->next->st_paths[i] = 0;
306 for (t=p->paths; t != 0; t=t->next)
308 for (c=p->cands; c != 0; c=c->next)
310 np = (*user_npath)(t,c,
f);
311 add_path(p->next,
np);
319void EST_Viterbi_Decoder::
350 printf(
"%s: ",(
const char *)p->s->name());
352 printf(
" %1.3f B %1.3f (%1.3f) st %d s %1.3f ",
354 (
np->c->score==0 ? 0 :
358 if (p->st_paths[i] == 0)
361 cout << p->st_paths[i]->c->name <<
endl;
383 if ((
np->state < 0) || (
np->state > p->num_states))
385 cerr <<
"EST_Viterbi: state too big (" <<
np->state <<
")" <<
endl;
387 else if ((p->st_paths[
np->state] == 0) ||
388 (betterthan(
np->score,p->st_paths[
np->state]->score)))
391 if (p->st_paths[
np->state] != 0)
392 delete p->st_paths[
np->state];
393 p->st_paths[
np->state] =
np;
420 cerr <<
"Viterbi: tried to add path to NULL point\n";
423 if ((beam_width == 0) ||
424 (p->num_paths < beam_width) ||
425 (betterthan(
np->score,p->paths->score)))
431 for (a=p->paths; ; a=a->next)
433 if ((a == 0) || (betterthan(a->score,
np->score)))
443 if ((beam_width > 0) &&
444 (p->num_paths > beam_width))
475 if ((cand_width == 0) ||
484 if ((a == 0) || (betterthan(a->score,
newcand->score)))
494 if ((cand_width > 0) &&
517 if ((timeline == 0) || (timeline->next == 0))
523 for (; p != 0; p=p->from)
528 p->c->s->
set_val(n,p->c->name);
529 p->c->s->
set(n+
"_score",p->f.
F(
"lscore",0.0));
540 if ((timeline == 0) || (timeline->next == 0))
561 for (; p != 0; p=p->from)
564 if ((p->c != 0) && (p->f.
present(n)))
569EST_VTPath *EST_Viterbi_Decoder::find_best_end()
const
584 for (i=0,t=timeline; t->next != 0; t=t->next,i++)
586 if ((t->num_states == 0) && (t->num_paths == 0))
588 cerr <<
"No paths at frame " << i <<
" " << t->s->name() <<
endl;
594 for (i=0; i<t->num_states; i++)
596 if ((t->st_paths[i] != 0) &&
597 (betterthan(t->st_paths[i]->score,
best)))
599 best = t->st_paths[i]->score;
604 for (p=t->paths; p!=0; p=p->next)
606 if (betterthan(p->score,
best))
617 cerr <<
"Failed to find path" <<
endl;
const float F(const EST_String &path) const
int present(const EST_String &name) const
void set(const EST_String &name, int ival)
void set_val(const EST_String &name, const EST_Val &sval)
EST_Features f
For holding values to pass to user called functions.
EST_VTCandidate * add_cand_prune(EST_VTCandidate *newcand, EST_VTCandidate *allcands)
void initialise(EST_Relation *r)
Build the initial table from a \Ref{EST_Relation}.
void search(void)
Do the the actual search.
void copy_feature(const EST_String &n)
Copy named feature from the best path to related stream item.
void set_pruning_parameters(float beam, float ob_beam)
set beam widths for pruning
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...
bool result(const EST_String &n)
EST_Viterbi_Decoder(uclist_f_t a, unpath_f_t b)