All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
fstisstochastic.cc File Reference
#include "base/kaldi-common.h"
#include "util/kaldi-io.h"
#include "util/parse-options.h"
#include "fst/fstlib.h"
#include "fstext/fstext-utils.h"
#include "fstext/kaldi-fst-io.h"
Include dependency graph for fstisstochastic.cc:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 43 of file fstisstochastic.cc.

References ParseOptions::GetOptArg(), fst::IsStochasticFst(), fst::IsStochasticFstInLog(), ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), fst::ReadFstKaldiGeneric(), and ParseOptions::Register().

43  {
44  try {
45  using namespace kaldi;
46  using namespace fst;
47  using kaldi::int32;
48 
49  const char *usage =
50  "Checks whether an FST is stochastic and exits with success if so.\n"
51  "Prints out maximum error (in log units).\n"
52  "\n"
53  "Usage: fstisstochastic [ in.fst ]\n";
54 
55  float delta = 0.01;
56  bool test_in_log = true;
57 
58  ParseOptions po(usage);
59  po.Register("delta", &delta, "Maximum error to accept.");
60  po.Register("test-in-log", &test_in_log, "Test stochasticity in log semiring.");
61  po.Read(argc, argv);
62 
63  if (po.NumArgs() > 1) {
64  po.PrintUsage();
65  exit(1);
66  }
67 
68  std::string fst_in_filename = po.GetOptArg(1);
69 
70  Fst<StdArc> *fst = ReadFstKaldiGeneric(fst_in_filename);
71 
72  bool ans;
73  StdArc::Weight min, max;
74  if (test_in_log) ans = IsStochasticFstInLog(*fst, delta, &min, &max);
75  else ans = IsStochasticFst(*fst, delta, &min, &max);
76 
77  std::cout << min.Value() << " " << max.Value() << '\n';
78  delete fst;
79  if (ans) return 0; // success;
80  else return 1;
81  } catch(const std::exception &e) {
82  std::cerr << e.what();
83  return -1;
84  }
85 }
Relabels neural network egs with the read pdf-id alignments.
Definition: chain.dox:20
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
Definition: kaldi-fst-io.cc:45
Definition: graph.dox:21
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
bool IsStochasticFstInLog(const Fst< StdArc > &fst, float delta, StdArc::Weight *min_sum, StdArc::Weight *max_sum)
bool IsStochasticFst(const Fst< LogArc > &fst, float delta, LogArc::Weight *min_sum, LogArc::Weight *max_sum)
fst::StdArc::Weight Weight