"Normalizing" arc/final weights on an FST?
I am using FSTs to represent probabilistic finite-state automata and
there are various situations in which I need to "normalize" them--that
is, scale the arc weights such that the probability of arcs leading
out of a state (plus the probability of state finality) sums to 1 for
each state. I am having trouble, however, figuring out how to modify
the weights on arcs of an FST. I have tried the following code, and
while this modifies the final weight appropriately, it doesn't affect the arc weights at all:
void makeProper(VectorFst &fst) {
using fst::TropicalWeight;
for(StateIterator > siter(fst); !siter.Done(); siter.Next()) {
int s = siter.Value();
float tot = pow(2, -1 * fst.Final(s).Value());
for(ArcIterator > aiter(fst,s); ! aiter.Done(); aiter.Next()) {
StdArc arc = aiter.Value();
float contribution = pow(2, -1 * arc.weight.Value());
tot += contribution;
}
float adjustment = -1 * log(tot) / log(2);
float newFinal = fst.Final(s).Value() - adjustment;
fst.SetFinal(s,TropicalWeight(newFinal));
for(ArcIterator > aiter(fst,s); ! aiter.Done(); aiter.Next()) {
StdArc arc = aiter.Value();
float newWeight = arc.weight.Value() - adjustment;
arc.weight = TropicalWeight(0.0);
}
}
}
How can I modify the arc weights? Or is there some other
functionality I haven't noticed yet that performs this normalization
on its own?
Many thanks once again,
Roger