From: Jérôme Benoit Date: Fri, 15 Sep 2023 20:08:51 +0000 (+0200) Subject: refactor: cleanup standard deviation implementation X-Git-Tag: v1.2.22~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8f60746ca1192bfcab03d890016a4704703a701a;p=e-mobility-charging-stations-simulator.git refactor: cleanup standard deviation implementation Signed-off-by: Jérôme Benoit --- diff --git a/src/utils/StatisticUtils.ts b/src/utils/StatisticUtils.ts index ecd47a17..7f338ff9 100644 --- a/src/utils/StatisticUtils.ts +++ b/src/utils/StatisticUtils.ts @@ -68,9 +68,9 @@ export const stdDeviation = ( dataSet: number[], dataSetAverage: number = average(dataSet), ): number => { - const geometricDeviation = dataSet.reduce((accumulator, nb) => { - const deviation = nb - dataSetAverage; - return accumulator + deviation * deviation; - }, 0); - return Math.sqrt(geometricDeviation / dataSet.length); + return Math.sqrt( + dataSet.reduce((accumulator, num) => { + return accumulator + Math.pow(num - dataSetAverage, 2); + }, 0) / dataSet.length, + ); };