DiscriminativeSupervision Struct Reference

`#include <discriminative-supervision.h>`

Collaboration diagram for DiscriminativeSupervision:

## Public Member Functions

DiscriminativeSupervision ()

DiscriminativeSupervision (const DiscriminativeSupervision &other)

bool Initialize (const std::vector< int32 > &alignment, const Lattice &lat, BaseFloat weight)

void Swap (DiscriminativeSupervision *other)

bool operator== (const DiscriminativeSupervision &other) const

void Check () const

int32 NumFrames () const

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

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

## Public Attributes

BaseFloat weight

int32 num_sequences

int32 frames_per_sequence

std::vector< int32 > num_ali

Lattice den_lat

## Detailed Description

Definition at line 75 of file discriminative-supervision.h.

## Constructor & Destructor Documentation

 DiscriminativeSupervision ( const DiscriminativeSupervision & other )

## Member Function Documentation

 void Check ( ) const

Definition at line 124 of file discriminative-supervision.cc.

124  {
125  int32 num_frames_subsampled = num_ali.size();
126  KALDI_ASSERT(num_frames_subsampled ==
128
129  {
130  std::vector<int32> state_times;
131  int32 max_time = LatticeStateTimes(den_lat, &state_times);
132  KALDI_ASSERT(max_time == num_frames_subsampled);
133  }
134 }
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
 bool Initialize ( const std::vector< int32 > & alignment, const Lattice & lat, BaseFloat weight )

Definition at line 105 of file discriminative-supervision.cc.

Referenced by main().

107  {
108  if (num_ali.size() == 0) return false;
109  if (den_lat.NumStates() == 0) return false;
110
111  this->weight = weight;
112  this->num_sequences = 1;
113  this->frames_per_sequence = num_ali.size();
114  this->num_ali = num_ali;
115  this->den_lat = den_lat;
116  KALDI_ASSERT(TopSort(&(this->den_lat)));
117
118  // Checks if num frames in alignment matches lattice
119  Check();
120
121  return true;
122 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
 int32 NumFrames ( ) const
inline
 bool operator== ( const DiscriminativeSupervision & other ) const

Definition at line 42 of file discriminative-supervision.cc.

43  {
44  return ( weight == other.weight &&
45  num_sequences == other.num_sequences &&
46  frames_per_sequence == other.frames_per_sequence &&
47  num_ali == other.num_ali &&
48  fst::Equal(den_lat, other.den_lat) );
49 }
 void Read ( std::istream & is, bool binary )

Definition at line 75 of file discriminative-supervision.cc.

75  {
76  ExpectToken(is, binary, "<DiscriminativeSupervision>");
77  ExpectToken(is, binary, "<Weight>");
79  ExpectToken(is, binary, "<NumSequences>");
81  ExpectToken(is, binary, "<FramesPerSeq>");
84  num_sequences > 0);
85
86  ExpectToken(is, binary, "<NumAli>");
88
89  ExpectToken(is, binary, "<DenLat>");
90  {
91  Lattice *lat = NULL;
92  if (!ReadLattice(is, binary, &lat) || lat == NULL) {
93  // We can't return error status from this function so we
94  // throw an exception.
95  KALDI_ERR << "Error reading Lattice from stream";
96  }
97  den_lat = *lat;
98  delete lat;
99  TopSort(&den_lat);
100  }
101
102  ExpectToken(is, binary, "</DiscriminativeSupervision>");
103 }
bool ReadLattice(std::istream &is, bool binary, Lattice **lat)
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 ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232
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:188
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:127
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
 void Swap ( DiscriminativeSupervision * other )

Definition at line 34 of file discriminative-supervision.cc.

Referenced by kaldi::nnet3::MergeSupervision(), and NnetDiscriminativeSupervision::Swap().

34  {
35  std::swap(weight, other->weight);
36  std::swap(num_sequences, other->num_sequences);
37  std::swap(frames_per_sequence, other->frames_per_sequence);
38  std::swap(num_ali, other->num_ali);
39  std::swap(den_lat, other->den_lat);
40 }
void swap(basic_filebuf< CharT, Traits > &x, basic_filebuf< CharT, Traits > &y)
 void Write ( std::ostream & os, bool binary ) const

Definition at line 51 of file discriminative-supervision.cc.

Referenced by NnetDiscriminativeSupervision::Write().

51  {
52  WriteToken(os, binary, "<DiscriminativeSupervision>");
53  WriteToken(os, binary, "<Weight>");
54  WriteBasicType(os, binary, weight);
55  WriteToken(os, binary, "<NumSequences>");
56  WriteBasicType(os, binary, num_sequences);
57  WriteToken(os, binary, "<FramesPerSeq>");
60  num_sequences > 0);
61
62  WriteToken(os, binary, "<NumAli>");
63  WriteIntegerVector(os, binary, num_ali);
64
65  WriteToken(os, binary, "<DenLat>");
66  if (!WriteLattice(os, binary, den_lat)) {
67  // We can't return error status from this function so we
68  // throw an exception.
69  KALDI_ERR << "Error writing denominator lattice to stream";
70  }
71
72  WriteToken(os, binary, "</DiscriminativeSupervision>");
73 }
#define KALDI_ERR
Definition: kaldi-error.h:127
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
bool WriteLattice(std::ostream &os, bool binary, const Lattice &t)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198
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

## Member Data Documentation

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