clusterable-itf.h
Go to the documentation of this file.
1 // itf/clusterable-itf.h
2 
3 // Copyright 2009-2011 Microsoft Corporation; Go Vivace Inc.
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 
21 #ifndef KALDI_ITF_CLUSTERABLE_ITF_H_
22 #define KALDI_ITF_CLUSTERABLE_ITF_H_ 1
23 
24 #include <string>
25 #include "base/kaldi-common.h"
26 
27 namespace kaldi {
28 
29 
38 class Clusterable {
39  public:
42 
44  virtual Clusterable *Copy() const = 0;
47  virtual BaseFloat Objf() const = 0;
49  virtual BaseFloat Normalizer() const = 0;
51  virtual void SetZero() = 0;
53  virtual void Add(const Clusterable &other) = 0;
55  virtual void Sub(const Clusterable &other) = 0;
57  virtual void Scale(BaseFloat f) {
58  KALDI_ERR << "This Clusterable object does not implement Scale().";
59  }
60 
62  virtual std::string Type() const = 0;
63 
65  virtual void Write(std::ostream &os, bool binary) const = 0;
66 
70  virtual Clusterable* ReadNew(std::istream &os, bool binary) const = 0;
71 
72  virtual ~Clusterable() {}
73 
75 
78 
79  // These functions have default implementations (but may be overridden for
80  // speed). Implementatons in tree/clusterable-classes.cc
81 
83  virtual BaseFloat ObjfPlus(const Clusterable &other) const;
85  virtual BaseFloat ObjfMinus(const Clusterable &other) const;
88  virtual BaseFloat Distance(const Clusterable &other) const;
90 
91 };
93 
94 } // end namespace kaldi
95 
96 #endif // KALDI_ITF_CLUSTERABLE_ITF_H_
97 
virtual void Sub(const Clusterable &other)=0
Subtract other stats.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
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 SetZero()=0
Set stats to empty.
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.
virtual Clusterable * Copy() const =0
Return a copy of this object.
virtual BaseFloat Distance(const Clusterable &other) const
Return the objective function decrease from merging the two clusters, negated to be a positive number...
#define KALDI_ERR
Definition: kaldi-error.h:147
virtual void Scale(BaseFloat f)
Scale the stats by a positive number f [not mandatory to supply this].
virtual BaseFloat ObjfPlus(const Clusterable &other) const
Return the objective function of the combined object this + other.
virtual BaseFloat Normalizer() const =0
Return the normalizer (typically, count) associated with the stats.
virtual Clusterable * ReadNew(std::istream &os, bool binary) const =0
Read data from a stream and return the corresponding object (const function; it&#39;s a class member beca...
virtual void Write(std::ostream &os, bool binary) const =0
Write data to stream.