sum-tree-stats.cc File Reference
Include dependency graph for sum-tree-stats.cc:

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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

Definition at line 26 of file sum-tree-stats.cc.

References Clusterable::Add(), kaldi::DeleteBuildTreeStats(), ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::ReadBuildTreeStats(), ParseOptions::Register(), Output::Stream(), Input::Stream(), and kaldi::WriteBuildTreeStats().

26  {
27  using namespace kaldi;
28  typedef kaldi::int32 int32;
29  try {
30  const char *usage =
31  "Sum statistics for phonetic-context tree building.\n"
32  "Usage: sum-tree-stats [options] tree-accs-out tree-accs-in1 tree-accs-in2 ...\n"
33  "e.g.: \n"
34  " sum-tree-stats treeacc 1.treeacc 2.treeacc 3.treeacc\n";
35 
36  ParseOptions po(usage);
37  bool binary = true;
38 
39  po.Register("binary", &binary, "Write output in binary mode");
40  po.Read(argc, argv);
41 
42  if (po.NumArgs() < 2) {
43  po.PrintUsage();
44  exit(1);
45  }
46 
47  std::map<EventType, Clusterable*> tree_stats;
48 
49  std::string tree_stats_wxfilename = po.GetArg(1);
50 
51  // A reminder on what BuildTreeStatsType is:
52  // typedef std::vector<std::pair<EventType, Clusterable*> > BuildTreeStatsType;
53 
54  for (int32 arg = 2; arg <= po.NumArgs(); arg++) {
55  std::string tree_stats_rxfilename = po.GetArg(arg);
56  bool binary_in;
57  Input ki(tree_stats_rxfilename, &binary_in);
58  BuildTreeStatsType stats_array;
59  GaussClusterable example; // Lets ReadBuildTreeStats know which type to read..
60  ReadBuildTreeStats(ki.Stream(), binary_in, example, &stats_array);
61  for (BuildTreeStatsType::iterator iter = stats_array.begin();
62  iter != stats_array.end(); ++iter) {
63  EventType e = iter->first;
64  Clusterable *c = iter->second;
65  std::map<EventType, Clusterable*>::iterator map_iter = tree_stats.find(e);
66  if (map_iter == tree_stats.end()) { // Not already present.
67  tree_stats[e] = c;
68  } else {
69  map_iter->second->Add(*c);
70  delete c;
71  }
72  }
73  }
74 
75  BuildTreeStatsType stats; // vectorized form.
76 
77  for (std::map<EventType, Clusterable*>::const_iterator iter = tree_stats.begin();
78  iter != tree_stats.end();
79  ++iter) {
80  stats.push_back(std::make_pair(iter->first, iter->second));
81  }
82  tree_stats.clear();
83 
84  {
85  Output ko(tree_stats_wxfilename, binary);
86  WriteBuildTreeStats(ko.Stream(), binary, stats);
87  }
88  KALDI_LOG << "Wrote summed accs ( " << stats.size() << " individual stats)";
89  DeleteBuildTreeStats(&stats);
90  return (stats.size() != 0 ? 0 : 1);
91  } catch(const std::exception &e) {
92  std::cerr << e.what();
93  return -1;
94  }
95 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
virtual void Add(const Clusterable &other)=0
Add other stats.
kaldi::int32 int32
void DeleteBuildTreeStats(BuildTreeStatsType *stats)
This frees the Clusterable* pointers in "stats", where non-NULL, and sets them to NULL...
void ReadBuildTreeStats(std::istream &is, bool binary, const Clusterable &example, BuildTreeStatsType *stats)
Reads BuildTreeStats object.
std::vector< std::pair< EventKeyType, EventValueType > > EventType
Definition: event-map.h:58
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
std::vector< std::pair< EventType, Clusterable * > > BuildTreeStatsType
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...
#define KALDI_LOG
Definition: kaldi-error.h:153
void WriteBuildTreeStats(std::ostream &os, bool binary, const BuildTreeStatsType &stats)
Writes BuildTreeStats object. This works even if pointers are NULL.