contrib/mul/mbl/mbl_stats_1d.h

Go to the documentation of this file.
00001 #ifndef mbl_stats_1d_h_
00002 #define mbl_stats_1d_h_
00003 
00004 //:
00005 // \file
00006 // \brief Simple statistics on a 1D variable.
00007 // \author Tim Cootes
00008 
00009 #include <vcl_iosfwd.h>
00010 #include <vsl/vsl_binary_io.h>
00011 #include <vcl_vector.h>
00012 
00013 // windows thinks min and max are macros in this file, but they
00014 // are not, don't know where they are defined (somewhere in vxl!)
00015 #undef min
00016 #undef max
00017 
00018 //: Simple statistics on a 1D variable
00019 // \code
00020 //   // A rather trivial example
00021 //   mbl_stats_1d stats,odd_stats,even_stats,sum_stats;
00022 //
00023 //   const int n = 10;
00024 //   for (int i=0;i<n;i++)
00025 //   {
00026 //     stats.obs(i);
00027 //     if (i%2) even_stats.obs(i);
00028 //     else     odd_stats.obs(i);
00029 //   }
00030 //
00031 //   vcl_cout << stats << "\nStats of odd numbers :\n" << odd_stats;
00032 //
00033 //   sum_stats = odd_stats + even_stats;
00034 //
00035 //   vcl_cout << "Sum of odd and even stats\n" << sum_stats;
00036 // \endcode
00037 class mbl_stats_1d
00038 {
00039   double sum_;
00040   double sum_sq_;
00041   double min_v_;
00042   double max_v_;
00043   int n_obs_;
00044 
00045 
00046 public:
00047 
00048   //: Default constructor
00049   mbl_stats_1d();
00050 
00051   //: Construct with a set of observations
00052   mbl_stats_1d(const vcl_vector<double>& observations);
00053 
00054     //: Remove all data
00055   void clear();
00056 
00057     //: Add given observation
00058   void obs(double v);
00059 
00060     //: Number of observations
00061   int nObs() const;
00062 
00063     //: Mean of current observations
00064   double mean() const ;
00065 
00066 
00067     //: Standard deviation of current observations
00068   double sd() const;
00069     //: Standard error (sd of estimate of mean) of current observations
00070   double stdError() const;
00071     //: Variance of current observations
00072   double variance() const;
00073     //: Min of current observations
00074   double min() const;
00075     //: Max of current observations
00076   double max() const;
00077     //: Sum of current observations
00078   double sum() const;
00079     //: Sum of squares of current observations
00080   double sumSq() const;
00081 
00082   //: RMS of current observations;
00083   // \note If nobs==0, returns -1.0
00084   double rms() const;
00085 
00086     //: Add statistics together
00087   mbl_stats_1d& operator+=(const mbl_stats_1d& s1);
00088   void print_summary(vcl_ostream& os) const;
00089     //: Version number for I/O
00090   short version_no() const;
00091   void b_write(vsl_b_ostream& bfs) const;
00092   void b_read(vsl_b_istream& bfs);
00093 
00094     //: Test for equality
00095   bool operator==(const mbl_stats_1d& s) const;
00096 
00097   friend
00098   mbl_stats_1d operator+(const mbl_stats_1d& s1, const mbl_stats_1d& s2);
00099 };
00100 
00101 //: Binary file stream output operator for class reference
00102 void vsl_b_write(vsl_b_ostream& bfs, const mbl_stats_1d& b);
00103 
00104 //: Binary file stream input operator for class reference
00105 void vsl_b_read(vsl_b_istream& bfs, mbl_stats_1d& b);
00106 
00107 //: Stream output operator for class reference
00108 vcl_ostream& operator<<(vcl_ostream& os,const mbl_stats_1d& stats);
00109 
00110 //: Stream output operator for class reference
00111 void vsl_print_summary(vcl_ostream& os,const mbl_stats_1d& stats);
00112 
00113 #endif

Generated on Sat Sep 6 05:11:03 2008 for contrib/mul/mbl by  doxygen 1.5.1