All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gmm-diff-accs.cc File Reference
Include dependency graph for gmm-diff-accs.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 25 of file gmm-diff-accs.cc.

References AccumAmDiagGmm::Add(), VectorBase< Real >::AddVec(), ParseOptions::GetArg(), KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), AccumAmDiagGmm::Read(), ParseOptions::Read(), Vector< Real >::Read(), ParseOptions::Register(), Output::Stream(), Input::Stream(), AccumAmDiagGmm::TotStatsCount(), AccumAmDiagGmm::Write(), and VectorBase< Real >::Write().

25  {
26  typedef kaldi::int32 int32;
27  try {
28  const char *usage =
29  "Compute difference between accumulators\n"
30  "Usage: gmm-diff-accs [options] plus-stats minus-stats diff-stats-out\n";
31 
32  bool binary = true;
33  kaldi::ParseOptions po(usage);
34  po.Register("binary", &binary, "Write output in binary mode");
35  po.Read(argc, argv);
36 
37  if (po.NumArgs() != 3) {
38  po.PrintUsage();
39  exit(1);
40  }
41 
42  std::string plus_stats_rxfilename = po.GetArg(1),
43  minus_stats_rxfilename = po.GetArg(2),
44  diff_stats_wxfilename = po.GetArg(3);
45 
46  kaldi::Vector<double> transition_accs_plus;
47  kaldi::AccumAmDiagGmm gmm_accs_plus;
48  {
49  bool binary_read;
50  kaldi::Input ki(plus_stats_rxfilename, &binary_read);
51  transition_accs_plus.Read(ki.Stream(), binary_read, false);
52  gmm_accs_plus.Read(ki.Stream(), binary_read, false);
53  }
54  kaldi::Vector<double> transition_accs_minus;
55  kaldi::AccumAmDiagGmm gmm_accs_minus;
56  {
57  bool binary_read;
58  kaldi::Input ki(minus_stats_rxfilename, &binary_read);
59  transition_accs_minus.Read(ki.Stream(), binary_read, false);
60  gmm_accs_minus.Read(ki.Stream(), binary_read, false);
61  }
62 
63  double tot_count_before = gmm_accs_plus.TotStatsCount();
64  // subtract accs.
65  {
66  transition_accs_plus.AddVec(-1.0, transition_accs_minus);
67  gmm_accs_plus.Add(-1.0, gmm_accs_minus);
68  }
69  double tot_count_after = gmm_accs_plus.TotStatsCount();
70 
71  // Write out the accs
72  {
73  kaldi::Output ko(diff_stats_wxfilename, binary);
74  transition_accs_plus.Write(ko.Stream(), binary);
75  gmm_accs_plus.Write(ko.Stream(), binary);
76  }
77  KALDI_LOG << "Differenced stats, count of first stats was "
78  << tot_count_before << ", count of difference was "
79  << tot_count_after;
80  KALDI_LOG << "Wrote stats to " << diff_stats_wxfilename;
81  } catch(const std::exception &e) {
82  std::cerr << e.what() << '\n';
83  return -1;
84  }
85 }
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
void Add(BaseFloat scale, const AccumAmDiagGmm &other)
void Write(std::ostream &out_stream, bool binary) const
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
void Read(std::istream &in_stream, bool binary, bool add=false)
BaseFloat TotStatsCount() const
#define KALDI_LOG
Definition: kaldi-error.h:133
void AddVec(const Real alpha, const VectorBase< OtherReal > &v)
Add vector : *this = *this + alpha * rv (with casting between floats and doubles) ...
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.