Ignore:
Timestamp:
May 15, 2008, 12:25:54 AM (13 years ago)
Author:
Peter
Message:

Adding a functor that calculate average of a range. Also added a metafunction that return Averager or AveragerWeighted? depending on context.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/statistics/utility.h

    r1275 r1305  
    2929*/
    3030
     31#include "averager_traits.h"
    3132#include "yat/classifier/DataLookupWeighted1D.h"
    3233#include "yat/classifier/Target.h"
     
    4445namespace yat {
    4546namespace statistics { 
     47
     48  /**
     49     \brief Functor to take average of a range.
     50   */
     51  struct Average
     52  {
     53    /**
     54       If range is weighted an AveragerWeighted is used else a Averager.
     55       
     56       \return average of range
     57     */
     58    template<typename ForwardIterator>
     59    inline double operator()(ForwardIterator first, ForwardIterator last) const
     60    {
     61      typename averager<ForwardIterator>::type a;
     62      add(a, first, last);
     63      return a.mean();
     64    }
     65
     66  };
     67
     68
    4669
    4770  //forward declarations
     
    77100  ///
    78101  /// @return cumulative hypergeomtric distribution functions P(k).
     102  ///
     103  /// \deprecated
    79104  ///
    80105  double cdf_hypergeometric_P(unsigned int k, unsigned int n1,
     
    167192  double percentile(T first, T last, double p, bool sorted=false)
    168193  {
    169     utility::yat_assert<std::range_error>(first<last);
     194    utility::yat_assert<std::range_error>(first<last,
     195                                          "percentile: invalid range");
    170196    utility::yat_assert<std::runtime_error>(p>=0, "percentage is negative");
    171197    utility::yat_assert<std::runtime_error>(p<=100,
Note: See TracChangeset for help on using the changeset viewer.