Go to the documentation of this file.00001 #ifndef mbl_sample_stats_1d_h_
00002 #define mbl_sample_stats_1d_h_
00003
00004
00005
00006
00007
00008 #include <vcl_stdexcept.h>
00009 #include <vcl_iostream.h>
00010 #include <vcl_vector.h>
00011 #include <vnl/vnl_vector.h>
00012 #include <vsl/vsl_fwd.h>
00013 #include <mbl/mbl_stats_1d.h>
00014
00015
00016 class mbl_sample_stats_1d
00017 {
00018 vcl_vector<double> samples_;
00019 mbl_stats_1d stats_1d_;
00020 bool use_mvue_;
00021
00022 public:
00023
00024
00025 mbl_sample_stats_1d();
00026
00027
00028 mbl_sample_stats_1d(const vcl_vector<double> &samples);
00029
00030
00031 mbl_sample_stats_1d(const vnl_vector<double> &samples);
00032
00033 ~mbl_sample_stats_1d();
00034
00035
00036
00037
00038 void set_use_mvue(bool b) { use_mvue_=b; }
00039
00040
00041 void clear();
00042
00043
00044 void add_sample(double v);
00045
00046
00047 unsigned n_samples() const;
00048
00049
00050 const vcl_vector<double>& samples() const { return samples_; }
00051
00052
00053 double mean() const ;
00054
00055
00056 double mean_of_absolutes() const ;
00057
00058
00059
00060
00061 double median() const;
00062
00063
00064
00065
00066 double nth_percentile(int n) const;
00067
00068
00069
00070
00071 double quantile(double q) const;
00072
00073
00074 double sd() const;
00075
00076
00077 double stdError() const;
00078
00079
00080 double variance() const;
00081
00082
00083 double skewness() const;
00084
00085
00086 double kurtosis() const;
00087
00088
00089
00090
00091 double min() const;
00092
00093
00094
00095
00096 double max() const;
00097
00098
00099 double sum() const;
00100
00101
00102 double sum_squares() const;
00103
00104
00105 double rms() const;
00106
00107
00108 mbl_sample_stats_1d& operator+=(const mbl_sample_stats_1d& s1);
00109
00110
00111 void print_summary(vcl_ostream& os) const;
00112
00113
00114
00115 void print_all(vcl_ostream& os,
00116 const vcl_string& delim="\n") const;
00117
00118
00119 short version_no() const;
00120 void b_write(vsl_b_ostream& bfs) const;
00121 void b_read(vsl_b_istream& bfs);
00122
00123
00124 bool operator==(const mbl_sample_stats_1d& s) const;
00125
00126 friend
00127 mbl_sample_stats_1d operator+(const mbl_sample_stats_1d& s1, const mbl_sample_stats_1d& s2);
00128 };
00129
00130
00131
00132
00133
00134
00135
00136 template <class S, class M>
00137 vcl_vector<double> mbl_apply_mask(const S &sample, const M &mask)
00138 {
00139 if (sample.size()==0 || sample.size()!=mask.size()) throw vcl_runtime_error("Mask should be the same size as the sample and not empty\n");
00140 mbl_sample_stats_1d stats;
00141 typename S::const_iterator sit=sample.begin();
00142 typename M::const_iterator mit=mask.begin();
00143 vcl_vector<double> ret;
00144 for ( ; sit!=sample.end(); ++sit, ++mit)
00145 {
00146 if ((*mit))
00147 {
00148 ret.push_back(*sit);
00149 }
00150 }
00151 return ret;
00152 }
00153
00154
00155 void vsl_b_write(vsl_b_ostream& bfs, const mbl_sample_stats_1d& b);
00156
00157
00158 void vsl_b_read(vsl_b_istream& bfs, mbl_sample_stats_1d& b);
00159
00160
00161 vcl_ostream& operator<<(vcl_ostream& os,const mbl_sample_stats_1d& stats);
00162
00163
00164 void vsl_print_summary(vcl_ostream& os,const mbl_sample_stats_1d& stats);
00165
00166
00167 void vsl_print_all(vcl_ostream& os, const mbl_sample_stats_1d& stats);
00168
00169 #endif // mbl_sample_stats_1d_h_