Changeset 372
 Timestamp:
 Aug 5, 2005, 4:14:02 PM (18 years ago)
 Location:
 trunk/lib/statistics
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/lib/statistics/Histogram.cc
r298 r372 55 55 56 56 57 void Histogram::normalize( double scale_factor)57 void Histogram::normalize(bool choice) 58 58 { 59 double scale_factor; 60 if (choice) 61 scale_factor = sum_all_.sum_w(); 62 else 63 scale_factor = sum_all_.sum_w()*spacing(); 59 64 for (size_t i=0; i<histogram_.size(); i++) 60 65 histogram_[i]/=scale_factor; 66 61 67 } 62 68 
trunk/lib/statistics/Histogram.h
r370 r372 86 86 87 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. 88 /// There are two ways to normalize the counts. 91 89 /// 92 /// @todo Redefine the behaviour of this function. The parameter 93 /// should define the integral of the function. 90 /// If choice is true: The normalized count is the count in a 91 /// bin divided by the total number of observations. In this 92 /// case the relative counts are normalized to sum to unity ( 93 /// minus values outside histogram). This is the intuitive case 94 /// where the height of the histogram bar represents the 95 /// proportion of the data in each class. 94 96 /// 95 void normalize(double scale_factor=1); 97 /// If choice is false: The normalized count is the count in the 98 /// class divided by the number of observations times the bin 99 /// width. For this normalization, the area (or integral) under 100 /// the histogram is equal to unity (minus the missing area 101 /// corresponding to counts outside histogram). From a 102 /// probabilistic point of view, this normalization results in a 103 /// relative histogram that is most akin to the probability 104 /// density function If you want to overlay a probability density 105 /// on top of the histogram, use this normalization. Although this 106 /// normalization is less intuitive (relative frequencies greater 107 /// than 1 are quite permissible), it is the appropriate 108 /// normalization if you are using the histogram to model a 109 /// probability density function. 110 /// 111 /// @short Normalizing the histogram 112 /// 113 void normalize(bool choice = true); 96 114 97 115 /// … … 111 129 112 130 /// 113 /// @return The sizeof the bins in the histogram.131 /// @return The width of the bins in the histogram. 114 132 /// 115 133 inline double spacing(void) const { return (xmax_xmin_)/nof_bins(); } … … 118 136 /// @return The histogram upper boundary. 119 137 /// 120 /// @note The upper boundary value is inside the histogram.138 /// @note The upper boundary value is outside the histogram. 121 139 /// 122 140 inline double xmax(void) const { return xmax_; } … … 125 143 /// @return The histogram lower boundary. 126 144 /// 127 /// @note The lower boundary value is outside the histogram.145 /// @note The lower boundary value is inside the histogram. 128 146 /// 129 147 inline double xmin(void) const { return xmin_; } 130 148 131 149 /// 132 /// @return The count of bin \a k.in the histogram. 150 /// @return The count of bin \a k in the histogram. 151 /// 133 152 inline double operator[](size_t k) const { return histogram_[k]; } 134 153 135 154 /// 136 155 /// The assignment operator 156 /// 137 157 const Histogram& operator=(const Histogram&); 138 158
Note: See TracChangeset
for help on using the changeset viewer.