PLearn 0.1
|
this class holds simple statistics about a field More...
#include <VMField.h>
Public Member Functions | |
VMFieldStat (int the_maxndiscrete=255) | |
VMFieldStat. | |
int | count () const |
should be equal to length of VMField | |
int | nmissing () const |
int | nnonmissing () const |
int | npositive () const |
int | nnegative () const |
int | nzero () const |
real | sum () const |
real | sumsquare () const |
real | min () const |
real | max () const |
real | mean () const |
real | variance () const |
real | stddev () const |
real | prob (real value) |
void | update (real val) |
void | write (PStream &out) const |
void | read (PStream &in) |
Public Attributes | |
map< real, int > | counts |
counts of discrete values. | |
Protected Attributes | |
int | nmissing_ |
number of missing values | |
int | nnonmissing_ |
number of non-missing values | |
int | npositive_ |
number of values >0 | |
int | nnegative_ |
number of values <0 | |
double | sum_ |
sum of all non missing values | |
double | sumsquare_ |
sum of square of all non missing values | |
real | min_ |
minimum value | |
real | max_ |
maximum value | |
int | maxndiscrete |
maximum number of different discrete values to keep track of |
PLearn::VMFieldStat::VMFieldStat | ( | int | the_maxndiscrete = 255 | ) |
Definition at line 83 of file VMField.cc.
: nmissing_(0), nnonmissing_(0), npositive_(0), nnegative_(0), sum_(0.), sumsquare_(0.), min_(FLT_MAX), max_(-FLT_MAX), maxndiscrete(the_maxndiscrete) {}
int PLearn::VMFieldStat::count | ( | ) | const [inline] |
real PLearn::VMFieldStat::max | ( | ) | const [inline] |
Definition at line 119 of file VMField.h.
Referenced by PLearn::CompactVMatrix::CompactVMatrix().
{ return max_; }
real PLearn::VMFieldStat::mean | ( | ) | const [inline] |
Definition at line 120 of file VMField.h.
{ return real(sum_/nnonmissing_); }
real PLearn::VMFieldStat::min | ( | ) | const [inline] |
Definition at line 118 of file VMField.h.
Referenced by PLearn::CompactVMatrix::CompactVMatrix().
{ return min_; }
int PLearn::VMFieldStat::nmissing | ( | ) | const [inline] |
Definition at line 111 of file VMField.h.
Referenced by PLearn::SparseVMatrix::SparseVMatrix().
{ return nmissing_; }
int PLearn::VMFieldStat::nnegative | ( | ) | const [inline] |
Definition at line 114 of file VMField.h.
Referenced by PLearn::SparseVMatrix::SparseVMatrix().
{ return nnegative_; }
int PLearn::VMFieldStat::nnonmissing | ( | ) | const [inline] |
Definition at line 112 of file VMField.h.
{ return nnonmissing_; }
int PLearn::VMFieldStat::npositive | ( | ) | const [inline] |
Definition at line 113 of file VMField.h.
Referenced by PLearn::SparseVMatrix::SparseVMatrix().
{ return npositive_; }
int PLearn::VMFieldStat::nzero | ( | ) | const [inline] |
Definition at line 115 of file VMField.h.
{ return nnonmissing_ - (npositive_+nnegative_); }
Definition at line 124 of file VMField.h.
Referenced by PLearn::CompactVMatrix::perturb().
{ return counts[value]/real(nnonmissing()); }
void PLearn::VMFieldStat::read | ( | PStream & | in | ) |
Definition at line 140 of file VMField.cc.
References count(), counts, max_, min_, nmissing_, nnegative_, nnonmissing_, npositive_, sum_, and sumsquare_.
{ in >> nmissing_ >> nnonmissing_ >> npositive_ >> nnegative_ >> sum_ >> sumsquare_ >> min_ >> max_ ; int ndiscrete; real value; int count; counts.clear(); in >> ndiscrete; for(int k=0; k<ndiscrete; k++) { in >> value >> count; counts[value] = count; } }
real PLearn::VMFieldStat::stddev | ( | ) | const [inline] |
Definition at line 122 of file VMField.h.
References PLearn::sqrt(), and PLearn::variance().
real PLearn::VMFieldStat::sum | ( | ) | const [inline] |
real PLearn::VMFieldStat::sumsquare | ( | ) | const [inline] |
Definition at line 117 of file VMField.h.
{ return real(sumsquare_); }
void PLearn::VMFieldStat::update | ( | real | val | ) |
Definition at line 88 of file VMField.cc.
References counts, PLearn::is_missing(), max_, maxndiscrete, min_, nmissing_, nnegative_, nnonmissing_, npositive_, sum_, and sumsquare_.
{ if(is_missing(val)) nmissing_++; else { nnonmissing_++; sum_ += val; sumsquare_ += val*val; if(val>0.) npositive_++; else if(val<0.) nnegative_++; if(val<min_) min_ = val; if(val>max_) max_ = val; if(maxndiscrete>0) { if(int(counts.size())<maxndiscrete) counts[val]++; else // reached maxndiscrete. Stop counting and reset counts. { maxndiscrete = -1; counts.clear(); } } } }
real PLearn::VMFieldStat::variance | ( | ) | const [inline] |
Definition at line 121 of file VMField.h.
References PLearn::square().
{ return real((sumsquare_ - square(sum_)/nnonmissing_)/(nnonmissing_-1)); }
void PLearn::VMFieldStat::write | ( | PStream & | out | ) | const |
Definition at line 118 of file VMField.cc.
References counts, max_, min_, nmissing_, nnegative_, nnonmissing_, npositive_, sum_, and sumsquare_.
{ out << nmissing_ << ' ' << nnonmissing_ << ' ' << npositive_ << ' ' << nnegative_ << ' ' << sum_ << ' ' << sumsquare_ << ' ' << min_ << ' ' << max_ << " "; out << (unsigned int) counts.size() << " "; map<real,int>::const_iterator it = counts.begin(); map<real,int>::const_iterator countsend = counts.end(); while(it!=countsend) { out << it->first << ' ' << it->second << " "; ++it; } }
real PLearn::VMFieldStat::max_ [protected] |
int PLearn::VMFieldStat::maxndiscrete [protected] |
real PLearn::VMFieldStat::min_ [protected] |
int PLearn::VMFieldStat::nmissing_ [protected] |
int PLearn::VMFieldStat::nnegative_ [protected] |
int PLearn::VMFieldStat::nnonmissing_ [protected] |
int PLearn::VMFieldStat::npositive_ [protected] |
double PLearn::VMFieldStat::sum_ [protected] |
double PLearn::VMFieldStat::sumsquare_ [protected] |