double MyMethod::getStandardDeviation(double* info, int length)
{
double result = 0;//存放每个值与平均值差的平方和
double average = MyMethod::getAverage(info, length);//得到平均值
for (int i = 0; i < length; i++)
{
result += (info[i] - average)*(info[i] - average);
}
result /= (length - 1);//方差
result = sqrt(result);//标准差
return result;
}
double MyMethod::getVariance(double* info, int length)
{
double result = 0;//存放每个值与平均值差的平方和
double average = MyMethod::getAverage(info, length);//得到平均值
for (int i = 0; i < length;i++)
{
result += (info[i] - average)*(info[i] - average);
}
result /= (length - 1);
return result;
}
用的是样本方差【不是全体方差】,样本数需要-1