@higher.archi/boe 1.0.4 → 1.0.6
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/qfacts/collapse.d.ts +6 -0
- package/dist/qfacts/collapse.d.ts.map +1 -0
- package/dist/qfacts/collapse.js +95 -0
- package/dist/qfacts/collapse.js.map +1 -0
- package/dist/qfacts/index.d.ts +5 -0
- package/dist/qfacts/index.d.ts.map +1 -0
- package/dist/qfacts/index.js +20 -0
- package/dist/qfacts/index.js.map +1 -0
- package/dist/qfacts/simulate.d.ts +7 -0
- package/dist/qfacts/simulate.d.ts.map +1 -0
- package/dist/qfacts/simulate.js +19 -0
- package/dist/qfacts/simulate.js.map +1 -0
- package/dist/qfacts/strategies/crypto.d.ts +2 -0
- package/dist/qfacts/strategies/crypto.d.ts.map +1 -0
- package/dist/qfacts/strategies/crypto.js +21 -0
- package/dist/qfacts/strategies/crypto.js.map +1 -0
- package/dist/qfacts/strategies/deterministic.d.ts +2 -0
- package/dist/qfacts/strategies/deterministic.d.ts.map +1 -0
- package/dist/qfacts/strategies/deterministic.js +15 -0
- package/dist/qfacts/strategies/deterministic.js.map +1 -0
- package/dist/qfacts/strategies/index.d.ts +8 -0
- package/dist/qfacts/strategies/index.d.ts.map +1 -0
- package/dist/qfacts/strategies/index.js +29 -0
- package/dist/qfacts/strategies/index.js.map +1 -0
- package/dist/qfacts/strategies/quasi-random.d.ts +2 -0
- package/dist/qfacts/strategies/quasi-random.d.ts.map +1 -0
- package/dist/qfacts/strategies/quasi-random.js +26 -0
- package/dist/qfacts/strategies/quasi-random.js.map +1 -0
- package/dist/qfacts/strategies/seeded.d.ts +2 -0
- package/dist/qfacts/strategies/seeded.d.ts.map +1 -0
- package/dist/qfacts/strategies/seeded.js +34 -0
- package/dist/qfacts/strategies/seeded.js.map +1 -0
- package/dist/qfacts/types.d.ts +36 -0
- package/dist/qfacts/types.d.ts.map +1 -0
- package/dist/qfacts/types.js +3 -0
- package/dist/qfacts/types.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/qfacts/README.md +243 -0
- package/src/qfacts/collapse.ts +111 -0
- package/src/qfacts/index.ts +27 -0
- package/src/qfacts/simulate.ts +25 -0
- package/src/qfacts/strategies/crypto.ts +20 -0
- package/src/qfacts/strategies/deterministic.ts +11 -0
- package/src/qfacts/strategies/index.ts +25 -0
- package/src/qfacts/strategies/quasi-random.ts +23 -0
- package/src/qfacts/strategies/seeded.ts +32 -0
- package/src/qfacts/types.ts +44 -0
package/dist/index.d.ts
CHANGED
|
@@ -53,4 +53,5 @@ export type { ExpertRule, ExpertRuleSet, ExpertConfig, ExplainBlock, CompiledExp
|
|
|
53
53
|
export { PricingStrategy, compilePricingRuleSet, compilePricingRule, pricingStrategy, pricingEngine, calculateFlat, calculateGraduated, calculateVolume, formatCurrency, formatNumber, formatPercent, round, calculateDiscount, applyMinMax, CURRENCIES, getCurrencyInfo } from './engines/pricing';
|
|
54
54
|
export type { CurrencyCode, CurrencyInfo, PricingRule, PricingRuleSet, PricingConfig, PricingComponent, PricingMode, PricingInput, PricingPackage, FlatPricing, GraduatedTier, GraduatedPricing, VolumeBracket, VolumePricing, Meter, MultiMeterPricing, FormulaPricing, Adjustment, DiscountAdjustment, MinimumAdjustment, MaximumAdjustment, Metric, ScenarioDefinition, ScenarioDefinitions, AttributeSchema, ProductType, ResolvedPricingConfig, CompiledPricingRuleSet, CompiledPricingRule, CompiledPricingComponent, CompiledPricingMode, CompiledAdjustment, CompiledMetric, PricingOptions, PricingResult, ScenarioComparisonResult, ScenarioResult, ComponentResult, AdjustmentResult, TierBreakdown, MeterResult, PricingSummary, CalculatorContext, TierCalculationResult } from './engines/pricing';
|
|
55
55
|
export { soundex, nysiis, caverphone2, cosineSimilarity } from './functions';
|
|
56
|
+
export * from './qfacts';
|
|
56
57
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMlD,cAAc,QAAQ,CAAC;AAOvB,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,WAAW,EACX,cAAc,EACd,aAAa,EACb,sBAAsB,EACtB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACd,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,YAAY,EACZ,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,SAAS,EACT,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAG5B,OAAO,E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,aAAa,CAAC;AAM7E,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -169,4 +169,8 @@ Object.defineProperty(exports, "soundex", { enumerable: true, get: function () {
|
|
|
169
169
|
Object.defineProperty(exports, "nysiis", { enumerable: true, get: function () { return functions_1.nysiis; } });
|
|
170
170
|
Object.defineProperty(exports, "caverphone2", { enumerable: true, get: function () { return functions_1.caverphone2; } });
|
|
171
171
|
Object.defineProperty(exports, "cosineSimilarity", { enumerable: true, get: function () { return functions_1.cosineSimilarity; } });
|
|
172
|
+
// ========================================
|
|
173
|
+
// QFacts - Probabilistic Fact Hydration
|
|
174
|
+
// ========================================
|
|
175
|
+
__exportStar(require("./qfacts"), exports);
|
|
172
176
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;AAEH,2CAA2C;AAC3C,UAAU;AACV,2CAA2C;AAE3C,iEAAiE;AACjE,6CAAkD;AAAzC,wGAAA,aAAa,OAAA;AACtB,+CAAoD;AAA3C,0GAAA,cAAc,OAAA;AACvB,6CAAkD;AAAzC,wGAAA,aAAa,OAAA;AACtB,mDAAwD;AAA/C,8GAAA,gBAAgB,OAAA;AACzB,yCAA8C;AAArC,oGAAA,WAAW,OAAA;AACpB,+CAAoD;AAA3C,0GAAA,cAAc,OAAA;AACvB,qDAAyD;AAAhD,+GAAA,gBAAgB,OAAA;AACzB,yDAA6D;AAApD,mHAAA,kBAAkB,OAAA;AAC3B,mDAAwD;AAA/C,8GAAA,gBAAgB,OAAA;AACzB,6CAAkD;AAAzC,wGAAA,aAAa,OAAA;AACtB,6CAAkD;AAAzC,wGAAA,aAAa,OAAA;AAEtB,2CAA2C;AAC3C,yBAAyB;AACzB,2CAA2C;AAE3C,yCAAuB;AAEvB,2CAA2C;AAC3C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,eAAe,OAAA;AACf,gHAAA,qBAAqB,OAAA;AACrB,6GAAA,kBAAkB,OAAA;AAClB,0GAAA,eAAe,OAAA;AACf,wGAAA,aAAa,OAAA;AACb,wGAAA,aAAa,OAAA;AACb,6GAAA,kBAAkB,OAAA;AAClB,0GAAA,eAAe,OAAA;AACf,yGAAA,cAAc,OAAA;AACd,uGAAA,YAAY,OAAA;AACZ,wGAAA,aAAa,OAAA;AACb,gGAAA,KAAK,OAAA;AACL,4GAAA,iBAAiB,OAAA;AACjB,sGAAA,WAAW,OAAA;AACX,qBAAqB;AACrB,qGAAA,UAAU,OAAA;AACV,0GAAA,eAAe,OAAA;AAqDjB,2CAA2C;AAC3C,oEAAoE;AACpE,2CAA2C;AAE3C,yCAA6E;AAApE,oGAAA,OAAO,OAAA;AAAE,mGAAA,MAAM,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAEvD,2CAA2C;AAC3C,wCAAwC;AACxC,2CAA2C;AAE3C,2CAAyB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Superposition, QFactInput, CollapseOptions, CollapsedFact, AmplitudeValue } from './types';
|
|
2
|
+
export declare function isSuperposition(value: unknown): value is Superposition;
|
|
3
|
+
export declare function superposition(amplitudes: Record<string, AmplitudeValue>): Superposition;
|
|
4
|
+
export declare function collapse(qfact: QFactInput, options?: CollapseOptions): CollapsedFact;
|
|
5
|
+
export declare function collapseAll(qfacts: QFactInput[], options?: CollapseOptions): CollapsedFact[];
|
|
6
|
+
//# sourceMappingURL=collapse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collapse.d.ts","sourceRoot":"","sources":["../../src/qfacts/collapse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,eAAe,EAEf,aAAa,EACb,cAAc,EACf,MAAM,SAAS,CAAC;AAGjB,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAQtE;AAiCD,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,aAAa,CAKvF;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,aAAa,CAyCpF;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,aAAa,EAAE,CAQ5F"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSuperposition = isSuperposition;
|
|
4
|
+
exports.superposition = superposition;
|
|
5
|
+
exports.collapse = collapse;
|
|
6
|
+
exports.collapseAll = collapseAll;
|
|
7
|
+
const strategies_1 = require("./strategies");
|
|
8
|
+
function isSuperposition(value) {
|
|
9
|
+
return (typeof value === 'object' &&
|
|
10
|
+
value !== null &&
|
|
11
|
+
value.state === 'superposition' &&
|
|
12
|
+
typeof value.amplitudes === 'object' &&
|
|
13
|
+
value.amplitudes !== null);
|
|
14
|
+
}
|
|
15
|
+
function normalizeAmplitudes(amplitudes) {
|
|
16
|
+
const parsed = {};
|
|
17
|
+
for (const [key, raw] of Object.entries(amplitudes)) {
|
|
18
|
+
if (typeof raw === 'string' && raw.endsWith('%')) {
|
|
19
|
+
parsed[key] = parseFloat(raw.slice(0, -1));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
parsed[key] = Number(raw);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const values = Object.values(parsed);
|
|
26
|
+
const total = values.reduce((sum, v) => sum + v, 0);
|
|
27
|
+
const anyAboveOne = values.some((v) => v > 1);
|
|
28
|
+
if (anyAboveOne || total > 1.001) {
|
|
29
|
+
// Treat as raw numbers, normalize against total
|
|
30
|
+
for (const key of Object.keys(parsed)) {
|
|
31
|
+
parsed[key] = parsed[key] / total;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (Math.abs(total - 1.0) > 0.001) {
|
|
35
|
+
// All ≤ 1 but doesn't sum to 1 — normalize
|
|
36
|
+
for (const key of Object.keys(parsed)) {
|
|
37
|
+
parsed[key] = parsed[key] / total;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// else: all ≤ 1 and total ≈ 1.0 — use as-is
|
|
41
|
+
return parsed;
|
|
42
|
+
}
|
|
43
|
+
function superposition(amplitudes) {
|
|
44
|
+
return {
|
|
45
|
+
state: 'superposition',
|
|
46
|
+
amplitudes: normalizeAmplitudes(amplitudes),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function collapse(qfact, options) {
|
|
50
|
+
const strategy = options?.strategy ?? 'seeded';
|
|
51
|
+
const collapseLog = [];
|
|
52
|
+
const data = {};
|
|
53
|
+
let fieldIndex = 0;
|
|
54
|
+
for (const [field, value] of Object.entries(qfact.data)) {
|
|
55
|
+
if (isSuperposition(value)) {
|
|
56
|
+
const resolve = (0, strategies_1.resolveStrategy)(strategy, options ?? {}, fieldIndex);
|
|
57
|
+
const selectedKey = resolve(value.amplitudes, field);
|
|
58
|
+
let selectedValue = selectedKey;
|
|
59
|
+
if (options?.coerce) {
|
|
60
|
+
try {
|
|
61
|
+
selectedValue = JSON.parse(selectedKey);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// keep as string
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
data[field] = selectedValue;
|
|
68
|
+
collapseLog.push({
|
|
69
|
+
field,
|
|
70
|
+
selectedValue,
|
|
71
|
+
amplitudes: { ...value.amplitudes },
|
|
72
|
+
strategy,
|
|
73
|
+
...(strategy === 'seeded' ? { seed: options?.seed ?? 0 } : {}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
data[field] = value;
|
|
78
|
+
}
|
|
79
|
+
fieldIndex++;
|
|
80
|
+
}
|
|
81
|
+
const fact = {
|
|
82
|
+
...(qfact.id != null ? { id: qfact.id } : {}),
|
|
83
|
+
type: qfact.type,
|
|
84
|
+
data,
|
|
85
|
+
};
|
|
86
|
+
return { fact, collapseLog };
|
|
87
|
+
}
|
|
88
|
+
function collapseAll(qfacts, options) {
|
|
89
|
+
const baseSeed = options?.seed ?? 0;
|
|
90
|
+
return qfacts.map((qfact, index) => collapse(qfact, {
|
|
91
|
+
...options,
|
|
92
|
+
seed: (baseSeed + index) >>> 0,
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=collapse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collapse.js","sourceRoot":"","sources":["../../src/qfacts/collapse.ts"],"names":[],"mappings":";;AAWA,0CAQC;AAiCD,sCAKC;AAED,4BAyCC;AAED,kCAQC;AArGD,6CAA+C;AAE/C,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAa,CAAC,KAAK,KAAK,eAAe;QACxC,OAAQ,KAAa,CAAC,UAAU,KAAK,QAAQ;QAC5C,KAAa,CAAC,UAAU,KAAK,IAAI,CACnC,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,UAA0C;IACrE,MAAM,MAAM,GAA2B,EAAE,CAAC;IAE1C,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACjD,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,G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AC,CAAC,CAAC,EAAE,CAAC;QAC7C,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,IAAI;KACL,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AAC/B,CAAC;AAED,SAAgB,WAAW,CAAC,MAAoB,EAAE,OAAyB;IACzE,MAAM,QAAQ,GAAG,OAAO,EAAE,IAAI,IAAI,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CACjC,QAAQ,CAAC,KAAK,EAAE;QACd,GAAG,OAAO;QACV,IAAI,EAAE,CAAC,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC;KAC/B,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { AmplitudeValue, Superposition, QValue, QFactInput, CollapseStrategy, CollapseOptions, CollapseRecord, CollapsedFact, SimulationResult, } from './types';
|
|
2
|
+
export { isSuperposition, superposition, collapse, collapseAll } from './collapse';
|
|
3
|
+
export { simulate } from './simulate';
|
|
4
|
+
export { seededCollapse, cryptoCollapse, deterministicCollapse, quasiRandomCollapse, resolveStrategy, } from './strategies';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/qfacts/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,cAAc,EACd,aAAa,EACb,MAAM,EACN,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,aAAa,EACb,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGnF,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,OAAO,EACL,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,GAChB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveStrategy = exports.quasiRandomCollapse = exports.deterministicCollapse = exports.cryptoCollapse = exports.seededCollapse = exports.simulate = exports.collapseAll = exports.collapse = exports.superposition = exports.isSuperposition = void 0;
|
|
4
|
+
// Core collapse functions
|
|
5
|
+
var collapse_1 = require("./collapse");
|
|
6
|
+
Object.defineProperty(exports, "isSuperposition", { enumerable: true, get: function () { return collapse_1.isSuperposition; } });
|
|
7
|
+
Object.defineProperty(exports, "superposition", { enumerable: true, get: function () { return collapse_1.superposition; } });
|
|
8
|
+
Object.defineProperty(exports, "collapse", { enumerable: true, get: function () { return collapse_1.collapse; } });
|
|
9
|
+
Object.defineProperty(exports, "collapseAll", { enumerable: true, get: function () { return collapse_1.collapseAll; } });
|
|
10
|
+
// Simulation
|
|
11
|
+
var simulate_1 = require("./simulate");
|
|
12
|
+
Object.defineProperty(exports, "simulate", { enumerable: true, get: function () { return simulate_1.simulate; } });
|
|
13
|
+
// Strategies
|
|
14
|
+
var strategies_1 = require("./strategies");
|
|
15
|
+
Object.defineProperty(exports, "seededCollapse", { enumerable: true, get: function () { return strategies_1.seededCollapse; } });
|
|
16
|
+
Object.defineProperty(exports, "cryptoCollapse", { enumerable: true, get: function () { return strategies_1.cryptoCollapse; } });
|
|
17
|
+
Object.defineProperty(exports, "deterministicCollapse", { enumerable: true, get: function () { return strategies_1.deterministicCollapse; } });
|
|
18
|
+
Object.defineProperty(exports, "quasiRandomCollapse", { enumerable: true, get: function () { return strategies_1.quasiRandomCollapse; } });
|
|
19
|
+
Object.defineProperty(exports, "resolveStrategy", { enumerable: true, get: function () { return strategies_1.resolveStrategy; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/qfacts/index.ts"],"names":[],"mappings":";;;AAaA,0BAA0B;AAC1B,uCAAmF;AAA1E,2GAAA,eAAe,OAAA;AAAE,yGAAA,aAAa,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAAE,uGAAA,WAAW,OAAA;AAE9D,aAAa;AACb,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAEjB,aAAa;AACb,2CAMsB;AALpB,4GAAA,cAAc,OAAA;AACd,4GAAA,cAAc,OAAA;AACd,mHAAA,qBAAqB,OAAA;AACrB,iHAAA,mBAAmB,OAAA;AACnB,6GAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FactInput } from '../core';
|
|
2
|
+
import type { QFactInput, CollapseStrategy, SimulationResult } from './types';
|
|
3
|
+
export declare function simulate<T>(qfacts: QFactInput[], engineFn: (facts: FactInput[]) => T, options?: {
|
|
4
|
+
runs?: number;
|
|
5
|
+
strategy?: CollapseStrategy;
|
|
6
|
+
}): SimulationResult<T>;
|
|
7
|
+
//# sourceMappingURL=simulate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulate.d.ts","sourceRoot":"","sources":["../../src/qfacts/simulate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAkB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG9F,wBAAgB,QAAQ,CAAC,CAAC,EACxB,MAAM,EAAE,UAAU,EAAE,EACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,EACnC,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAA;CAAE,GACvD,gBAAgB,CAAC,CAAC,CAAC,CAgBrB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.simulate = simulate;
|
|
4
|
+
const collapse_1 = require("./collapse");
|
|
5
|
+
function simulate(qfacts, engineFn, options) {
|
|
6
|
+
const runs = options?.runs ?? 1000;
|
|
7
|
+
const strategy = options?.strategy ?? 'seeded';
|
|
8
|
+
const results = [];
|
|
9
|
+
const collapseHistory = [];
|
|
10
|
+
for (let i = 0; i < runs; i++) {
|
|
11
|
+
const collapsed = (0, collapse_1.collapseAll)(qfacts, { strategy, seed: i });
|
|
12
|
+
const facts = collapsed.map((c) => c.fact);
|
|
13
|
+
const logs = collapsed.flatMap((c) => c.collapseLog);
|
|
14
|
+
results.push(engineFn(facts));
|
|
15
|
+
collapseHistory.push(logs);
|
|
16
|
+
}
|
|
17
|
+
return { runs, results, collapseHistory, strategy };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=simulate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulate.js","sourceRoot":"","sources":["../../src/qfacts/simulate.ts"],"names":[],"mappings":";;AAIA,4BAoBC;AAtBD,yCAAyC;AAEzC,SAAgB,QAAQ,CACtB,MAAoB,EACpB,QAAmC,EACnC,OAAwD;IAExD,MAAM,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,IAAI,CAAC;IACnC,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,QAAQ,CAAC;IAC/C,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,MAAM,eAAe,GAAuB,EAAE,CAAC;IAE/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAG,IAAA,sBAAW,EAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;QAC7D,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QAErD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9B,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../../src/qfacts/strategies/crypto.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAmBzE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cryptoCollapse = cryptoCollapse;
|
|
4
|
+
function cryptoCollapse(amplitudes) {
|
|
5
|
+
if (!globalThis.crypto?.getRandomValues) {
|
|
6
|
+
throw new Error('crypto.getRandomValues is not available. Requires Node >= 19 or a browser environment. ' +
|
|
7
|
+
'Use strategy "seeded" or "deterministic" as an alternative.');
|
|
8
|
+
}
|
|
9
|
+
const arr = new Uint32Array(1);
|
|
10
|
+
globalThis.crypto.getRandomValues(arr);
|
|
11
|
+
const roll = arr[0] / 4294967296;
|
|
12
|
+
const keys = Object.keys(amplitudes);
|
|
13
|
+
let cumulative = 0;
|
|
14
|
+
for (const key of keys) {
|
|
15
|
+
cumulative += amplitudes[key];
|
|
16
|
+
if (roll < cumulative)
|
|
17
|
+
return key;
|
|
18
|
+
}
|
|
19
|
+
return keys[keys.length - 1];
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/qfacts/strategies/crypto.ts"],"names":[],"mappings":";;AAAA,wCAmBC;AAnBD,SAAgB,cAAc,CAAC,UAAkC;IAC/D,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CACb,yFAAyF;YACzF,6DAA6D,CAC9D,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC;IAC/B,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC;IAEjC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,UAAU,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,IAAI,GAAG,UAAU;YAAE,OAAO,GAAG,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deterministic.d.ts","sourceRoot":"","sources":["../../../src/qfacts/strategies/deterministic.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAUhF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deterministicCollapse = deterministicCollapse;
|
|
4
|
+
function deterministicCollapse(amplitudes) {
|
|
5
|
+
let maxKey = '';
|
|
6
|
+
let maxVal = -Infinity;
|
|
7
|
+
for (const [key, val] of Object.entries(amplitudes)) {
|
|
8
|
+
if (val > maxVal) {
|
|
9
|
+
maxVal = val;
|
|
10
|
+
maxKey = key;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return maxKey;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=deterministic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deterministic.js","sourceRoot":"","sources":["../../../src/qfacts/strategies/deterministic.ts"],"names":[],"mappings":";;AAAA,sDAUC;AAVD,SAAgB,qBAAqB,CAAC,UAAkC;IACtE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,CAAC,QAAQ,CAAC;IACvB,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACpD,IAAI,GAAG,GAAG,MAAM,EAAE,CAAC;YACjB,MAAM,GAAG,GAAG,CAAC;YACb,MAAM,GAAG,GAAG,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { seededCollapse } from './seeded';
|
|
2
|
+
export { cryptoCollapse } from './crypto';
|
|
3
|
+
export { deterministicCollapse } from './deterministic';
|
|
4
|
+
export { quasiRandomCollapse } from './quasi-random';
|
|
5
|
+
import type { CollapseStrategy, CollapseOptions } from '../types';
|
|
6
|
+
type CollapseFunction = (amplitudes: Record<string, number>, fieldName: string) => string;
|
|
7
|
+
export declare function resolveStrategy(strategy: CollapseStrategy, options: CollapseOptions, fieldIndex?: number): CollapseFunction;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/qfacts/strategies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAMrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAElE,KAAK,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;AAE1F,wBAAgB,eAAe,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAW3H"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quasiRandomCollapse = exports.deterministicCollapse = exports.cryptoCollapse = exports.seededCollapse = void 0;
|
|
4
|
+
exports.resolveStrategy = resolveStrategy;
|
|
5
|
+
var seeded_1 = require("./seeded");
|
|
6
|
+
Object.defineProperty(exports, "seededCollapse", { enumerable: true, get: function () { return seeded_1.seededCollapse; } });
|
|
7
|
+
var crypto_1 = require("./crypto");
|
|
8
|
+
Object.defineProperty(exports, "cryptoCollapse", { enumerable: true, get: function () { return crypto_1.cryptoCollapse; } });
|
|
9
|
+
var deterministic_1 = require("./deterministic");
|
|
10
|
+
Object.defineProperty(exports, "deterministicCollapse", { enumerable: true, get: function () { return deterministic_1.deterministicCollapse; } });
|
|
11
|
+
var quasi_random_1 = require("./quasi-random");
|
|
12
|
+
Object.defineProperty(exports, "quasiRandomCollapse", { enumerable: true, get: function () { return quasi_random_1.quasiRandomCollapse; } });
|
|
13
|
+
const seeded_2 = require("./seeded");
|
|
14
|
+
const crypto_2 = require("./crypto");
|
|
15
|
+
const deterministic_2 = require("./deterministic");
|
|
16
|
+
const quasi_random_2 = require("./quasi-random");
|
|
17
|
+
function resolveStrategy(strategy, options, fieldIndex) {
|
|
18
|
+
switch (strategy) {
|
|
19
|
+
case 'seeded':
|
|
20
|
+
return (amplitudes, fieldName) => (0, seeded_2.seededCollapse)(amplitudes, options.seed ?? 0, fieldName);
|
|
21
|
+
case 'crypto':
|
|
22
|
+
return (amplitudes) => (0, crypto_2.cryptoCollapse)(amplitudes);
|
|
23
|
+
case 'deterministic':
|
|
24
|
+
return (amplitudes) => (0, deterministic_2.deterministicCollapse)(amplitudes);
|
|
25
|
+
case 'quasi-random':
|
|
26
|
+
return (amplitudes) => (0, quasi_random_2.quasiRandomCollapse)(amplitudes, fieldIndex ?? 0);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/qfacts/strategies/index.ts"],"names":[],"mappings":";;;AAaA,0CAWC;AAxBD,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,iDAAwD;AAA/C,sHAAA,qBAAqB,OAAA;AAC9B,+CAAqD;AAA5C,mHAAA,mBAAmB,OAAA;AAE5B,qCAA0C;AAC1C,qCAA0C;AAC1C,mDAAwD;AACxD,iDAAqD;AAKrD,SAAgB,eAAe,CAAC,QAA0B,EAAE,OAAwB,EAAE,UAAmB;IACvG,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,IAAA,uBAAc,EAAC,UAAU,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;QAC7F,KAAK,QAAQ;YACX,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAA,uBAAc,EAAC,UAAU,CAAC,CAAC;QACpD,KAAK,eAAe;YAClB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAA,qCAAqB,EAAC,UAAU,CAAC,CAAC;QAC3D,KAAK,cAAc;YACjB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAA,kCAAmB,EAAC,UAAU,EAAE,UAAU,IAAI,CAAC,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quasi-random.d.ts","sourceRoot":"","sources":["../../../src/qfacts/strategies/quasi-random.ts"],"names":[],"mappings":"AAYA,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAU7F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quasiRandomCollapse = quasiRandomCollapse;
|
|
4
|
+
function halton(index, base) {
|
|
5
|
+
let result = 0;
|
|
6
|
+
let f = 1 / base;
|
|
7
|
+
let i = index;
|
|
8
|
+
while (i > 0) {
|
|
9
|
+
result += f * (i % base);
|
|
10
|
+
i = Math.floor(i / base);
|
|
11
|
+
f /= base;
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
function quasiRandomCollapse(amplitudes, index) {
|
|
16
|
+
const roll = halton(index + 1, 2); // +1 to avoid halton(0) = 0
|
|
17
|
+
const keys = Object.keys(amplitudes);
|
|
18
|
+
let cumulative = 0;
|
|
19
|
+
for (const key of keys) {
|
|
20
|
+
cumulative += amplitudes[key];
|
|
21
|
+
if (roll < cumulative)
|
|
22
|
+
return key;
|
|
23
|
+
}
|
|
24
|
+
return keys[keys.length - 1];
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=quasi-random.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quasi-random.js","sourceRoot":"","sources":["../../../src/qfacts/strategies/quasi-random.ts"],"names":[],"mappings":";;AAYA,kDAUC;AAtBD,SAAS,MAAM,CAAC,KAAa,EAAE,IAAY;IACzC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACjB,IAAI,CAAC,GAAG,KAAK,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACzB,CAAC,IAAI,IAAI,CAAC;IACZ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,mBAAmB,CAAC,UAAkC,EAAE,KAAa;IACnF,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,4BAA4B;IAE/D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACrC,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,UAAU,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,IAAI,GAAG,UAAU;YAAE,OAAO,GAAG,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seeded.d.ts","sourceRoot":"","sources":["../../../src/qfacts/strategies/seeded.ts"],"names":[],"mappings":"AAmBA,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAY1G"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.seededCollapse = seededCollapse;
|
|
4
|
+
function createRng(seed) {
|
|
5
|
+
let state = seed;
|
|
6
|
+
return () => {
|
|
7
|
+
state |= 0;
|
|
8
|
+
state = (state + 0x6d2b79f5) | 0;
|
|
9
|
+
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
10
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
11
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function djb2Hash(str) {
|
|
15
|
+
let hash = 5381;
|
|
16
|
+
for (let i = 0; i < str.length; i++) {
|
|
17
|
+
hash = ((hash << 5) + hash + str.charCodeAt(i)) | 0;
|
|
18
|
+
}
|
|
19
|
+
return hash >>> 0;
|
|
20
|
+
}
|
|
21
|
+
function seededCollapse(amplitudes, seed, fieldName) {
|
|
22
|
+
const fieldSeed = (seed ^ djb2Hash(fieldName)) >>> 0;
|
|
23
|
+
const rng = createRng(fieldSeed);
|
|
24
|
+
const roll = rng();
|
|
25
|
+
const keys = Object.keys(amplitudes);
|
|
26
|
+
let cumulative = 0;
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
cumulative += amplitudes[key];
|
|
29
|
+
if (roll < cumulative)
|
|
30
|
+
return key;
|
|
31
|
+
}
|
|
32
|
+
return keys[keys.length - 1];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=seeded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seeded.js","sourceRoot":"","sources":["../../../src/qfacts/strategies/seeded.ts"],"names":[],"mappings":";;AAmBA,wCAYC;AA/BD,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,KAAK,GAAG,IAAI,CAAC;IAC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AG,CAAC,CAAC;IACnB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,UAAU,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAI,IAAI,GAAG,UAAU;YAAE,OAAO,GAAG,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { FactInput } from '../core';
|
|
2
|
+
export type AmplitudeValue = number | `${number}%`;
|
|
3
|
+
export type Superposition = {
|
|
4
|
+
state: 'superposition';
|
|
5
|
+
amplitudes: Record<string, number>;
|
|
6
|
+
};
|
|
7
|
+
export type QValue = any | Superposition;
|
|
8
|
+
export type QFactInput = {
|
|
9
|
+
id?: string;
|
|
10
|
+
type: string;
|
|
11
|
+
data: Record<string, QValue>;
|
|
12
|
+
};
|
|
13
|
+
export type CollapseStrategy = 'seeded' | 'crypto' | 'deterministic' | 'quasi-random';
|
|
14
|
+
export type CollapseOptions = {
|
|
15
|
+
strategy?: CollapseStrategy;
|
|
16
|
+
seed?: number;
|
|
17
|
+
coerce?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type CollapseRecord = {
|
|
20
|
+
field: string;
|
|
21
|
+
selectedValue: any;
|
|
22
|
+
amplitudes: Record<string, number>;
|
|
23
|
+
strategy: CollapseStrategy;
|
|
24
|
+
seed?: number;
|
|
25
|
+
};
|
|
26
|
+
export type CollapsedFact = {
|
|
27
|
+
fact: FactInput;
|
|
28
|
+
collapseLog: CollapseRecord[];
|
|
29
|
+
};
|
|
30
|
+
export type SimulationResult<T = any> = {
|
|
31
|
+
runs: number;
|
|
32
|
+
results: T[];
|
|
33
|
+
collapseHistory: CollapseRecord[][];
|
|
34
|
+
strategy: CollapseStrategy;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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AC,EAAE,CAAC;IACb,eAAe,EAAE,cAAc,EAAE,EAAE,CAAC;IACpC,QAAQ,EAAE,gBAAgB,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/qfacts/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@higher.archi/boe",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A multi-strategy rule engine supporting forward chaining, backward chaining, scoring, sequential, fuzzy logic, and Bayesian inference",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -374,3 +374,9 @@ export type {
|
|
|
374
374
|
// ========================================
|
|
375
375
|
|
|
376
376
|
export { soundex, nysiis, caverphone2, cosineSimilarity } from './functions';
|
|
377
|
+
|
|
378
|
+
// ========================================
|
|
379
|
+
// QFacts - Probabilistic Fact Hydration
|
|
380
|
+
// ========================================
|
|
381
|
+
|
|
382
|
+
export * from './qfacts';
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# QFacts - Probabilistic Fact Hydration
|
|
2
|
+
|
|
3
|
+
QFacts is a pre-processing layer that handles **uncertain data** before it reaches any BOE engine. It accepts facts where some fields have multiple possible values (probability distributions), picks a concrete value for each one, and hands clean `FactInput` objects to the engine. BOE stays deterministic and auditable. QFacts extends the audit trail upstream.
|
|
4
|
+
|
|
5
|
+
## What Problem Does This Solve?
|
|
6
|
+
|
|
7
|
+
The real world doesn't arrive in clean rows. An NLP model says "this is 80% positive, 15% neutral, 5% negative." A sensor reads a temperature but with a margin of error. A classifier returns probabilities across several categories. Right now, something upstream has to commit to a single value before BOE ever sees it — and that throws away the uncertainty silently.
|
|
8
|
+
|
|
9
|
+
QFacts keeps the uncertainty visible. You describe the distribution, QFacts collapses it to a single value, and the collapse is recorded — what the options were, what was picked, and how.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Uncertain World → QFacts (collapse) → FactInput → BOE Engine → Result
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## When to Use QFacts
|
|
16
|
+
|
|
17
|
+
Use QFacts when your input data has uncertainty that you want to preserve, collapse deliberately, or simulate across:
|
|
18
|
+
|
|
19
|
+
- **ML/NLP output** - Classifiers return probability distributions, not hard labels
|
|
20
|
+
- **Sensor data** - Readings have confidence intervals or error margins
|
|
21
|
+
- **Survey data** - Responses mapped to weighted categories
|
|
22
|
+
- **Monte Carlo analysis** - Run thousands of collapses to see how uncertainty affects outcomes
|
|
23
|
+
- **Reproducible pipelines** - Same seed, same collapse, every time
|
|
24
|
+
|
|
25
|
+
If your facts are already concrete values, you don't need QFacts. Just use `FactInput` directly.
|
|
26
|
+
|
|
27
|
+
## Core Concepts
|
|
28
|
+
|
|
29
|
+
### Superposition
|
|
30
|
+
|
|
31
|
+
A superposition is a field that hasn't been decided yet. It holds multiple possible values, each with a weight (amplitude) representing how likely that value is.
|
|
32
|
+
|
|
33
|
+
Think of it like a coin that hasn't been flipped. It's not heads or tails — it's both, with weights. A fair coin would be `{ heads: 0.5, tails: 0.5 }`. A loaded coin might be `{ heads: 0.8, tails: 0.2 }`.
|
|
34
|
+
|
|
35
|
+
You create a superposition using the `superposition()` factory:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
superposition({ high: 0.8, moderate: 0.15, low: 0.05 })
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This returns an object with `state: 'superposition'` and normalized amplitudes that always sum to 1.0.
|
|
42
|
+
|
|
43
|
+
### Amplitude Formats
|
|
44
|
+
|
|
45
|
+
The `superposition()` factory is flexible about how you express weights. All three of these mean exactly the same thing:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
superposition({ high: 0.9, moderate: 0.1 }) // decimals
|
|
49
|
+
superposition({ high: 90, moderate: 10 }) // whole numbers
|
|
50
|
+
superposition({ high: '90%', moderate: '10%' }) // percentage strings
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can even mix formats:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
superposition({ high: '90%', moderate: 10 }) // mixed — fine
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Values don't need to sum to 100 or 1.0. QFacts normalizes everything automatically:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
superposition({ high: 120, moderate: 80 })
|
|
63
|
+
// total = 200 → stored as { high: 0.6, moderate: 0.4 }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Internally, amplitudes are always stored as numbers between 0 and 1 that sum to 1.0. The flexible input is only accepted by the factory — the `Superposition` type itself is always normalized.
|
|
67
|
+
|
|
68
|
+
### QFactInput
|
|
69
|
+
|
|
70
|
+
A `QFactInput` looks just like a `FactInput`, but any field in `data` can be a superposition instead of a concrete value:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const qfact: QFactInput = {
|
|
74
|
+
type: 'SentimentAnalysis',
|
|
75
|
+
data: {
|
|
76
|
+
text: 'Great product, minor issues', // concrete
|
|
77
|
+
sentiment: superposition({ positive: 0.8, mixed: 0.15, negative: 0.05 }), // uncertain
|
|
78
|
+
confidence: 0.92 // concrete
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Fields that are already concrete pass through untouched. Only superpositions get collapsed.
|
|
84
|
+
|
|
85
|
+
### Collapse
|
|
86
|
+
|
|
87
|
+
Collapsing is the act of picking one concrete value from a superposition. The `collapse()` function walks through every field in a `QFactInput`, collapses any superpositions it finds, and returns a clean `FactInput` plus a log of what happened.
|
|
88
|
+
|
|
89
|
+
The collapse log records each decision: which field, what the options were, what was picked, which strategy was used, and (for seeded strategies) what seed was used. This is your audit trail.
|
|
90
|
+
|
|
91
|
+
### Strategies
|
|
92
|
+
|
|
93
|
+
QFacts supports four collapse strategies. Each one answers the same question — "given these weighted options, pick one" — but they differ in how they pick.
|
|
94
|
+
|
|
95
|
+
| Strategy | Randomness | Best For |
|
|
96
|
+
|----------|-----------|----------|
|
|
97
|
+
| **seeded** | Pseudo-random (reproducible) | Default. Same seed always gives same result. |
|
|
98
|
+
| **deterministic** | None | Always picks the highest-weighted option. No surprises. |
|
|
99
|
+
| **crypto** | True random | When you need cryptographic randomness. Not reproducible. |
|
|
100
|
+
| **quasi-random** | Low-discrepancy sequence | Monte Carlo simulations. Better coverage with fewer runs. |
|
|
101
|
+
|
|
102
|
+
#### Seeded (default)
|
|
103
|
+
|
|
104
|
+
Uses a fast pseudo-random number generator (Mulberry32). Given the same seed, it always produces the same result. This is the default because it follows the principle of least surprise — calling `collapse(qfact)` with no options always returns the same output.
|
|
105
|
+
|
|
106
|
+
Each field gets its own derived seed based on the field name, so the collapse of one field doesn't affect another. Reordering fields won't change results.
|
|
107
|
+
|
|
108
|
+
#### Deterministic
|
|
109
|
+
|
|
110
|
+
Always picks the option with the highest amplitude. On ties, picks the first one in insertion order. No randomness at all. Useful when you just want the most likely value and don't care about simulating alternatives.
|
|
111
|
+
|
|
112
|
+
#### Crypto
|
|
113
|
+
|
|
114
|
+
Uses `crypto.getRandomValues()` for true randomness. Not reproducible — every call gives a different result. Throws a descriptive error if crypto isn't available (Node < 19 without the global).
|
|
115
|
+
|
|
116
|
+
#### Quasi-Random
|
|
117
|
+
|
|
118
|
+
Uses a Halton sequence instead of pseudo-random numbers. Halton sequences are "low-discrepancy" — they spread out more evenly than random numbers. This means Monte Carlo simulations converge faster. You get better coverage of the probability space with fewer runs.
|
|
119
|
+
|
|
120
|
+
Takes an `index` parameter (typically the simulation loop counter) to determine position in the sequence.
|
|
121
|
+
|
|
122
|
+
## API
|
|
123
|
+
|
|
124
|
+
### `superposition(amplitudes)`
|
|
125
|
+
|
|
126
|
+
Creates a superposition from weighted options. Accepts numbers, percentages, or percentage strings. Always normalizes to 0-1 internally.
|
|
127
|
+
|
|
128
|
+
### `isSuperposition(value)`
|
|
129
|
+
|
|
130
|
+
Type guard. Returns `true` if the value is a `Superposition` object (has `state: 'superposition'` and an `amplitudes` record).
|
|
131
|
+
|
|
132
|
+
### `collapse(qfact, options?)`
|
|
133
|
+
|
|
134
|
+
Collapses a single `QFactInput` into a `CollapsedFact`, which contains a clean `FactInput` and a `collapseLog` array.
|
|
135
|
+
|
|
136
|
+
**Options:**
|
|
137
|
+
|
|
138
|
+
| Option | Type | Default | Description |
|
|
139
|
+
|--------|------|---------|-------------|
|
|
140
|
+
| `strategy` | `CollapseStrategy` | `'seeded'` | Which collapse strategy to use |
|
|
141
|
+
| `seed` | `number` | `0` | Base seed for the `'seeded'` strategy |
|
|
142
|
+
| `coerce` | `boolean` | `false` | Parse string keys to numbers/booleans via `JSON.parse` |
|
|
143
|
+
|
|
144
|
+
When `coerce` is `true`, QFacts attempts to parse the selected key back to its original type. Since amplitude keys are always strings (`Record<string, number>`), a superposition like `{ "100": 0.7, "200": 0.3 }` would normally collapse to the string `"100"`. With `coerce: true`, it becomes the number `100`.
|
|
145
|
+
|
|
146
|
+
### `collapseAll(qfacts, options?)`
|
|
147
|
+
|
|
148
|
+
Collapses an array of `QFactInput` objects. Each fact gets its own derived seed (base seed + index) so collapses are independent of each other and of array order.
|
|
149
|
+
|
|
150
|
+
### `simulate(qfacts, engineFn, options?)`
|
|
151
|
+
|
|
152
|
+
Runs a Monte Carlo simulation. Collapses the same set of `QFactInput` objects many times with different seeds, passes each set of collapsed facts through your engine function, and collects the results.
|
|
153
|
+
|
|
154
|
+
**Options:**
|
|
155
|
+
|
|
156
|
+
| Option | Type | Default | Description |
|
|
157
|
+
|--------|------|---------|-------------|
|
|
158
|
+
| `runs` | `number` | `1000` | Number of simulation runs |
|
|
159
|
+
| `strategy` | `CollapseStrategy` | `'seeded'` | Strategy for each run |
|
|
160
|
+
|
|
161
|
+
Returns a `SimulationResult` with the array of engine results, the full collapse history for every run, and metadata.
|
|
162
|
+
|
|
163
|
+
## Types
|
|
164
|
+
|
|
165
|
+
### `Superposition`
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
type Superposition = {
|
|
169
|
+
state: 'superposition';
|
|
170
|
+
amplitudes: Record<string, number>; // normalized 0-1, sums to 1.0
|
|
171
|
+
};
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### `QFactInput`
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
type QFactInput = {
|
|
178
|
+
id?: string;
|
|
179
|
+
type: string;
|
|
180
|
+
data: Record<string, QValue>; // QValue = any concrete value OR a Superposition
|
|
181
|
+
};
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### `CollapseRecord`
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
type CollapseRecord = {
|
|
188
|
+
field: string; // which field was collapsed
|
|
189
|
+
selectedValue: any; // what it collapsed to
|
|
190
|
+
amplitudes: Record<string, number>; // what the options were
|
|
191
|
+
strategy: CollapseStrategy; // how it was picked
|
|
192
|
+
seed?: number; // seed used (seeded strategy only)
|
|
193
|
+
};
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### `CollapsedFact`
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
type CollapsedFact = {
|
|
200
|
+
fact: FactInput; // clean, ready for any BOE engine
|
|
201
|
+
collapseLog: CollapseRecord[];
|
|
202
|
+
};
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### `SimulationResult<T>`
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
type SimulationResult<T> = {
|
|
209
|
+
runs: number;
|
|
210
|
+
results: T[]; // one engine result per run
|
|
211
|
+
collapseHistory: CollapseRecord[][]; // one collapse log per run
|
|
212
|
+
strategy: CollapseStrategy;
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Structure
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
src/qfacts/
|
|
220
|
+
├── types.ts # All type definitions
|
|
221
|
+
├── collapse.ts # Core collapse functions + superposition factory
|
|
222
|
+
├── simulate.ts # Monte Carlo simulation wrapper
|
|
223
|
+
├── strategies/
|
|
224
|
+
│ ├── seeded.ts # Mulberry32 PRNG collapse
|
|
225
|
+
│ ├── deterministic.ts # Argmax collapse (no randomness)
|
|
226
|
+
│ ├── crypto.ts # crypto.getRandomValues collapse
|
|
227
|
+
│ ├── quasi-random.ts # Halton sequence collapse
|
|
228
|
+
│ └── index.ts # Strategy barrel + dispatcher
|
|
229
|
+
└── index.ts # Module barrel exports
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Design Decisions
|
|
233
|
+
|
|
234
|
+
| Decision | Choice | Why |
|
|
235
|
+
|----------|--------|-----|
|
|
236
|
+
| BOE stays untouched | QFacts is pre-processing only | BOE remains deterministic and auditable. QFacts extends the audit trail upstream, not inside. |
|
|
237
|
+
| Default seed is `0`, not random | Reproducibility by default | First call always gives the same result. No surprises. Opt into randomness explicitly. |
|
|
238
|
+
| Per-field seed derivation | `baseSeed ^ hash(fieldName)` | Collapse of one field doesn't affect another. Reordering fields doesn't change results. |
|
|
239
|
+
| Amplitude normalization | Accept 0.9, 90, or '90%' | All three forms mean the same thing. Don't make users do math. |
|
|
240
|
+
| Duplicate Mulberry32 PRNG | Copied, not imported from Monte Carlo engine | 14 lines. Avoids coupling QFacts to a specific engine. |
|
|
241
|
+
| Top-level fields only | No nested superposition (v1) | Recursive traversal complicates types significantly. Can add later without breaking the API. |
|
|
242
|
+
| Pure functions | No classes, no state | Matches the existing functions module pattern. Composable and testable. |
|
|
243
|
+
| Coercion is opt-in | Off by default | Amplitude keys are strings. Automatic type guessing is risky. User opts in when they know their keys are parseable. |
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { FactInput } from '../core';
|
|
2
|
+
import type {
|
|
3
|
+
Superposition,
|
|
4
|
+
QFactInput,
|
|
5
|
+
CollapseOptions,
|
|
6
|
+
CollapseRecord,
|
|
7
|
+
CollapsedFact,
|
|
8
|
+
AmplitudeValue,
|
|
9
|
+
} from './types';
|
|
10
|
+
import { resolveStrategy } from './strategies';
|
|
11
|
+
|
|
12
|
+
export function isSuperposition(value: unknown): value is Superposition {
|
|
13
|
+
return (
|
|
14
|
+
typeof value === 'object' &&
|
|
15
|
+
value !== null &&
|
|
16
|
+
(value as any).state === 'superposition' &&
|
|
17
|
+
typeof (value as any).amplitudes === 'object' &&
|
|
18
|
+
(value as any).amplitudes !== null
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeAmplitudes(amplitudes: Record<string, AmplitudeValue>): Record<string, number> {
|
|
23
|
+
const parsed: Record<string, number> = {};
|
|
24
|
+
|
|
25
|
+
for (const [key, raw] of Object.entries(amplitudes)) {
|
|
26
|
+
if (typeof raw === 'string' && raw.endsWith('%')) {
|
|
27
|
+
parsed[key] = parseFloat(raw.slice(0, -1));
|
|
28
|
+
} else {
|
|
29
|
+
parsed[key] = Number(raw);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const values = Object.values(parsed);
|
|
34
|
+
const total = values.reduce((sum, v) => sum + v, 0);
|
|
35
|
+
const anyAboveOne = values.some((v) => v > 1);
|
|
36
|
+
|
|
37
|
+
if (anyAboveOne || total > 1.001) {
|
|
38
|
+
// Treat as raw numbers, normalize against total
|
|
39
|
+
for (const key of Object.keys(parsed)) {
|
|
40
|
+
parsed[key] = parsed[key] / total;
|
|
41
|
+
}
|
|
42
|
+
} else if (Math.abs(total - 1.0) > 0.001) {
|
|
43
|
+
// All ≤ 1 but doesn't sum to 1 — normalize
|
|
44
|
+
for (const key of Object.keys(parsed)) {
|
|
45
|
+
parsed[key] = parsed[key] / total;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// else: all ≤ 1 and total ≈ 1.0 — use as-is
|
|
49
|
+
|
|
50
|
+
return parsed;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function superposition(amplitudes: Record<string, AmplitudeValue>): Superposition {
|
|
54
|
+
return {
|
|
55
|
+
state: 'superposition',
|
|
56
|
+
amplitudes: normalizeAmplitudes(amplitudes),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function collapse(qfact: QFactInput, options?: CollapseOptions): CollapsedFact {
|
|
61
|
+
const strategy = options?.strategy ?? 'seeded';
|
|
62
|
+
const collapseLog: CollapseRecord[] = [];
|
|
63
|
+
const data: Record<string, any> = {};
|
|
64
|
+
|
|
65
|
+
let fieldIndex = 0;
|
|
66
|
+
for (const [field, value] of Object.entries(qfact.data)) {
|
|
67
|
+
if (isSuperposition(value)) {
|
|
68
|
+
const resolve = resolveStrategy(strategy, options ?? {}, fieldIndex);
|
|
69
|
+
const selectedKey = resolve(value.amplitudes, field);
|
|
70
|
+
let selectedValue: any = selectedKey;
|
|
71
|
+
|
|
72
|
+
if (options?.coerce) {
|
|
73
|
+
try {
|
|
74
|
+
selectedValue = JSON.parse(selectedKey);
|
|
75
|
+
} catch {
|
|
76
|
+
// keep as string
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
data[field] = selectedValue;
|
|
81
|
+
collapseLog.push({
|
|
82
|
+
field,
|
|
83
|
+
selectedValue,
|
|
84
|
+
amplitudes: { ...value.amplitudes },
|
|
85
|
+
strategy,
|
|
86
|
+
...(strategy === 'seeded' ? { seed: options?.seed ?? 0 } : {}),
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
data[field] = value;
|
|
90
|
+
}
|
|
91
|
+
fieldIndex++;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const fact: FactInput = {
|
|
95
|
+
...(qfact.id != null ? { id: qfact.id } : {}),
|
|
96
|
+
type: qfact.type,
|
|
97
|
+
data,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return { fact, collapseLog };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function collapseAll(qfacts: QFactInput[], options?: CollapseOptions): CollapsedFact[] {
|
|
104
|
+
const baseSeed = options?.seed ?? 0;
|
|
105
|
+
return qfacts.map((qfact, index) =>
|
|
106
|
+
collapse(qfact, {
|
|
107
|
+
...options,
|
|
108
|
+
seed: (baseSeed + index) >>> 0,
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
export type {
|
|
3
|
+
AmplitudeValue,
|
|
4
|
+
Superposition,
|
|
5
|
+
QValue,
|
|
6
|
+
QFactInput,
|
|
7
|
+
CollapseStrategy,
|
|
8
|
+
CollapseOptions,
|
|
9
|
+
CollapseRecord,
|
|
10
|
+
CollapsedFact,
|
|
11
|
+
SimulationResult,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
// Core collapse functions
|
|
15
|
+
export { isSuperposition, superposition, collapse, collapseAll } from './collapse';
|
|
16
|
+
|
|
17
|
+
// Simulation
|
|
18
|
+
export { simulate } from './simulate';
|
|
19
|
+
|
|
20
|
+
// Strategies
|
|
21
|
+
export {
|
|
22
|
+
seededCollapse,
|
|
23
|
+
cryptoCollapse,
|
|
24
|
+
deterministicCollapse,
|
|
25
|
+
quasiRandomCollapse,
|
|
26
|
+
resolveStrategy,
|
|
27
|
+
} from './strategies';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FactInput } from '../core';
|
|
2
|
+
import type { QFactInput, CollapseStrategy, CollapseRecord, SimulationResult } from './types';
|
|
3
|
+
import { collapseAll } from './collapse';
|
|
4
|
+
|
|
5
|
+
export function simulate<T>(
|
|
6
|
+
qfacts: QFactInput[],
|
|
7
|
+
engineFn: (facts: FactInput[]) => T,
|
|
8
|
+
options?: { runs?: number; strategy?: CollapseStrategy }
|
|
9
|
+
): SimulationResult<T> {
|
|
10
|
+
const runs = options?.runs ?? 1000;
|
|
11
|
+
const strategy = options?.strategy ?? 'seeded';
|
|
12
|
+
const results: T[] = [];
|
|
13
|
+
const collapseHistory: CollapseRecord[][] = [];
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < runs; i++) {
|
|
16
|
+
const collapsed = collapseAll(qfacts, { strategy, seed: i });
|
|
17
|
+
const facts = collapsed.map((c) => c.fact);
|
|
18
|
+
const logs = collapsed.flatMap((c) => c.collapseLog);
|
|
19
|
+
|
|
20
|
+
results.push(engineFn(facts));
|
|
21
|
+
collapseHistory.push(logs);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { runs, results, collapseHistory, strategy };
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function cryptoCollapse(amplitudes: Record<string, number>): string {
|
|
2
|
+
if (!globalThis.crypto?.getRandomValues) {
|
|
3
|
+
throw new Error(
|
|
4
|
+
'crypto.getRandomValues is not available. Requires Node >= 19 or a browser environment. ' +
|
|
5
|
+
'Use strategy "seeded" or "deterministic" as an alternative.'
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const arr = new Uint32Array(1);
|
|
10
|
+
globalThis.crypto.getRandomValues(arr);
|
|
11
|
+
const roll = arr[0] / 4294967296;
|
|
12
|
+
|
|
13
|
+
const keys = Object.keys(amplitudes);
|
|
14
|
+
let cumulative = 0;
|
|
15
|
+
for (const key of keys) {
|
|
16
|
+
cumulative += amplitudes[key];
|
|
17
|
+
if (roll < cumulative) return key;
|
|
18
|
+
}
|
|
19
|
+
return keys[keys.length - 1];
|
|
20
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function deterministicCollapse(amplitudes: Record<string, number>): string {
|
|
2
|
+
let maxKey = '';
|
|
3
|
+
let maxVal = -Infinity;
|
|
4
|
+
for (const [key, val] of Object.entries(amplitudes)) {
|
|
5
|
+
if (val > maxVal) {
|
|
6
|
+
maxVal = val;
|
|
7
|
+
maxKey = key;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return maxKey;
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { seededCollapse } from './seeded';
|
|
2
|
+
export { cryptoCollapse } from './crypto';
|
|
3
|
+
export { deterministicCollapse } from './deterministic';
|
|
4
|
+
export { quasiRandomCollapse } from './quasi-random';
|
|
5
|
+
|
|
6
|
+
import { seededCollapse } from './seeded';
|
|
7
|
+
import { cryptoCollapse } from './crypto';
|
|
8
|
+
import { deterministicCollapse } from './deterministic';
|
|
9
|
+
import { quasiRandomCollapse } from './quasi-random';
|
|
10
|
+
import type { CollapseStrategy, CollapseOptions } from '../types';
|
|
11
|
+
|
|
12
|
+
type CollapseFunction = (amplitudes: Record<string, number>, fieldName: string) => string;
|
|
13
|
+
|
|
14
|
+
export function resolveStrategy(strategy: CollapseStrategy, options: CollapseOptions, fieldIndex?: number): CollapseFunction {
|
|
15
|
+
switch (strategy) {
|
|
16
|
+
case 'seeded':
|
|
17
|
+
return (amplitudes, fieldName) => seededCollapse(amplitudes, options.seed ?? 0, fieldName);
|
|
18
|
+
case 'crypto':
|
|
19
|
+
return (amplitudes) => cryptoCollapse(amplitudes);
|
|
20
|
+
case 'deterministic':
|
|
21
|
+
return (amplitudes) => deterministicCollapse(amplitudes);
|
|
22
|
+
case 'quasi-random':
|
|
23
|
+
return (amplitudes) => quasiRandomCollapse(amplitudes, fieldIndex ?? 0);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function halton(index: number, base: number): number {
|
|
2
|
+
let result = 0;
|
|
3
|
+
let f = 1 / base;
|
|
4
|
+
let i = index;
|
|
5
|
+
while (i > 0) {
|
|
6
|
+
result += f * (i % base);
|
|
7
|
+
i = Math.floor(i / base);
|
|
8
|
+
f /= base;
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function quasiRandomCollapse(amplitudes: Record<string, number>, index: number): string {
|
|
14
|
+
const roll = halton(index + 1, 2); // +1 to avoid halton(0) = 0
|
|
15
|
+
|
|
16
|
+
const keys = Object.keys(amplitudes);
|
|
17
|
+
let cumulative = 0;
|
|
18
|
+
for (const key of keys) {
|
|
19
|
+
cumulative += amplitudes[key];
|
|
20
|
+
if (roll < cumulative) return key;
|
|
21
|
+
}
|
|
22
|
+
return keys[keys.length - 1];
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function createRng(seed: number): () => number {
|
|
2
|
+
let state = seed;
|
|
3
|
+
return () => {
|
|
4
|
+
state |= 0;
|
|
5
|
+
state = (state + 0x6d2b79f5) | 0;
|
|
6
|
+
let t = Math.imul(state ^ (state >>> 15), 1 | state);
|
|
7
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
8
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function djb2Hash(str: string): number {
|
|
13
|
+
let hash = 5381;
|
|
14
|
+
for (let i = 0; i < str.length; i++) {
|
|
15
|
+
hash = ((hash << 5) + hash + str.charCodeAt(i)) | 0;
|
|
16
|
+
}
|
|
17
|
+
return hash >>> 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function seededCollapse(amplitudes: Record<string, number>, seed: number, fieldName: string): string {
|
|
21
|
+
const fieldSeed = (seed ^ djb2Hash(fieldName)) >>> 0;
|
|
22
|
+
const rng = createRng(fieldSeed);
|
|
23
|
+
const roll = rng();
|
|
24
|
+
|
|
25
|
+
const keys = Object.keys(amplitudes);
|
|
26
|
+
let cumulative = 0;
|
|
27
|
+
for (const key of keys) {
|
|
28
|
+
cumulative += amplitudes[key];
|
|
29
|
+
if (roll < cumulative) return key;
|
|
30
|
+
}
|
|
31
|
+
return keys[keys.length - 1];
|
|
32
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { FactInput } from '../core';
|
|
2
|
+
|
|
3
|
+
export type AmplitudeValue = number | `${number}%`;
|
|
4
|
+
|
|
5
|
+
export type Superposition = {
|
|
6
|
+
state: 'superposition';
|
|
7
|
+
amplitudes: Record<string, number>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type QValue = any | Superposition;
|
|
11
|
+
|
|
12
|
+
export type QFactInput = {
|
|
13
|
+
id?: string;
|
|
14
|
+
type: string;
|
|
15
|
+
data: Record<string, QValue>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type CollapseStrategy = 'seeded' | 'crypto' | 'deterministic' | 'quasi-random';
|
|
19
|
+
|
|
20
|
+
export type CollapseOptions = {
|
|
21
|
+
strategy?: CollapseStrategy;
|
|
22
|
+
seed?: number;
|
|
23
|
+
coerce?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type CollapseRecord = {
|
|
27
|
+
field: string;
|
|
28
|
+
selectedValue: any;
|
|
29
|
+
amplitudes: Record<string, number>;
|
|
30
|
+
strategy: CollapseStrategy;
|
|
31
|
+
seed?: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type CollapsedFact = {
|
|
35
|
+
fact: FactInput;
|
|
36
|
+
collapseLog: CollapseRecord[];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type SimulationResult<T = any> = {
|
|
40
|
+
runs: number;
|
|
41
|
+
results: T[];
|
|
42
|
+
collapseHistory: CollapseRecord[][];
|
|
43
|
+
strategy: CollapseStrategy;
|
|
44
|
+
};
|