@memberjunction/predictive-studio 0.0.1 → 5.44.0
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/README.md +101 -28
- package/dist/actions/base-predictive-studio.action.d.ts +63 -0
- package/dist/actions/base-predictive-studio.action.d.ts.map +1 -0
- package/dist/actions/base-predictive-studio.action.js +125 -0
- package/dist/actions/base-predictive-studio.action.js.map +1 -0
- package/dist/actions/index.d.ts +38 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +49 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/model-scoring-action-generator.d.ts +108 -0
- package/dist/actions/model-scoring-action-generator.d.ts.map +1 -0
- package/dist/actions/model-scoring-action-generator.js +316 -0
- package/dist/actions/model-scoring-action-generator.js.map +1 -0
- package/dist/actions/promote-model.action.d.ts +102 -0
- package/dist/actions/promote-model.action.d.ts.map +1 -0
- package/dist/actions/promote-model.action.js +132 -0
- package/dist/actions/promote-model.action.js.map +1 -0
- package/dist/actions/promote-model.gate.d.ts +77 -0
- package/dist/actions/promote-model.gate.d.ts.map +1 -0
- package/dist/actions/promote-model.gate.js +205 -0
- package/dist/actions/promote-model.gate.js.map +1 -0
- package/dist/actions/run-experiment.action.d.ts +60 -0
- package/dist/actions/run-experiment.action.d.ts.map +1 -0
- package/dist/actions/run-experiment.action.js +134 -0
- package/dist/actions/run-experiment.action.js.map +1 -0
- package/dist/actions/run-experiment.deps.d.ts +47 -0
- package/dist/actions/run-experiment.deps.d.ts.map +1 -0
- package/dist/actions/run-experiment.deps.js +71 -0
- package/dist/actions/run-experiment.deps.js.map +1 -0
- package/dist/actions/schedule-model-scoring.action.d.ts +71 -0
- package/dist/actions/schedule-model-scoring.action.d.ts.map +1 -0
- package/dist/actions/schedule-model-scoring.action.js +148 -0
- package/dist/actions/schedule-model-scoring.action.js.map +1 -0
- package/dist/actions/score-record-set.action.d.ts +133 -0
- package/dist/actions/score-record-set.action.d.ts.map +1 -0
- package/dist/actions/score-record-set.action.js +136 -0
- package/dist/actions/score-record-set.action.js.map +1 -0
- package/dist/actions/score-record-set.runner.d.ts +192 -0
- package/dist/actions/score-record-set.runner.d.ts.map +1 -0
- package/dist/actions/score-record-set.runner.js +416 -0
- package/dist/actions/score-record-set.runner.js.map +1 -0
- package/dist/actions/train-model.action.d.ts +57 -0
- package/dist/actions/train-model.action.d.ts.map +1 -0
- package/dist/actions/train-model.action.js +111 -0
- package/dist/actions/train-model.action.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +14 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/model-dev-orchestrator-agent.d.ts +42 -0
- package/dist/agent/model-dev-orchestrator-agent.d.ts.map +1 -0
- package/dist/agent/model-dev-orchestrator-agent.js +76 -0
- package/dist/agent/model-dev-orchestrator-agent.js.map +1 -0
- package/dist/agent/modeling-plan-to-pipeline.d.ts +49 -0
- package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -0
- package/dist/agent/modeling-plan-to-pipeline.js +101 -0
- package/dist/agent/modeling-plan-to-pipeline.js.map +1 -0
- package/dist/agent/pipeline-builder-agent.d.ts +58 -0
- package/dist/agent/pipeline-builder-agent.d.ts.map +1 -0
- package/dist/agent/pipeline-builder-agent.js +101 -0
- package/dist/agent/pipeline-builder-agent.js.map +1 -0
- package/dist/agent/pipeline-builder.d.ts +67 -0
- package/dist/agent/pipeline-builder.d.ts.map +1 -0
- package/dist/agent/pipeline-builder.js +114 -0
- package/dist/agent/pipeline-builder.js.map +1 -0
- package/dist/experiment/concurrency.d.ts +41 -0
- package/dist/experiment/concurrency.d.ts.map +1 -0
- package/dist/experiment/concurrency.js +54 -0
- package/dist/experiment/concurrency.js.map +1 -0
- package/dist/experiment/experiment-orchestrator.d.ts +136 -0
- package/dist/experiment/experiment-orchestrator.d.ts.map +1 -0
- package/dist/experiment/experiment-orchestrator.js +408 -0
- package/dist/experiment/experiment-orchestrator.js.map +1 -0
- package/dist/experiment/index.d.ts +17 -0
- package/dist/experiment/index.d.ts.map +1 -0
- package/dist/experiment/index.js +17 -0
- package/dist/experiment/index.js.map +1 -0
- package/dist/experiment/leaderboard.d.ts +50 -0
- package/dist/experiment/leaderboard.d.ts.map +1 -0
- package/dist/experiment/leaderboard.js +91 -0
- package/dist/experiment/leaderboard.js.map +1 -0
- package/dist/experiment/seams.d.ts +95 -0
- package/dist/experiment/seams.d.ts.map +1 -0
- package/dist/experiment/seams.js +126 -0
- package/dist/experiment/seams.js.map +1 -0
- package/dist/experiment/types.d.ts +228 -0
- package/dist/experiment/types.d.ts.map +1 -0
- package/dist/experiment/types.js +19 -0
- package/dist/experiment/types.js.map +1 -0
- package/dist/experiment/wave-strategist.d.ts +31 -0
- package/dist/experiment/wave-strategist.d.ts.map +1 -0
- package/dist/experiment/wave-strategist.js +50 -0
- package/dist/experiment/wave-strategist.js.map +1 -0
- package/dist/feature-assembly/as-of.d.ts +74 -0
- package/dist/feature-assembly/as-of.d.ts.map +1 -0
- package/dist/feature-assembly/as-of.js +136 -0
- package/dist/feature-assembly/as-of.js.map +1 -0
- package/dist/feature-assembly/data-access.d.ts +114 -0
- package/dist/feature-assembly/data-access.d.ts.map +1 -0
- package/dist/feature-assembly/data-access.js +68 -0
- package/dist/feature-assembly/data-access.js.map +1 -0
- package/dist/feature-assembly/feature-assembly-executor.d.ts +273 -0
- package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -0
- package/dist/feature-assembly/feature-assembly-executor.js +521 -0
- package/dist/feature-assembly/feature-assembly-executor.js.map +1 -0
- package/dist/feature-assembly/index.d.ts +13 -0
- package/dist/feature-assembly/index.d.ts.map +1 -0
- package/dist/feature-assembly/index.js +13 -0
- package/dist/feature-assembly/index.js.map +1 -0
- package/dist/feature-assembly/leakage-guard.d.ts +86 -0
- package/dist/feature-assembly/leakage-guard.d.ts.map +1 -0
- package/dist/feature-assembly/leakage-guard.js +111 -0
- package/dist/feature-assembly/leakage-guard.js.map +1 -0
- package/dist/feature-assembly/vision-llm.d.ts +125 -0
- package/dist/feature-assembly/vision-llm.d.ts.map +1 -0
- package/dist/feature-assembly/vision-llm.js +211 -0
- package/dist/feature-assembly/vision-llm.js.map +1 -0
- package/dist/feature-pipelines/feature-pipeline-engine.d.ts +159 -0
- package/dist/feature-pipelines/feature-pipeline-engine.d.ts.map +1 -0
- package/dist/feature-pipelines/feature-pipeline-engine.js +298 -0
- package/dist/feature-pipelines/feature-pipeline-engine.js.map +1 -0
- package/dist/feature-pipelines/index.d.ts +13 -0
- package/dist/feature-pipelines/index.d.ts.map +1 -0
- package/dist/feature-pipelines/index.js +13 -0
- package/dist/feature-pipelines/index.js.map +1 -0
- package/dist/feature-pipelines/types.d.ts +72 -0
- package/dist/feature-pipelines/types.d.ts.map +1 -0
- package/dist/feature-pipelines/types.js +17 -0
- package/dist/feature-pipelines/types.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/maintenance/index.d.ts +19 -0
- package/dist/maintenance/index.d.ts.map +1 -0
- package/dist/maintenance/index.js +19 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/maintenance/maintenance-engine.d.ts +152 -0
- package/dist/maintenance/maintenance-engine.d.ts.map +1 -0
- package/dist/maintenance/maintenance-engine.js +412 -0
- package/dist/maintenance/maintenance-engine.js.map +1 -0
- package/dist/maintenance/metrics.d.ts +37 -0
- package/dist/maintenance/metrics.d.ts.map +1 -0
- package/dist/maintenance/metrics.js +85 -0
- package/dist/maintenance/metrics.js.map +1 -0
- package/dist/maintenance/seams.d.ts +85 -0
- package/dist/maintenance/seams.d.ts.map +1 -0
- package/dist/maintenance/seams.js +166 -0
- package/dist/maintenance/seams.js.map +1 -0
- package/dist/maintenance/types.d.ts +318 -0
- package/dist/maintenance/types.d.ts.map +1 -0
- package/dist/maintenance/types.js +27 -0
- package/dist/maintenance/types.js.map +1 -0
- package/dist/operations/__tests__/helpers.d.ts +30 -0
- package/dist/operations/__tests__/helpers.d.ts.map +1 -0
- package/dist/operations/__tests__/helpers.js +44 -0
- package/dist/operations/__tests__/helpers.js.map +1 -0
- package/dist/operations/control-experiment-session.operation.d.ts +33 -0
- package/dist/operations/control-experiment-session.operation.d.ts.map +1 -0
- package/dist/operations/control-experiment-session.operation.js +71 -0
- package/dist/operations/control-experiment-session.operation.js.map +1 -0
- package/dist/operations/create-scoring-process.operation.d.ts +30 -0
- package/dist/operations/create-scoring-process.operation.d.ts.map +1 -0
- package/dist/operations/create-scoring-process.operation.js +65 -0
- package/dist/operations/create-scoring-process.operation.js.map +1 -0
- package/dist/operations/delegation.d.ts +113 -0
- package/dist/operations/delegation.d.ts.map +1 -0
- package/dist/operations/delegation.js +139 -0
- package/dist/operations/delegation.js.map +1 -0
- package/dist/operations/index.d.ts +40 -0
- package/dist/operations/index.d.ts.map +1 -0
- package/dist/operations/index.js +55 -0
- package/dist/operations/index.js.map +1 -0
- package/dist/operations/promote-model.operation.d.ts +57 -0
- package/dist/operations/promote-model.operation.d.ts.map +1 -0
- package/dist/operations/promote-model.operation.js +113 -0
- package/dist/operations/promote-model.operation.js.map +1 -0
- package/dist/operations/run-feature-pipeline.operation.d.ts +56 -0
- package/dist/operations/run-feature-pipeline.operation.d.ts.map +1 -0
- package/dist/operations/run-feature-pipeline.operation.js +94 -0
- package/dist/operations/run-feature-pipeline.operation.js.map +1 -0
- package/dist/operations/score-record-set.operation.d.ts +47 -0
- package/dist/operations/score-record-set.operation.d.ts.map +1 -0
- package/dist/operations/score-record-set.operation.js +113 -0
- package/dist/operations/score-record-set.operation.js.map +1 -0
- package/dist/operations/start-experiment-session.operation.d.ts +66 -0
- package/dist/operations/start-experiment-session.operation.d.ts.map +1 -0
- package/dist/operations/start-experiment-session.operation.js +132 -0
- package/dist/operations/start-experiment-session.operation.js.map +1 -0
- package/dist/operations/train-model.operation.d.ts +50 -0
- package/dist/operations/train-model.operation.d.ts.map +1 -0
- package/dist/operations/train-model.operation.js +114 -0
- package/dist/operations/train-model.operation.js.map +1 -0
- package/dist/scheduling/index.d.ts +13 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +13 -0
- package/dist/scheduling/index.js.map +1 -0
- package/dist/scheduling/scheduled-model-scoring.d.ts +169 -0
- package/dist/scheduling/scheduled-model-scoring.d.ts.map +1 -0
- package/dist/scheduling/scheduled-model-scoring.js +189 -0
- package/dist/scheduling/scheduled-model-scoring.js.map +1 -0
- package/dist/scoring/artifact-loader.d.ts +65 -0
- package/dist/scoring/artifact-loader.d.ts.map +1 -0
- package/dist/scoring/artifact-loader.js +97 -0
- package/dist/scoring/artifact-loader.js.map +1 -0
- package/dist/scoring/index.d.ts +26 -0
- package/dist/scoring/index.d.ts.map +1 -0
- package/dist/scoring/index.js +26 -0
- package/dist/scoring/index.js.map +1 -0
- package/dist/scoring/ml-model-inference-processor.d.ts +154 -0
- package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -0
- package/dist/scoring/ml-model-inference-processor.js +320 -0
- package/dist/scoring/ml-model-inference-processor.js.map +1 -0
- package/dist/scoring/ml-model-score-enricher.d.ts +80 -0
- package/dist/scoring/ml-model-score-enricher.d.ts.map +1 -0
- package/dist/scoring/ml-model-score-enricher.js +139 -0
- package/dist/scoring/ml-model-score-enricher.js.map +1 -0
- package/dist/scoring/register.d.ts +81 -0
- package/dist/scoring/register.d.ts.map +1 -0
- package/dist/scoring/register.js +105 -0
- package/dist/scoring/register.js.map +1 -0
- package/dist/scoring/scoring-binding.d.ts +72 -0
- package/dist/scoring/scoring-binding.d.ts.map +1 -0
- package/dist/scoring/scoring-binding.js +76 -0
- package/dist/scoring/scoring-binding.js.map +1 -0
- package/dist/scoring/scoring-process-shared.d.ts +105 -0
- package/dist/scoring/scoring-process-shared.d.ts.map +1 -0
- package/dist/scoring/scoring-process-shared.js +141 -0
- package/dist/scoring/scoring-process-shared.js.map +1 -0
- package/dist/scoring/scoring-process.d.ts +128 -0
- package/dist/scoring/scoring-process.d.ts.map +1 -0
- package/dist/scoring/scoring-process.js +146 -0
- package/dist/scoring/scoring-process.js.map +1 -0
- package/dist/scoring/seams.d.ts +40 -0
- package/dist/scoring/seams.d.ts.map +1 -0
- package/dist/scoring/seams.js +66 -0
- package/dist/scoring/seams.js.map +1 -0
- package/dist/scoring/startup-register.d.ts +49 -0
- package/dist/scoring/startup-register.d.ts.map +1 -0
- package/dist/scoring/startup-register.js +72 -0
- package/dist/scoring/startup-register.js.map +1 -0
- package/dist/scoring/types.d.ts +134 -0
- package/dist/scoring/types.d.ts.map +1 -0
- package/dist/scoring/types.js +26 -0
- package/dist/scoring/types.js.map +1 -0
- package/dist/training/artifact-store.d.ts +124 -0
- package/dist/training/artifact-store.d.ts.map +1 -0
- package/dist/training/artifact-store.js +163 -0
- package/dist/training/artifact-store.js.map +1 -0
- package/dist/training/index.d.ts +13 -0
- package/dist/training/index.d.ts.map +1 -0
- package/dist/training/index.js +13 -0
- package/dist/training/index.js.map +1 -0
- package/dist/training/seams.d.ts +57 -0
- package/dist/training/seams.d.ts.map +1 -0
- package/dist/training/seams.js +103 -0
- package/dist/training/seams.js.map +1 -0
- package/dist/training/training-engine.d.ts +96 -0
- package/dist/training/training-engine.d.ts.map +1 -0
- package/dist/training/training-engine.js +300 -0
- package/dist/training/training-engine.js.map +1 -0
- package/dist/training/types.d.ts +159 -0
- package/dist/training/types.d.ts.map +1 -0
- package/dist/training/types.js +16 -0
- package/dist/training/types.js.map +1 -0
- package/package.json +44 -7
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module experiment/seams
|
|
3
|
+
*
|
|
4
|
+
* Production implementations of the {@link ExperimentDeps} seams — the
|
|
5
|
+
* {@link IClock} (real wall-clock), the {@link IExperimentEntityFactory}
|
|
6
|
+
* (over `Metadata.GetEntityObject`), and the {@link IExperimentTrainer} that
|
|
7
|
+
* bridges the orchestrator's per-iteration training contract to the
|
|
8
|
+
* {@link TrainingEngine}. These are the only place the experiment engine touches
|
|
9
|
+
* MJ's live plumbing; the orchestrator itself depends solely on the narrow
|
|
10
|
+
* interfaces, so unit tests substitute in-memory fakes and a fake clock.
|
|
11
|
+
*/
|
|
12
|
+
import { type BaseEntity, type UserInfo, type IMetadataProvider } from '@memberjunction/core';
|
|
13
|
+
import { TrainingEngine } from '../training/index.js';
|
|
14
|
+
import type { TrainingDeps } from '../training/index.js';
|
|
15
|
+
import type { IClock, IExperimentEntityFactory, IExperimentTrainer, TrainExperimentInput, TrainExperimentResult } from './types.js';
|
|
16
|
+
/** Real wall-clock {@link IClock}. Tests inject a controllable fake instead. */
|
|
17
|
+
export declare class SystemClock implements IClock {
|
|
18
|
+
/** @inheritdoc */
|
|
19
|
+
now(): number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `Metadata.GetEntityObject`-backed {@link IExperimentEntityFactory}. Optionally
|
|
23
|
+
* bound to a specific provider for multi-provider correctness.
|
|
24
|
+
*/
|
|
25
|
+
export declare class MetadataExperimentEntityFactory implements IExperimentEntityFactory {
|
|
26
|
+
private readonly provider?;
|
|
27
|
+
/**
|
|
28
|
+
* @param provider optional provider; when supplied it (and its `CurrentUser`)
|
|
29
|
+
* is honored so multi-provider callers create entities on the RIGHT server.
|
|
30
|
+
* When omitted the global default `Metadata` provider is used.
|
|
31
|
+
*/
|
|
32
|
+
constructor(provider?: IMetadataProvider);
|
|
33
|
+
/** @inheritdoc */
|
|
34
|
+
getEntityObject<T extends BaseEntity>(entityName: string, contextUser?: UserInfo): Promise<T>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* How the production trainer maps an approved plan's experiment to a concrete
|
|
38
|
+
* `MJ: ML Training Pipelines` row. The orchestrator carries algorithm × feature
|
|
39
|
+
* set × hyperparameters on the experiment, but `TrainingEngine.trainModel`
|
|
40
|
+
* trains by **pipeline id** (an immutable, versioned pipeline definition). This
|
|
41
|
+
* resolver bridges the two: given an experiment + plan, it returns the pipeline
|
|
42
|
+
* id to train (materializing/looking up a pipeline that encodes that
|
|
43
|
+
* experiment's algorithm + feature set + hyperparameters).
|
|
44
|
+
*
|
|
45
|
+
* It is itself a seam so the materialization strategy (reuse an existing
|
|
46
|
+
* pipeline vs. create one per experiment) can vary without touching the
|
|
47
|
+
* orchestrator or the training engine.
|
|
48
|
+
*/
|
|
49
|
+
export interface IPipelineResolver {
|
|
50
|
+
/**
|
|
51
|
+
* Resolve (or materialize) the `MJ: ML Training Pipelines` id that encodes the
|
|
52
|
+
* given experiment under the plan.
|
|
53
|
+
*
|
|
54
|
+
* @param input the experiment + plan + iteration/session context
|
|
55
|
+
* @returns the pipeline id to hand to `TrainingEngine.trainModel`
|
|
56
|
+
*/
|
|
57
|
+
resolvePipelineId(input: TrainExperimentInput): Promise<string>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* {@link IExperimentTrainer} backed by the {@link TrainingEngine}. For each
|
|
61
|
+
* iteration it resolves the pipeline (via an injected {@link IPipelineResolver}),
|
|
62
|
+
* trains it through the engine (producing an immutable Draft `MJ: ML Models` +
|
|
63
|
+
* its `MJ: ML Training Runs` leaf linked to the iteration via
|
|
64
|
+
* `experimentSessionIterationId`), and extracts the normalized holdout Score for
|
|
65
|
+
* the plan's `SuccessMetric` to drive the leaderboard.
|
|
66
|
+
*/
|
|
67
|
+
export declare class TrainingEngineExperimentTrainer implements IExperimentTrainer {
|
|
68
|
+
private readonly trainingDeps;
|
|
69
|
+
private readonly pipelineResolver;
|
|
70
|
+
private readonly engine;
|
|
71
|
+
/**
|
|
72
|
+
* @param trainingDeps the training engine's injected dependency bundle
|
|
73
|
+
* @param pipelineResolver maps experiment → pipeline id
|
|
74
|
+
* @param engine optional TrainingEngine override (defaults to a fresh instance)
|
|
75
|
+
*/
|
|
76
|
+
constructor(trainingDeps: TrainingDeps, pipelineResolver: IPipelineResolver, engine?: TrainingEngine);
|
|
77
|
+
/** @inheritdoc */
|
|
78
|
+
train(input: TrainExperimentInput): Promise<TrainExperimentResult>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Extract the **normalized** leaderboard score from a model's holdout metrics
|
|
82
|
+
* (preferred — the honest, search-never-saw-it number, §8.2), falling back to
|
|
83
|
+
* the training metrics. The score is normalized so **higher is always better**:
|
|
84
|
+
* error metrics (RMSE/MAE/loss) are negated, ranking metrics (AUC/F1/accuracy)
|
|
85
|
+
* pass through. Returns `0` when the metric is absent (a failed/empty run).
|
|
86
|
+
*
|
|
87
|
+
* Exported for unit testing the normalization in isolation.
|
|
88
|
+
*
|
|
89
|
+
* @param holdoutMetricsJson the model's `HoldoutMetrics` JSON (preferred)
|
|
90
|
+
* @param trainMetricsJson the model's `Metrics` JSON (fallback)
|
|
91
|
+
* @param successMetric the plan's `SuccessMetric` (e.g. `AUC`, `RMSE`)
|
|
92
|
+
* @param problemType classification vs. regression (informs the error-metric direction)
|
|
93
|
+
*/
|
|
94
|
+
export declare function extractNormalizedScore(holdoutMetricsJson: string | null, trainMetricsJson: string | null, successMetric: string, problemType: 'classification' | 'regression'): number;
|
|
95
|
+
//# sourceMappingURL=seams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seams.d.ts","sourceRoot":"","sources":["../../src/experiment/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EACV,MAAM,EACN,wBAAwB,EACxB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAEjB,gFAAgF;AAChF,qBAAa,WAAY,YAAW,MAAM;IACxC,kBAAkB;IACX,GAAG,IAAI,MAAM;CAGrB;AAED;;;GAGG;AACH,qBAAa,+BAAgC,YAAW,wBAAwB;IAMlE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IALtC;;;;OAIG;gBAC0B,QAAQ,CAAC,EAAE,iBAAiB;IAEzD,kBAAkB;IACL,eAAe,CAAC,CAAC,SAAS,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;CAO3G;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACjE;AAED;;;;;;;GAOG;AACH,qBAAa,+BAAgC,YAAW,kBAAkB;IAOtE,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM;IARzB;;;;OAIG;gBAEgB,YAAY,EAAE,YAAY,EAC1B,gBAAgB,EAAE,iBAAiB,EACnC,MAAM,GAAE,cAAqC;IAGhE,kBAAkB;IACL,KAAK,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAkBhF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACpC,kBAAkB,EAAE,MAAM,GAAG,IAAI,EACjC,gBAAgB,EAAE,MAAM,GAAG,IAAI,EAC/B,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,gBAAgB,GAAG,YAAY,GAC3C,MAAM,CAYR"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module experiment/seams
|
|
3
|
+
*
|
|
4
|
+
* Production implementations of the {@link ExperimentDeps} seams — the
|
|
5
|
+
* {@link IClock} (real wall-clock), the {@link IExperimentEntityFactory}
|
|
6
|
+
* (over `Metadata.GetEntityObject`), and the {@link IExperimentTrainer} that
|
|
7
|
+
* bridges the orchestrator's per-iteration training contract to the
|
|
8
|
+
* {@link TrainingEngine}. These are the only place the experiment engine touches
|
|
9
|
+
* MJ's live plumbing; the orchestrator itself depends solely on the narrow
|
|
10
|
+
* interfaces, so unit tests substitute in-memory fakes and a fake clock.
|
|
11
|
+
*/
|
|
12
|
+
import { Metadata, } from '@memberjunction/core';
|
|
13
|
+
import { isErrorMetric } from '@memberjunction/predictive-studio-core';
|
|
14
|
+
import { TrainingEngine } from '../training/index.js';
|
|
15
|
+
/** Real wall-clock {@link IClock}. Tests inject a controllable fake instead. */
|
|
16
|
+
export class SystemClock {
|
|
17
|
+
/** @inheritdoc */
|
|
18
|
+
now() {
|
|
19
|
+
return Date.now();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `Metadata.GetEntityObject`-backed {@link IExperimentEntityFactory}. Optionally
|
|
24
|
+
* bound to a specific provider for multi-provider correctness.
|
|
25
|
+
*/
|
|
26
|
+
export class MetadataExperimentEntityFactory {
|
|
27
|
+
/**
|
|
28
|
+
* @param provider optional provider; when supplied it (and its `CurrentUser`)
|
|
29
|
+
* is honored so multi-provider callers create entities on the RIGHT server.
|
|
30
|
+
* When omitted the global default `Metadata` provider is used.
|
|
31
|
+
*/
|
|
32
|
+
constructor(provider) {
|
|
33
|
+
this.provider = provider;
|
|
34
|
+
}
|
|
35
|
+
/** @inheritdoc */
|
|
36
|
+
async getEntityObject(entityName, contextUser) {
|
|
37
|
+
if (this.provider) {
|
|
38
|
+
return this.provider.GetEntityObject(entityName, contextUser ?? this.provider.CurrentUser);
|
|
39
|
+
}
|
|
40
|
+
const md = this.provider ?? new Metadata();
|
|
41
|
+
return md.GetEntityObject(entityName, contextUser);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* {@link IExperimentTrainer} backed by the {@link TrainingEngine}. For each
|
|
46
|
+
* iteration it resolves the pipeline (via an injected {@link IPipelineResolver}),
|
|
47
|
+
* trains it through the engine (producing an immutable Draft `MJ: ML Models` +
|
|
48
|
+
* its `MJ: ML Training Runs` leaf linked to the iteration via
|
|
49
|
+
* `experimentSessionIterationId`), and extracts the normalized holdout Score for
|
|
50
|
+
* the plan's `SuccessMetric` to drive the leaderboard.
|
|
51
|
+
*/
|
|
52
|
+
export class TrainingEngineExperimentTrainer {
|
|
53
|
+
/**
|
|
54
|
+
* @param trainingDeps the training engine's injected dependency bundle
|
|
55
|
+
* @param pipelineResolver maps experiment → pipeline id
|
|
56
|
+
* @param engine optional TrainingEngine override (defaults to a fresh instance)
|
|
57
|
+
*/
|
|
58
|
+
constructor(trainingDeps, pipelineResolver, engine = new TrainingEngine()) {
|
|
59
|
+
this.trainingDeps = trainingDeps;
|
|
60
|
+
this.pipelineResolver = pipelineResolver;
|
|
61
|
+
this.engine = engine;
|
|
62
|
+
}
|
|
63
|
+
/** @inheritdoc */
|
|
64
|
+
async train(input) {
|
|
65
|
+
const pipelineId = await this.pipelineResolver.resolvePipelineId(input);
|
|
66
|
+
const { model, run } = await this.engine.trainModel({
|
|
67
|
+
pipelineId,
|
|
68
|
+
experimentSessionIterationId: input.iterationId,
|
|
69
|
+
}, this.trainingDeps);
|
|
70
|
+
const score = extractNormalizedScore(model.HoldoutMetrics, model.Metrics, input.plan.TargetDefinition.SuccessMetric, input.plan.TargetDefinition.ProblemType);
|
|
71
|
+
return {
|
|
72
|
+
model,
|
|
73
|
+
run,
|
|
74
|
+
Score: score,
|
|
75
|
+
ComputeCost: run.ComputeCost ?? 0,
|
|
76
|
+
TokensUsed: 0,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Extract the **normalized** leaderboard score from a model's holdout metrics
|
|
82
|
+
* (preferred — the honest, search-never-saw-it number, §8.2), falling back to
|
|
83
|
+
* the training metrics. The score is normalized so **higher is always better**:
|
|
84
|
+
* error metrics (RMSE/MAE/loss) are negated, ranking metrics (AUC/F1/accuracy)
|
|
85
|
+
* pass through. Returns `0` when the metric is absent (a failed/empty run).
|
|
86
|
+
*
|
|
87
|
+
* Exported for unit testing the normalization in isolation.
|
|
88
|
+
*
|
|
89
|
+
* @param holdoutMetricsJson the model's `HoldoutMetrics` JSON (preferred)
|
|
90
|
+
* @param trainMetricsJson the model's `Metrics` JSON (fallback)
|
|
91
|
+
* @param successMetric the plan's `SuccessMetric` (e.g. `AUC`, `RMSE`)
|
|
92
|
+
* @param problemType classification vs. regression (informs the error-metric direction)
|
|
93
|
+
*/
|
|
94
|
+
export function extractNormalizedScore(holdoutMetricsJson, trainMetricsJson, successMetric, problemType) {
|
|
95
|
+
const metrics = parseMetrics(holdoutMetricsJson) ?? parseMetrics(trainMetricsJson) ?? {};
|
|
96
|
+
const key = successMetric.toLowerCase();
|
|
97
|
+
const raw = metrics[key];
|
|
98
|
+
if (raw == null || !Number.isFinite(raw)) {
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
// `problemType` is retained on the signature for callers/back-compat; the
|
|
102
|
+
// error-metric direction is metric-name driven (shared with maintenance via
|
|
103
|
+
// the Core `isErrorMetric`) so the two consumers can never drift apart.
|
|
104
|
+
void problemType;
|
|
105
|
+
return isErrorMetric(key) ? -raw : raw;
|
|
106
|
+
}
|
|
107
|
+
/** Parse a metrics JSON column into a lower-cased numeric record, or null. */
|
|
108
|
+
function parseMetrics(json) {
|
|
109
|
+
if (json == null || json.trim().length === 0) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const parsed = JSON.parse(json);
|
|
114
|
+
const out = {};
|
|
115
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
116
|
+
if (typeof v === 'number') {
|
|
117
|
+
out[k.toLowerCase()] = v;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return null;
|
|
124
|
+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AAC,CAAC,CAAC,GAAG,CAAC;AACzC,CAAC;AAED,8EAA8E;AAC9E,SAAS,YAAY,CAAC,IAAmB;IACvC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAC;QAC3D,MAAM,GAAG,GAA2B,EAAE,CAAC;QACvC,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC1B,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module experiment/types
|
|
3
|
+
*
|
|
4
|
+
* Dependency-injection seams and input/output shapes for the
|
|
5
|
+
* {@link ExperimentOrchestrator} (plan §8.3 / §8.4 / §9.1). Every external
|
|
6
|
+
* dependency the orchestrator touches — entity creation, model training, the
|
|
7
|
+
* wall-clock (for budget), and the adaptive "what-next" wave strategist — is
|
|
8
|
+
* expressed as a narrow interface here so the orchestrator is fully
|
|
9
|
+
* deterministic and unit-testable with no live database, no live sidecar, and
|
|
10
|
+
* no real time.
|
|
11
|
+
*
|
|
12
|
+
* The orchestrator is the **execution-phase** code (plan §9.1): it receives an
|
|
13
|
+
* already-**approved** `ModelingPlanSpec` (the approval gate is the agent's job)
|
|
14
|
+
* and executes its `ProposedExperiments` as **waves** with bounded concurrency,
|
|
15
|
+
* a leaderboard, pruning, and a between-wave budget gate.
|
|
16
|
+
*/
|
|
17
|
+
import type { BaseEntity, UserInfo, IMetadataProvider } from '@memberjunction/core';
|
|
18
|
+
import type { ModelingPlanSpec, Budget, LeaderboardEntry } from '@memberjunction/predictive-studio-core';
|
|
19
|
+
import type { MJExperimentEntity, MJExperimentSessionEntity, MJExperimentSessionIterationEntity, MJMLModelEntity, MJMLTrainingRunEntity } from '@memberjunction/core-entities';
|
|
20
|
+
/**
|
|
21
|
+
* One proposed experiment lifted off a {@link ModelingPlanSpec}. Mirrors an
|
|
22
|
+
* element of `ModelingPlanSpec.ProposedExperiments` — kept as a local alias so
|
|
23
|
+
* the orchestrator code reads against a named type.
|
|
24
|
+
*/
|
|
25
|
+
export type ProposedExperiment = ModelingPlanSpec['ProposedExperiments'][number];
|
|
26
|
+
/**
|
|
27
|
+
* Factory seam for creating strongly-typed entity objects. Wraps
|
|
28
|
+
* `Metadata.GetEntityObject` in production; tests inject a fake returning
|
|
29
|
+
* in-memory entity stand-ins. Mirrors {@link IEntityFactory} from the training
|
|
30
|
+
* module but is re-declared here so the experiment engine doesn't re-export
|
|
31
|
+
* across its own sub-modules.
|
|
32
|
+
*/
|
|
33
|
+
export interface IExperimentEntityFactory {
|
|
34
|
+
/**
|
|
35
|
+
* Create a new, unsaved entity object for the named entity. Mirrors
|
|
36
|
+
* `Metadata.GetEntityObject<T>(entityName, contextUser)`.
|
|
37
|
+
*
|
|
38
|
+
* @param entityName MJ entity name (e.g. `MJ: Experiment Sessions`)
|
|
39
|
+
* @param contextUser request user — required on the server for isolation/audit
|
|
40
|
+
*/
|
|
41
|
+
getEntityObject<T extends BaseEntity>(entityName: string, contextUser?: UserInfo): Promise<T>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Monotonic clock seam for wall-clock budget enforcement (plan §8.4). The
|
|
45
|
+
* orchestrator never calls `Date.now()` directly so tests can advance time
|
|
46
|
+
* deterministically. Returns milliseconds since an arbitrary fixed epoch.
|
|
47
|
+
*/
|
|
48
|
+
export interface IClock {
|
|
49
|
+
/** @returns the current time in milliseconds (monotonic, test-controllable). */
|
|
50
|
+
now(): number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The single ML-execution seam the orchestrator depends on for each iteration —
|
|
54
|
+
* "train this experiment, give me the model + run + normalized score." In
|
|
55
|
+
* production this delegates to the `TrainingEngine` (which produces an immutable
|
|
56
|
+
* `MJ: ML Models` + `MJ: ML Training Runs`); tests inject a deterministic fake.
|
|
57
|
+
*
|
|
58
|
+
* The orchestrator is intentionally decoupled from the `TrainingEngine`'s
|
|
59
|
+
* pipeline-id contract: it hands the trainer a {@link TrainExperimentInput}
|
|
60
|
+
* (the experiment definition + the owning iteration id) and receives a
|
|
61
|
+
* {@link TrainExperimentResult}. The production adapter
|
|
62
|
+
* (`TrainingEngineExperimentTrainer`) bridges this to `TrainingEngine.trainModel`.
|
|
63
|
+
*/
|
|
64
|
+
export interface IExperimentTrainer {
|
|
65
|
+
/**
|
|
66
|
+
* Train one experiment and return the produced model, its training-run row,
|
|
67
|
+
* and the normalized holdout {@link TrainExperimentResult.Score} for the
|
|
68
|
+
* plan's `SuccessMetric`. The implementation links the run to the iteration
|
|
69
|
+
* (`ExperimentSessionIterationID`).
|
|
70
|
+
*
|
|
71
|
+
* @param input the experiment to train + the owning iteration/session context
|
|
72
|
+
*/
|
|
73
|
+
train(input: TrainExperimentInput): Promise<TrainExperimentResult>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Input handed to {@link IExperimentTrainer.train} for a single iteration.
|
|
77
|
+
*/
|
|
78
|
+
export interface TrainExperimentInput {
|
|
79
|
+
/** The proposed experiment being trained (algorithm × feature set × hyperparameters). */
|
|
80
|
+
experiment: ProposedExperiment;
|
|
81
|
+
/** The plan being executed (carries TargetDefinition, SuccessMetric, ValidationStrategy). */
|
|
82
|
+
plan: ModelingPlanSpec;
|
|
83
|
+
/** The `MJ: Experiment Session Iterations` id this run belongs to. */
|
|
84
|
+
iterationId: string;
|
|
85
|
+
/** The owning `MJ: Experiment Sessions` id. */
|
|
86
|
+
sessionId: string;
|
|
87
|
+
/** Request user — threaded for isolation/audit. */
|
|
88
|
+
contextUser?: UserInfo;
|
|
89
|
+
/** Optional provider for multi-provider correctness. */
|
|
90
|
+
provider?: IMetadataProvider;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The result of training one experiment — the model produced, the training-run
|
|
94
|
+
* leaf (linked to the iteration), the normalized leaderboard score, and the
|
|
95
|
+
* compute/token cost attributed to the attempt (for budget enforcement, §8.4).
|
|
96
|
+
*/
|
|
97
|
+
export interface TrainExperimentResult {
|
|
98
|
+
/** The immutable `MJ: ML Models` row produced (Draft). */
|
|
99
|
+
model: MJMLModelEntity;
|
|
100
|
+
/** The `MJ: ML Training Runs` leaf recording the attempt (linked to the iteration). */
|
|
101
|
+
run: MJMLTrainingRunEntity;
|
|
102
|
+
/** Normalized holdout metric for the plan's `SuccessMetric` — drives the leaderboard. */
|
|
103
|
+
Score: number;
|
|
104
|
+
/** Compute cost attributed to this attempt (defaults to 0 when unknown). */
|
|
105
|
+
ComputeCost?: number;
|
|
106
|
+
/** LLM tokens used by this attempt (defaults to 0 when unknown). */
|
|
107
|
+
TokensUsed?: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The adaptive "what-next" seam (plan §9.1 — "internal LLM inference is used
|
|
111
|
+
* only for choices"). Given the results so far, decide which experiments to run
|
|
112
|
+
* in the next wave. The **default** implementation is fully deterministic
|
|
113
|
+
* ({@link PlanOrderWaveStrategist}) — it just iterates the plan's
|
|
114
|
+
* `ProposedExperiments` in priority order, in waves. An optional LLM-backed
|
|
115
|
+
* strategist can be injected later to swap in adaptive "given these results,
|
|
116
|
+
* what to try next" behavior without touching the deterministic loop.
|
|
117
|
+
*/
|
|
118
|
+
export interface IWaveStrategist {
|
|
119
|
+
/**
|
|
120
|
+
* Choose the experiments for the next wave.
|
|
121
|
+
*
|
|
122
|
+
* @param context the leaderboard + already-run experiments + remaining
|
|
123
|
+
* candidates + the plan, so the strategist can decide what to try next
|
|
124
|
+
* @returns the experiments to run in the next wave (empty array ends the loop)
|
|
125
|
+
*/
|
|
126
|
+
proposeNextWave(context: WaveStrategistContext): Promise<ProposedExperiment[]> | ProposedExperiment[];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Context handed to {@link IWaveStrategist.proposeNextWave} — everything a
|
|
130
|
+
* strategist (deterministic or LLM-backed) needs to decide the next wave.
|
|
131
|
+
*/
|
|
132
|
+
export interface WaveStrategistContext {
|
|
133
|
+
/** The plan being executed. */
|
|
134
|
+
plan: ModelingPlanSpec;
|
|
135
|
+
/** Experiments NOT yet dispatched (deterministic default draws from here, priority-ordered). */
|
|
136
|
+
remaining: ProposedExperiment[];
|
|
137
|
+
/** The current leaderboard, best-first, across all completed iterations so far. */
|
|
138
|
+
leaderboard: LeaderboardEntry[];
|
|
139
|
+
/** Index of the wave about to be produced (0-based). */
|
|
140
|
+
waveIndex: number;
|
|
141
|
+
/** The max iterations this wave may contain (the configured concurrency). */
|
|
142
|
+
maxWaveSize: number;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Tunables for an orchestration run. All optional with sensible deterministic
|
|
146
|
+
* defaults; tests vary them to drive wave/prune/budget behavior precisely.
|
|
147
|
+
*/
|
|
148
|
+
export interface ExperimentRunOptions {
|
|
149
|
+
/**
|
|
150
|
+
* Max iterations executed concurrently within a wave (bounded concurrency,
|
|
151
|
+
* §8.3). Also bounds the default wave size. Defaults to {@link DEFAULT_WAVE_CONCURRENCY}.
|
|
152
|
+
*/
|
|
153
|
+
concurrency?: number;
|
|
154
|
+
/**
|
|
155
|
+
* Keep the top-K iterations on the leaderboard after each wave; iterations
|
|
156
|
+
* ranked below K are pruned (their Status set to `Pruned`). When omitted, no
|
|
157
|
+
* top-K cap is applied (only the relative-threshold prune, if set, runs).
|
|
158
|
+
*/
|
|
159
|
+
keepTopK?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Prune any completed iteration whose Score is below
|
|
162
|
+
* `bestScore * relativePruneThreshold` (a fraction in [0,1]). E.g. `0.8`
|
|
163
|
+
* prunes anything scoring under 80% of the current best. When omitted, no
|
|
164
|
+
* relative prune is applied.
|
|
165
|
+
*/
|
|
166
|
+
relativePruneThreshold?: number;
|
|
167
|
+
/**
|
|
168
|
+
* Optional override of the session's budget (otherwise taken from
|
|
169
|
+
* `ModelingPlanSpec.ProposedBudget`). Useful for tests.
|
|
170
|
+
*/
|
|
171
|
+
budget?: Budget;
|
|
172
|
+
/** Optional human-readable session name (defaults to a name derived from the plan goal). */
|
|
173
|
+
sessionName?: string;
|
|
174
|
+
/** Optional `MJ: AI Agent Runs` id that owns/drives this session (plan §9.1). */
|
|
175
|
+
agentRunID?: string;
|
|
176
|
+
/**
|
|
177
|
+
* Optional pre-resolved `MJ: Experiments` id to create the session under. When
|
|
178
|
+
* omitted, the orchestrator creates a new durable Experiment definition.
|
|
179
|
+
*/
|
|
180
|
+
experimentID?: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* The injected dependency bundle passed to
|
|
184
|
+
* {@link ExperimentOrchestrator.runSession}. Bundling the seams keeps the
|
|
185
|
+
* orchestrator stateless across calls and lets a caller vary implementations
|
|
186
|
+
* per call.
|
|
187
|
+
*/
|
|
188
|
+
export interface ExperimentDeps {
|
|
189
|
+
/** Entity-creation seam (Experiment / Session / Iteration rows). */
|
|
190
|
+
entityFactory: IExperimentEntityFactory;
|
|
191
|
+
/** Per-iteration training seam (delegates to the TrainingEngine in production). */
|
|
192
|
+
trainer: IExperimentTrainer;
|
|
193
|
+
/** Wall-clock seam for wall-clock budget enforcement (deterministic in tests). */
|
|
194
|
+
clock: IClock;
|
|
195
|
+
/**
|
|
196
|
+
* Optional adaptive wave strategist (plan §9.1). When omitted the orchestrator
|
|
197
|
+
* uses the deterministic {@link PlanOrderWaveStrategist}.
|
|
198
|
+
*/
|
|
199
|
+
waveStrategist?: IWaveStrategist;
|
|
200
|
+
/** Request user — threaded through every entity op for isolation/audit. */
|
|
201
|
+
contextUser?: UserInfo;
|
|
202
|
+
/** Optional provider for multi-provider correctness. */
|
|
203
|
+
provider?: IMetadataProvider;
|
|
204
|
+
}
|
|
205
|
+
/** The reason a session stopped, surfaced on {@link ExperimentSessionResult}. */
|
|
206
|
+
export type SessionStopReason = 'completed' | 'budget-maxRuns' | 'budget-maxComputeCost' | 'budget-maxWallclock';
|
|
207
|
+
/**
|
|
208
|
+
* The result of {@link ExperimentOrchestrator.runSession} — the durable
|
|
209
|
+
* Experiment, the executed Session, the iterations created, the final
|
|
210
|
+
* leaderboard, the best model surfaced, and how/why the session stopped.
|
|
211
|
+
*/
|
|
212
|
+
export interface ExperimentSessionResult {
|
|
213
|
+
/** The durable `MJ: Experiments` definition. */
|
|
214
|
+
experiment: MJExperimentEntity;
|
|
215
|
+
/** The `MJ: Experiment Sessions` row executed (Completed or Paused). */
|
|
216
|
+
session: MJExperimentSessionEntity;
|
|
217
|
+
/** All `MJ: Experiment Session Iterations` created during the run. */
|
|
218
|
+
iterations: MJExperimentSessionIterationEntity[];
|
|
219
|
+
/** The final leaderboard, best-first. */
|
|
220
|
+
leaderboard: LeaderboardEntry[];
|
|
221
|
+
/** The best (winning) model surfaced, if any iteration produced one. */
|
|
222
|
+
bestModel: MJMLModelEntity | null;
|
|
223
|
+
/** Why the session stopped (completed vs. a clean budget pause). */
|
|
224
|
+
stopReason: SessionStopReason;
|
|
225
|
+
}
|
|
226
|
+
/** Default bounded concurrency / max wave size when none is configured (§8.3). */
|
|
227
|
+
export declare const DEFAULT_WAVE_CONCURRENCY = 3;
|
|
228
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/experiment/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAA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IACH,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,2EAA2E;IAC3E,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED,iFAAiF;AACjF,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,gBAAgB,GAChB,uBAAuB,GACvB,qBAAqB,CAAC;AAE1B;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,gDAAgD;IAChD,UAAU,EAAE,kBAAkB,CAAC;IAC/B,wEAAwE;IACxE,OAAO,EAAE,yBAAyB,CAAC;IACnC,sEAAsE;IACtE,UAAU,EAAE,kCAAkC,EAAE,CAAC;IACjD,yCAAyC;IACzC,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,wEAAwE;IACxE,SAAS,EAAE,eAAe,GAAG,IAAI,CAAC;IAClC,oEAAoE;IACpE,UAAU,EAAE,iBAAiB,CAAC;CAC/B;AAED,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,IAAI,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module experiment/types
|
|
3
|
+
*
|
|
4
|
+
* Dependency-injection seams and input/output shapes for the
|
|
5
|
+
* {@link ExperimentOrchestrator} (plan §8.3 / §8.4 / §9.1). Every external
|
|
6
|
+
* dependency the orchestrator touches — entity creation, model training, the
|
|
7
|
+
* wall-clock (for budget), and the adaptive "what-next" wave strategist — is
|
|
8
|
+
* expressed as a narrow interface here so the orchestrator is fully
|
|
9
|
+
* deterministic and unit-testable with no live database, no live sidecar, and
|
|
10
|
+
* no real time.
|
|
11
|
+
*
|
|
12
|
+
* The orchestrator is the **execution-phase** code (plan §9.1): it receives an
|
|
13
|
+
* already-**approved** `ModelingPlanSpec` (the approval gate is the agent's job)
|
|
14
|
+
* and executes its `ProposedExperiments` as **waves** with bounded concurrency,
|
|
15
|
+
* a leaderboard, pruning, and a between-wave budget gate.
|
|
16
|
+
*/
|
|
17
|
+
/** Default bounded concurrency / max wave size when none is configured (§8.3). */
|
|
18
|
+
export const DEFAULT_WAVE_CONCURRENCY = 3;
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/experiment/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA8OH,kFAAkF;AAClF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module experiment/wave-strategist
|
|
3
|
+
*
|
|
4
|
+
* The default, fully-deterministic {@link IWaveStrategist} for the
|
|
5
|
+
* {@link ExperimentOrchestrator}. It simply draws the next wave from the plan's
|
|
6
|
+
* remaining `ProposedExperiments` in **priority order** (plan §9.1 — the
|
|
7
|
+
* execution phase is deterministic-heavy; the adaptive "what-next" hook is an
|
|
8
|
+
* optional injectable strategist that can be swapped in later).
|
|
9
|
+
*
|
|
10
|
+
* Keeping the default here (rather than inline in the orchestrator) makes the
|
|
11
|
+
* "what-next" seam an explicit, separately-testable strategy.
|
|
12
|
+
*/
|
|
13
|
+
import type { IWaveStrategist, ProposedExperiment, WaveStrategistContext } from './types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Deterministic plan-order strategist: emits the next `maxWaveSize` remaining
|
|
16
|
+
* experiments, lowest `Priority` number first (1 = highest priority). Ties break
|
|
17
|
+
* by the experiment's original index so the order is stable. Ignores the
|
|
18
|
+
* leaderboard entirely — it is purely "work the plan, in waves."
|
|
19
|
+
*/
|
|
20
|
+
export declare class PlanOrderWaveStrategist implements IWaveStrategist {
|
|
21
|
+
/** @inheritdoc */
|
|
22
|
+
proposeNextWave(context: WaveStrategistContext): ProposedExperiment[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Sort proposed experiments by ascending `Priority` (1 first), stable on
|
|
26
|
+
* original order for ties. Does not mutate the input.
|
|
27
|
+
*
|
|
28
|
+
* @param experiments the experiments to order
|
|
29
|
+
*/
|
|
30
|
+
export declare function sortByPriority(experiments: ProposedExperiment[]): ProposedExperiment[];
|
|
31
|
+
//# sourceMappingURL=wave-strategist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wave-strategist.d.ts","sourceRoot":"","sources":["../../src/experiment/wave-strategist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,eAAe;IAC7D,kBAAkB;IACX,eAAe,CAAC,OAAO,EAAE,qBAAqB,GAAG,kBAAkB,EAAE;CAI7E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,kBAAkB,EAAE,CAYtF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module experiment/wave-strategist
|
|
3
|
+
*
|
|
4
|
+
* The default, fully-deterministic {@link IWaveStrategist} for the
|
|
5
|
+
* {@link ExperimentOrchestrator}. It simply draws the next wave from the plan's
|
|
6
|
+
* remaining `ProposedExperiments` in **priority order** (plan §9.1 — the
|
|
7
|
+
* execution phase is deterministic-heavy; the adaptive "what-next" hook is an
|
|
8
|
+
* optional injectable strategist that can be swapped in later).
|
|
9
|
+
*
|
|
10
|
+
* Keeping the default here (rather than inline in the orchestrator) makes the
|
|
11
|
+
* "what-next" seam an explicit, separately-testable strategy.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Deterministic plan-order strategist: emits the next `maxWaveSize` remaining
|
|
15
|
+
* experiments, lowest `Priority` number first (1 = highest priority). Ties break
|
|
16
|
+
* by the experiment's original index so the order is stable. Ignores the
|
|
17
|
+
* leaderboard entirely — it is purely "work the plan, in waves."
|
|
18
|
+
*/
|
|
19
|
+
export class PlanOrderWaveStrategist {
|
|
20
|
+
/** @inheritdoc */
|
|
21
|
+
proposeNextWave(context) {
|
|
22
|
+
const ordered = sortByPriority(context.remaining);
|
|
23
|
+
return ordered.slice(0, Math.max(0, context.maxWaveSize));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sort proposed experiments by ascending `Priority` (1 first), stable on
|
|
28
|
+
* original order for ties. Does not mutate the input.
|
|
29
|
+
*
|
|
30
|
+
* @param experiments the experiments to order
|
|
31
|
+
*/
|
|
32
|
+
export function sortByPriority(experiments) {
|
|
33
|
+
return experiments
|
|
34
|
+
.map((experiment, index) => ({ experiment, index }))
|
|
35
|
+
.sort((a, b) => {
|
|
36
|
+
const pa = priorityOf(a.experiment);
|
|
37
|
+
const pb = priorityOf(b.experiment);
|
|
38
|
+
if (pa !== pb) {
|
|
39
|
+
return pa - pb;
|
|
40
|
+
}
|
|
41
|
+
return a.index - b.index;
|
|
42
|
+
})
|
|
43
|
+
.map((wrapped) => wrapped.experiment);
|
|
44
|
+
}
|
|
45
|
+
/** Read a stable numeric priority, treating missing/NaN as lowest priority. */
|
|
46
|
+
function priorityOf(experiment) {
|
|
47
|
+
const p = experiment.Priority;
|
|
48
|
+
return Number.isFinite(p) ? p : Number.MAX_SAFE_INTEGER;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=wave-strategist.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wave-strategist.js","sourceRoot":"","sources":["../../src/experiment/wave-strategist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAQH;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IAClC,kBAAkB;IACX,eAAe,CAAC,OAA8B;QACnD,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAClD,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,WAAiC;IAC9D,OAAO,WAAW;SACf,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;SACnD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QACpC,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QACpC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACd,OAAO,EAAE,GAAG,EAAE,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;IAC3B,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC1C,CAAC;AAED,+EAA+E;AAC/E,SAAS,UAAU,CAAC,UAA8B;IAChD,MAAM,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC;IAC9B,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,gBAAgB,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module feature-assembly/as-of
|
|
3
|
+
*
|
|
4
|
+
* Point-in-time ("as-of") assembly — the single biggest **new** correctness
|
|
5
|
+
* primitive in Predictive Studio (plan §6.3). For forward prediction, features
|
|
6
|
+
* must be assembled **as they were at the decision point**, not as they are
|
|
7
|
+
* today. A time-relative feature like `days_since_last_activity` computed over
|
|
8
|
+
* data that includes events *after* the decision date leaks the future and
|
|
9
|
+
* produces a model that scores beautifully in the lab and uselessly in
|
|
10
|
+
* production.
|
|
11
|
+
*
|
|
12
|
+
* This module resolves a per-record **as-of date** from the {@link AsOfStrategy}
|
|
13
|
+
* and provides helpers that filter dated source rows to those at-or-before that
|
|
14
|
+
* date, then compute recency/aggregate features only over the surviving rows.
|
|
15
|
+
*/
|
|
16
|
+
import type { AsOfStrategy } from '@memberjunction/predictive-studio-core';
|
|
17
|
+
import type { SourceRow } from './data-access.js';
|
|
18
|
+
/** A single dated event/activity row scoped to a target record. */
|
|
19
|
+
export interface DatedRow {
|
|
20
|
+
/** The event's timestamp. */
|
|
21
|
+
Date: Date;
|
|
22
|
+
/** The underlying source row (carried through for aggregate computations). */
|
|
23
|
+
Row: SourceRow;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the per-record as-of date from the configured {@link AsOfStrategy}.
|
|
27
|
+
*
|
|
28
|
+
* - `none` → `null` (no point-in-time filtering; features reflect "now").
|
|
29
|
+
* - `column` → the value of `Strategy.Column` on the record, parsed as a date.
|
|
30
|
+
* - `offset` → `labelEventDate − OffsetDays`. The label-event date is the
|
|
31
|
+
* per-record anchor (e.g. the renewal-window start); we assemble features as
|
|
32
|
+
* of N days *before* it so the model only ever sees pre-decision data.
|
|
33
|
+
*
|
|
34
|
+
* @param strategy the configured as-of strategy
|
|
35
|
+
* @param record the training/scoring unit record
|
|
36
|
+
* @param labelEventDate the record's label-event date (required for `offset`)
|
|
37
|
+
* @returns the resolved as-of cutoff, or `null` when no filtering applies
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveAsOfDate(strategy: AsOfStrategy, record: SourceRow, labelEventDate?: Date | null): Date | null;
|
|
40
|
+
/**
|
|
41
|
+
* Filters dated rows to those occurring at-or-before the as-of cutoff. A `null`
|
|
42
|
+
* cutoff (i.e. `Mode='none'`) is the identity filter — all rows survive.
|
|
43
|
+
*
|
|
44
|
+
* This is the leakage-prevention boundary: **only** rows passing this filter may
|
|
45
|
+
* feed any time-relative feature.
|
|
46
|
+
*
|
|
47
|
+
* @param rows the candidate dated rows for one record
|
|
48
|
+
* @param asOfDate the resolved cutoff, or `null` for no filtering
|
|
49
|
+
* @returns the rows at-or-before the cutoff
|
|
50
|
+
*/
|
|
51
|
+
export declare function filterAsOf(rows: DatedRow[], asOfDate: Date | null): DatedRow[];
|
|
52
|
+
/**
|
|
53
|
+
* Computes `days_since_last_activity` as of the cutoff: the whole-day gap
|
|
54
|
+
* between the cutoff date and the most recent surviving event. Returns `null`
|
|
55
|
+
* when there is no qualifying activity (the caller decides how to encode "no
|
|
56
|
+
* activity" — typically imputed downstream by the sidecar, §6.2).
|
|
57
|
+
*
|
|
58
|
+
* Computing recency relative to the **as-of date** (not "now") is what keeps
|
|
59
|
+
* train-time ("as-of-then") and score-time ("as-of-now") consistent.
|
|
60
|
+
*
|
|
61
|
+
* @param rows candidate dated rows (will be filtered to the cutoff internally)
|
|
62
|
+
* @param asOfDate the resolved cutoff; when `null`, recency is measured from "now"
|
|
63
|
+
*/
|
|
64
|
+
export declare function daysSinceLastActivityAsOf(rows: DatedRow[], asOfDate: Date | null): number | null;
|
|
65
|
+
/**
|
|
66
|
+
* Counts surviving activity rows as of the cutoff — a generic point-in-time
|
|
67
|
+
* aggregate (e.g. `activity_count_asof`). Only rows at-or-before the cutoff are
|
|
68
|
+
* counted, preventing future leakage.
|
|
69
|
+
*
|
|
70
|
+
* @param rows candidate dated rows
|
|
71
|
+
* @param asOfDate the resolved cutoff, or `null` for no filtering
|
|
72
|
+
*/
|
|
73
|
+
export declare function activityCountAsOf(rows: DatedRow[], asOfDate: Date | null): number;
|
|
74
|
+
//# sourceMappingURL=as-of.d.ts.map
|