Skip to content

Commit

Permalink
ml
Browse files Browse the repository at this point in the history
  • Loading branch information
mzusin committed Feb 21, 2024
1 parent 681ebe7 commit 9a33e09
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/mz-math.esm.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/mz-math.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mz-math.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/mz-math.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mz-math.node.cjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/mz-math.node.cjs.map

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions src/main/ml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { getArithmeticMean, getStandardDeviation } from './statistics';

/**
* Returns a copy of array, where each value will be in the range [0, 1].
* const newValue = (value - array_min) / (array_max - array_min)
*/
export const mlNormalize = (data: number[], decimalPlaces = Infinity): number[] => {
const copy = [...data];
Expand All @@ -21,8 +20,12 @@ export const mlNormalize = (data: number[], decimalPlaces = Infinity): number[]
return copy;
};

/**
* Returns a copy of array, where each value will be in the range [-1, 1]
*/
export const mlStandardize = (data: number[], decimalPlaces = Infinity): number[] => {
const mean = getArithmeticMean(data) ?? 0;
const stdDev = getStandardDeviation(data, decimalPlaces);
return data.map(val => (val - mean) / stdDev);
const copy = [...data];
const mean = getArithmeticMean(copy) ?? 0;
const stdDev = getStandardDeviation(copy, decimalPlaces);
return copy.map(val => (val - mean) / stdDev);
};

0 comments on commit 9a33e09

Please sign in to comment.