Skip to content

Commit

Permalink
option to normalise the zscore
Browse files Browse the repository at this point in the history
  • Loading branch information
focus1691 committed Sep 10, 2024
1 parent 6af8e85 commit bb32caf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lib/zscores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
}

0 comments on commit bb32caf

Please sign in to comment.