From bb32caf569860bc7dba18ec11d9c5ba302aaf315 Mon Sep 17 00:00:00 2001 From: focus1691 Date: Tue, 10 Sep 2024 23:34:51 +0100 Subject: [PATCH] option to normalise the zscore --- src/lib/zscores/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/zscores/index.ts b/src/lib/zscores/index.ts index 3a04c43f..985ad062 100644 --- a/src/lib/zscores/index.ts +++ b/src/lib/zscores/index.ts @@ -9,7 +9,11 @@ export class ZScoreOutput { } export class ZScore { - public static calc(input: number[], lag: number, threshold: number, influence: number): ZScoreOutput { + public static calc(input: number[], lag: number, threshold: number, influence: number, normaliseData?: boolean): ZScoreOutput { + if (normaliseData) { + input = ZScore.normaliseData(input); + } + const result: ZScoreOutput = new ZScoreOutput() const signals: number[] = Array(input.length).fill(0) const filteredY: number[] = input.slice(0) @@ -88,4 +92,10 @@ export class ZScore { return round(stdDev) } + + private static normaliseData(data: number[]): number[] { + const min = Math.min(...data); + const max = Math.max(...data); + return data.map(value => (value - min) / (max - min)); + } }