@seanhogg/builderforce-memory-engine 2026.9.34 → 2026.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/evermind/delta_wire.d.ts +26 -2
- package/dist/evermind/delta_wire.d.ts.map +1 -1
- package/dist/evermind/delta_wire.js +46 -4
- package/dist/evermind/delta_wire.js.map +1 -1
- package/dist/evermind/index.d.ts +5 -5
- package/dist/evermind/index.d.ts.map +1 -1
- package/dist/evermind/index.js +2 -2
- package/dist/evermind/index.js.map +1 -1
- package/dist/evermind/merge.d.ts +28 -0
- package/dist/evermind/merge.d.ts.map +1 -1
- package/dist/evermind/merge.js +33 -0
- package/dist/evermind/merge.js.map +1 -1
- package/dist/evermind/ml_head.d.ts +28 -0
- package/dist/evermind/ml_head.d.ts.map +1 -0
- package/dist/evermind/ml_head.js +47 -0
- package/dist/evermind/ml_head.js.map +1 -0
- package/dist/evermind/package.d.ts +9 -0
- package/dist/evermind/package.d.ts.map +1 -1
- package/dist/evermind/package.js +20 -0
- package/dist/evermind/package.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/limbic/index.d.ts +3 -0
- package/dist/limbic/index.d.ts.map +1 -1
- package/dist/limbic/index.js +3 -0
- package/dist/limbic/index.js.map +1 -1
- package/dist/limbic/limbic_model.d.ts.map +1 -1
- package/dist/limbic/limbic_model.js +1 -3
- package/dist/limbic/limbic_model.js.map +1 -1
- package/dist/limbic/limbic_task.d.ts +22 -0
- package/dist/limbic/limbic_task.d.ts.map +1 -0
- package/dist/limbic/limbic_task.js +45 -0
- package/dist/limbic/limbic_task.js.map +1 -0
- package/dist/limbic/limbic_trainer.d.ts +17 -30
- package/dist/limbic/limbic_trainer.d.ts.map +1 -1
- package/dist/limbic/limbic_trainer.js +38 -144
- package/dist/limbic/limbic_trainer.js.map +1 -1
- package/dist/ml/classical/anomaly_composite.d.ts +32 -0
- package/dist/ml/classical/anomaly_composite.d.ts.map +1 -0
- package/dist/ml/classical/anomaly_composite.js +29 -0
- package/dist/ml/classical/anomaly_composite.js.map +1 -0
- package/dist/ml/classical/ewma.d.ts +37 -0
- package/dist/ml/classical/ewma.d.ts.map +1 -0
- package/dist/ml/classical/ewma.js +48 -0
- package/dist/ml/classical/ewma.js.map +1 -0
- package/dist/ml/classical/gbm.d.ts +42 -0
- package/dist/ml/classical/gbm.d.ts.map +1 -0
- package/dist/ml/classical/gbm.js +117 -0
- package/dist/ml/classical/gbm.js.map +1 -0
- package/dist/ml/classical/index.d.ts +52 -0
- package/dist/ml/classical/index.d.ts.map +1 -0
- package/dist/ml/classical/index.js +49 -0
- package/dist/ml/classical/index.js.map +1 -0
- package/dist/ml/classical/isolation_forest.d.ts +37 -0
- package/dist/ml/classical/isolation_forest.d.ts.map +1 -0
- package/dist/ml/classical/isolation_forest.js +72 -0
- package/dist/ml/classical/isolation_forest.js.map +1 -0
- package/dist/ml/classical/kmeans.d.ts +31 -0
- package/dist/ml/classical/kmeans.d.ts.map +1 -0
- package/dist/ml/classical/kmeans.js +112 -0
- package/dist/ml/classical/kmeans.js.map +1 -0
- package/dist/ml/classical/knn.d.ts +51 -0
- package/dist/ml/classical/knn.d.ts.map +1 -0
- package/dist/ml/classical/knn.js +69 -0
- package/dist/ml/classical/knn.js.map +1 -0
- package/dist/ml/classical/linear.d.ts +29 -0
- package/dist/ml/classical/linear.d.ts.map +1 -0
- package/dist/ml/classical/linear.js +114 -0
- package/dist/ml/classical/linear.js.map +1 -0
- package/dist/ml/classical/logistic.d.ts +31 -0
- package/dist/ml/classical/logistic.d.ts.map +1 -0
- package/dist/ml/classical/logistic.js +111 -0
- package/dist/ml/classical/logistic.js.map +1 -0
- package/dist/ml/classical/math.d.ts +26 -0
- package/dist/ml/classical/math.d.ts.map +1 -0
- package/dist/ml/classical/math.js +90 -0
- package/dist/ml/classical/math.js.map +1 -0
- package/dist/ml/classical/naive_bayes.d.ts +28 -0
- package/dist/ml/classical/naive_bayes.d.ts.map +1 -0
- package/dist/ml/classical/naive_bayes.js +72 -0
- package/dist/ml/classical/naive_bayes.js.map +1 -0
- package/dist/ml/classical/robust_z.d.ts +38 -0
- package/dist/ml/classical/robust_z.d.ts.map +1 -0
- package/dist/ml/classical/robust_z.js +47 -0
- package/dist/ml/classical/robust_z.js.map +1 -0
- package/dist/ml/dense_head.d.ts +33 -0
- package/dist/ml/dense_head.d.ts.map +1 -0
- package/dist/ml/dense_head.js +140 -0
- package/dist/ml/dense_head.js.map +1 -0
- package/dist/ml/eval_loss.d.ts +15 -0
- package/dist/ml/eval_loss.d.ts.map +1 -0
- package/dist/ml/eval_loss.js +20 -0
- package/dist/ml/eval_loss.js.map +1 -0
- package/dist/ml/features.d.ts +25 -0
- package/dist/ml/features.d.ts.map +1 -0
- package/dist/ml/features.js +46 -0
- package/dist/ml/features.js.map +1 -0
- package/dist/ml/federate.d.ts +56 -0
- package/dist/ml/federate.d.ts.map +1 -0
- package/dist/ml/federate.js +99 -0
- package/dist/ml/federate.js.map +1 -0
- package/dist/ml/head_trainer.d.ts +78 -0
- package/dist/ml/head_trainer.d.ts.map +1 -0
- package/dist/ml/head_trainer.js +182 -0
- package/dist/ml/head_trainer.js.map +1 -0
- package/dist/ml/index.d.ts +23 -0
- package/dist/ml/index.d.ts.map +1 -0
- package/dist/ml/index.js +11 -0
- package/dist/ml/index.js.map +1 -0
- package/dist/ml/registry.d.ts +20 -0
- package/dist/ml/registry.d.ts.map +1 -0
- package/dist/ml/registry.js +43 -0
- package/dist/ml/registry.js.map +1 -0
- package/dist/ml/run.d.ts +103 -0
- package/dist/ml/run.d.ts.map +1 -0
- package/dist/ml/run.js +169 -0
- package/dist/ml/run.js.map +1 -0
- package/dist/ml/tasks/experience.d.ts +127 -0
- package/dist/ml/tasks/experience.d.ts.map +1 -0
- package/dist/ml/tasks/experience.js +213 -0
- package/dist/ml/tasks/experience.js.map +1 -0
- package/dist/ml/tasks/index.d.ts +10 -0
- package/dist/ml/tasks/index.d.ts.map +1 -0
- package/dist/ml/tasks/index.js +28 -0
- package/dist/ml/tasks/index.js.map +1 -0
- package/dist/ml/tasks/local_success.d.ts +55 -0
- package/dist/ml/tasks/local_success.d.ts.map +1 -0
- package/dist/ml/tasks/local_success.js +77 -0
- package/dist/ml/tasks/local_success.js.map +1 -0
- package/dist/ml/tasks/run_anomaly.d.ts +52 -0
- package/dist/ml/tasks/run_anomaly.d.ts.map +1 -0
- package/dist/ml/tasks/run_anomaly.js +50 -0
- package/dist/ml/tasks/run_anomaly.js.map +1 -0
- package/dist/ml/train.d.ts +59 -0
- package/dist/ml/train.d.ts.map +1 -0
- package/dist/ml/train.js +84 -0
- package/dist/ml/train.js.map +1 -0
- package/dist/ml/types.d.ts +115 -0
- package/dist/ml/types.d.ts.map +1 -0
- package/dist/ml/types.js +24 -0
- package/dist/ml/types.js.map +1 -0
- package/dist/moe/moe_model.d.ts.map +1 -1
- package/dist/moe/moe_model.js +1 -16
- package/dist/moe/moe_model.js.map +1 -1
- package/dist/training/cpu_ops.d.ts +2 -0
- package/dist/training/cpu_ops.d.ts.map +1 -1
- package/dist/training/cpu_ops.js +16 -0
- package/dist/training/cpu_ops.js.map +1 -1
- package/package.json +1 -1
- package/src/evermind/delta_wire.ts +63 -4
- package/src/evermind/index.ts +7 -3
- package/src/evermind/merge.ts +59 -0
- package/src/evermind/ml_head.ts +63 -0
- package/src/evermind/package.ts +24 -0
- package/src/index.ts +17 -1
- package/src/limbic/index.ts +5 -0
- package/src/limbic/limbic_model.ts +1 -4
- package/src/limbic/limbic_task.ts +62 -0
- package/src/limbic/limbic_trainer.ts +41 -208
- package/src/ml/classical/anomaly_composite.ts +46 -0
- package/src/ml/classical/ewma.ts +74 -0
- package/src/ml/classical/gbm.ts +144 -0
- package/src/ml/classical/index.ts +82 -0
- package/src/ml/classical/isolation_forest.ts +88 -0
- package/src/ml/classical/kmeans.ts +120 -0
- package/src/ml/classical/knn.ts +102 -0
- package/src/ml/classical/linear.ts +119 -0
- package/src/ml/classical/logistic.ts +125 -0
- package/src/ml/classical/math.ts +93 -0
- package/src/ml/classical/naive_bayes.ts +84 -0
- package/src/ml/classical/robust_z.ts +74 -0
- package/src/ml/dense_head.ts +157 -0
- package/src/ml/eval_loss.ts +27 -0
- package/src/ml/features.ts +61 -0
- package/src/ml/federate.ts +130 -0
- package/src/ml/head_trainer.ts +247 -0
- package/src/ml/index.ts +57 -0
- package/src/ml/registry.ts +44 -0
- package/src/ml/run.ts +222 -0
- package/src/ml/tasks/experience.ts +293 -0
- package/src/ml/tasks/index.ts +30 -0
- package/src/ml/tasks/local_success.ts +118 -0
- package/src/ml/tasks/run_anomaly.ts +84 -0
- package/src/ml/train.ts +120 -0
- package/src/ml/types.ts +135 -0
- package/src/moe/moe_model.ts +1 -13
- package/src/training/cpu_ops.ts +14 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limbic_trainer.js","sourceRoot":"","sources":["../../src/limbic/limbic_trainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"limbic_trainer.js","sourceRoot":"","sources":["../../src/limbic/limbic_trainer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,WAAW,EAA6C,MAAM,uBAAuB,CAAC;AAkB/F;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAkB;IAC3C,OAAO;QACL,UAAU,EAAE,GAAkB,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE;QACnD,SAAS,EAAE,GAAkB,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE;QACjD,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE;QAChC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAChB,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,UAA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;IAClD,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;IACnC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAuB,EAAE,OAA2B,EAAE;QAC1D,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,+EAA+E;IAC/E,QAAQ,CAAC,OAAuB;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ml/classical/anomaly_composite.ts — robust z and EWMA as ONE anomaly engine.
|
|
3
|
+
*
|
|
4
|
+
* Two detectors, one answer: robust z (median/MAD over the whole history — "far
|
|
5
|
+
* from normal") and EWMA (the recent trend — "drifting away from lately"). The
|
|
6
|
+
* score is the larger of the two normalised scores, so either one can flag. It is
|
|
7
|
+
* one engine because it is one fitted thing: a task that lists it gets back exactly
|
|
8
|
+
* what it stores under `local:classical:anomaly-composite`.
|
|
9
|
+
*/
|
|
10
|
+
import type { MlPrediction, MlPredictor, MlSample } from "../types.js";
|
|
11
|
+
import { EwmaModel, type EwmaOptions } from "./ewma.js";
|
|
12
|
+
import { RobustZModel, type RobustZOptions } from "./robust_z.js";
|
|
13
|
+
export interface AnomalyCompositeOptions {
|
|
14
|
+
robustZ?: RobustZOptions;
|
|
15
|
+
ewma?: EwmaOptions;
|
|
16
|
+
}
|
|
17
|
+
export declare class AnomalyCompositeModel implements MlPredictor {
|
|
18
|
+
readonly population: RobustZModel;
|
|
19
|
+
readonly trend: EwmaModel;
|
|
20
|
+
constructor(population: RobustZModel, trend: EwmaModel);
|
|
21
|
+
/** Per feature, per detector: z / threshold (≥ 1 = out of range). */
|
|
22
|
+
featureScores(x: ArrayLike<number>): {
|
|
23
|
+
population: number;
|
|
24
|
+
trend: number;
|
|
25
|
+
}[];
|
|
26
|
+
/** Fold a finished, non-anomalous observation into the trend. */
|
|
27
|
+
observe(x: ArrayLike<number>): void;
|
|
28
|
+
predict(x: Float32Array): MlPrediction;
|
|
29
|
+
}
|
|
30
|
+
/** Fit both detectors on a chronological history (feature vectors, oldest first). */
|
|
31
|
+
export declare function fitAnomalyComposite(samples: readonly MlSample[], opts?: AnomalyCompositeOptions): AnomalyCompositeModel;
|
|
32
|
+
//# sourceMappingURL=anomaly_composite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anomaly_composite.d.ts","sourceRoot":"","sources":["../../../src/ml/classical/anomaly_composite.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,SAAS,EAAW,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAiC,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEjG,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,qBAAa,qBAAsB,YAAW,WAAW;IAErD,QAAQ,CAAC,UAAU,EAAE,YAAY;IACjC,QAAQ,CAAC,KAAK,EAAE,SAAS;gBADhB,UAAU,EAAE,YAAY,EACxB,KAAK,EAAE,SAAS;IAG3B,qEAAqE;IACrE,aAAa,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE;IAM5E,iEAAiE;IACjE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI;IAInC,OAAO,CAAC,CAAC,EAAE,YAAY,GAAG,YAAY;CAIvC;AAED,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,IAAI,GAAE,uBAA4B,GAAG,qBAAqB,CAE3H"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { fitEwma } from "./ewma.js";
|
|
2
|
+
import { anomalyConfidence, fitRobustZ } from "./robust_z.js";
|
|
3
|
+
export class AnomalyCompositeModel {
|
|
4
|
+
population;
|
|
5
|
+
trend;
|
|
6
|
+
constructor(population, trend) {
|
|
7
|
+
this.population = population;
|
|
8
|
+
this.trend = trend;
|
|
9
|
+
}
|
|
10
|
+
/** Per feature, per detector: z / threshold (≥ 1 = out of range). */
|
|
11
|
+
featureScores(x) {
|
|
12
|
+
const pz = this.population.zScores(x);
|
|
13
|
+
const tz = this.trend.zScores(x);
|
|
14
|
+
return pz.map((z, i) => ({ population: z / this.population.threshold, trend: tz[i] / this.trend.threshold }));
|
|
15
|
+
}
|
|
16
|
+
/** Fold a finished, non-anomalous observation into the trend. */
|
|
17
|
+
observe(x) {
|
|
18
|
+
this.trend.update(x);
|
|
19
|
+
}
|
|
20
|
+
predict(x) {
|
|
21
|
+
const score = Math.max(this.population.predict(x).scores[0], this.trend.predict(x).scores[0]);
|
|
22
|
+
return { scores: [score], confidence: anomalyConfidence(score) };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Fit both detectors on a chronological history (feature vectors, oldest first). */
|
|
26
|
+
export function fitAnomalyComposite(samples, opts = {}) {
|
|
27
|
+
return new AnomalyCompositeModel(fitRobustZ(samples, opts.robustZ), fitEwma(samples, opts.ewma));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=anomaly_composite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anomaly_composite.js","sourceRoot":"","sources":["../../../src/ml/classical/anomaly_composite.ts"],"names":[],"mappings":"AAUA,OAAO,EAAa,OAAO,EAAoB,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAqC,M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C,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ml/classical/ewma.ts — exponentially-weighted moving average + variance, for
|
|
3
|
+
* drift anomalies in an ordered series (a run's cost creeping up over the week).
|
|
4
|
+
*
|
|
5
|
+
* Per feature, over the history IN ORDER: diff = x − μ; μ += α·diff;
|
|
6
|
+
* σ² = (1 − α)(σ² + α·diff²). A new point scores z = |x − μ| / σ against the
|
|
7
|
+
* state BEFORE it is folded in. Prediction: `scores[0] = max_i z_i / threshold`.
|
|
8
|
+
* σ is floored like robust z's scale: a fraction of |μ|, and `minScale` in absolute
|
|
9
|
+
* units — σ² starts at 0, so a constant history would otherwise flag any change.
|
|
10
|
+
*/
|
|
11
|
+
import type { MlPrediction, MlPredictor, MlSample } from "../types.js";
|
|
12
|
+
export interface EwmaOptions {
|
|
13
|
+
/** Smoothing factor in (0, 1]. Default 0.3. */
|
|
14
|
+
alpha?: number;
|
|
15
|
+
/** z at which a feature counts as anomalous. Default 3. */
|
|
16
|
+
threshold?: number;
|
|
17
|
+
/** Smallest σ per feature, as a fraction of |μ| (plus 1e-9). Default 0.01. */
|
|
18
|
+
minScaleFraction?: number;
|
|
19
|
+
/** Smallest σ per feature in absolute feature units. Default 0 (see `RobustZOptions.minScale`). */
|
|
20
|
+
minScale?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare class EwmaModel implements MlPredictor {
|
|
23
|
+
readonly mean: Float64Array;
|
|
24
|
+
readonly variance: Float64Array;
|
|
25
|
+
readonly alpha: number;
|
|
26
|
+
readonly threshold: number;
|
|
27
|
+
readonly minScaleFraction: number;
|
|
28
|
+
readonly minScale: number;
|
|
29
|
+
constructor(mean: Float64Array, variance: Float64Array, alpha: number, threshold: number, minScaleFraction: number, minScale?: number);
|
|
30
|
+
zScores(x: ArrayLike<number>): number[];
|
|
31
|
+
/** Fold one observation into the running state. */
|
|
32
|
+
update(x: ArrayLike<number>): void;
|
|
33
|
+
predict(x: Float32Array): MlPrediction;
|
|
34
|
+
}
|
|
35
|
+
/** Fit over `samples` in the given (chronological) order. */
|
|
36
|
+
export declare function fitEwma(samples: readonly MlSample[], opts?: EwmaOptions): EwmaModel;
|
|
37
|
+
//# sourceMappingURL=ewma.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ewma.d.ts","sourceRoot":"","sources":["../../../src/ml/classical/ewma.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvE,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mGAAmG;IACnG,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,SAAU,YAAW,WAAW;IAEzC,QAAQ,CAAC,IAAI,EAAE,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,YAAY;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM;gBALhB,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,GAAE,MAAU;IAK/B,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE;IAOvC,mDAAmD;IACnD,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI;IASlC,OAAO,CAAC,CAAC,EAAE,YAAY,GAAG,YAAY;CAIvC;AAED,6DAA6D;AAC7D,wBAAgB,OAAO,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,IAAI,GAAE,WAAgB,GAAG,SAAS,CAYvF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { featureDim } from "./math.js";
|
|
2
|
+
import { anomalyConfidence } from "./robust_z.js";
|
|
3
|
+
export class EwmaModel {
|
|
4
|
+
mean;
|
|
5
|
+
variance;
|
|
6
|
+
alpha;
|
|
7
|
+
threshold;
|
|
8
|
+
minScaleFraction;
|
|
9
|
+
minScale;
|
|
10
|
+
constructor(mean, variance, alpha, threshold, minScaleFraction, minScale = 0) {
|
|
11
|
+
this.mean = mean;
|
|
12
|
+
this.variance = variance;
|
|
13
|
+
this.alpha = alpha;
|
|
14
|
+
this.threshold = threshold;
|
|
15
|
+
this.minScaleFraction = minScaleFraction;
|
|
16
|
+
this.minScale = minScale;
|
|
17
|
+
if (!(alpha > 0 && alpha <= 1))
|
|
18
|
+
throw new Error(`EwmaModel: alpha must be in (0, 1] (got ${alpha})`);
|
|
19
|
+
}
|
|
20
|
+
zScores(x) {
|
|
21
|
+
return Array.from(this.mean, (m, i) => {
|
|
22
|
+
const sd = Math.max(Math.sqrt(this.variance[i]), this.minScaleFraction * Math.abs(m) + 1e-9, this.minScale);
|
|
23
|
+
return Math.abs((x[i] ?? 0) - m) / sd;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Fold one observation into the running state. */
|
|
27
|
+
update(x) {
|
|
28
|
+
for (let i = 0; i < this.mean.length; i++) {
|
|
29
|
+
const diff = (x[i] ?? 0) - this.mean[i];
|
|
30
|
+
const incr = this.alpha * diff;
|
|
31
|
+
this.mean[i] = this.mean[i] + incr;
|
|
32
|
+
this.variance[i] = (1 - this.alpha) * (this.variance[i] + diff * incr);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
predict(x) {
|
|
36
|
+
const score = Math.max(0, ...this.zScores(x)) / this.threshold;
|
|
37
|
+
return { scores: [score], confidence: anomalyConfidence(score) };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Fit over `samples` in the given (chronological) order. */
|
|
41
|
+
export function fitEwma(samples, opts = {}) {
|
|
42
|
+
const d = featureDim(samples.map((s) => s.x));
|
|
43
|
+
const model = new EwmaModel(Float64Array.from(samples[0].x), new Float64Array(d), opts.alpha ?? 0.3, opts.threshold ?? 3, opts.minScaleFraction ?? 0.01, opts.minScale ?? 0);
|
|
44
|
+
for (let i = 1; i < samples.length; i++)
|
|
45
|
+
model.update(samples[i].x);
|
|
46
|
+
return model;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=ewma.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ewma.js","sourceRoot":"","sources":["../../../src/ml/classical/ewma.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAalD,MAAM,OAAO,SAAS;IAET;IACA;IACA;IACA;IACA;IACA;IANX,YACW,IAAkB,EAClB,QAAsB,EACtB,KAAa,EACb,SAAiB,EACjB,gBAAwB,EACxB,WAAmB,CAAC;QALpB,SAAI,GAAJ,IAAI,CAAc;QAClB,aAAQ,GAAR,QAAQ,CAAc;QACtB,UAAK,GAAL,KAAK,CAAQ;QACb,cAAS,GAAT,SAAS,CAAQ;QACjB,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,aAAQ,GAAR,QAAQ,CAAY;QAE7B,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,KAAK,GAAG,CAAC,CAAC;IACvG,CAAC;IAED,OAAO,CAAC,CAAoB;QAC1B,OAAO,K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AAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;QAC/D,OAAO,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;IACnE,CAAC;CACF;AAED,6DAA6D;AAC7D,MAAM,UAAU,OAAO,CAAC,OAA4B,EAAE,OAAoB,EAAE;IAC1E,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,IAAI,SAAS,CACzB,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,EAChC,IAAI,YAAY,CAAC,CAAC,CAAC,EACnB,IAAI,CAAC,KAAK,IAAI,GAAG,EACjB,IAAI,CAAC,SAAS,IAAI,CAAC,EACnB,IAAI,CAAC,gBAAgB,IAAI,IAAI,EAC7B,IAAI,CAAC,QAAQ,IAAI,CAAC,CACnB,CAAC;IACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC;IACrE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ml/classical/gbm.ts — a small gradient-boosted tree ensemble.
|
|
3
|
+
*
|
|
4
|
+
* Depth-limited regression trees fitted to the loss gradient, one after another,
|
|
5
|
+
* shrunk by a learning rate. Objectives: `binary` (log-loss, Newton leaf values)
|
|
6
|
+
* and `regression` (squared error). Exhaustive split search over midpoints —
|
|
7
|
+
* fine for the catalog's small numeric feature sets, not for wide embeddings.
|
|
8
|
+
*/
|
|
9
|
+
import type { MlPrediction, MlPredictor, MlSample } from "../types.js";
|
|
10
|
+
import { type Vec } from "./math.js";
|
|
11
|
+
export type GbmObjective = "binary" | "regression";
|
|
12
|
+
export interface GbmOptions {
|
|
13
|
+
objective?: GbmObjective;
|
|
14
|
+
trees?: number;
|
|
15
|
+
maxDepth?: number;
|
|
16
|
+
learningRate?: number;
|
|
17
|
+
/** Minimum summed sample weight in a leaf. Default 1. */
|
|
18
|
+
minLeafWeight?: number;
|
|
19
|
+
/** L2 on leaf values (Newton denominator). Default 1. */
|
|
20
|
+
lambda?: number;
|
|
21
|
+
}
|
|
22
|
+
type RTree = {
|
|
23
|
+
value: number;
|
|
24
|
+
} | {
|
|
25
|
+
feature: number;
|
|
26
|
+
split: number;
|
|
27
|
+
left: RTree;
|
|
28
|
+
right: RTree;
|
|
29
|
+
};
|
|
30
|
+
export declare class GbmModel implements MlPredictor {
|
|
31
|
+
readonly objective: GbmObjective;
|
|
32
|
+
readonly base: number;
|
|
33
|
+
readonly trees: readonly RTree[];
|
|
34
|
+
readonly learningRate: number;
|
|
35
|
+
constructor(objective: GbmObjective, base: number, trees: readonly RTree[], learningRate: number);
|
|
36
|
+
/** The raw additive score (log-odds for `binary`). */
|
|
37
|
+
margin(x: Vec): number;
|
|
38
|
+
predict(x: Float32Array): MlPrediction;
|
|
39
|
+
}
|
|
40
|
+
export declare function fitGbm(samples: readonly MlSample[], opts?: GbmOptions): GbmModel;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=gbm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gbm.d.ts","sourceRoot":"","sources":["../../../src/ml/classical/gbm.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAuB,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAE1D,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,YAAY,CAAC;AAEnD,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
return -g / (h + lambda);
|
|
10
|
+
}
|
|
11
|
+
/** XGBoost-style structure score G²/(H+λ) of a node. */
|
|
12
|
+
function gain(g, h, lambda) {
|
|
13
|
+
return (g * g) / (h + lambda);
|
|
14
|
+
}
|
|
15
|
+
function buildTree(rows, depth, opts) {
|
|
16
|
+
if (depth >= opts.maxDepth || rows.length < 2)
|
|
17
|
+
return { value: leafValue(rows, opts.lambda) };
|
|
18
|
+
let G = 0;
|
|
19
|
+
let H = 0;
|
|
20
|
+
let W = 0;
|
|
21
|
+
for (const r of rows) {
|
|
22
|
+
G += r.w * r.g;
|
|
23
|
+
H += r.w * r.h;
|
|
24
|
+
W += r.w;
|
|
25
|
+
}
|
|
26
|
+
const parent = gain(G, H, opts.lambda);
|
|
27
|
+
let best = null;
|
|
28
|
+
const d = rows[0].x.length;
|
|
29
|
+
for (let f = 0; f < d; f++) {
|
|
30
|
+
const sorted = [...rows].sort((a, b) => a.x[f] - b.x[f]);
|
|
31
|
+
let gl = 0;
|
|
32
|
+
let hl = 0;
|
|
33
|
+
let wl = 0;
|
|
34
|
+
for (let i = 0; i < sorted.length - 1; i++) {
|
|
35
|
+
const r = sorted[i];
|
|
36
|
+
gl += r.w * r.g;
|
|
37
|
+
hl += r.w * r.h;
|
|
38
|
+
wl += r.w;
|
|
39
|
+
const a = r.x[f];
|
|
40
|
+
const b = sorted[i + 1].x[f];
|
|
41
|
+
if (a === b)
|
|
42
|
+
continue;
|
|
43
|
+
if (wl < opts.minLeafWeight || W - wl < opts.minLeafWeight)
|
|
44
|
+
continue;
|
|
45
|
+
const score = gain(gl, hl, opts.lambda) + gain(G - gl, H - hl, opts.lambda) - parent;
|
|
46
|
+
if (score > 1e-12 && (!best || score > best.score))
|
|
47
|
+
best = { feature: f, split: (a + b) / 2, score };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!best)
|
|
51
|
+
return { value: leafValue(rows, opts.lambda) };
|
|
52
|
+
const left = rows.filter((r) => r.x[best.feature] < best.split);
|
|
53
|
+
const right = rows.filter((r) => r.x[best.feature] >= best.split);
|
|
54
|
+
return { feature: best.feature, split: best.split, left: buildTree(left, depth + 1, opts), right: buildTree(right, depth + 1, opts) };
|
|
55
|
+
}
|
|
56
|
+
function treeValue(t, x) {
|
|
57
|
+
while (!("value" in t))
|
|
58
|
+
t = x[t.feature] < t.split ? t.left : t.right;
|
|
59
|
+
return t.value;
|
|
60
|
+
}
|
|
61
|
+
export class GbmModel {
|
|
62
|
+
objective;
|
|
63
|
+
base;
|
|
64
|
+
trees;
|
|
65
|
+
learningRate;
|
|
66
|
+
constructor(objective, base, trees, learningRate) {
|
|
67
|
+
this.objective = objective;
|
|
68
|
+
this.base = base;
|
|
69
|
+
this.trees = trees;
|
|
70
|
+
this.learningRate = learningRate;
|
|
71
|
+
}
|
|
72
|
+
/** The raw additive score (log-odds for `binary`). */
|
|
73
|
+
margin(x) {
|
|
74
|
+
let s = this.base;
|
|
75
|
+
for (const t of this.trees)
|
|
76
|
+
s += this.learningRate * treeValue(t, x);
|
|
77
|
+
return s;
|
|
78
|
+
}
|
|
79
|
+
predict(x) {
|
|
80
|
+
const m = this.margin(x);
|
|
81
|
+
if (this.objective === "regression")
|
|
82
|
+
return { scores: [m], confidence: 1 };
|
|
83
|
+
const p = sigmoid(m);
|
|
84
|
+
return { scores: [1 - p, p], confidence: Math.max(p, 1 - p) };
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function fitGbm(samples, opts = {}) {
|
|
88
|
+
featureDim(samples.map((s) => s.x));
|
|
89
|
+
const objective = opts.objective ?? "binary";
|
|
90
|
+
const lr = opts.learningRate ?? 0.3;
|
|
91
|
+
const treeOpts = { maxDepth: opts.maxDepth ?? 2, minLeafWeight: opts.minLeafWeight ?? 1, lambda: opts.lambda ?? 1 };
|
|
92
|
+
let wSum = 0;
|
|
93
|
+
let ySum = 0;
|
|
94
|
+
for (const s of samples) {
|
|
95
|
+
wSum += s.weight ?? 1;
|
|
96
|
+
ySum += (s.weight ?? 1) * s.y;
|
|
97
|
+
}
|
|
98
|
+
// All-zero weights would make this 0/0: fall back to the unweighted mean.
|
|
99
|
+
const yMean = wSum > 0 ? ySum / wSum : samples.reduce((a, s) => a + s.y, 0) / samples.length;
|
|
100
|
+
const base = objective === "binary" ? Math.log(Math.max(yMean, 1e-6) / Math.max(1 - yMean, 1e-6)) : yMean;
|
|
101
|
+
const margins = samples.map(() => base);
|
|
102
|
+
const trees = [];
|
|
103
|
+
for (let t = 0; t < (opts.trees ?? 50); t++) {
|
|
104
|
+
const rows = samples.map((s, i) => {
|
|
105
|
+
if (objective === "binary") {
|
|
106
|
+
const p = sigmoid(margins[i]);
|
|
107
|
+
return { x: s.x, g: p - s.y, h: Math.max(p * (1 - p), 1e-6), w: s.weight ?? 1 };
|
|
108
|
+
}
|
|
109
|
+
return { x: s.x, g: margins[i] - s.y, h: 1, w: s.weight ?? 1 };
|
|
110
|
+
});
|
|
111
|
+
const tree = buildTree(rows, 0, treeOpts);
|
|
112
|
+
trees.push(tree);
|
|
113
|
+
samples.forEach((s, i) => (margins[i] = margins[i] + lr * treeValue(tree, s.x)));
|
|
114
|
+
}
|
|
115
|
+
return new GbmModel(objective, base, trees, lr);
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=gbm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gbm.js","sourceRoot":"","sources":["../../../src/ml/classical/gbm.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAY,MAAM,WAAW,CAAC;AAwB1D,SAAS,SAAS,CAAC,IAAoB,EAAE,MAAc;IACrD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACf,CAAC,IAAI,CAAC,CAAC,CAAC,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E,CAAC,CAAC;gBAC/B,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YAClF,CAAC;YACD,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAClE,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC1C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,GAAG,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ml/classical — pure-TypeScript algorithms, one file each, and the ONE dispatch
|
|
3
|
+
* from a {@link ClassicalAlgorithm} name to its fit.
|
|
4
|
+
*/
|
|
5
|
+
import type { ClassicalAlgorithm, MlPredictor, MlSample } from "../types.js";
|
|
6
|
+
import { type KnnOptions } from "./knn.js";
|
|
7
|
+
import { type NaiveBayesOptions } from "./naive_bayes.js";
|
|
8
|
+
import { type LogisticOptions } from "./logistic.js";
|
|
9
|
+
import { type LinearOptions } from "./linear.js";
|
|
10
|
+
import { type KMeansOptions } from "./kmeans.js";
|
|
11
|
+
import { type RobustZOptions } from "./robust_z.js";
|
|
12
|
+
import { type EwmaOptions } from "./ewma.js";
|
|
13
|
+
import { type AnomalyCompositeOptions } from "./anomaly_composite.js";
|
|
14
|
+
import { type IsolationForestOptions } from "./isolation_forest.js";
|
|
15
|
+
import { type GbmOptions } from "./gbm.js";
|
|
16
|
+
export { KnnModel, fitKnn } from "./knn.js";
|
|
17
|
+
export type { KnnOptions, KnnMetric, Neighbour } from "./knn.js";
|
|
18
|
+
export { NaiveBayesModel, fitNaiveBayes } from "./naive_bayes.js";
|
|
19
|
+
export type { NaiveBayesOptions } from "./naive_bayes.js";
|
|
20
|
+
export { LogisticModel, fitLogistic } from "./logistic.js";
|
|
21
|
+
export type { LogisticOptions } from "./logistic.js";
|
|
22
|
+
export { LinearModel, fitLinear, solveLinearSystem } from "./linear.js";
|
|
23
|
+
export type { LinearOptions } from "./linear.js";
|
|
24
|
+
export { KMeansModel, fitKMeans } from "./kmeans.js";
|
|
25
|
+
export type { KMeansOptions } from "./kmeans.js";
|
|
26
|
+
export { RobustZModel, fitRobustZ, anomalyConfidence } from "./robust_z.js";
|
|
27
|
+
export type { RobustZOptions } from "./robust_z.js";
|
|
28
|
+
export { EwmaModel, fitEwma } from "./ewma.js";
|
|
29
|
+
export type { EwmaOptions } from "./ewma.js";
|
|
30
|
+
export { AnomalyCompositeModel, fitAnomalyComposite } from "./anomaly_composite.js";
|
|
31
|
+
export type { AnomalyCompositeOptions } from "./anomaly_composite.js";
|
|
32
|
+
export { IsolationForestModel, fitIsolationForest } from "./isolation_forest.js";
|
|
33
|
+
export type { IsolationForestOptions } from "./isolation_forest.js";
|
|
34
|
+
export { GbmModel, fitGbm } from "./gbm.js";
|
|
35
|
+
export type { GbmOptions, GbmObjective } from "./gbm.js";
|
|
36
|
+
export { cosine, dot } from "./math.js";
|
|
37
|
+
/** Per-algorithm options, keyed by algorithm name. */
|
|
38
|
+
export interface ClassicalOptions {
|
|
39
|
+
knn?: KnnOptions;
|
|
40
|
+
"naive-bayes"?: NaiveBayesOptions;
|
|
41
|
+
logistic?: LogisticOptions;
|
|
42
|
+
linear?: LinearOptions;
|
|
43
|
+
kmeans?: KMeansOptions;
|
|
44
|
+
"robust-z"?: RobustZOptions;
|
|
45
|
+
ewma?: EwmaOptions;
|
|
46
|
+
"anomaly-composite"?: AnomalyCompositeOptions;
|
|
47
|
+
"isolation-forest"?: IsolationForestOptions;
|
|
48
|
+
"gbm-small"?: GbmOptions;
|
|
49
|
+
}
|
|
50
|
+
/** Fit `algorithm` on `samples`. Unsupervised algorithms ignore `y`. */
|
|
51
|
+
export declare function fitClassical(algorithm: ClassicalAlgorithm, samples: readonly MlSample[], opts?: ClassicalOptions): MlPredictor;
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ml/classical/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAiB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAa,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAuB,KAAK,uBA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,QAAQ,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAExC,sDAAsD;AACtD,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,QAAQ,CAAC,EAAE,eAAe,CAAC;IAC3B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,mBAAmB,CAAC,EAAE,uBAAuB,CAAC;IAC9C,kBAAkB,CAAC,EAAE,sBAAsB,CAAC;IAC5C,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED,wEAAwE;AACxE,wBAAgB,YAAY,CAC1B,SAAS,EAAE,kBAAkB,EAC7B,OAAO,EAAE,SAAS,QAAQ,EAAE,EAC5B,IAAI,GAAE,gBAAqB,GAC1B,WAAW,CAwBb"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { fitKnn } from "./knn.js";
|
|
2
|
+
import { fitNaiveBayes } from "./naive_bayes.js";
|
|
3
|
+
import { fitLogistic } from "./logistic.js";
|
|
4
|
+
import { fitLinear } from "./linear.js";
|
|
5
|
+
import { fitKMeans } from "./kmeans.js";
|
|
6
|
+
import { fitRobustZ } from "./robust_z.js";
|
|
7
|
+
import { fitEwma } from "./ewma.js";
|
|
8
|
+
import { fitAnomalyComposite } from "./anomaly_composite.js";
|
|
9
|
+
import { fitIsolationForest } from "./isolation_forest.js";
|
|
10
|
+
import { fitGbm } from "./gbm.js";
|
|
11
|
+
export { KnnModel, fitKnn } from "./knn.js";
|
|
12
|
+
export { NaiveBayesModel, fitNaiveBayes } from "./naive_bayes.js";
|
|
13
|
+
export { LogisticModel, fitLogistic } from "./logistic.js";
|
|
14
|
+
export { LinearModel, fitLinear, solveLinearSystem } from "./linear.js";
|
|
15
|
+
export { KMeansModel, fitKMeans } from "./kmeans.js";
|
|
16
|
+
export { RobustZModel, fitRobustZ, anomalyConfidence } from "./robust_z.js";
|
|
17
|
+
export { EwmaModel, fitEwma } from "./ewma.js";
|
|
18
|
+
export { AnomalyCompositeModel, fitAnomalyComposite } from "./anomaly_composite.js";
|
|
19
|
+
export { IsolationForestModel, fitIsolationForest } from "./isolation_forest.js";
|
|
20
|
+
export { GbmModel, fitGbm } from "./gbm.js";
|
|
21
|
+
export { cosine, dot } from "./math.js";
|
|
22
|
+
/** Fit `algorithm` on `samples`. Unsupervised algorithms ignore `y`. */
|
|
23
|
+
export function fitClassical(algorithm, samples, opts = {}) {
|
|
24
|
+
if (samples.length === 0)
|
|
25
|
+
throw new Error(`fitClassical(${algorithm}): no samples`);
|
|
26
|
+
switch (algorithm) {
|
|
27
|
+
case "knn":
|
|
28
|
+
return fitKnn(samples, opts.knn);
|
|
29
|
+
case "naive-bayes":
|
|
30
|
+
return fitNaiveBayes(samples, opts["naive-bayes"]);
|
|
31
|
+
case "logistic":
|
|
32
|
+
return fitLogistic(samples, opts.logistic);
|
|
33
|
+
case "linear":
|
|
34
|
+
return fitLinear(samples, opts.linear);
|
|
35
|
+
case "kmeans":
|
|
36
|
+
return fitKMeans(samples, opts.kmeans);
|
|
37
|
+
case "robust-z":
|
|
38
|
+
return fitRobustZ(samples, opts["robust-z"]);
|
|
39
|
+
case "ewma":
|
|
40
|
+
return fitEwma(samples, opts.ewma);
|
|
41
|
+
case "anomaly-composite":
|
|
42
|
+
return fitAnomalyComposite(samples, opts["anomaly-composite"]);
|
|
43
|
+
case "isolation-forest":
|
|
44
|
+
return fitIsolationForest(samples, opts["isolation-forest"]);
|
|
45
|
+
case "gbm-small":
|
|
46
|
+
return fitGbm(samples, opts["gbm-small"]);
|
|
47
|
+
}
|
|
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AW,CAAC,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ml/classical/isolation_forest.ts — Isolation Forest (Liu, Ting & Zhou 2008).
|
|
3
|
+
*
|
|
4
|
+
* Anomalies are few and different, so random axis-aligned splits isolate them in
|
|
5
|
+
* fewer steps. Score s(x) = 2^(−E[h(x)] / c(ψ)): near 1 = anomalous, ≤ 0.5 =
|
|
6
|
+
* normal. Prediction: `scores[0] = s / threshold` — ≥ 1 is anomalous.
|
|
7
|
+
*/
|
|
8
|
+
import type { MlPrediction, MlPredictor, MlSample } from "../types.js";
|
|
9
|
+
import { type Vec } from "./math.js";
|
|
10
|
+
export interface IsolationForestOptions {
|
|
11
|
+
trees?: number;
|
|
12
|
+
/** Subsample size ψ per tree. Default min(256, n). */
|
|
13
|
+
sampleSize?: number;
|
|
14
|
+
/** Raw score at which a point is anomalous. Default 0.6. */
|
|
15
|
+
threshold?: number;
|
|
16
|
+
seed?: number;
|
|
17
|
+
}
|
|
18
|
+
type ITree = {
|
|
19
|
+
size: number;
|
|
20
|
+
} | {
|
|
21
|
+
feature: number;
|
|
22
|
+
split: number;
|
|
23
|
+
left: ITree;
|
|
24
|
+
right: ITree;
|
|
25
|
+
};
|
|
26
|
+
export declare class IsolationForestModel implements MlPredictor {
|
|
27
|
+
readonly trees: readonly ITree[];
|
|
28
|
+
readonly sampleSize: number;
|
|
29
|
+
readonly threshold: number;
|
|
30
|
+
constructor(trees: readonly ITree[], sampleSize: number, threshold: number);
|
|
31
|
+
/** The raw isolation score in (0, 1]. */
|
|
32
|
+
score(x: Vec): number;
|
|
33
|
+
predict(x: Float32Array): MlPrediction;
|
|
34
|
+
}
|
|
35
|
+
export declare function fitIsolationForest(samples: readonly MlSample[], opts?: IsolationForestOptions): IsolationForestModel;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=isolation_forest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolation_forest.d.ts","sourceRoot":"","sources":["../../../src/ml/classical/isolation_forest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAgD,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AAGnF,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,KAAK,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AA6B9F,qBAAa,oBAAqB,YAAW,WAAW;IAEpD,QAAQ,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM;gBAFjB,KAAK,EAAE,SAAS,KAAK,EAAE,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM;IAG5B,yCAAyC;IACzC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM;IAOrB,OAAO,CAAC,CAAC,EAAE,YAAY,GAAG,YAAY;CAIvC;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,QAAQ,EAAE,EAAE,IAAI,GAAE,sBAA2B,GAAG,oBAAoB,CAiBxH"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { averagePathLength, featureDim, seededUniform } from "./math.js";
|
|
2
|
+
import { anomalyConfidence } from "./robust_z.js";
|
|
3
|
+
function buildTree(X, depth, limit, rnd) {
|
|
4
|
+
if (depth >= limit || X.length <= 1)
|
|
5
|
+
return { size: X.length };
|
|
6
|
+
const d = X[0].length;
|
|
7
|
+
// Only features that still vary can split; none left = an isolated leaf.
|
|
8
|
+
const varying = [];
|
|
9
|
+
for (let f = 0; f < d; f++) {
|
|
10
|
+
let lo = Infinity;
|
|
11
|
+
let hi = -Infinity;
|
|
12
|
+
for (const x of X) {
|
|
13
|
+
lo = Math.min(lo, x[f]);
|
|
14
|
+
hi = Math.max(hi, x[f]);
|
|
15
|
+
}
|
|
16
|
+
if (hi > lo)
|
|
17
|
+
varying.push({ f, lo, hi });
|
|
18
|
+
}
|
|
19
|
+
if (varying.length === 0)
|
|
20
|
+
return { size: X.length };
|
|
21
|
+
const { f, lo, hi } = varying[Math.floor(rnd() * varying.length)];
|
|
22
|
+
const split = lo + rnd() * (hi - lo);
|
|
23
|
+
const left = X.filter((x) => x[f] < split);
|
|
24
|
+
const right = X.filter((x) => x[f] >= split);
|
|
25
|
+
return { feature: f, split, left: buildTree(left, depth + 1, limit, rnd), right: buildTree(right, depth + 1, limit, rnd) };
|
|
26
|
+
}
|
|
27
|
+
function pathLength(tree, x, depth = 0) {
|
|
28
|
+
if ("size" in tree)
|
|
29
|
+
return depth + averagePathLength(tree.size);
|
|
30
|
+
return pathLength(x[tree.feature] < tree.split ? tree.left : tree.right, x, depth + 1);
|
|
31
|
+
}
|
|
32
|
+
export class IsolationForestModel {
|
|
33
|
+
trees;
|
|
34
|
+
sampleSize;
|
|
35
|
+
threshold;
|
|
36
|
+
constructor(trees, sampleSize, threshold) {
|
|
37
|
+
this.trees = trees;
|
|
38
|
+
this.sampleSize = sampleSize;
|
|
39
|
+
this.threshold = threshold;
|
|
40
|
+
}
|
|
41
|
+
/** The raw isolation score in (0, 1]. */
|
|
42
|
+
score(x) {
|
|
43
|
+
const c = averagePathLength(this.sampleSize);
|
|
44
|
+
if (c === 0)
|
|
45
|
+
return 0.5;
|
|
46
|
+
const mean = this.trees.reduce((s, t) => s + pathLength(t, x), 0) / this.trees.length;
|
|
47
|
+
return Math.pow(2, -mean / c);
|
|
48
|
+
}
|
|
49
|
+
predict(x) {
|
|
50
|
+
const s = this.score(x) / this.threshold;
|
|
51
|
+
return { scores: [s], confidence: anomalyConfidence(s) };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function fitIsolationForest(samples, opts = {}) {
|
|
55
|
+
const X = samples.map((s) => s.x);
|
|
56
|
+
featureDim(X);
|
|
57
|
+
const rnd = seededUniform(opts.seed ?? 0x15f0);
|
|
58
|
+
const psi = Math.min(opts.sampleSize ?? 256, X.length);
|
|
59
|
+
const limit = Math.ceil(Math.log2(Math.max(psi, 2)));
|
|
60
|
+
const trees = [];
|
|
61
|
+
for (let t = 0; t < (opts.trees ?? 100); t++) {
|
|
62
|
+
// Sample ψ points without replacement (partial Fisher–Yates over indices).
|
|
63
|
+
const idx = X.map((_, i) => i);
|
|
64
|
+
for (let i = 0; i < psi; i++) {
|
|
65
|
+
const j = i + Math.floor(rnd() * (idx.length - i));
|
|
66
|
+
[idx[i], idx[j]] = [idx[j], idx[i]];
|
|
67
|
+
}
|
|
68
|
+
trees.push(buildTree(idx.slice(0, psi).map((i) => X[i]), 0, limit, rnd));
|
|
69
|
+
}
|
|
70
|
+
return new IsolationForestModel(trees, psi, opts.threshold ?? 0.6);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=isolation_forest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolation_forest.js","sourceRoot":"","sources":["../../../src/ml/classical/isolation_forest.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,aAAa,EAAY,MAAM,WAAW,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAalD,SAAS,SAAS,CAAC,CAAQ,EAAE,KAAa,EAAE,KAAa,EAAE,GAAiB;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