Go to the documentation of this file.00001
00002 #ifndef bsta_histogram_h_
00003 #define bsta_histogram_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <vcl_vector.h>
00019 #include <vcl_cassert.h>
00020 #include <vcl_iostream.h>
00021 #include <bsta/bsta_histogram_base.h>
00022 template <class T> class bsta_histogram : public bsta_histogram_base
00023 {
00024 public:
00025
00026 bsta_histogram();
00027
00028
00029 bsta_histogram(const T range, const unsigned int nbins,
00030 const T min_prob = 0.0);
00031
00032
00033 bsta_histogram(const T min, const T max, const unsigned int nbins,
00034 const T min_prob = 0.0);
00035
00036
00037 bsta_histogram(const unsigned int nbins, const T min, const T delta,
00038 const T min_prob = 0.0);
00039
00040
00041 bsta_histogram(const T min, const T max, vcl_vector<T> const& data,
00042 const T min_prob = 0.0);
00043
00044 ~bsta_histogram() {}
00045
00046
00047 unsigned int nbins() const { return nbins_; }
00048
00049
00050 T min() const {return min_;}
00051 T max() const {return max_;}
00052
00053
00054 T delta() const {return delta_;}
00055
00056
00057 T min_prob() const {return min_prob_;}
00058
00059
00060 void value_range(const unsigned int bin, T& vmin, T& vmax) const
00061 { assert(bin<nbins_); vmin = bin*delta_+min_; vmax = (bin+1)*delta_+min_; }
00062
00063
00064 T avg_bin_value(const unsigned int bin) const
00065 { assert(bin<nbins_); return min_ + bin*delta_ + delta_/2; }
00066
00067
00068 T counts(const unsigned int bin) const
00069 { assert(bin<nbins_); return counts_[bin]; }
00070
00071
00072 T p(const unsigned int bin) const;
00073
00074
00075 T p(const T value) const;
00076
00077
00078 T area() const;
00079
00080
00081 T cumulative_area(unsigned bin) const;
00082
00083
00084 T mean() const;
00085
00086
00087 T mean(const unsigned int lowbin, const unsigned int highbin) const;
00088
00089
00090 T mean_vals(const T low, const T high) const;
00091
00092
00093 T variance() const;
00094
00095
00096 T variance(const unsigned int lowbin, const unsigned int highbin) const;
00097
00098
00099 T variance_vals(const T low, const T high) const;
00100
00101
00102 unsigned low_bin();
00103
00104
00105 unsigned high_bin();
00106
00107
00108 T fraction_below(const T value) const;
00109
00110
00111 T fraction_above(const T value) const;
00112
00113
00114 T value_with_area_below(const T area_fraction) const;
00115
00116
00117 T value_with_area_above(const T area_fraction) const;
00118
00119
00120 T entropy() const;
00121
00122
00123 T renyi_entropy() const;
00124
00125
00126 void upcount(T val, T mag);
00127
00128
00129 int bin_at_val(T val);
00130
00131
00132 void set_count(const unsigned bin, const T count)
00133 { if (bin<nbins_){ counts_[bin]=count; area_valid_ = false;}}
00134
00135
00136 vcl_vector<T> value_array() const {
00137 vcl_vector<T> v(nbins_);
00138 for (unsigned b = 0; b<nbins_; ++b) v[b]=avg_bin_value(b); return v; }
00139
00140
00141 vcl_vector<T> count_array() const {
00142 vcl_vector<T> v(nbins_);
00143 for (unsigned b = 0; b<nbins_; ++b) v[b]=counts(b); return v; }
00144
00145
00146 void parzen(const T sigma);
00147
00148
00149 vcl_ostream& write(vcl_ostream&) const;
00150
00151
00152 vcl_istream& read(vcl_istream&);
00153
00154 void pretty_print(vcl_ostream& os = vcl_cout) const;
00155
00156 void print(vcl_ostream& os = vcl_cout) const;
00157
00158
00159 void print_to_m(vcl_ostream& os = vcl_cout) const;
00160
00161
00162 void print_to_arrays(vcl_ostream& os = vcl_cout) const;
00163
00164
00165 void print_vals_prob(vcl_ostream& os = vcl_cout) const;
00166
00167
00168 void clear();
00169
00170 private:
00171 void compute_area() const;
00172 mutable bool area_valid_;
00173 mutable T area_;
00174 unsigned int nbins_;
00175 T range_;
00176 T delta_;
00177 T min_prob_;
00178 T min_;
00179 T max_;
00180 vcl_vector<T> counts_;
00181 };
00182
00183
00184
00185 template <class T>
00186 vcl_ostream& operator<<(vcl_ostream& s, bsta_histogram<T> const& h);
00187
00188
00189
00190 template <class T>
00191 vcl_istream& operator>>(vcl_istream& is, bsta_histogram<T>& h);
00192
00193
00194 template <>
00195 void bsta_histogram<char>::pretty_print(vcl_ostream& os) const;
00196 #include <bsta/bsta_histogram_sptr.h>
00197 #define BSTA_HISTOGRAM_INSTANTIATE(T) extern "Please #include <bsta/bsta_histogram.txx>"
00198
00199 #endif // bsta_histogram_h_