Skip to content

Commit

Permalink
numerically more stable variance; but I think this could still be muc…
Browse files Browse the repository at this point in the history
…h better
  • Loading branch information
kgyrtkirk committed Aug 18, 2023
1 parent db916dc commit 48019e6
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,35 +127,23 @@ public VarianceAggregatorCollector(long count, double sum, double nvariance)

public VarianceAggregatorCollector add(float v)
{
count++;
sum += v;
if (count > 1) {
double t = count * v - sum;
nvariance += (t * t) / ((double) count * (count - 1));
}
return this;
return add((double)v);
}

public VarianceAggregatorCollector add(double v)
{
count++;
sum += v;
if (count > 1) {
double t = count * v - sum;
nvariance += (t * t) / ((double) count * (count - 1));
double t = v - sum / count;
nvariance += (t * t) * count / (count - 1);
}
return this;
}

public VarianceAggregatorCollector add(long v)
{
count++;
sum += v;
if (count > 1) {
double t = count * v - sum;
nvariance += (t * t) / ((double) count * (count - 1));
}
return this;
return add((double)v);
}

@Nullable
Expand Down

0 comments on commit 48019e6

Please sign in to comment.