@memberjunction/predictive-studio 6.2.0-edge.5 → 6.2.0-edge.7
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 +18 -14
- package/dist/actions/driver-classes.d.ts +11 -0
- package/dist/actions/driver-classes.d.ts.map +1 -0
- package/dist/actions/driver-classes.js +11 -0
- package/dist/actions/driver-classes.js.map +1 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.d.ts.map +1 -1
- package/dist/actions/index.js +1 -0
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/model-scoring-action-generator.d.ts.map +1 -1
- package/dist/actions/model-scoring-action-generator.js +4 -1
- package/dist/actions/model-scoring-action-generator.js.map +1 -1
- package/dist/actions/promote-model.action.d.ts +3 -2
- package/dist/actions/promote-model.action.d.ts.map +1 -1
- package/dist/actions/promote-model.action.js +4 -3
- package/dist/actions/promote-model.action.js.map +1 -1
- package/dist/actions/promote-model.gate.d.ts +5 -5
- package/dist/actions/promote-model.gate.d.ts.map +1 -1
- package/dist/actions/promote-model.gate.js +10 -14
- package/dist/actions/promote-model.gate.js.map +1 -1
- package/dist/actions/run-experiment.action.d.ts +13 -5
- package/dist/actions/run-experiment.action.d.ts.map +1 -1
- package/dist/actions/run-experiment.action.js +26 -7
- package/dist/actions/run-experiment.action.js.map +1 -1
- package/dist/actions/run-experiment.deps.d.ts +19 -27
- package/dist/actions/run-experiment.deps.d.ts.map +1 -1
- package/dist/actions/run-experiment.deps.js +23 -48
- package/dist/actions/run-experiment.deps.js.map +1 -1
- package/dist/actions/schedule-model-scoring.action.d.ts +1 -1
- package/dist/actions/schedule-model-scoring.action.d.ts.map +1 -1
- package/dist/actions/schedule-model-scoring.action.js +2 -1
- package/dist/actions/schedule-model-scoring.action.js.map +1 -1
- package/dist/actions/score-record-set.action.d.ts +8 -3
- package/dist/actions/score-record-set.action.d.ts.map +1 -1
- package/dist/actions/score-record-set.action.js +16 -7
- package/dist/actions/score-record-set.action.js.map +1 -1
- package/dist/actions/score-record-set.runner.d.ts +62 -32
- package/dist/actions/score-record-set.runner.d.ts.map +1 -1
- package/dist/actions/score-record-set.runner.js +123 -68
- package/dist/actions/score-record-set.runner.js.map +1 -1
- package/dist/actions/train-model.action.d.ts +4 -6
- package/dist/actions/train-model.action.d.ts.map +1 -1
- package/dist/actions/train-model.action.js +13 -20
- package/dist/actions/train-model.action.js.map +1 -1
- package/dist/agent/modeling-plan-to-pipeline.d.ts +5 -2
- package/dist/agent/modeling-plan-to-pipeline.d.ts.map +1 -1
- package/dist/agent/modeling-plan-to-pipeline.js +32 -7
- package/dist/agent/modeling-plan-to-pipeline.js.map +1 -1
- package/dist/agent/pipeline-builder-agent.d.ts +20 -5
- package/dist/agent/pipeline-builder-agent.d.ts.map +1 -1
- package/dist/agent/pipeline-builder-agent.js +73 -46
- package/dist/agent/pipeline-builder-agent.js.map +1 -1
- package/dist/agent/pipeline-builder.d.ts +37 -5
- package/dist/agent/pipeline-builder.d.ts.map +1 -1
- package/dist/agent/pipeline-builder.js +91 -96
- package/dist/agent/pipeline-builder.js.map +1 -1
- package/dist/feature-assembly/data-access.d.ts +12 -8
- package/dist/feature-assembly/data-access.d.ts.map +1 -1
- package/dist/feature-assembly/data-access.js +8 -10
- package/dist/feature-assembly/data-access.js.map +1 -1
- package/dist/feature-assembly/feature-assembly-executor.d.ts +4 -4
- package/dist/feature-assembly/feature-assembly-executor.d.ts.map +1 -1
- package/dist/feature-assembly/feature-assembly-executor.js +6 -0
- package/dist/feature-assembly/feature-assembly-executor.js.map +1 -1
- package/dist/feature-assembly/index.d.ts +1 -0
- package/dist/feature-assembly/index.d.ts.map +1 -1
- package/dist/feature-assembly/index.js +1 -0
- package/dist/feature-assembly/index.js.map +1 -1
- package/dist/feature-assembly/read-cap-error.d.ts +23 -0
- package/dist/feature-assembly/read-cap-error.d.ts.map +1 -0
- package/dist/feature-assembly/read-cap-error.js +35 -0
- package/dist/feature-assembly/read-cap-error.js.map +1 -0
- package/dist/maintenance/seams.d.ts +4 -4
- package/dist/maintenance/seams.d.ts.map +1 -1
- package/dist/maintenance/seams.js +9 -4
- package/dist/maintenance/seams.js.map +1 -1
- package/dist/maintenance/types.d.ts +10 -10
- package/dist/maintenance/types.d.ts.map +1 -1
- package/dist/operations/delegation.d.ts +16 -17
- package/dist/operations/delegation.d.ts.map +1 -1
- package/dist/operations/delegation.js +18 -19
- package/dist/operations/delegation.js.map +1 -1
- package/dist/operations/index.d.ts +1 -0
- package/dist/operations/index.d.ts.map +1 -1
- package/dist/operations/index.js +1 -0
- package/dist/operations/index.js.map +1 -1
- package/dist/operations/promote-model.operation.d.ts +1 -1
- package/dist/operations/promote-model.operation.js +1 -1
- package/dist/operations/refusals.d.ts +16 -0
- package/dist/operations/refusals.d.ts.map +1 -0
- package/dist/operations/refusals.js +44 -0
- package/dist/operations/refusals.js.map +1 -0
- package/dist/operations/score-record-set.operation.d.ts +4 -2
- package/dist/operations/score-record-set.operation.d.ts.map +1 -1
- package/dist/operations/score-record-set.operation.js +7 -1
- package/dist/operations/score-record-set.operation.js.map +1 -1
- package/dist/operations/start-experiment-session.operation.d.ts +14 -18
- package/dist/operations/start-experiment-session.operation.d.ts.map +1 -1
- package/dist/operations/start-experiment-session.operation.js +23 -21
- package/dist/operations/start-experiment-session.operation.js.map +1 -1
- package/dist/operations/train-model.operation.d.ts +4 -2
- package/dist/operations/train-model.operation.d.ts.map +1 -1
- package/dist/operations/train-model.operation.js +10 -1
- package/dist/operations/train-model.operation.js.map +1 -1
- package/dist/scheduling/scheduled-model-scoring.d.ts +2 -2
- package/dist/scheduling/scheduled-model-scoring.d.ts.map +1 -1
- package/dist/scheduling/scheduled-model-scoring.js +1 -2
- package/dist/scheduling/scheduled-model-scoring.js.map +1 -1
- package/dist/scoring/auto-train.d.ts.map +1 -1
- package/dist/scoring/auto-train.js +6 -10
- package/dist/scoring/auto-train.js.map +1 -1
- package/dist/scoring/ml-model-inference-processor.d.ts +13 -0
- package/dist/scoring/ml-model-inference-processor.d.ts.map +1 -1
- package/dist/scoring/ml-model-inference-processor.js +36 -7
- package/dist/scoring/ml-model-inference-processor.js.map +1 -1
- package/dist/scoring/ml-model-score-enricher.d.ts.map +1 -1
- package/dist/scoring/ml-model-score-enricher.js +5 -0
- package/dist/scoring/ml-model-score-enricher.js.map +1 -1
- package/dist/scoring/model-readiness.d.ts +13 -0
- package/dist/scoring/model-readiness.d.ts.map +1 -1
- package/dist/scoring/model-readiness.js +20 -0
- package/dist/scoring/model-readiness.js.map +1 -1
- package/dist/scoring/scoring-process.d.ts +2 -2
- package/dist/scoring/scoring-process.d.ts.map +1 -1
- package/dist/scoring/scoring-process.js +1 -2
- package/dist/scoring/scoring-process.js.map +1 -1
- package/dist/scoring/seams.d.ts +1 -1
- package/dist/scoring/seams.d.ts.map +1 -1
- package/dist/scoring/seams.js +2 -1
- package/dist/scoring/seams.js.map +1 -1
- package/dist/scoring/startup-register.d.ts +1 -1
- package/dist/scoring/startup-register.js +1 -1
- package/dist/scoring/types.d.ts +2 -2
- package/dist/scoring/types.d.ts.map +1 -1
- package/dist/training/artifact-store.d.ts +3 -3
- package/dist/training/artifact-store.d.ts.map +1 -1
- package/dist/training/artifact-store.js +3 -2
- package/dist/training/artifact-store.js.map +1 -1
- package/dist/training/as-of-refusal.d.ts +35 -0
- package/dist/training/as-of-refusal.d.ts.map +1 -0
- package/dist/training/as-of-refusal.js +48 -0
- package/dist/training/as-of-refusal.js.map +1 -0
- package/dist/training/index.d.ts +2 -0
- package/dist/training/index.d.ts.map +1 -1
- package/dist/training/index.js +2 -0
- package/dist/training/index.js.map +1 -1
- package/dist/training/locked-holdout.d.ts +73 -0
- package/dist/training/locked-holdout.d.ts.map +1 -0
- package/dist/training/locked-holdout.js +151 -0
- package/dist/training/locked-holdout.js.map +1 -0
- package/dist/training/seams.d.ts +10 -11
- package/dist/training/seams.d.ts.map +1 -1
- package/dist/training/seams.js +13 -15
- package/dist/training/seams.js.map +1 -1
- package/dist/training/training-engine.d.ts +23 -9
- package/dist/training/training-engine.d.ts.map +1 -1
- package/dist/training/training-engine.js +80 -55
- package/dist/training/training-engine.js.map +1 -1
- package/dist/training/types.d.ts +40 -12
- package/dist/training/types.d.ts.map +1 -1
- package/package.json +13 -13
package/dist/training/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/training/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/training/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module training/locked-holdout
|
|
3
|
+
*
|
|
4
|
+
* The seeded carve of the **locked holdout** (plan §8.2) that training takes off the assembled rows before anything
|
|
5
|
+
* is sent to the sidecar. The rows that land in the holdout depend only on the row values, their order and the seed,
|
|
6
|
+
* so the same training read with the same seed always holds out the same rows. Classification holdouts are
|
|
7
|
+
* stratified on the label (as the sidecar's own split is), so an imbalanced or small target keeps every class in the
|
|
8
|
+
* holdout when the data allows it; regression holdouts are a plain seeded sample.
|
|
9
|
+
*/
|
|
10
|
+
import type { MatrixData, ProblemType } from '@memberjunction/predictive-studio-core';
|
|
11
|
+
/**
|
|
12
|
+
* The seed for every training split: the engine's locked-holdout carve and the sidecar's train/test and k-fold splits
|
|
13
|
+
* (sent as `ValidationConfig.random_state`). 42 is the sidecar's own default, so the two sides always agree.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_SPLIT_SEED = 42;
|
|
16
|
+
/** The result of carving a matrix into a training portion and a locked holdout; both keep the input row order. */
|
|
17
|
+
export interface LockedHoldoutSplit {
|
|
18
|
+
/** The rows the model may train and tune on. */
|
|
19
|
+
Training: MatrixData;
|
|
20
|
+
/** The rows scored exactly once, never trained on. */
|
|
21
|
+
LockedHoldout: MatrixData;
|
|
22
|
+
/** `LockedHoldout.rows.length`. */
|
|
23
|
+
HoldoutRowCount: number;
|
|
24
|
+
/** `Training.rows.length`. */
|
|
25
|
+
TrainingRowCount: number;
|
|
26
|
+
/**
|
|
27
|
+
* Holdout rows per label (label as text → row count) for a classification carve; an empty object for regression
|
|
28
|
+
* or when the label column is absent. Training stores it in the model Lineage as `lockedHoldoutClassCounts`.
|
|
29
|
+
*/
|
|
30
|
+
HoldoutClassCounts: Record<string, number>;
|
|
31
|
+
}
|
|
32
|
+
/** Seeded, stratified locked-holdout carve. Pure; no I/O. */
|
|
33
|
+
export declare class LockedHoldoutSplitter {
|
|
34
|
+
/**
|
|
35
|
+
* How many rows a fraction holds out of `total`: at least one when the fraction is positive, never every row (one
|
|
36
|
+
* row always stays for training), and none when there is at most one row.
|
|
37
|
+
*/
|
|
38
|
+
static HoldoutCount(total: number, fraction: number): number;
|
|
39
|
+
/**
|
|
40
|
+
* Carve the locked holdout off `matrix`.
|
|
41
|
+
*
|
|
42
|
+
* @param matrix the assembled rows (rows with no label already removed)
|
|
43
|
+
* @param fraction the pipeline's `LockedHoldoutFraction`
|
|
44
|
+
* @param targetColumn the label column; when it is not in the matrix the carve is a plain seeded sample
|
|
45
|
+
* @param problemType classification carves are stratified on the label; regression carves are not
|
|
46
|
+
* @param seed the split seed (normally {@link DEFAULT_SPLIT_SEED})
|
|
47
|
+
*/
|
|
48
|
+
static Carve(matrix: MatrixData, fraction: number, targetColumn: string, problemType: ProblemType, seed: number): LockedHoldoutSplit;
|
|
49
|
+
/** Rows per label, keyed by the label as text (the same key the stratified carve groups on), in sorted label order. */
|
|
50
|
+
private static countLabels;
|
|
51
|
+
/**
|
|
52
|
+
* Pick `holdoutCount` row indices so each label keeps its share of the rows (largest remainder), every label with
|
|
53
|
+
* at least two rows gets one holdout row when there are enough holdout rows to go round, and no label loses all of
|
|
54
|
+
* its training rows unless the holdout cannot be filled otherwise.
|
|
55
|
+
*/
|
|
56
|
+
private static stratifiedPick;
|
|
57
|
+
/** Remove holdout rows from the most over-allocated labels until the total fits, keeping each label's first row. */
|
|
58
|
+
private static trimTo;
|
|
59
|
+
/** Add holdout rows to the most under-allocated labels (up to `cap`) until the total is reached or no label has room. */
|
|
60
|
+
private static fillTo;
|
|
61
|
+
/** `0..count-1` in a seeded random order. */
|
|
62
|
+
private static shuffledIndices;
|
|
63
|
+
/** Fisher–Yates shuffle driven by the seeded generator. */
|
|
64
|
+
private static shuffleInPlace;
|
|
65
|
+
/**
|
|
66
|
+
* mulberry32: a small, fast 32-bit seeded generator returning floats in [0, 1). Local so the carve has no dependency
|
|
67
|
+
* whose algorithm could change under it — the same seed must give the same holdout across releases.
|
|
68
|
+
*/
|
|
69
|
+
private static mulberry32;
|
|
70
|
+
/** A fraction clamped into [0, 1]; a non-finite or negative value is 0. */
|
|
71
|
+
private static clampFraction;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=locked-holdout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locked-holdout.d.ts","sourceRoot":"","sources":["../../src/training/locked-holdout.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AAEtF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC,kHAAkH;AAClH,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,QAAQ,EAAE,UAAU,CAAC;IACrB,sDAAsD;IACtD,aAAa,EAAE,UAAU,CAAC;IAC1B,mCAAmC;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,8BAA8B;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C;AAYD,6DAA6D;AAC7D,qBAAa,qBAAqB;IAChC;;;OAGG;WACW,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAMnE;;;;;;;;OAQG;WACW,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB;IAsB3I,uHAAuH;IACvH,OAAO,CAAC,MAAM,CAAC,WAAW;IAW1B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;IA4B7B,oHAAoH;IACpH,OAAO,CAAC,MAAM,CAAC,MAAM;IAWrB,yHAAyH;IACzH,OAAO,CAAC,MAAM,CAAC,MAAM;IAWrB,6CAA6C;IAC7C,OAAO,CAAC,MAAM,CAAC,eAAe;IAM9B,2DAA2D;IAC3D,OAAO,CAAC,MAAM,CAAC,cAAc;IAS7B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAWzB,2EAA2E;IAC3E,OAAO,CAAC,MAAM,CAAC,aAAa;CAI7B"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seed for every training split: the engine's locked-holdout carve and the sidecar's train/test and k-fold splits
|
|
3
|
+
* (sent as `ValidationConfig.random_state`). 42 is the sidecar's own default, so the two sides always agree.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_SPLIT_SEED = 42;
|
|
6
|
+
/** Seeded, stratified locked-holdout carve. Pure; no I/O. */
|
|
7
|
+
export class LockedHoldoutSplitter {
|
|
8
|
+
/**
|
|
9
|
+
* How many rows a fraction holds out of `total`: at least one when the fraction is positive, never every row (one
|
|
10
|
+
* row always stays for training), and none when there is at most one row.
|
|
11
|
+
*/
|
|
12
|
+
static HoldoutCount(total, fraction) {
|
|
13
|
+
const f = LockedHoldoutSplitter.clampFraction(fraction);
|
|
14
|
+
if (total <= 1)
|
|
15
|
+
return 0;
|
|
16
|
+
return Math.min(Math.max(Math.floor(total * f), f > 0 ? 1 : 0), total - 1);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Carve the locked holdout off `matrix`.
|
|
20
|
+
*
|
|
21
|
+
* @param matrix the assembled rows (rows with no label already removed)
|
|
22
|
+
* @param fraction the pipeline's `LockedHoldoutFraction`
|
|
23
|
+
* @param targetColumn the label column; when it is not in the matrix the carve is a plain seeded sample
|
|
24
|
+
* @param problemType classification carves are stratified on the label; regression carves are not
|
|
25
|
+
* @param seed the split seed (normally {@link DEFAULT_SPLIT_SEED})
|
|
26
|
+
*/
|
|
27
|
+
static Carve(matrix, fraction, targetColumn, problemType, seed) {
|
|
28
|
+
const total = matrix.rows.length;
|
|
29
|
+
const holdoutCount = LockedHoldoutSplitter.HoldoutCount(total, fraction);
|
|
30
|
+
const targetIdx = matrix.columns.indexOf(targetColumn);
|
|
31
|
+
const random = LockedHoldoutSplitter.mulberry32(seed);
|
|
32
|
+
const holdoutIndices = problemType === 'classification' && targetIdx >= 0
|
|
33
|
+
? LockedHoldoutSplitter.stratifiedPick(matrix, targetIdx, holdoutCount, random)
|
|
34
|
+
: LockedHoldoutSplitter.shuffledIndices(total, random).slice(0, holdoutCount);
|
|
35
|
+
const inHoldout = new Set(holdoutIndices);
|
|
36
|
+
const trainingRows = matrix.rows.filter((_r, i) => !inHoldout.has(i));
|
|
37
|
+
const holdoutRows = matrix.rows.filter((_r, i) => inHoldout.has(i));
|
|
38
|
+
return {
|
|
39
|
+
Training: { columns: matrix.columns, rows: trainingRows },
|
|
40
|
+
LockedHoldout: { columns: matrix.columns, rows: holdoutRows },
|
|
41
|
+
HoldoutRowCount: holdoutRows.length,
|
|
42
|
+
TrainingRowCount: trainingRows.length,
|
|
43
|
+
HoldoutClassCounts: problemType === 'classification' && targetIdx >= 0 ? LockedHoldoutSplitter.countLabels(holdoutRows, targetIdx) : {},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Rows per label, keyed by the label as text (the same key the stratified carve groups on), in sorted label order. */
|
|
47
|
+
static countLabels(rows, targetIdx) {
|
|
48
|
+
const counts = new Map();
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
const key = String(row[targetIdx]);
|
|
51
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
52
|
+
}
|
|
53
|
+
const sorted = {};
|
|
54
|
+
for (const key of [...counts.keys()].sort())
|
|
55
|
+
sorted[key] = counts.get(key);
|
|
56
|
+
return sorted;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Pick `holdoutCount` row indices so each label keeps its share of the rows (largest remainder), every label with
|
|
60
|
+
* at least two rows gets one holdout row when there are enough holdout rows to go round, and no label loses all of
|
|
61
|
+
* its training rows unless the holdout cannot be filled otherwise.
|
|
62
|
+
*/
|
|
63
|
+
static stratifiedPick(matrix, targetIdx, holdoutCount, random) {
|
|
64
|
+
const total = matrix.rows.length;
|
|
65
|
+
const byLabel = new Map();
|
|
66
|
+
matrix.rows.forEach((row, i) => {
|
|
67
|
+
const key = String(row[targetIdx]);
|
|
68
|
+
const list = byLabel.get(key);
|
|
69
|
+
if (list)
|
|
70
|
+
list.push(i);
|
|
71
|
+
else
|
|
72
|
+
byLabel.set(key, [i]);
|
|
73
|
+
});
|
|
74
|
+
// Sorted label order, so the result does not depend on which label happens to appear first.
|
|
75
|
+
const groups = [...byLabel.keys()].sort().map((key) => {
|
|
76
|
+
const indices = byLabel.get(key);
|
|
77
|
+
LockedHoldoutSplitter.shuffleInPlace(indices, random);
|
|
78
|
+
const ideal = (indices.length * holdoutCount) / total;
|
|
79
|
+
return { indices, ideal, take: Math.min(Math.floor(ideal), indices.length - 1) };
|
|
80
|
+
});
|
|
81
|
+
const splittable = groups.filter((g) => g.indices.length >= 2);
|
|
82
|
+
if (holdoutCount >= splittable.length) {
|
|
83
|
+
for (const g of splittable)
|
|
84
|
+
g.take = Math.max(g.take, 1);
|
|
85
|
+
}
|
|
86
|
+
LockedHoldoutSplitter.trimTo(groups, holdoutCount);
|
|
87
|
+
LockedHoldoutSplitter.fillTo(groups, holdoutCount, (g) => g.indices.length - 1);
|
|
88
|
+
// Only when every label is down to one training row: complete the holdout from the remaining rows.
|
|
89
|
+
LockedHoldoutSplitter.fillTo(groups, holdoutCount, (g) => g.indices.length);
|
|
90
|
+
return groups.flatMap((g) => g.indices.slice(0, g.take));
|
|
91
|
+
}
|
|
92
|
+
/** Remove holdout rows from the most over-allocated labels until the total fits, keeping each label's first row. */
|
|
93
|
+
static trimTo(groups, holdoutCount) {
|
|
94
|
+
let sum = groups.reduce((s, g) => s + g.take, 0);
|
|
95
|
+
while (sum > holdoutCount) {
|
|
96
|
+
const candidates = groups.filter((g) => g.take > 1);
|
|
97
|
+
const pool = candidates.length > 0 ? candidates : groups.filter((g) => g.take > 0);
|
|
98
|
+
const most = pool.reduce((a, b) => (b.take - b.ideal > a.take - a.ideal ? b : a));
|
|
99
|
+
most.take--;
|
|
100
|
+
sum--;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** Add holdout rows to the most under-allocated labels (up to `cap`) until the total is reached or no label has room. */
|
|
104
|
+
static fillTo(groups, holdoutCount, cap) {
|
|
105
|
+
let sum = groups.reduce((s, g) => s + g.take, 0);
|
|
106
|
+
while (sum < holdoutCount) {
|
|
107
|
+
const pool = groups.filter((g) => g.take < cap(g));
|
|
108
|
+
if (pool.length === 0)
|
|
109
|
+
return;
|
|
110
|
+
const least = pool.reduce((a, b) => (b.ideal - b.take > a.ideal - a.take ? b : a));
|
|
111
|
+
least.take++;
|
|
112
|
+
sum++;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** `0..count-1` in a seeded random order. */
|
|
116
|
+
static shuffledIndices(count, random) {
|
|
117
|
+
const indices = Array.from({ length: count }, (_v, i) => i);
|
|
118
|
+
LockedHoldoutSplitter.shuffleInPlace(indices, random);
|
|
119
|
+
return indices;
|
|
120
|
+
}
|
|
121
|
+
/** Fisher–Yates shuffle driven by the seeded generator. */
|
|
122
|
+
static shuffleInPlace(values, random) {
|
|
123
|
+
for (let i = values.length - 1; i > 0; i--) {
|
|
124
|
+
const j = Math.floor(random() * (i + 1));
|
|
125
|
+
const swap = values[i];
|
|
126
|
+
values[i] = values[j];
|
|
127
|
+
values[j] = swap;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* mulberry32: a small, fast 32-bit seeded generator returning floats in [0, 1). Local so the carve has no dependency
|
|
132
|
+
* whose algorithm could change under it — the same seed must give the same holdout across releases.
|
|
133
|
+
*/
|
|
134
|
+
static mulberry32(seed) {
|
|
135
|
+
let state = seed >>> 0;
|
|
136
|
+
return () => {
|
|
137
|
+
state = (state + 0x6d2b79f5) >>> 0;
|
|
138
|
+
let t = state;
|
|
139
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
140
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
141
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** A fraction clamped into [0, 1]; a non-finite or negative value is 0. */
|
|
145
|
+
static clampFraction(value) {
|
|
146
|
+
if (!Number.isFinite(value) || value < 0)
|
|
147
|
+
return 0;
|
|
148
|
+
return value > 1 ? 1 : value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=locked-holdout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locked-holdout.js","sourceRoot":"","sources":["../../src/training/locked-holdout.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC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GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;YAC1C,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC;QAC/C,CAAC,CAAC;IACJ,CAAC;IAED,2EAA2E;IACnE,MAAM,CAAC,aAAa,CAAC,KAAa;QACxC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;YAAE,OAAO,CAAC,CAAC;QACnD,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/training/seams.d.ts
CHANGED
|
@@ -14,32 +14,31 @@ import type { TrainRequest, TrainResponse, MatrixData } from '@memberjunction/pr
|
|
|
14
14
|
import { MLSidecar } from '@memberjunction/predictive-studio-sidecar';
|
|
15
15
|
import type { IEntityFactory, IRecordLoader, ISidecarTrainer } from './types.js';
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* Provider-bound {@link IEntityFactory}: every entity is created through the
|
|
18
|
+
* caller's provider, never the global `Metadata` default.
|
|
19
19
|
*/
|
|
20
20
|
export declare class MetadataEntityFactory implements IEntityFactory {
|
|
21
|
-
private readonly provider
|
|
21
|
+
private readonly provider;
|
|
22
22
|
/**
|
|
23
|
-
* @param provider
|
|
24
|
-
*
|
|
25
|
-
* When omitted the global default `Metadata` provider is used.
|
|
23
|
+
* @param provider the provider entities are created on (it and its `CurrentUser`
|
|
24
|
+
* are honored so multi-provider callers create entities on the RIGHT server)
|
|
26
25
|
*/
|
|
27
|
-
constructor(provider
|
|
26
|
+
constructor(provider: IMetadataProvider);
|
|
28
27
|
/** @inheritdoc */
|
|
29
28
|
getEntityObject<T extends BaseEntity>(entityName: string, contextUser?: UserInfo): Promise<T>;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
|
-
* `RunView`-backed {@link IRecordLoader}. Loads the pipeline as a full
|
|
31
|
+
* `RunView`-backed {@link IRecordLoader}; every read runs on the caller's provider. Loads the pipeline as a full
|
|
33
32
|
* `entity_object` (it is read, not mutated) and computes the next version from a
|
|
34
33
|
* narrow `simple` projection over `MJ: ML Models`.
|
|
35
34
|
*/
|
|
36
35
|
export declare class RunViewRecordLoader implements IRecordLoader {
|
|
37
36
|
/** @inheritdoc */
|
|
38
|
-
loadPipeline(pipelineId: string, contextUser
|
|
37
|
+
loadPipeline(pipelineId: string, contextUser: UserInfo, provider: IMetadataProvider): Promise<MJMLTrainingPipelineEntity | null>;
|
|
39
38
|
/** @inheritdoc */
|
|
40
|
-
nextModelVersion(pipelineId: string, contextUser
|
|
39
|
+
nextModelVersion(pipelineId: string, contextUser: UserInfo, provider: IMetadataProvider): Promise<number>;
|
|
41
40
|
/** @inheritdoc */
|
|
42
|
-
resolveAlgorithmDriverKey(algorithmId: string, contextUser
|
|
41
|
+
resolveAlgorithmDriverKey(algorithmId: string, contextUser: UserInfo, provider: IMetadataProvider): Promise<string | null>;
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
44
|
* {@link ISidecarTrainer} backed by the self-managing {@link MLSidecar} client.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seams.d.ts","sourceRoot":"","sources":["../../src/training/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"seams.d.ts","sourceRoot":"","sources":["../../src/training/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,iBAAiB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK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AC;CAiB1F"}
|
package/dist/training/seams.js
CHANGED
|
@@ -8,44 +8,40 @@
|
|
|
8
8
|
* orchestrator itself depends solely on the narrow interfaces, so unit tests
|
|
9
9
|
* substitute in-memory fakes and never need a DB or sidecar.
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import { RunView, } from '@memberjunction/core';
|
|
12
12
|
import { MLSidecarProvider } from '../sidecar-provider.js';
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Provider-bound {@link IEntityFactory}: every entity is created through the
|
|
15
|
+
* caller's provider, never the global `Metadata` default.
|
|
16
16
|
*/
|
|
17
17
|
export class MetadataEntityFactory {
|
|
18
18
|
/**
|
|
19
|
-
* @param provider
|
|
20
|
-
*
|
|
21
|
-
* When omitted the global default `Metadata` provider is used.
|
|
19
|
+
* @param provider the provider entities are created on (it and its `CurrentUser`
|
|
20
|
+
* are honored so multi-provider callers create entities on the RIGHT server)
|
|
22
21
|
*/
|
|
23
22
|
constructor(provider) {
|
|
24
23
|
this.provider = provider;
|
|
25
24
|
}
|
|
26
25
|
/** @inheritdoc */
|
|
27
26
|
async getEntityObject(entityName, contextUser) {
|
|
28
|
-
|
|
29
|
-
return this.provider.GetEntityObject(entityName, contextUser ?? this.provider.CurrentUser);
|
|
30
|
-
}
|
|
31
|
-
const md = this.provider ?? new Metadata();
|
|
32
|
-
return md.GetEntityObject(entityName, contextUser);
|
|
27
|
+
return this.provider.GetEntityObject(entityName, contextUser || this.provider.CurrentUser);
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
30
|
/**
|
|
36
|
-
* `RunView`-backed {@link IRecordLoader}. Loads the pipeline as a full
|
|
31
|
+
* `RunView`-backed {@link IRecordLoader}; every read runs on the caller's provider. Loads the pipeline as a full
|
|
37
32
|
* `entity_object` (it is read, not mutated) and computes the next version from a
|
|
38
33
|
* narrow `simple` projection over `MJ: ML Models`.
|
|
39
34
|
*/
|
|
40
35
|
export class RunViewRecordLoader {
|
|
41
36
|
/** @inheritdoc */
|
|
42
37
|
async loadPipeline(pipelineId, contextUser, provider) {
|
|
43
|
-
const rv =
|
|
38
|
+
const rv = RunView.FromMetadataProvider(provider);
|
|
44
39
|
const result = await rv.RunView({
|
|
45
40
|
EntityName: 'MJ: ML Training Pipelines',
|
|
46
41
|
ExtraFilter: `ID='${pipelineId}'`,
|
|
47
42
|
ResultType: 'entity_object',
|
|
48
43
|
MaxRows: 1,
|
|
44
|
+
SkipTotalRowCount: true,
|
|
49
45
|
}, contextUser);
|
|
50
46
|
if (!result.Success || result.Results.length === 0) {
|
|
51
47
|
return null;
|
|
@@ -54,13 +50,14 @@ export class RunViewRecordLoader {
|
|
|
54
50
|
}
|
|
55
51
|
/** @inheritdoc */
|
|
56
52
|
async nextModelVersion(pipelineId, contextUser, provider) {
|
|
57
|
-
const rv =
|
|
53
|
+
const rv = RunView.FromMetadataProvider(provider);
|
|
58
54
|
const result = await rv.RunView({
|
|
59
55
|
EntityName: 'MJ: ML Models',
|
|
60
56
|
ExtraFilter: `PipelineID='${pipelineId}'`,
|
|
61
57
|
Fields: ['Version'],
|
|
62
58
|
OrderBy: 'Version DESC',
|
|
63
59
|
MaxRows: 1,
|
|
60
|
+
SkipTotalRowCount: true,
|
|
64
61
|
ResultType: 'simple',
|
|
65
62
|
}, contextUser);
|
|
66
63
|
if (!result.Success || result.Results.length === 0) {
|
|
@@ -70,12 +67,13 @@ export class RunViewRecordLoader {
|
|
|
70
67
|
}
|
|
71
68
|
/** @inheritdoc */
|
|
72
69
|
async resolveAlgorithmDriverKey(algorithmId, contextUser, provider) {
|
|
73
|
-
const rv =
|
|
70
|
+
const rv = RunView.FromMetadataProvider(provider);
|
|
74
71
|
const result = await rv.RunView({
|
|
75
72
|
EntityName: 'MJ: ML Algorithms',
|
|
76
73
|
ExtraFilter: `ID='${algorithmId}'`,
|
|
77
74
|
Fields: ['DriverClass'],
|
|
78
75
|
MaxRows: 1,
|
|
76
|
+
SkipTotalRowCount: true,
|
|
79
77
|
ResultType: 'simple',
|
|
80
78
|
}, contextUser);
|
|
81
79
|
if (!result.Success || result.Results.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seams.js","sourceRoot":"","sources":["../../src/training/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"seams.js","sourceRoot":"","sources":["../../src/training/seams.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,OAAO,GAIR,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;;GAGG;AACH,MAAM,OAAO,qBAAqB;IAChC;;;OAGG;IACH,YAA6B,QAA2B;QAA3B,aAAQ,GAAR,QAAQ,CAAmB;IAAG,CAAC;IAE5D,kBAAkB;IACX,KAAK,CAAC,eAAe,CAAuB,UAAkB,EAAE,WAAsB;QAC3F,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAI,UAAU,EAAE,WAAW,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChG,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAC9B,kBAAkB;IACX,KAAK,CAAC,YAAY,CACvB,UAAkB,EAClB,WAAqB,EACrB,QAA2B;QAE3B,MAAM,EAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAC7B;YACE,UAAU,EAAE,2BAA2B;YACvC,WAAW,EAAE,OAAO,UAAU,GAAG;YACjC,UAAU,EAAE,eAAe;YAC3B,OAAO,EAAE,CAAC;YACV,iBAAiB,EAAE,IAAI;SACxB,EACD,WAAW,CACZ,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,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I,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,IAAI,CAAC;IAC/C,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAgB;IAG3B;;;OAGG;IACH,YAA6B,UAAqB,iBAAiB,CAAC,QAAQ,CAAC,UAAU,EAAE;QAA5D,YAAO,GAAP,OAAO,CAAqD;QANjF,YAAO,GAAG,KAAK,CAAC;IAMoE,CAAC;IAE7F,kBAAkB;IACX,KAAK,CAAC,KAAK,CAAC,GAAiB,EAAE,aAA0B;QAC9D,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,+EAA+E;QAC/E,wEAAwE;QACxE,2EAA2E;QAC3E,+EAA+E;QAC/E,4EAA4E;QAC5E,6EAA6E;QAC7E,6EAA6E;QAC7E,+DAA+D;QAC/D,MAAM,WAAW,GACf,aAAa,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAC5F,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -8,13 +8,18 @@
|
|
|
8
8
|
* row that recorded the attempt.
|
|
9
9
|
*
|
|
10
10
|
* ## Flow ({@link TrainingEngine.trainModel})
|
|
11
|
-
* 1. Resolve the pipeline (parse its JSON columns via the core type contracts)
|
|
11
|
+
* 1. Resolve the pipeline (parse its JSON columns via the core type contracts),
|
|
12
|
+
* then refuse — before any row is written — an as-of mode training would ignore
|
|
13
|
+
* ({@link AsOfSettingHasNoEffectError}) and an unknown `MajorityBaselineRule`
|
|
14
|
+
* (`InvalidMajorityBaselineRuleError`).
|
|
12
15
|
* 2. Create the training-run row (`Status='Running'`, `StartedAt`).
|
|
13
16
|
* 3. Assemble the raw matrix + schema + preprocessing ops via FeatureAssembly
|
|
14
|
-
* (context `'train'`), carrying the label column.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* (context `'train'`), carrying the label column. The target read is ordered by
|
|
18
|
+
* the entity's primary key, so the same data always arrives in the same order.
|
|
19
|
+
* 4. **Carve the locked holdout FIRST** (§8.2 — never trained/tuned on) with the
|
|
20
|
+
* seeded, stratified {@link LockedHoldoutSplitter}; the remaining
|
|
21
|
+
* `train_test_split`/`kfold`/`holdout` validation is delegated to the sidecar
|
|
22
|
+
* with the same seed. Build the sidecar `ValidationConfig`.
|
|
18
23
|
* 5. Build the `TrainRequest` and call the sidecar → `TrainResponse`; the locked
|
|
19
24
|
* holdout is scored exactly once → `HoldoutMetrics`.
|
|
20
25
|
* 6. Persist the artifact to `MJ: Files` via the injected store → `ArtifactFileID`.
|
|
@@ -59,12 +64,21 @@ export declare class TrainingEngine {
|
|
|
59
64
|
/** Assemble the raw matrix + schema + preprocessing recipe (train context). */
|
|
60
65
|
private assemble;
|
|
61
66
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
67
|
+
* The ORDER BY for the training read: the target entity's primary-key columns. Without it an uncapped read (the
|
|
68
|
+
* default) has no ORDER BY at all, so the database may return rows in any order and the seeded holdout carve would
|
|
69
|
+
* pick different rows between runs.
|
|
70
|
+
*/
|
|
71
|
+
private primaryKeyOrder;
|
|
72
|
+
/**
|
|
73
|
+
* Carve the locked holdout FIRST (§8.2), before any train/test split: a seeded sample of
|
|
74
|
+
* `LockedHoldoutFraction` of the rows, stratified on the label for classification. The holdout
|
|
75
|
+
* rows are never sent in the training `data`.
|
|
65
76
|
*/
|
|
66
77
|
private carveLockedHoldout;
|
|
67
|
-
/**
|
|
78
|
+
/**
|
|
79
|
+
* Translate the pipeline's {@link ValidationStrategy} into a sidecar {@link ValidationConfig}. The seed is sent
|
|
80
|
+
* explicitly so the sidecar's splits use the same seed as the locked-holdout carve.
|
|
81
|
+
*/
|
|
68
82
|
private buildValidationConfig;
|
|
69
83
|
/** Build the `/train` request from the resolved pipeline + assembled training matrix. */
|
|
70
84
|
private buildTrainRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"training-engine.d.ts","sourceRoot":"","sources":["../../src/training/training-engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"training-engine.d.ts","sourceRoot":"","sources":["../../src/training/training-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAyBH,OAAO,EAAE,uBAAuB,EAAkF,MAAM,qBAAqB,CAAC;AAG9I,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAwB,MAAM,SAAS,CAAC;AAkBrG;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IAEpD;;OAEG;gBACS,SAAS,CAAC,EAAE,uBAAuB;IAI/C;;;;;;OAMG;IACU,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAuC9F,6EAA6E;YAC/D,eAAe;IAmC7B,iFAAiF;YACnE,YAAY;IAc1B,qFAAqF;YACvE,kBAAkB;IAyBhC,0EAA0E;YAC5D,kBAAkB;IAWhC,sFAAsF;IACtF,OAAO,CAAC,aAAa;IAkBrB,+EAA+E;YACjE,QAAQ;IAiBtB;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAUvB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAI1B;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAW7B,yFAAyF;IACzF,OAAO,CAAC,iBAAiB;IAoBzB,mFAAmF;IACnF,OAAO,CAAC,YAAY;IAMpB;;;;OAIG;YACW,cAAc;IAqC5B;;;;;;;;;OASG;IACH,OAAO,CAAC,YAAY;IAyBpB;;;OAGG;YACW,WAAW;CAO1B"}
|