FmpeStats Struct Reference

#include <fmpe.h>

Collaboration diagram for FmpeStats:

Public Member Functions

 FmpeStats ()
 
void Init (const Fmpe &fmpe)
 
 FmpeStats (const Fmpe &fmpe)
 
void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &is, bool binary, bool add=false)
 
SubMatrix< BaseFloatDerivPlus () const
 
SubMatrix< BaseFloatDerivMinus () const
 
void AccumulateChecks (const MatrixBase< BaseFloat > &feats, const MatrixBase< BaseFloat > &direct_deriv, const MatrixBase< BaseFloat > &indirect_deriv)
 If we're using the indirect differential, accumulates certain quantities that will be used in the update phase to verify that the computation of the indirect differential was done correctly. More...
 
void DoChecks ()
 

Private Attributes

Matrix< BaseFloatderiv
 
Matrix< double > checks
 

Detailed Description

Definition at line 105 of file fmpe.h.

Constructor & Destructor Documentation

◆ FmpeStats() [1/2]

FmpeStats ( )
inline

Definition at line 106 of file fmpe.h.

106 { };

◆ FmpeStats() [2/2]

FmpeStats ( const Fmpe fmpe)
inline

Definition at line 108 of file fmpe.h.

References FmpeOptions::Read(), and FmpeOptions::Write().

108 { Init(fmpe); }
void Init(const Fmpe &fmpe)
Definition: fmpe.cc:618

Member Function Documentation

◆ AccumulateChecks()

void AccumulateChecks ( const MatrixBase< BaseFloat > &  feats,
const MatrixBase< BaseFloat > &  direct_deriv,
const MatrixBase< BaseFloat > &  indirect_deriv 
)

If we're using the indirect differential, accumulates certain quantities that will be used in the update phase to verify that the computation of the indirect differential was done correctly.

Definition at line 627 of file fmpe.cc.

References rnnlm::d, KALDI_ASSERT, MatrixBase< Real >::NumCols(), and MatrixBase< Real >::NumRows().

Referenced by Fmpe::AccStats().

629  {
630  int32 T = feats.NumRows(), dim = feats.NumCols();
631  KALDI_ASSERT(direct_deriv.NumRows() == T && direct_deriv.NumCols() == dim &&
632  indirect_deriv.NumRows() == T && indirect_deriv.NumCols() == dim);
633  KALDI_ASSERT(checks.NumRows() == 8 && checks.NumCols() == dim);
634  for (int32 t = 0; t < T; t++) {
635  for (int32 d = 0; d < dim; d++) {
636  BaseFloat zero = 0.0;
637  checks(0, d) += std::max(zero, direct_deriv(t, d));
638  checks(1, d) += std::max(zero, -direct_deriv(t, d));
639  checks(2, d) += std::max(zero, indirect_deriv(t, d));
640  checks(3, d) += std::max(zero, -indirect_deriv(t, d));
641  checks(4, d) += std::max(zero, feats(t, d)*direct_deriv(t, d));
642  checks(5, d) += std::max(zero, -feats(t, d)*direct_deriv(t, d));
643  checks(6, d) += std::max(zero, feats(t, d)*indirect_deriv(t, d));
644  checks(7, d) += std::max(zero, -feats(t, d)*indirect_deriv(t, d));
645  }
646  }
647 }
Matrix< double > checks
Definition: fmpe.h:133
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ DerivMinus()

SubMatrix< BaseFloat > DerivMinus ( ) const

Definition at line 610 of file fmpe.cc.

References KALDI_ASSERT.

Referenced by Fmpe::AccStats(), and Fmpe::Update().

610  { // const-ness not preserved.
611  KALDI_ASSERT(deriv.NumRows() != 0);
612  int32 proj_num_rows = deriv.NumRows(),
613  proj_num_cols = deriv.NumCols()/2;
614  return SubMatrix<BaseFloat>(deriv, 0, proj_num_rows,
615  proj_num_cols, proj_num_cols);
616 }
Matrix< BaseFloat > deriv
Definition: fmpe.h:125
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ DerivPlus()

SubMatrix< BaseFloat > DerivPlus ( ) const

Definition at line 603 of file fmpe.cc.

References KALDI_ASSERT.

Referenced by Fmpe::AccStats(), and Fmpe::Update().

603  { // const-ness not preserved.
604  KALDI_ASSERT(deriv.NumRows() != 0);
605  int32 proj_num_rows = deriv.NumRows(),
606  proj_num_cols = deriv.NumCols()/2;
607  return SubMatrix<BaseFloat>(deriv, 0, proj_num_rows,
608  0, proj_num_cols);
609 }
Matrix< BaseFloat > deriv
Definition: fmpe.h:125
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64

◆ DoChecks()

void DoChecks ( )

Definition at line 649 of file fmpe.cc.

References rnnlm::d, and KALDI_LOG.

Referenced by main().

649  {
650  if (checks.IsZero()) {
651  KALDI_LOG << "No checks will be done, probably indirect derivative was not used.";
652  return;
653  }
654  int32 dim = checks.NumCols();
655  Vector<double> shift_check(dim), shift_check2(dim), scale_check(dim), scale_check2(dim);
656  for (int32 d = 0; d < dim; d++) {
657  // shiftnumerator = direct+indirect deriv-- should be zero.
658  double shift_num = checks(0, d) - checks(1, d) + checks(2, d) - checks(3, d),
659  shift_den = checks(0, d) + checks(1, d) + checks(2, d) + checks(3, d),
660  shift_den2 = fabs(checks(0, d) - checks(1, d)) + fabs(checks(2, d) - checks(3, d));
661  shift_check(d) = shift_num / shift_den;
662  shift_check2(d) = shift_num / shift_den2;
663  double scale_num = checks(4, d) - checks(5, d) + checks(6, d) - checks(7, d),
664  scale_den = checks(4, d) + checks(5, d) + checks(6, d) + checks(7, d),
665  scale_den2 = fabs(checks(4, d) - checks(5, d)) + fabs(checks(6, d) - checks(7, d));
666  scale_check(d) = scale_num / scale_den;
667  scale_check2(d) = scale_num / scale_den2;
668  }
669 
670  KALDI_LOG << "Shift-check is as follows (should be in range +- 0.01 or less)."
671  << shift_check;
672  KALDI_LOG << "Scale-check is as follows (should be in range +- 0.01 or less)."
673  << scale_check;
674  KALDI_LOG << "Shift-check(2) is as follows: most elements should be in range +-0.1: "
675  << shift_check2;
676  KALDI_LOG << "Scale-check(2) is as follows: most elements should be in range +-0.1: "
677  << scale_check2;
678 }
Matrix< double > checks
Definition: fmpe.h:133
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Definition: kaldi-matrix.h:67
kaldi::int32 int32
bool IsZero(Real cutoff=1.0e-05) const
Returns true if matrix is all zeros.
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ Init()

void Init ( const Fmpe fmpe)

Definition at line 618 of file fmpe.cc.

References Fmpe::FeatDim(), Fmpe::ProjectionTNumCols(), and Fmpe::ProjectionTNumRows().

618  {
619  int32 num_rows = fmpe.ProjectionTNumRows(),
620  num_cols = fmpe.ProjectionTNumCols();
621  deriv.Resize(num_rows, num_cols*2);
622 
623  int32 feat_dim = fmpe.FeatDim();
624  checks.Resize(8, feat_dim);
625 }
Matrix< BaseFloat > deriv
Definition: fmpe.h:125
Matrix< double > checks
Definition: fmpe.h:133
kaldi::int32 int32
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).

◆ Read()

void Read ( std::istream &  is,
bool  binary,
bool  add = false 
)

Definition at line 685 of file fmpe.cc.

Referenced by main().

685  {
686  deriv.Read(is, binary, add);
687  checks.Read(is, binary, add);
688 }
Matrix< BaseFloat > deriv
Definition: fmpe.h:125
Matrix< double > checks
Definition: fmpe.h:133
void Read(std::istream &in, bool binary, bool add=false)
read from stream.

◆ Write()

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

Definition at line 680 of file fmpe.cc.

Referenced by main().

680  {
681  deriv.Write(os, binary);
682  checks.Write(os, binary);
683 }
Matrix< BaseFloat > deriv
Definition: fmpe.h:125
Matrix< double > checks
Definition: fmpe.h:133
void Write(std::ostream &out, bool binary) const
write to stream.

Member Data Documentation

◆ checks

Matrix<double> checks
private

Definition at line 133 of file fmpe.h.

◆ deriv

Matrix<BaseFloat> deriv
private

Definition at line 125 of file fmpe.h.


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