compressed-transform-stats.h
Go to the documentation of this file.
1 // transform/compressed-transform-stats.h
2 
3 // Copyright 2012 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 #ifndef KALDI_TRANSFORM_COMPRESSED_TRANSFORM_STATS_H_
22 #define KALDI_TRANSFORM_COMPRESSED_TRANSFORM_STATS_H_
23 
24 #include <vector>
25 
27 
28 namespace kaldi {
29 
30 // The purpose of this class is to compress the AffineXformStats into less
31 // memory for easier storage and transmission across the network. It was a
32 // feature requested by particular user of Kaldi. It's based on the
33 // CompressedMatrix class, which compresses a matrix into around one byte per
34 // element, but before applying that, we first use various techniques to
35 // normalize the range of elements of the stats and to make it so that the
36 // compressed G matrices will still be positive definite. [Basically, we
37 // compress the Cholesky of each G_i, and we first normalize all the G_i to have
38 // the same trace.] We also mess with the K stats a bit, to ensure that the
39 // derivative of the "compressed" transform taken where the transformation
40 // matrix is the "default" matrix, is the same as the derivative of the
41 // un-compressed matrix. [I.e. we correct the stored K to account for the
42 // compression of G.]
43 
45  public:
49  }
50  void CopyFromAffineXformStats(const AffineXformStats &input);
51 
52  void CopyToAffineXformStats(AffineXformStats *output) const;
53 
54  void Write(std::ostream &os, bool binary) const;
55 
56  void Read(std::istream &is, bool binary);
57 
58  private:
59  // Note: normally we don't use float, only BaseFloat. In this case
60  // it seems more appropriate to use float (since the stuff in G_ is
61  // already a lot more approximate than float.)
62  float beta_;
64  CompressedMatrix G_; // This dim x [ 1 + (0.5*(dim+1)*(dim+2))] matrix
65  // stores the contents of the G_ matrix of the AffineXform Stats, in a
66  // compressed form.
67 
68  // Convert one G matrix into linearized, normalized form ready
69  // for compression.
70  static void PrepareOneG(const SpMatrix<double> &Gi, double beta,
71  SubVector<double> *linearized);
72  // Reverse the process of PrepareOneG.
73  static void ExtractOneG(const SubVector<double> &linearized, double beta,
74  SpMatrix<double> *Gi);
75 
76 };
77 
78 
79 } // namespace kaldi
80 
81 #endif // KALDI_TRANSFORM_COMPRESSED_TRANSFORM_STATS_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
static void PrepareOneG(const SpMatrix< double > &Gi, double beta, SubVector< double > *linearized)
void CopyFromAffineXformStats(const AffineXformStats &input)
void CopyToAffineXformStats(AffineXformStats *output) const
CompressedAffineXformStats(const AffineXformStats &input)
void Write(std::ostream &os, bool binary) const
static void ExtractOneG(const SubVector< double > &linearized, double beta, SpMatrix< double > *Gi)
void Read(std::istream &is, bool binary)
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
Definition: kaldi-vector.h:501