PLearn 0.1
Public Member Functions | Public Attributes | Protected Attributes
PLearn::VMFieldStat Class Reference

this class holds simple statistics about a field More...

#include <VMField.h>

Collaboration diagram for PLearn::VMFieldStat:
Collaboration graph
[legend]

List of all members.

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, intcounts
 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

Detailed Description

this class holds simple statistics about a field

Definition at line 87 of file VMField.h.


Constructor & Destructor Documentation

PLearn::VMFieldStat::VMFieldStat ( int  the_maxndiscrete = 255)

VMFieldStat.

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) {}

Member Function Documentation

int PLearn::VMFieldStat::count ( ) const [inline]

should be equal to length of VMField

Definition at line 110 of file VMField.h.

Referenced by read().

Here is the caller graph for this function:

real PLearn::VMFieldStat::max ( ) const [inline]

Definition at line 119 of file VMField.h.

Referenced by PLearn::CompactVMatrix::CompactVMatrix().

{ return max_; }

Here is the caller graph for this function:

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_; }

Here is the caller graph for this function:

int PLearn::VMFieldStat::nmissing ( ) const [inline]

Definition at line 111 of file VMField.h.

Referenced by PLearn::SparseVMatrix::SparseVMatrix().

{ return nmissing_; }

Here is the caller graph for this function:

int PLearn::VMFieldStat::nnegative ( ) const [inline]

Definition at line 114 of file VMField.h.

Referenced by PLearn::SparseVMatrix::SparseVMatrix().

{ return nnegative_; }

Here is the caller graph for this function:

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_; }

Here is the caller graph for this function:

int PLearn::VMFieldStat::nzero ( ) const [inline]

Definition at line 115 of file VMField.h.

real PLearn::VMFieldStat::prob ( real  value) [inline]

Definition at line 124 of file VMField.h.

Referenced by PLearn::CompactVMatrix::perturb().

{ return counts[value]/real(nnonmissing()); }

Here is the caller graph for this function:

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;
    }
}

Here is the call graph for this function:

real PLearn::VMFieldStat::stddev ( ) const [inline]

Definition at line 122 of file VMField.h.

References PLearn::sqrt(), and PLearn::variance().

{ return sqrt(variance()); }

Here is the call graph for this function:

real PLearn::VMFieldStat::sum ( ) const [inline]

Definition at line 116 of file VMField.h.

{ return real(sum_); }
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();
            }
        }
    }
}

Here is the call graph for this function:

real PLearn::VMFieldStat::variance ( ) const [inline]

Definition at line 121 of file VMField.h.

References PLearn::square().

Here is the call graph for this function:

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;
    }
}

Member Data Documentation

counts of discrete values.

If the size of counts exceeds maxndiscrete maxndiscrete is set to -1, counts is erased, and we stop counting!

Definition at line 106 of file VMField.h.

Referenced by PLearn::CompactVMatrix::CompactVMatrix(), read(), update(), and write().

maximum value

Definition at line 97 of file VMField.h.

Referenced by read(), update(), and write().

maximum number of different discrete values to keep track of

Definition at line 100 of file VMField.h.

Referenced by update().

minimum value

Definition at line 96 of file VMField.h.

Referenced by read(), update(), and write().

number of missing values

Definition at line 90 of file VMField.h.

Referenced by read(), update(), and write().

number of values <0

Definition at line 93 of file VMField.h.

Referenced by read(), update(), and write().

number of non-missing values

Definition at line 91 of file VMField.h.

Referenced by read(), update(), and write().

number of values >0

Definition at line 92 of file VMField.h.

Referenced by read(), update(), and write().

double PLearn::VMFieldStat::sum_ [protected]

sum of all non missing values

Definition at line 94 of file VMField.h.

Referenced by read(), update(), and write().

double PLearn::VMFieldStat::sumsquare_ [protected]

sum of square of all non missing values

Definition at line 95 of file VMField.h.

Referenced by read(), update(), and write().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines