Changeset 372


Ignore:
Timestamp:
Aug 5, 2005, 4:14:02 PM (18 years ago)
Author:
Peter
Message:

modified function normalize in histogram

Location:
trunk/lib/statistics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/statistics/Histogram.cc

    r298 r372  
    5555
    5656
    57 void Histogram::normalize(double scale_factor)
     57void Histogram::normalize(bool choice)
    5858{
     59  double scale_factor;
     60  if (choice)
     61    scale_factor = sum_all_.sum_w();
     62  else
     63    scale_factor = sum_all_.sum_w()*spacing();
    5964  for (size_t i=0; i<histogram_.size(); i++)
    6065    histogram_[i]/=scale_factor;
     66
    6167}
    6268
  • trunk/lib/statistics/Histogram.h

    r370 r372  
    8686
    8787    ///
    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.
    9189    ///
    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.
    9496    ///
    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);
    96114
    97115    ///
     
    111129
    112130    ///
    113     /// @return The size of the bins in the histogram.
     131    /// @return The width of the bins in the histogram.
    114132    ///
    115133    inline double spacing(void) const { return (xmax_-xmin_)/nof_bins(); }
     
    118136    /// @return The histogram upper boundary.
    119137    ///
    120     /// @note The upper boundary value is inside the histogram.
     138    /// @note The upper boundary value is outside the histogram.
    121139    ///
    122140    inline double xmax(void) const { return xmax_; }
     
    125143    /// @return The histogram lower boundary.
    126144    ///
    127     /// @note The lower boundary value is outside the histogram.
     145    /// @note The lower boundary value is inside the histogram.
    128146    ///
    129147    inline double xmin(void) const { return xmin_; }
    130148
    131149    ///
    132     /// @return The count of bin \a k.in the histogram.
     150    /// @return The count of bin \a k in the histogram.
     151    ///
    133152    inline double operator[](size_t k) const { return histogram_[k]; }
    134153
    135154    ///
    136155    /// The assignment operator
     156    ///
    137157    const Histogram& operator=(const Histogram&);
    138158
Note: See TracChangeset for help on using the changeset viewer.