Public Member Functions | Private Attributes | Friends
mbl_stats_1d Class Reference

Simple statistics on a 1D variable. More...

#include <mbl_stats_1d.h>

List of all members.

Public Member Functions

 mbl_stats_1d ()
 Default constructor.
 mbl_stats_1d (const vcl_vector< double > &observations)
 Construct with a set of observations.
void clear ()
 Remove all data.
void obs (double v)
 Add given observation.
void obs (double v, double weight)
 Add given weighted observation.
int nObs () const
 Number of discrete observations.
double wObs () const
 Weight of all observations.
double mean () const
 Mean of current observations.
double sd () const
 Standard deviation of current observations.
double stdError () const
 Standard error (sd of estimate of mean) of current observations.
double variance () const
 Variance of current observations.
double min () const
 Min of current observations.
double max () const
 Max of current observations.
double sum () const
 Sum of current observations.
double sumSq () const
 Sum of squares of current observations.
double rms () const
 RMS of current observations;.
mbl_stats_1doperator+= (const mbl_stats_1d &s1)
 Add statistics together.
void print_summary (vcl_ostream &os) const
void b_write (vsl_b_ostream &bfs) const
 Version number for I/O.
void b_read (vsl_b_istream &bfs)
bool operator== (const mbl_stats_1d &s) const
 Test for equality.

Private Attributes

double sum_
double sum_sq_
double min_v_
double max_v_
unsigned n_obs_
double w_obs_

Friends

mbl_stats_1d operator+ (const mbl_stats_1d &s1, const mbl_stats_1d &s2)

Detailed Description

Simple statistics on a 1D variable.

   // A rather trivial example
   mbl_stats_1d stats,odd_stats,even_stats,sum_stats;

   const int n = 10;
   for (unsigned i=0;i<n;i++)
   {
     stats.obs(i);
     if (i%2) even_stats.obs(i);
     else     odd_stats.obs(i);
   }

   vcl_cout << stats << "\nStats of odd numbers :\n" << odd_stats;

   sum_stats = odd_stats + even_stats;

   vcl_cout << "Sum of odd and even stats\n" << sum_stats;

Definition at line 37 of file mbl_stats_1d.h.


Constructor & Destructor Documentation

mbl_stats_1d::mbl_stats_1d ( )

Default constructor.

Definition at line 11 of file mbl_stats_1d.cxx.

mbl_stats_1d::mbl_stats_1d ( const vcl_vector< double > &  observations)

Construct with a set of observations.

Definition at line 16 of file mbl_stats_1d.cxx.


Member Function Documentation

void mbl_stats_1d::b_read ( vsl_b_istream bfs)

Definition at line 174 of file mbl_stats_1d.cxx.

void mbl_stats_1d::b_write ( vsl_b_ostream bfs) const

Version number for I/O.

Definition at line 163 of file mbl_stats_1d.cxx.

void mbl_stats_1d::clear ( )

Remove all data.

Definition at line 26 of file mbl_stats_1d.cxx.

double mbl_stats_1d::max ( ) const

Max of current observations.

Definition at line 116 of file mbl_stats_1d.cxx.

double mbl_stats_1d::mean ( ) const

Mean of current observations.

Definition at line 76 of file mbl_stats_1d.cxx.

double mbl_stats_1d::min ( ) const

Min of current observations.

Definition at line 110 of file mbl_stats_1d.cxx.

int mbl_stats_1d::nObs ( ) const [inline]

Number of discrete observations.

Definition at line 66 of file mbl_stats_1d.h.

void mbl_stats_1d::obs ( double  v)

Add given observation.

Definition at line 34 of file mbl_stats_1d.cxx.

void mbl_stats_1d::obs ( double  v,
double  weight 
)

Add given weighted observation.

weight doesn't affect the max or min records.

Definition at line 55 of file mbl_stats_1d.cxx.

mbl_stats_1d & mbl_stats_1d::operator+= ( const mbl_stats_1d s1)

Add statistics together.

Definition at line 138 of file mbl_stats_1d.cxx.

bool mbl_stats_1d::operator== ( const mbl_stats_1d s) const

Test for equality.

Definition at line 152 of file mbl_stats_1d.cxx.

void mbl_stats_1d::print_summary ( vcl_ostream &  os) const

Definition at line 219 of file mbl_stats_1d.cxx.

double mbl_stats_1d::rms ( ) const

RMS of current observations;.

Note:
If nobs==0, returns -1.0

Definition at line 132 of file mbl_stats_1d.cxx.

double mbl_stats_1d::sd ( ) const

Standard deviation of current observations.

Definition at line 91 of file mbl_stats_1d.cxx.

double mbl_stats_1d::stdError ( ) const

Standard error (sd of estimate of mean) of current observations.

Definition at line 102 of file mbl_stats_1d.cxx.

double mbl_stats_1d::sum ( ) const

Sum of current observations.

Definition at line 122 of file mbl_stats_1d.cxx.

double mbl_stats_1d::sumSq ( ) const

Sum of squares of current observations.

Definition at line 127 of file mbl_stats_1d.cxx.

double mbl_stats_1d::variance ( ) const

Variance of current observations.

Definition at line 82 of file mbl_stats_1d.cxx.

double mbl_stats_1d::wObs ( ) const [inline]

Weight of all observations.

Definition at line 69 of file mbl_stats_1d.h.


Friends And Related Function Documentation

mbl_stats_1d operator+ ( const mbl_stats_1d s1,
const mbl_stats_1d s2 
) [friend]

Definition at line 244 of file mbl_stats_1d.cxx.


Member Data Documentation

double mbl_stats_1d::max_v_ [private]

Definition at line 42 of file mbl_stats_1d.h.

double mbl_stats_1d::min_v_ [private]

Definition at line 41 of file mbl_stats_1d.h.

unsigned mbl_stats_1d::n_obs_ [private]

Definition at line 43 of file mbl_stats_1d.h.

double mbl_stats_1d::sum_ [private]

Definition at line 39 of file mbl_stats_1d.h.

double mbl_stats_1d::sum_sq_ [private]

Definition at line 40 of file mbl_stats_1d.h.

double mbl_stats_1d::w_obs_ [private]

Definition at line 44 of file mbl_stats_1d.h.


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