minimize-lattice-test.cc
Go to the documentation of this file.
1 // lat/minimize-lattice-test.cc
2 
3 // Copyright 2013 Johns Hopkins University (author: Daniel Povey)
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 "lat/kaldi-lattice.h"
22 #include "lat/minimize-lattice.h"
23 #include "lat/push-lattice.h"
24 #include "fstext/rand-fst.h"
25 
26 
27 namespace kaldi {
28 using namespace fst;
29 
31  RandFstOptions opts;
32  opts.acyclic = true;
33  while (1) {
34  Lattice *fst = fst::RandPairFst<LatticeArc>(opts);
35  CompactLattice *cfst = new CompactLattice;
36  if (!DeterminizeLattice(*fst, cfst)) {
37  delete fst;
38  delete cfst;
39  KALDI_WARN << "Determinization failed, trying again.";
40  } else {
41  delete fst;
42  return cfst;
43  }
44  }
45 }
46 
49  CompactLattice clat2(*clat);
50  BaseFloat delta = (Rand() % 2 == 0 ? 1.0 : 1.0e-05);
51 
52  // Minimization will only work well on determinized and pushed lattices.
55 
56  MinimizeCompactLattice(&clat2, delta);
57  KALDI_ASSERT(fst::RandEquivalent(*clat, clat2, 5, delta, Rand(), 10));
58 
59  delete clat;
60 }
61 
62 
63 } // end namespace kaldi
64 
65 int main() {
66  using namespace kaldi;
67  using kaldi::int32;
68  SetVerboseLevel(4);
69  for (int32 i = 0; i < 1000; i++) {
71  }
72  KALDI_LOG << "Success.";
73 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void TestMinimizeCompactLattice()
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Definition: graph.dox:21
CompactLattice * RandDeterministicCompactLattice()
bool PushCompactLatticeStrings(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, IntType > > > *clat)
This function pushes the transition-ids as far towards the start as they will go. ...
kaldi::int32 int32
bool PushCompactLatticeWeights(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, IntType > > > *clat)
This function pushes the weights in the CompactLattice so that all states except possibly the start s...
void SetVerboseLevel(int32 i)
This should be rarely used, except by programs using Kaldi as library; command-line programs set the ...
Definition: kaldi-error.h:64
bool MinimizeCompactLattice(MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, IntType > > > *clat, float delta)
This function minimizes the compact lattice.
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_WARN
Definition: kaldi-error.h:150
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
bool DeterminizeLattice(const Fst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< Weight > > *ofst, DeterminizeLatticeOptions opts, bool *debug_ptr)
This function implements the normal version of DeterminizeLattice, in which the output strings are re...
#define KALDI_LOG
Definition: kaldi-error.h:153
int main()