55 if (std::fabs(ans) > 0.01 * (1.0 + std::fabs(copy->
Objf()))) {
56 KALDI_WARN <<
"Negative number returned (badly defined Clusterable " 57 <<
"class?): ans= " << ans;
74 return -(x2_ - x_ * x_ / count_);
84 count_ += other->count_;
93 count_ -= other->count_;
111 sc->
Read(is, binary);
123 std::stringstream str;
127 str <<
"[mean " << (x_ / count_) <<
", var " << (x2_ / count_ -
128 (x_ * x_ / (count_ * count_))) <<
"]";
140 stats_.Row(0).AddVec(weight, vec);
141 stats_.Row(1).AddVec2(weight, vec);
149 stats_.AddMat(1.0, other->stats_);
157 stats_.AddMat(-1.0, other->stats_);
177 stats_.Write(os, binary);
182 gc->
Read(is, binary);
190 stats_.Read(is, binary);
196 KALDI_WARN <<
"GaussClusterable::Objf(), count is negative " << count_;
200 size_t dim = stats_.NumCols();
202 double objf_per_frame = 0.0;
203 for (
size_t d = 0;
d < dim;
d++) {
204 double mean(stats_(0,
d) / count_), var = stats_(1,
d) / count_ - mean
205 * mean, floored_var = std::max(var, var_floor_);
206 vars(
d) = floored_var;
207 objf_per_frame += -0.5 * var / floored_var;
211 KALDI_WARN <<
"GaussClusterable::Objf(), objf is NaN";
216 return objf_per_frame * count_;
230 stats_.AddVec(1.0, other->stats_);
231 sumsq_ += other->sumsq_;
239 sumsq_ -= other->sumsq_;
240 stats_.AddVec(-1.0, other->stats_);
242 if (weight_ < -0.1 && weight_ < -0.0001 * fabs(other->weight_)) {
245 KALDI_WARN <<
"Negative weight encountered " << weight_;
249 if (weight_ == 0.0) {
277 stats_.Write(os, binary);
282 vc->
Read(is, binary);
293 stats_.Read(is, binary);
298 weight_(weight), stats_(vector), sumsq_(0.0) {
307 if (
weight_ > std::numeric_limits<BaseFloat>::min()) {
314 double ans = -(
sumsq_ - direct_sumsq);
317 KALDI_WARN <<
"Positive objective function encountered (treating as zero): " void AddStats(const VectorBase< BaseFloat > &vec, BaseFloat weight=1.0)
virtual void Sub(const Clusterable &other)=0
Subtract other stats.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
virtual void Add(const Clusterable &other)=0
Add other stats.
virtual std::string Type() const =0
Return a string that describes the inherited type.
virtual void Write(std::ostream &os, bool binary) const
Write data to stream.
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...
virtual BaseFloat Objf() const =0
Return the objective function associated with the stats [assuming ML estimation]. ...
virtual BaseFloat ObjfMinus(const Clusterable &other) const
Return the objective function of the subtracted object this - other.
Real SumLog() const
Returns sum of the logs of the elements.
virtual void Scale(BaseFloat f)
Scale the stats by a positive number f [not mandatory to supply this].
virtual Clusterable * ReadNew(std::istream &is, bool binary) const
Read data from a stream and return the corresponding object (const function; it's a class member beca...
virtual void Sub(const Clusterable &other_in)
Subtract other stats.
VectorClusterable wraps vectors in a form accessible to generic clustering algorithms.
virtual void Add(const Clusterable &other_in)
Add other stats.
virtual Clusterable * Copy() const
Return a copy of this object.
virtual void Write(std::ostream &os, bool binary) const
Write data to stream.
virtual Clusterable * Copy() const =0
Return a copy of this object.
virtual void Add(const Clusterable &other_in)
Add other stats.
virtual BaseFloat Distance(const Clusterable &other) const
Return the objective function decrease from merging the two clusters, negated to be a positive number...
virtual Clusterable * Copy() const
Return a copy of this object.
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
virtual Clusterable * Copy() const
Return a copy of this object.
virtual void Add(const Clusterable &other_in)
Add other stats.
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
virtual Clusterable * ReadNew(std::istream &is, bool binary) const
Read data from a stream and return the corresponding object (const function; it's a class member beca...
void Scale(Real alpha)
Multiplies all elements by this constant.
virtual BaseFloat Objf() const
Return the objective function associated with the stats [assuming ML estimation]. ...
virtual BaseFloat ObjfPlus(const Clusterable &other) const
Return the objective function of the combined object this + other.
virtual void Write(std::ostream &os, bool binary) const
Write data to stream.
virtual Clusterable * ReadNew(std::istream &is, bool binary) const
Read data from a stream and return the corresponding object (const function; it's a class member beca...
#define KALDI_ASSERT(cond)
virtual BaseFloat Objf() const
Return the objective function associated with the stats [assuming ML estimation]. ...
virtual BaseFloat Objf() const
Return the objective function associated with the stats [assuming ML estimation]. ...
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...
virtual void Sub(const Clusterable &other_in)
Subtract other stats.
void Read(std::istream &is, bool binary)
void Read(std::istream &is, bool binary)
virtual void Scale(BaseFloat f)
Scale the stats by a positive number f [not mandatory to supply this].
Provides a vector abstraction class.
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
void Read(std::istream &is, bool binary)
virtual void Sub(const Clusterable &other_in)
Subtract other stats.
ScalarClusterable clusters scalars with x^2 loss.