Changeset 215
- Timestamp:
- Nov 7, 2004, 12:07:03 AM (18 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Histogram.cc
r199 r215 25 25 26 26 27 Histogram::Histogram(const double min, const double max, const size_t) 28 : xmax_(max), xmin_(min), sum_all_(), sum_histogram_() 27 Histogram::Histogram(const double min, const double max, const size_t n) 28 : histogram_(std::vector<double>(n,0.0)), 29 xmax_(max), xmin_(min), 30 sum_all_(), sum_histogram_() 29 31 { 30 // Peter, fix me31 32 } 32 33 34 /*35 Histogram::Histogram(const u_int nof_bins, const double min, const double max)36 : spacing_((max-min)/nof_bins), xmax_(max), xmin_(min), sum_all_(),37 sum_histogram_()38 {39 histogram_=vector<statistics::WeightedAverager>(nof_bins);40 }41 */42 33 43 34 … … 51 42 int Histogram::add(const double x, const double w) 52 43 { 44 std::cout << "Histogram::add Jari, check me!" << std::endl; 45 53 46 sum_all_.add(x,w); 54 47 if (x<xmin_) … … 64 57 65 58 66 void Histogram::normalize(double factor)67 {68 for (u_int i=0; i<histogram_.size(); i++)69 histogram_[i]/=factor;70 }71 72 73 74 /*75 59 void Histogram::normalize(double scale_factor) 76 60 { 77 for (u_int i=0; i<histogram_.size(); i++)78 histogram_[i]/=_sum_histogram.nof_entries()*spacing_*scale_factor;61 for (size_t i=0; i<histogram_.size(); i++) 62 histogram_[i]/=scale_factor; 79 63 } 80 */81 64 82 65 … … 89 72 sum_histogram_.reset(); 90 73 } 91 92 93 94 /*95 const statistics::WeightedAverager& Histogram::operator[](double d) const96 {97 if ((d<xmin_) || (d>xmax_))98 return statistics::WeightedAverager();// requested bin not within boundaries99 return histogram_[static_cast<u_int>(floor((d-xmin_) /100 spacing_))];101 }102 */103 74 104 75 … … 118 89 119 90 120 std::ostream& operator<<(std::ostream& s,const Histogram& b)91 std::ostream& operator<<(std::ostream& s,const Histogram& histogram) 121 92 { 122 s << "# min : " << b.xmin() << '\n'; 123 s << "# max : " << b.xmax() << '\n'; 124 s << "# spacing : " << b.spacing() << '\n'; 125 s << "# number of bins: " << b.nof_bins() << '\n'; 126 127 // s << "# histogram averager: " << b.averager_histogram() << '\n'; 128 s << "# entries: " << b.averager_histogram().sum_w() << '\n'; 129 // s << "# all averager : " << b.averager_all() << '\n'; 130 s << "# entries: " << b.averager_all().sum_w() << '\n'; 93 s << "# histogram min : " << histogram.xmin() << '\n'; 94 s << "# histogram max : " << histogram.xmax() << '\n'; 95 s << "# number of bins: " << histogram.nof_bins() << '\n'; 96 s << "# histogram averager: " << histogram.averager_histogram() << '\n'; 97 s << "# all averager: " << histogram.averager_all() << '\n'; 131 98 132 99 s << "# column 1: center of observation bin\n" 133 << "# column 2: frequency\n" 134 << "# column 3: relative frequency\n" 135 << "# column 4: average of observations in bin\n" 136 << "# column 5: stddev of frequency\n"; 100 << "# column 2: frequency\n"; 137 101 138 double observation=b.xmin()+b.spacing()/2; 139 for (u_int i=0; i<b.nof_bins(); i++) { 102 for (u_int i=0; i<histogram.nof_bins(); i++) { 140 103 s.width(12); 141 s << observation;104 s << histogram.xmin()+(i+0.5)*histogram.spacing(); 142 105 s.width(12); 143 s << b[i]; 144 s.width(12); 145 // Peter, fix me 146 // if (b.nof_entries_all()) 147 // s << b[i].sum_w()/b.nof_entries_all(); 148 // else 149 // s << 0; 150 s.width(12); 151 // s << b[i] << "\n"; 152 observation+=b.spacing(); 106 s << histogram[i] << '\n'; 153 107 } 154 108 -
trunk/src/Histogram.h
r199 r215 80 80 { return sum_histogram_; } 81 81 82 // Peter, public or private? 83 inline int bin(double d); 82 /// 83 /// @return The number of bins in the histogram 84 /// 85 inline size_t nof_bins(void) const { return histogram_.size(); } 86 87 /// 88 /// Rescale the histogram using the scale factor \a 89 /// scale_factor. You may need to averager_all or 90 /// averager_histogram to set the proper scale factor. 91 /// 92 void normalize(double scale_factor=1); 93 94 /// 95 /// @return The value of the histogram corresponding to bin \a 96 /// bin. 97 /// 98 /// @note No check is done that \a bin is within the size of the 99 /// histogram. 100 /// 101 inline double observation_value(const size_t bin) const 102 { return xmin_+spacing()*(bin+0.5); } 103 104 /// 105 /// Set everyting to default values, here it means that everything 106 /// is set to zero except the boundary values that are kept. 107 /// 108 void reset(void); 109 110 /// 111 /// @return The size of the bins in the histogram. 112 /// 113 inline double spacing(void) const { return (xmax_-xmin_)/nof_bins(); } 114 115 /// 116 /// @return The histogram upper boundary. 117 /// 118 /// @note The upper boundary value is inside the histogram. 119 /// 120 inline double xmax(void) const { return xmax_; } 121 122 /// 123 /// @return The histogram lower boundary. 124 /// 125 /// @note The lower boundary value is outside the histogram. 126 /// 127 inline double xmin(void) const { return xmin_; } 128 129 /// 130 /// @return The count of bin \a bin.in the histogram. 131 inline double operator[](size_t bin) const { return histogram_[bin]; } 132 133 /// 134 /// The assignment operator 135 const Histogram& operator=(const Histogram&); 136 137 private: 138 inline size_t bin(double d) 139 { std::cout << "Histogram::bin Jari, implement me!" << std::endl; return 0; }; 84 140 // { return (((d<xmin_) || (d>xmax_)) ? -1 : 85 141 // static_cast<int>(floor((d-xmin_)/spacing_))); } 86 142 87 inline u_int nof_bins(void) const { return histogram_.size(); }88 inline double nof_entries_all(void) const { return sum_all_.sum_w(); }89 inline double nof_entries_histogram(void) const90 { return sum_histogram_.sum_w(); }91 void normalize(double scale_factor=1);92 void normalize_all(void);93 void normalize_histogram(void);94 inline double observation_value(const u_int i) const95 { return xmin_+spacing()*(i+0.5); }96 void reset(void);97 inline double spacing(void) const { return 0; } // Peter, fix me98 inline double xmax(void) const { return xmax_; }99 inline double xmin(void) const { return xmin_; }100 101 inline double operator[](size_t bin) const { return histogram_[bin]; }102 double operator[](double) const;103 104 const Histogram& operator=(const Histogram&);105 106 private:107 143 std::vector<double> histogram_; 108 144 double xmax_; … … 112 148 }; 113 149 150 /// 151 /// The Histogram output operator 152 /// 114 153 std::ostream& operator<<(std::ostream& s,const Histogram&); 115 154 -
trunk/src/WeightedAverager.h
r203 r215 132 132 }; 133 133 134 /// 135 /// The WeightedAverager output operator 136 /// 137 std::ostream& operator<<(std::ostream& s,const WeightedAverager&); 134 138 135 139 }} // of namespace statistics and namespace theplu
Note: See TracChangeset
for help on using the changeset viewer.