94 float delta):
fst_(fst) {
101 for (ArcIterator<VectorFst<StdArc> > aiter(*fst, s);
102 !aiter.Done(); aiter.Next()) {
103 const Arc &arc = aiter.Value();
104 StateId t = arc.nextstate;
105 double weight =
kaldi::Exp(-arc.weight.Value());
106 pred_[t].push_back(std::make_pair(s, weight));
118 double min_sum = 0, max_sum = 0;
121 for (ArcIterator<VectorFst<StdArc> > aiter(*
fst_, s);
122 !aiter.Done(); aiter.Next()) {
123 const Arc &arc = aiter.Value();
124 StateId t = arc.nextstate;
132 min_sum = std::min(min_sum, sum);
133 max_sum = std::max(max_sum, sum);
136 KALDI_VLOG(4) <<
"min,max is " << min_sum <<
" " << max_sum;
148 int iter, max_iter = 200;
150 for (iter = 0; iter < max_iter; iter++) {
159 new_occ[
i] = 0.1 *
occ_[
i];
162 std::vector<std::pair<StateId, double> >::const_iterator iter,
164 for (iter =
pred_[
i].begin(); iter != end; ++iter) {
165 StateId
j = iter->first;
166 double p = iter->second;
167 new_occ[
j] +=
occ_[
i] * p;
173 double inv_lambda = 1.0 /
lambda_;
176 if (iter % 5 == 0 && iter > 0 &&
TestAccuracy() <= delta) {
177 KALDI_VLOG(3) <<
"Weight-pushing converged after " << iter
182 KALDI_WARN <<
"push-special: finished " << iter
183 <<
" iterations without converging. Output will be inaccurate.";
197 for (MutableArcIterator<VectorFst<StdArc> > aiter(
fst_, s);
198 !aiter.Done(); aiter.Next()) {
199 Arc arc = aiter.Value();
200 StateId t = arc.nextstate;
215 std::vector<std::vector<std::pair<StateId, double> > >
pred_;
227 if (fst->NumStates() > 0)
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
VectorFst< StdArc > * fst_
LatticeWeightTpl< FloatType > Times(const LatticeWeightTpl< FloatType > &w1, const LatticeWeightTpl< FloatType > &w2)
std::vector< double > occ_
PushSpecialClass(VectorFst< StdArc > *fst, float delta)
void Iterate(float delta)
fst::StdArc::Weight Weight
void PushSpecial(VectorFst< StdArc > *fst, float delta)
std::vector< std::vector< std::pair< StateId, double > > > pred_