zoukankan      html  css  js  c++  java
  • 中位数计算

    template <class T>
    double VectorMedian(std::vector<T> &In) {
        std::sort(In.begin(), In.end());
        if(In.size() % 2 == 0) {
            return 0.5*(In.at(In.size()/2)+In.at(In.size()/2-1));
        }
        else
            return In.at((In.size()-1)/2);
    }

    Let {x(1), x(2), ..., x(m)} represent the values of x after they have been sorted in non-decreasing order.

    x(1)=min(x) and x(m)=max(x).

    median(x): x(r+1) if m is odd, i.e., m=2r+1

                     0.5*(x(r)+x(r+1)) if m is even, i.e., m=2r

    Thus, for seven values, the median is x(4), while for ten values, the median is 0.5*(x(5)+x(6)).

    The mean can be distorted by outliers, and since the variance is computed using the mean, it is also sensitive to outliers.

    Indeed, the variance is particularly sensitive to outliers since it uses the squared difference between the mean and other values.

  • 相关阅读:
    PetaPoco.Core.ttinclude修改
    NoCache
    MapHttpRoute
    打印print
    Throttling ASP.NET Web API calls
    CodeFirst进行数据迁移之添加字段
    sql 获取filename
    image onclick
    验证
    Unity3d疑难问题解决
  • 原文地址:https://www.cnblogs.com/donggongdechen/p/10685771.html
Copyright © 2011-2022 走看看