est-lda.cc
Go to the documentation of this file.
1 // bin/est-lda.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 "base/kaldi-common.h"
22 #include "util/common-utils.h"
23 #include "transform/lda-estimate.h"
24 
25 int main(int argc, char *argv[]) {
26  using namespace kaldi;
27  typedef kaldi::int32 int32;
28  try {
29  const char *usage =
30  "Estimate LDA transform using stats obtained with acc-lda.\n"
31  "Usage: est-lda [options] <lda-matrix-out> <lda-acc-1> <lda-acc-2> ...\n";
32 
33  bool binary = true;
34  std::string full_matrix_wxfilename;
35  LdaEstimateOptions opts;
36  ParseOptions po(usage);
37  po.Register("binary", &binary, "Write matrix in binary mode.");
38  po.Register("write-full-matrix", &full_matrix_wxfilename,
39  "Write full LDA matrix to this location.");
40  opts.Register(&po);
41  po.Read(argc, argv);
42 
43  if (po.NumArgs() < 2) {
44  po.PrintUsage();
45  exit(1);
46  }
47 
48  LdaEstimate lda;
49  std::string lda_mat_wxfilename = po.GetArg(1);
50 
51  for (int32 i = 2; i <= po.NumArgs(); i++) {
52  bool binary_in, add = true;
53  Input ki(po.GetArg(i), &binary_in);
54  lda.Read(ki.Stream(), binary_in, add);
55  }
56 
57  Matrix<BaseFloat> lda_mat;
58  Matrix<BaseFloat> full_lda_mat;
59  lda.Estimate(opts, &lda_mat, &full_lda_mat);
60  WriteKaldiObject(lda_mat, lda_mat_wxfilename, binary);
61  if (full_matrix_wxfilename != "") {
62  Output ko(full_matrix_wxfilename, binary);
63  full_lda_mat.Write(ko.Stream(), binary);
64  }
65  return 0;
66  } catch(const std::exception &e) {
67  std::cerr << e.what();
68  return -1;
69  }
70 }
71 
72 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Write(std::ostream &out, bool binary) const
write to stream.
Class for computing linear discriminant analysis (LDA) transform.
Definition: lda-estimate.h:57
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
kaldi::int32 int32
int main(int argc, char *argv[])
Definition: est-lda.cc:25
void Register(const std::string &name, bool *ptr, const std::string &doc)
void Estimate(const LdaEstimateOptions &opts, Matrix< BaseFloat > *M, Matrix< BaseFloat > *Mfull=NULL) const
Estimates the LDA transform matrix m.
Definition: lda-estimate.cc:85
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
std::ostream & Stream()
Definition: kaldi-io.cc:701
void Read(std::istream &in_stream, bool binary, bool add)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
Definition: kaldi-io.h:257
void Register(OptionsItf *opts)
Definition: lda-estimate.h:38