Changeset 933 for trunk/yat/statistics


Ignore:
Timestamp:
Oct 5, 2007, 11:15:07 PM (16 years ago)
Author:
Peter
Message:

mad function now takes iterators

Location:
trunk/yat/statistics
Files:
2 edited

Legend:

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

    r932 r933  
    4848  }
    4949
    50   double mad(const utility::vector& vec, const bool sorted)
    51   {
    52     double m = median(vec.begin(), vec.end(), sorted);
    53     std::vector<double> ad;
    54     ad.reserve(vec.size());
    55     for (size_t i = 0; i<vec.size(); ++i)
    56       ad.push_back(fabs(vec[i]-m));
    57     std::sort(ad.begin(), ad.end());
    58     return median(ad.begin(), ad.end(),true);
    59   }
    60  
    6150
    6251  double skewness(const utility::vector& v)
  • trunk/yat/statistics/utility.h

    r932 r933  
    104104  /// @brief Median absolute deviation from median
    105105  ///
     106  /// Function is non-mutable function
     107  ///
    106108  template <class T>
    107   double mad(const std::vector<T>& vec, const bool sorted=false)
     109  double mad(T first, T last, const bool sorted=false)
    108110  {
    109     double m = median(vec, sorted);
     111    double m = median(first, last, sorted);
    110112    std::vector<double> ad;
    111     ad.reserve(vec.size());
    112     for (size_t i = 0; i<vec.size(); ++i)
    113       ad.push_back(fabs(vec[i]-m));
     113    ad.reserve(std::distance(first, last));
     114    for( ; first!=last; ++first)
     115      ad.push_back(fabs(*first-m));
    114116    std::sort(ad.begin(), ad.end());
    115     return median(ad.begin(), ad.end(),true);
     117    return median(ad.begin(), ad.end(), true);
    116118  }
    117  
    118 
    119   ///
    120   /// @brief Median absolute deviation from median
    121   ///
    122   double mad(const utility::vector& vec, const bool sorted=false);
    123119 
    124120
     
    130126  /// used to calculate the median.
    131127  ///
     128  /// Function is a non-mutable function, i.e., \a first and \a last
     129  /// can be const_iterators.
     130  ///
    132131  /// Requirements: T should be an iterator over a range of doubles (or
    133   /// any type being convertable to double). If \a sorted is false
    134   /// iterator must be mutable, else read-only iterator is also ok.
     132  /// any type being convertable to double).
    135133  ///
    136134  /// @return median of range
     
    151149     and then used to calculate the median.
    152150
     151     Function is a non-mutable function, i.e., \a first and \a last
     152     can be const_iterators.
     153     
    153154     Requirements: T should be an iterator over a range of doubles (or
    154155     any type being convertable to double). If \a sorted is false
Note: See TracChangeset for help on using the changeset viewer.