contrib/mul/mbl/mbl_stats_nd.h
Go to the documentation of this file.
00001 #ifndef mbl_stats_nd_h_
00002 #define mbl_stats_nd_h_
00003 
00004 //:
00005 // \file
00006 // \brief Simple statistics (mean, variance) on vectors.
00007 // \author Tim Cootes
00008 
00009 #include <vcl_iosfwd.h>
00010 #include <vsl/vsl_binary_io.h>
00011 #include <vnl/vnl_vector.h>
00012 
00013 //: Simple statistics (mean, variance) on vectors.
00014 //  Note: Uses unbiased estimate of variance (ie divide by (n_obs()-1))
00015 class mbl_stats_nd
00016 {
00017   vnl_vector<double> sum_;
00018   vnl_vector<double> sum_sq_;
00019   unsigned n_obs_;
00020  public:
00021   mbl_stats_nd() ;
00022 
00023   //: Remove all data
00024   void clear();
00025 
00026   //: Add given observation
00027   void obs(const vnl_vector<double>& v);
00028 
00029   //: Number of observations
00030   unsigned n_obs() const { return n_obs_; }
00031 
00032   //: Mean of current observations
00033   vnl_vector<double> mean() const ;
00034 
00035   //: Standard deviation of current observations
00036   vnl_vector<double> sd() const;
00037   //: Standard error (sd of estimate of mean) of current observations
00038   vnl_vector<double> stdError() const;
00039   //: Variance of current observations
00040   vnl_vector<double> variance() const;
00041 
00042   //: Sum of current observations
00043   const vnl_vector<double>& sum() const { return sum_; }
00044 
00045   //: Sum of squares of current observations
00046   const vnl_vector<double> & sumSq() const { return sum_sq_; }
00047 
00048   //: Add statistics together
00049   mbl_stats_nd& operator+=(const mbl_stats_nd& s1);
00050   void print_summary(vcl_ostream& os) const;
00051   //: Version number for I/O
00052   short version_no() const;
00053   void b_write(vsl_b_ostream& bfs) const;
00054   void b_read(vsl_b_istream& bfs);
00055 
00056   //: Test for equality
00057   bool operator==(const mbl_stats_nd& s) const;
00058 
00059   friend
00060   mbl_stats_nd operator+(const mbl_stats_nd& s1, const mbl_stats_nd& s2);
00061 };
00062 
00063 //: Binary file stream output operator for class reference
00064 void vsl_b_write(vsl_b_ostream& bfs, const mbl_stats_nd& b);
00065 
00066 //: Binary file stream input operator for class reference
00067 void vsl_b_read(vsl_b_istream& bfs, mbl_stats_nd& b);
00068 
00069 //: Stream output operator for class reference
00070 vcl_ostream& operator<<(vcl_ostream& os,const mbl_stats_nd& stats);
00071 
00072 //: Stream output operator for class reference
00073 void vsl_print_summary(vcl_ostream& os,const mbl_stats_nd& stats);
00074 
00075 #endif