标准差、方差
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
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html