Changeset 933 for trunk/yat/statistics
 Timestamp:
 Oct 5, 2007, 11:15:07 PM (15 years ago)
 Location:
 trunk/yat/statistics
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/statistics/utility.cc
r932 r933 48 48 } 49 49 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 61 50 62 51 double skewness(const utility::vector& v) 
trunk/yat/statistics/utility.h
r932 r933 104 104 /// @brief Median absolute deviation from median 105 105 /// 106 /// Function is nonmutable function 107 /// 106 108 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) 108 110 { 109 double m = median( vec, sorted);111 double m = median(first, last, sorted); 110 112 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(*firstm)); 114 116 std::sort(ad.begin(), ad.end()); 115 return median(ad.begin(), ad.end(), true);117 return median(ad.begin(), ad.end(), true); 116 118 } 117 118 119 ///120 /// @brief Median absolute deviation from median121 ///122 double mad(const utility::vector& vec, const bool sorted=false);123 119 124 120 … … 130 126 /// used to calculate the median. 131 127 /// 128 /// Function is a nonmutable function, i.e., \a first and \a last 129 /// can be const_iterators. 130 /// 132 131 /// 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 readonly iterator is also ok. 132 /// any type being convertable to double). 135 133 /// 136 134 /// @return median of range … … 151 149 and then used to calculate the median. 152 150 151 Function is a nonmutable function, i.e., \a first and \a last 152 can be const_iterators. 153 153 154 Requirements: T should be an iterator over a range of doubles (or 154 155 any type being convertable to double). If \a sorted is false
Note: See TracChangeset
for help on using the changeset viewer.