AffineXformStats Class Reference

#include <transform-common.h>

Inheritance diagram for AffineXformStats:
Collaboration diagram for AffineXformStats:

Public Member Functions

 AffineXformStats ()
 
void Init (int32 dim, int32 num_gs)
 
int32 Dim () const
 
void SetZero ()
 
void CopyStats (const AffineXformStats &other)
 
void Add (const AffineXformStats &other)
 
void Write (std::ostream &out, bool binary) const
 
void Read (std::istream &in, bool binary, bool add)
 
 AffineXformStats (const AffineXformStats &other)
 

Public Attributes

double beta_
 beta_ is the occupation count. More...
 
Matrix< double > K_
 K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1) More...
 
std::vector< SpMatrix< double > > G_
 G_ is the outer product of extended-data, scaled by inverse variance, for each dimension. More...
 
int32 dim_
 dim_ is the feature dimension. More...
 

Detailed Description

Definition at line 30 of file transform-common.h.

Constructor & Destructor Documentation

◆ AffineXformStats() [1/2]

AffineXformStats ( )
inline

Definition at line 44 of file transform-common.h.

References AffineXformStats::Init().

44 : beta_(0.0), dim_(0.0) {}
int32 dim_
dim_ is the feature dimension.
double beta_
beta_ is the occupation count.

◆ AffineXformStats() [2/2]

AffineXformStats ( const AffineXformStats other)
inline

Definition at line 52 of file transform-common.h.

References kaldi::ApplyAffineTransform(), and kaldi::ComposeTransforms().

52  : beta_(other.beta_),
53  K_(other.K_),
54  G_(other.G_),
55  dim_(other.dim_) {}
Matrix< double > K_
K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1)
int32 dim_
dim_ is the feature dimension.
std::vector< SpMatrix< double > > G_
G_ is the outer product of extended-data, scaled by inverse variance, for each dimension.
double beta_
beta_ is the occupation count.

Member Function Documentation

◆ Add()

void Add ( const AffineXformStats other)

Definition at line 123 of file transform-common.cc.

References MatrixBase< Real >::AddMat(), AffineXformStats::beta_, AffineXformStats::dim_, AffineXformStats::G_, rnnlm::i, AffineXformStats::K_, KALDI_ASSERT, and kaldi::kNoTrans.

Referenced by AffineXformStats::Dim().

123  {
124  KALDI_ASSERT(G_.size() == other.G_.size());
125  KALDI_ASSERT(dim_ == other.dim_);
126  beta_ += other.beta_;
127  K_.AddMat(1.0, other.K_, kNoTrans);
128  for (size_t i = 0; i < G_.size(); i++)
129  G_[i].AddSp(1.0, other.G_[i]);
130 }
Matrix< double > K_
K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1)
void AddMat(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA=kNoTrans)
*this += alpha * M [or M^T]
int32 dim_
dim_ is the feature dimension.
std::vector< SpMatrix< double > > G_
G_ is the outer product of extended-data, scaled by inverse variance, for each dimension.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
double beta_
beta_ is the occupation count.

◆ CopyStats()

void CopyStats ( const AffineXformStats other)

Definition at line 114 of file transform-common.cc.

References AffineXformStats::beta_, MatrixBase< Real >::CopyFromMat(), AffineXformStats::dim_, AffineXformStats::G_, rnnlm::i, AffineXformStats::K_, KALDI_ASSERT, and kaldi::kNoTrans.

Referenced by AffineXformStats::Dim().

114  {
115  KALDI_ASSERT(G_.size() == other.G_.size());
116  KALDI_ASSERT(dim_ == other.dim_);
117  beta_ = other.beta_;
118  K_.CopyFromMat(other.K_, kNoTrans);
119  for (size_t i = 0; i < G_.size(); i++)
120  G_[i].CopyFromSp(other.G_[i]);
121 }
Matrix< double > K_
K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1)
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
int32 dim_
dim_ is the feature dimension.
std::vector< SpMatrix< double > > G_
G_ is the outer product of extended-data, scaled by inverse variance, for each dimension.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
double beta_
beta_ is the occupation count.

◆ Dim()

◆ Init()

void Init ( int32  dim,
int32  num_gs 
)

Definition at line 28 of file transform-common.cc.

References AffineXformStats::beta_, AffineXformStats::dim_, AffineXformStats::G_, rnnlm::i, AffineXformStats::K_, KALDI_WARN, kaldi::kSetZero, and Matrix< Real >::Resize().

Referenced by AffineXformStats::AffineXformStats(), CompressedAffineXformStats::CopyToAffineXformStats(), and FmllrDiagGmmAccs::Init().

28  {
29  if (dim == 0) {
30  if (num_gs != 0) {
31  KALDI_WARN << "Ignoring 'num_gs' (=" << num_gs << ") argument since "
32  << "dim = 0.";
33  }
34  beta_ = 0.0;
35  K_.Resize(0, 0);
36  G_.clear();
37  dim_ = 0;
38  } else {
39  beta_ = 0.0;
40  K_.Resize(dim, dim + 1, kSetZero);
41  G_.resize(num_gs);
42  for (int32 i = 0; i < num_gs; i++)
43  G_[i].Resize(dim + 1, kSetZero);
44  dim_ = dim;
45  }
46 }
Matrix< double > K_
K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1)
kaldi::int32 int32
int32 dim_
dim_ is the feature dimension.
#define KALDI_WARN
Definition: kaldi-error.h:150
std::vector< SpMatrix< double > > G_
G_ is the outer product of extended-data, scaled by inverse variance, for each dimension.
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
double beta_
beta_ is the occupation count.

◆ Read()

void Read ( std::istream &  in,
bool  binary,
bool  add 
)

Definition at line 69 of file transform-common.cc.

References MatrixBase< Real >::AddMat(), AffineXformStats::beta_, MatrixBase< Real >::CopyFromMat(), SpMatrix< Real >::CopyFromSp(), AffineXformStats::dim_, kaldi::ExpectToken(), AffineXformStats::G_, rnnlm::i, AffineXformStats::K_, kaldi::kNoTrans, MatrixBase< Real >::NumCols(), MatrixBase< Real >::NumRows(), PackedMatrix< Real >::NumRows(), PackedMatrix< Real >::Read(), Matrix< Real >::Read(), kaldi::ReadBasicType(), SpMatrix< Real >::Resize(), and Matrix< Real >::Resize().

Referenced by AffineXformStats::Dim(), and FmllrDiagGmmAccs::Read().

69  {
70  ExpectToken(in, binary, "<DIMENSION>");
71  ReadBasicType(in, binary, &dim_);
72  ExpectToken(in, binary, "<BETA>");
73  ReadBasicType(in, binary, &beta_);
74  ExpectToken(in, binary, "<K>");
75  Matrix<BaseFloat> tmp_k;
76  tmp_k.Read(in, binary);
77  K_.Resize(tmp_k.NumRows(), tmp_k.NumCols());
78  if (add) {
79  Matrix<double> tmp_k_d(tmp_k);
80  K_.AddMat(1.0, tmp_k_d, kNoTrans);
81  } else {
82  K_.CopyFromMat(tmp_k, kNoTrans);
83  }
84  ExpectToken(in, binary, "<G>");
85  int32 g_size;
86  ReadBasicType(in, binary, &g_size);
87  G_.resize(g_size);
88  SpMatrix<BaseFloat> tmp_g;
89  SpMatrix<double> tmp_g_d;
90  if (add) { tmp_g_d.Resize(tmp_g.NumRows()); }
91  for (size_t i = 0; i < G_.size(); i++) {
92  tmp_g.Read(in, binary, false /*no add*/);
93  G_[i].Resize(tmp_g.NumRows());
94  if (add) {
95  tmp_g_d.CopyFromSp(tmp_g);
96  G_[i].AddSp(1.0, tmp_g_d);
97  } else {
98  G_[i].CopyFromSp(tmp_g);
99  }
100  }
101 }
Matrix< double > K_
K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1)
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:55
void AddMat(const Real alpha, const MatrixBase< Real > &M, MatrixTransposeType transA=kNoTrans)
*this += alpha * M [or M^T]
kaldi::int32 int32
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
int32 dim_
dim_ is the feature dimension.
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
Definition: io-funcs.cc:191
std::vector< SpMatrix< double > > G_
G_ is the outer product of extended-data, scaled by inverse variance, for each dimension.
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
double beta_
beta_ is the occupation count.

◆ SetZero()

void SetZero ( )

Definition at line 105 of file transform-common.cc.

References AffineXformStats::beta_, AffineXformStats::G_, AffineXformStats::K_, and MatrixBase< Real >::SetZero().

Referenced by AffineXformStats::Dim().

105  {
106  beta_ = 0.0;
107  K_.SetZero();
108  for (std::vector< SpMatrix<double> >::iterator it = G_.begin(),
109  end = G_.end(); it != end; ++it) {
110  it->SetZero();
111  }
112 }
Matrix< double > K_
K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1)
void SetZero()
Sets matrix to zero.
std::vector< SpMatrix< double > > G_
G_ is the outer product of extended-data, scaled by inverse variance, for each dimension.
double beta_
beta_ is the occupation count.

◆ Write()

void Write ( std::ostream &  out,
bool  binary 
) const

Definition at line 48 of file transform-common.cc.

References AffineXformStats::beta_, AffineXformStats::dim_, AffineXformStats::G_, AffineXformStats::K_, PackedMatrix< Real >::Write(), MatrixBase< Real >::Write(), kaldi::WriteBasicType(), and kaldi::WriteToken().

Referenced by AffineXformStats::Dim(), and OnlineGmmAdaptationState::Write().

48  {
49  WriteToken(out, binary, "<DIMENSION>");
50  WriteBasicType(out, binary, dim_);
51  if (!binary) out << '\n';
52  WriteToken(out, binary, "<BETA>");
53  WriteBasicType(out, binary, beta_);
54  if (!binary) out << '\n';
55  WriteToken(out, binary, "<K>");
56  Matrix<BaseFloat> tmp_k(K_);
57  tmp_k.Write(out, binary);
58  WriteToken(out, binary, "<G>");
59  int32 g_size = static_cast<int32>(G_.size());
60  WriteBasicType(out, binary, g_size);
61  if (!binary) out << '\n';
62  for (std::vector< SpMatrix<double> >::const_iterator itr = G_.begin(),
63  end = G_.end(); itr != end; ++itr) {
64  SpMatrix<BaseFloat> tmp_g(*itr);
65  tmp_g.Write(out, binary);
66  }
67 }
Matrix< double > K_
K_ is the summed outer product of [mean times inverse variance] with [extended data], scaled by the occupation counts; dimension is dim by (dim+1)
kaldi::int32 int32
int32 dim_
dim_ is the feature dimension.
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
std::vector< SpMatrix< double > > G_
G_ is the outer product of extended-data, scaled by inverse variance, for each dimension.
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:34
double beta_
beta_ is the occupation count.

Member Data Documentation

◆ beta_

◆ dim_

◆ G_

◆ K_


The documentation for this class was generated from the following files: