Clusterable Class Referenceabstract

#include <clusterable-itf.h>

Inheritance diagram for Clusterable:

Public Member Functions

Functions that must be overridden
virtual ClusterableCopy () const =0
 Return a copy of this object. More...
 
virtual BaseFloat Objf () const =0
 Return the objective function associated with the stats [assuming ML estimation]. More...
 
virtual BaseFloat Normalizer () const =0
 Return the normalizer (typically, count) associated with the stats. More...
 
virtual void SetZero ()=0
 Set stats to empty. More...
 
virtual void Add (const Clusterable &other)=0
 Add other stats. More...
 
virtual void Sub (const Clusterable &other)=0
 Subtract other stats. More...
 
virtual void Scale (BaseFloat f)
 Scale the stats by a positive number f [not mandatory to supply this]. More...
 
virtual std::string Type () const =0
 Return a string that describes the inherited type. More...
 
virtual void Write (std::ostream &os, bool binary) const =0
 Write data to stream. More...
 
virtual ClusterableReadNew (std::istream &os, bool binary) const =0
 Read data from a stream and return the corresponding object (const function; it's a class member because we need access to the vtable so generic code can read derived types). More...
 
virtual ~Clusterable ()
 
Functions that have default implementations
virtual BaseFloat ObjfPlus (const Clusterable &other) const
 Return the objective function of the combined object this + other. More...
 
virtual BaseFloat ObjfMinus (const Clusterable &other) const
 Return the objective function of the subtracted object this - other. More...
 
virtual BaseFloat Distance (const Clusterable &other) const
 Return the objective function decrease from merging the two clusters, negated to be a positive number (or zero). More...
 

Detailed Description

Definition at line 38 of file clusterable-itf.h.

Constructor & Destructor Documentation

◆ ~Clusterable()

virtual ~Clusterable ( )
inlinevirtual

Member Function Documentation

◆ Add()

◆ Copy()

◆ Distance()

BaseFloat Distance ( const Clusterable other) const
virtual

Return the objective function decrease from merging the two clusters, negated to be a positive number (or zero).

Definition at line 49 of file clusterable-classes.cc.

References Clusterable::Add(), Clusterable::Copy(), KALDI_WARN, and Clusterable::Objf().

Referenced by DecisionTreeSplitter::DoSplitInternal(), and Clusterable::~Clusterable().

49  {
50  Clusterable *copy = this->Copy();
51  copy->Add(other);
52  BaseFloat ans = this->Objf() + other.Objf() - copy->Objf();
53  if (ans < 0) {
54  // This should not happen. Check if it is more than just rounding error.
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;
58  }
59  ans = 0;
60  }
61  delete copy;
62  return ans;
63 }
virtual BaseFloat Objf() const =0
Return the objective function associated with the stats [assuming ML estimation]. ...
virtual Clusterable * Copy() const =0
Return a copy of this object.
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_WARN
Definition: kaldi-error.h:150

◆ Normalizer()

virtual BaseFloat Normalizer ( ) const
pure virtual

Return the normalizer (typically, count) associated with the stats.

Implemented in VectorClusterable, GaussClusterable, and ScalarClusterable.

Referenced by kaldi::AddToClustersOptimized(), kaldi::SumNormalizer(), kaldi::TestClusterUtils(), kaldi::TestClusterUtilsVector(), and kaldi::TestContextDep().

◆ Objf()

◆ ObjfMinus()

BaseFloat ObjfMinus ( const Clusterable other) const
virtual

Return the objective function of the subtracted object this - other.

Definition at line 41 of file clusterable-classes.cc.

References Clusterable::Copy(), Clusterable::Objf(), and Clusterable::Sub().

Referenced by Clusterable::~Clusterable().

41  {
42  Clusterable *copy = this->Copy();
43  copy->Sub(other);
44  BaseFloat ans = copy->Objf();
45  delete copy;
46  return ans;
47 }
virtual Clusterable * Copy() const =0
Return a copy of this object.
float BaseFloat
Definition: kaldi-types.h:29

◆ ObjfPlus()

BaseFloat ObjfPlus ( const Clusterable other) const
virtual

Return the objective function of the combined object this + other.

Definition at line 33 of file clusterable-classes.cc.

References Clusterable::Add(), Clusterable::Copy(), and Clusterable::Objf().

Referenced by Clusterable::~Clusterable().

33  {
34  Clusterable *copy = this->Copy();
35  copy->Add(other);
36  BaseFloat ans = copy->Objf();
37  delete copy;
38  return ans;
39 }
virtual Clusterable * Copy() const =0
Return a copy of this object.
float BaseFloat
Definition: kaldi-types.h:29

◆ ReadNew()

virtual Clusterable* ReadNew ( std::istream &  os,
bool  binary 
) const
pure virtual

Read data from a stream and return the corresponding object (const function; it's a class member because we need access to the vtable so generic code can read derived types).

Implemented in VectorClusterable, GaussClusterable, and ScalarClusterable.

Referenced by kaldi::ReadBuildTreeStats(), and Clusterable::Scale().

◆ Scale()

virtual void Scale ( BaseFloat  f)
inlinevirtual

Scale the stats by a positive number f [not mandatory to supply this].

Reimplemented in VectorClusterable, and GaussClusterable.

Definition at line 57 of file clusterable-itf.h.

References KALDI_ERR, Clusterable::ReadNew(), Clusterable::Type(), and Clusterable::Write().

Referenced by GaussClusterable::Normalizer().

57  {
58  KALDI_ERR << "This Clusterable object does not implement Scale().";
59  }
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ SetZero()

virtual void SetZero ( )
pure virtual

Set stats to empty.

Implemented in VectorClusterable, GaussClusterable, and ScalarClusterable.

Referenced by kaldi::EnsureClusterableVectorNotNull().

◆ Sub()

virtual void Sub ( const Clusterable other)
pure virtual

Subtract other stats.

Implemented in VectorClusterable, GaussClusterable, and ScalarClusterable.

Referenced by Clusterable::ObjfMinus(), and RefineClusterer::UpdateInfo().

◆ Type()

virtual std::string Type ( ) const
pure virtual

◆ Write()

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

Write data to stream.

Implemented in VectorClusterable, GaussClusterable, and ScalarClusterable.

Referenced by Clusterable::Scale().


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