Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 1f59d11

Browse files
committed
fix(benchmark): fix standard deviation calculation
Previous algorithm was dividing total of squares by sample length, where it should have been dividing by sample length minus 1
1 parent 4614cc0 commit 1f59d11

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

benchmark/web/bp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bp.Statistics.calculateStandardDeviation = function(sample, mean) {
3737
sample.forEach(function(x) {
3838
deviation += Math.pow(x - mean, 2);
3939
});
40-
deviation = deviation / sample.length;
40+
deviation = deviation / (sample.length -1);
4141
deviation = Math.sqrt(deviation);
4242
return deviation;
4343
};

benchmark/web/bp.spec.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ describe('bp', function() {
5858
it('should provide the correct standardDeviation for the provided sample and mean', function() {
5959
expect(bp.Statistics.calculateStandardDeviation([
6060
2,4,4,4,5,5,7,9
61-
], 5)).toBe(2);
61+
], 5)).toBe(2.138089935299395);
62+
});
63+
64+
65+
it('should provide the correct standardDeviation for the provided sample and mean', function() {
66+
expect(bp.Statistics.calculateStandardDeviation([
67+
674.64,701.78,668.33,662.15,663.34,677.32,664.25,1233.00,1100.80,716.15,681.52,671.23,702.70,686.89,939.39,830.28,695.46,695.66,675.15,667.48], 750.38)).toBe(158.57877026559186);
6268
});
6369
});
6470
});

0 commit comments

Comments
 (0)