push-special-test.cc
Go to the documentation of this file.
1 // fstext/push-special-test.cc
2 
3 // Copyright 2009-2011 Microsoft Corporation
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #include "fstext/push-special.h"
22 #include "fstext/rand-fst.h"
23 #include "fstext/fstext-utils.h"
24 #include "base/kaldi-math.h"
25 
26 namespace fst
27 {
28 
29 
30 // Don't instantiate with log semiring, as RandEquivalent may fail.
31 static void TestPushSpecial() {
32  typedef StdArc Arc;
33  typedef Arc::Label Label;
34  typedef Arc::StateId StateId;
35  typedef Arc::Weight Weight;
36 
37  VectorFst<Arc> *fst = RandFst<StdArc>();
38 
39  {
40  FstPrinter<Arc> fstprinter(*fst, NULL, NULL, NULL, false, true, "\t");
41  fstprinter.Print(&std::cout, "standard output");
42  }
43 
44  VectorFst<Arc> fst_copy(*fst);
45 
46  float delta = kDelta;
47  PushSpecial(&fst_copy, delta);
48 
49  Weight min, max;
50  float delta_dontcare = 0.1;
51  IsStochasticFstInLog(fst_copy, delta_dontcare, &min, &max);
52  // the per-state normalizers are allowed to deviate from the average by delta
53  // up and down, so the difference from the min to max weight should be 2*delta
54  // or less. We give it a bit of wiggle room (->2.5) due to numerical roundoff.
55 
56 
57  {
58  FstPrinter<Arc> fstprinter(fst_copy, NULL, NULL, NULL, false, true, "\t");
59  fstprinter.Print(&std::cout, "standard output");
60  }
61  KALDI_LOG << "Min value is " << min.Value() << ", max value is " << max.Value();
62 
63  // below, should be <= delta but different pieces of code compute this in this
64  // part vs. push-special, so the roundoff may be different.
65  KALDI_ASSERT(std::abs(min.Value() - max.Value()) <= 1.2 * delta);
66 
67  KALDI_ASSERT(RandEquivalent(*fst, fst_copy,
68  5/*paths*/, 0.01/*delta*/, kaldi::Rand()/*seed*/, 100/*path length-- max?*/));
69  delete fst;
70 }
71 
72 
73 } // namespace fst
74 
75 int main() {
77  using namespace fst;
78  for (int i = 0; i < 25; i++) {
80  }
81 }
fst::StdArc::StateId StateId
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
fst::StdArc StdArc
int main()
bool IsStochasticFstInLog(const Fst< StdArc > &fst, float delta, StdArc::Weight *min_sum, StdArc::Weight *max_sum)
fst::StdArc::Label Label
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
fst::StdArc::Weight Weight
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void PushSpecial(VectorFst< StdArc > *fst, float delta)
int32 g_kaldi_verbose_level
This is set by util/parse-options.
Definition: kaldi-error.cc:46
static void TestPushSpecial()
#define KALDI_LOG
Definition: kaldi-error.h:153