Ignore:
Timestamp:
Oct 7, 2006, 8:44:31 AM (16 years ago)
Author:
Peter
Message:

added MAD function in statistics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/c++_tools/statistics/utility.cc

    r616 r672  
    1717    return p;
    1818  }
     19
     20  double mad(const utility::vector& vec, const bool sorted)
     21  {
     22    double m = median(vec, sorted);
     23    std::vector<double> ad;
     24    ad.reserve(vec.size());
     25    for (size_t i = 0; i<vec.size(); ++i)
     26      ad.push_back(fabs(vec[i]-m));
     27    std::sort(ad.begin(), ad.end());
     28    return median(ad,true);
     29  }
     30 
    1931
    2032  double median(const utility::vector& vec, const bool sorted)
Note: See TracChangeset for help on using the changeset viewer.