23 using namespace Eigen;
28 typedef enum _drwnPairSuffStatsType {
32 } drwnPairSuffStatsType;
46 drwnPairSuffStatsType _pairStats;
54 drwnSuffStats(
int n = 1, drwnPairSuffStatsType pairStats = DRWN_PSS_FULL);
65 void clear(
int n, drwnPairSuffStatsType pairStats = DRWN_PSS_FULL);
70 inline int size()
const {
return _n; }
72 inline bool isDiagonal()
const {
return (_pairStats == DRWN_PSS_DIAG); }
74 inline bool hasPairs()
const {
return (_pairStats != DRWN_PSS_NONE); }
76 inline double count()
const {
return _count; }
78 inline double sum(
int i = 0)
const {
return _sum(i); }
80 inline double sum2(
int i = 0,
int j = 0)
const {
82 case DRWN_PSS_FULL:
return _sum2(i, j);
83 case DRWN_PSS_DIAG:
return (i == j) ? _sum2(i, 0) : 0.0;
84 case DRWN_PSS_NONE:
return 0.0;
95 case DRWN_PSS_FULL:
return _sum2;
96 case DRWN_PSS_DIAG:
return _sum2.col(0).asDiagonal();
97 case DRWN_PSS_NONE:
return MatrixXd::Zero(_n, _n);
103 const char *
type()
const {
return "drwnSuffStats"; }
105 bool save(drwnXMLNode& xml)
const;
106 bool load(drwnXMLNode& xml);
110 void accumulate(
const vector<double>& x);
112 void accumulate(
const vector<double>& x,
double w);
114 void accumulate(
const vector<vector<double> >& x,
double w = 1.0);
118 void subtract(
const vector<double>& x);
120 void subtract(
const vector<double>& x,
double w);
122 void subtract(
const vector<vector<double> >& x,
double w = 1.0);
155 vector<drwnSuffStats> _stats;
160 drwnCondSuffStats(
int n = 1,
int k = 2, drwnPairSuffStatsType pairStats = DRWN_PSS_FULL);
169 void clear(
int n,
int k, drwnPairSuffStatsType pairStats = DRWN_PSS_FULL);
172 inline int size()
const {
return _n; }
176 inline double count()
const;
178 inline double count(
int k)
const {
return _stats[k].count(); }
186 const char *
type()
const {
return "drwnCondSuffStats"; }
188 bool save(drwnXMLNode& xml)
const;
189 bool load(drwnXMLNode& xml);
193 inline void accumulate(
const vector<double>& x,
int y);
195 inline void accumulate(
const vector<double>& x,
int y,
double w);
197 void accumulate(
const vector<vector<double> >& x,
int y,
double w = 1.0);
199 void accumulate(
const vector<vector<double> >& x,
const vector<int>& y);
201 void accumulate(
const vector<vector<double> >& x,
const vector<int>& y,
const vector<double>& w);
203 void accumulate(
const drwnSuffStats& stats,
int y,
double w = 1.0);
205 inline void subtract(
const vector<double>& x,
int y);
207 inline void subtract(
const vector<double>& x,
int y,
double w);
209 void subtract(
const vector<vector<double> >& x,
int y,
double w = 1.0);
211 void subtract(
const vector<vector<double> >& x,
const vector<int>& y);
213 void subtract(
const vector<vector<double> >& x,
const vector<int>& y,
const vector<double>& w);
215 void subtract(
const drwnSuffStats& stats,
int y,
double w = 1.0);
217 void redistribute(
int y,
int k);
228 for (
int y = 0; y < _k; y++) {
229 c += _stats[y].count();
236 DRWN_ASSERT_MSG((y >= 0) && (y < _k), y);
237 _stats[y].accumulate(x);
241 DRWN_ASSERT_MSG((y >= 0) && (y < _k), y);
242 _stats[y].accumulate(x, w);
246 DRWN_ASSERT_MSG((y >= 0) && (y < _k), y);
247 _stats[y].subtract(x);
251 DRWN_ASSERT_MSG((y >= 0) && (y < _k), y);
252 _stats[y].subtract(x, w);
drwnCondSuffStats * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnSuffStats.h:187
const VectorXd & firstMoments() const
return the first moment return the weighted sum of samples accumulated
Definition: drwnSuffStats.h:91
Implements a class for accumulating conditional first- and second-order sufficient statistics...
Definition: drwnSuffStats.h:150
double count() const
return the weighted count of samples accumulated
Definition: drwnSuffStats.h:76
int size() const
return the number of dimensions
Definition: drwnSuffStats.h:172
void subtract(const vector< double > &x, int y)
remove a single sample from the sufficient statistics for state y
Definition: drwnSuffStats.h:245
const drwnSuffStats & operator[](unsigned k) const
copy constructor
Definition: drwnSuffStats.h:221
double sum2(int i=0, int j=0) const
return the weighted sum-of-squares of samples accumulated a given dimension
Definition: drwnSuffStats.h:80
const char * type() const
returns object type as a string (e.g., Foo::type() { return "Foo"; })
Definition: drwnSuffStats.h:186
bool isDiagonal() const
return true if only accumulating diagonalized statistics (i.e., no cross terms)
Definition: drwnSuffStats.h:72
int states() const
return the number of conditional states
Definition: drwnSuffStats.h:174
double count() const
return the total weight of samples accumulated
Definition: drwnSuffStats.h:226
Implements a class for accumulating first- and second-order sufficient statistics (moments)...
Definition: drwnSuffStats.h:43
MatrixXd secondMoments() const
return the weighted sum-of-squares of samples accumulated
Definition: drwnSuffStats.h:93
int size() const
return the dimensionality of the sufficient statistics
Definition: drwnSuffStats.h:70
bool hasPairs() const
return true if accumulating both first- and second-order statistics
Definition: drwnSuffStats.h:74
void accumulate(const vector< double > &x, int y)
add a single sample to the sufficient statistics for state y
Definition: drwnSuffStats.h:235
double sum(int i=0) const
return the weighted sum of samples accumulated for a given dimension
Definition: drwnSuffStats.h:78
const char * type() const
returns object type as a string (e.g., Foo::type() { return "Foo"; })
Definition: drwnSuffStats.h:103
double count(int k) const
return the weight of samples accumulated for the k-th state
Definition: drwnSuffStats.h:178
drwnSuffStats const & suffStats(int k) const
return the sufficient statistics for the k-th state
Definition: drwnSuffStats.h:181
drwnSuffStats * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnSuffStats.h:104
standard Darwin object interface (cloneable and writeable)
Definition: drwnInterfaces.h:72