gpt4 book ai didi

algorithm - 标准差证明的在线算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:18:26 24 4
gpt4 key购买 nike

<分区>

我在对这个 question 的回答中看到了这个算法.

这是否正确计算了标准偏差?有人可以告诉我为什么这在数学上有效吗?最好从这个公式开始工作:

enter image description here

public class Statistics {

private int n;
private double sum;
private double sumsq;

public void reset() {
this.n = 0;
this.sum = 0.0;
this.sumsq = 0.0;
}

public synchronized void addValue(double x) {
++this.n;
this.sum += x;
this.sumsq += x*x;
}

public synchronized double calculateMean() {
double mean = 0.0;
if (this.n > 0) {
mean = this.sum/this.n;
}
return mean;
}

public synchronized double calculateStandardDeviation() {
double deviation = 0.0;
if (this.n > 1) {
deviation = Math.sqrt((this.sumsq - this.sum*this.sum/this.n)/(this.n-1));
}
return deviation;
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com