@elaraai/east-py-datascience 0.0.2-beta.8 → 0.0.2-beta.80
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 +58 -1
- package/dist/src/alns/alns.d.ts +528 -0
- package/dist/src/alns/alns.d.ts.map +1 -0
- package/dist/src/alns/alns.js +238 -0
- package/dist/src/alns/alns.js.map +1 -0
- package/dist/src/google_or/google_or.d.ts +2422 -0
- package/dist/src/google_or/google_or.d.ts.map +1 -0
- package/dist/src/google_or/google_or.js +542 -0
- package/dist/src/google_or/google_or.js.map +1 -0
- package/dist/{gp → src/gp}/gp.d.ts +185 -136
- package/dist/src/gp/gp.d.ts.map +1 -0
- package/dist/{gp → src/gp}/gp.js +64 -12
- package/dist/src/gp/gp.js.map +1 -0
- package/dist/src/index.d.ts +34 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +57 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lightgbm/lightgbm.d.ts +575 -0
- package/dist/src/lightgbm/lightgbm.d.ts.map +1 -0
- package/dist/{lightgbm → src/lightgbm}/lightgbm.js +104 -18
- package/dist/src/lightgbm/lightgbm.js.map +1 -0
- package/dist/src/lightning/lightning.d.ts +1594 -0
- package/dist/src/lightning/lightning.d.ts.map +1 -0
- package/dist/src/lightning/lightning.js +468 -0
- package/dist/src/lightning/lightning.js.map +1 -0
- package/dist/{mads → src/mads}/mads.d.ts +109 -112
- package/dist/src/mads/mads.d.ts.map +1 -0
- package/dist/{mads → src/mads}/mads.js +6 -8
- package/dist/src/mads/mads.js.map +1 -0
- package/dist/src/mapie/mapie.d.ts +3680 -0
- package/dist/src/mapie/mapie.d.ts.map +1 -0
- package/dist/src/mapie/mapie.js +616 -0
- package/dist/src/mapie/mapie.js.map +1 -0
- package/dist/{ngboost → src/ngboost}/ngboost.d.ts +192 -142
- package/dist/src/ngboost/ngboost.d.ts.map +1 -0
- package/dist/{ngboost → src/ngboost}/ngboost.js +67 -14
- package/dist/src/ngboost/ngboost.js.map +1 -0
- package/dist/src/optimization/optimization.d.ts +420 -0
- package/dist/src/optimization/optimization.d.ts.map +1 -0
- package/dist/src/optimization/optimization.js +257 -0
- package/dist/src/optimization/optimization.js.map +1 -0
- package/dist/{optuna → src/optuna}/optuna.d.ts +374 -314
- package/dist/src/optuna/optuna.d.ts.map +1 -0
- package/dist/{optuna → src/optuna}/optuna.js +2 -0
- package/dist/src/optuna/optuna.js.map +1 -0
- package/dist/src/pymc/pymc.d.ts +2932 -0
- package/dist/src/pymc/pymc.d.ts.map +1 -0
- package/dist/src/pymc/pymc.js +688 -0
- package/dist/src/pymc/pymc.js.map +1 -0
- package/dist/src/scipy/scipy.d.ts +2205 -0
- package/dist/src/scipy/scipy.d.ts.map +1 -0
- package/dist/src/scipy/scipy.js +884 -0
- package/dist/src/scipy/scipy.js.map +1 -0
- package/dist/src/shap/shap.d.ts +2988 -0
- package/dist/src/shap/shap.d.ts.map +1 -0
- package/dist/src/shap/shap.js +500 -0
- package/dist/src/shap/shap.js.map +1 -0
- package/dist/{simanneal → src/simanneal}/simanneal.d.ts +257 -160
- package/dist/src/simanneal/simanneal.d.ts.map +1 -0
- package/dist/{simanneal → src/simanneal}/simanneal.js +105 -8
- package/dist/src/simanneal/simanneal.js.map +1 -0
- package/dist/src/simulation/simulation.d.ts +431 -0
- package/dist/src/simulation/simulation.d.ts.map +1 -0
- package/dist/src/simulation/simulation.js +306 -0
- package/dist/src/simulation/simulation.js.map +1 -0
- package/dist/src/sklearn/sklearn.d.ts +6362 -0
- package/dist/src/sklearn/sklearn.d.ts.map +1 -0
- package/dist/src/sklearn/sklearn.js +1508 -0
- package/dist/src/sklearn/sklearn.js.map +1 -0
- package/dist/src/torch/torch.d.ts +1205 -0
- package/dist/src/torch/torch.d.ts.map +1 -0
- package/dist/{torch → src/torch}/torch.js +109 -18
- package/dist/src/torch/torch.js.map +1 -0
- package/dist/src/types.d.ts +43 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +44 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/xgboost/xgboost.d.ts +1424 -0
- package/dist/src/xgboost/xgboost.d.ts.map +1 -0
- package/dist/src/xgboost/xgboost.js +432 -0
- package/dist/src/xgboost/xgboost.js.map +1 -0
- package/package.json +12 -12
- package/dist/gp/gp.d.ts.map +0 -1
- package/dist/gp/gp.js.map +0 -1
- package/dist/index.d.ts +0 -27
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -41
- package/dist/index.js.map +0 -1
- package/dist/lightgbm/lightgbm.d.ts +0 -494
- package/dist/lightgbm/lightgbm.d.ts.map +0 -1
- package/dist/lightgbm/lightgbm.js.map +0 -1
- package/dist/mads/mads.d.ts.map +0 -1
- package/dist/mads/mads.js.map +0 -1
- package/dist/ngboost/ngboost.d.ts.map +0 -1
- package/dist/ngboost/ngboost.js.map +0 -1
- package/dist/optuna/optuna.d.ts.map +0 -1
- package/dist/optuna/optuna.js.map +0 -1
- package/dist/scipy/scipy.d.ts +0 -1260
- package/dist/scipy/scipy.d.ts.map +0 -1
- package/dist/scipy/scipy.js +0 -413
- package/dist/scipy/scipy.js.map +0 -1
- package/dist/shap/shap.d.ts +0 -657
- package/dist/shap/shap.d.ts.map +0 -1
- package/dist/shap/shap.js +0 -241
- package/dist/shap/shap.js.map +0 -1
- package/dist/simanneal/simanneal.d.ts.map +0 -1
- package/dist/simanneal/simanneal.js.map +0 -1
- package/dist/sklearn/sklearn.d.ts +0 -2691
- package/dist/sklearn/sklearn.d.ts.map +0 -1
- package/dist/sklearn/sklearn.js +0 -524
- package/dist/sklearn/sklearn.js.map +0 -1
- package/dist/torch/torch.d.ts +0 -1081
- package/dist/torch/torch.d.ts.map +0 -1
- package/dist/torch/torch.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/types.d.ts +0 -80
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -81
- package/dist/types.js.map +0 -1
- package/dist/xgboost/xgboost.d.ts +0 -504
- package/dist/xgboost/xgboost.d.ts.map +0 -1
- package/dist/xgboost/xgboost.js +0 -177
- package/dist/xgboost/xgboost.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simanneal.d.ts","sourceRoot":"","sources":["../../../src/simanneal/simanneal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAEH,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,EACb,MAAM,eAAe,CAAC;AAMvB;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;IAC1B,sDAAsD;;IAEtD,6CAA6C;;EAE/C,CAAC;AAMH;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;IAhB3B,sDAAsD;;IAEtD,6CAA6C;;eAiBhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;IA3BzB,sDAAsD;;IAEtD,6CAA6C;;;IAF7C,sDAAsD;;IAEtD,6CAA6C;;GA4BhD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,oDAGjC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,oDAG5B,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,gBAAgB;IACzB,8CAA8C;;IAE9C,wCAAwC;;IAExC,wCAAwC;;IAExC,sDAAsD;;IAEtD,mDAAmD;;IAEnD,sCAAsC;;EAExC,CAAC;AAMH;;GAEG;AACH,eAAO,MAAM,gBAAgB;IACzB,uBAAuB;;QAlFvB,sDAAsD;;QAEtD,6CAA6C;;;IAkF7C,2BAA2B;;IAE3B,kCAAkC;;IAElC,kDAAkD;;EAEpD,CAAC;AAMH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB;IA3G3B,sDAAsD;;IAEtD,6CAA6C;;;IAF7C,sDAAsD;;IAEtD,6CAA6C;;;IAF7C,s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0K7C,yBAAyB;;YA5KzB,sDAAsD;;YAEtD,6CAA6C;;;YAF7C,sDAAsD;;YAEtD,6CAA6C;;;QA4K7C,uCAAuC;;QAEvC,kCAAkC;;QAElC,yBAAyB;;YAtHzB,8CAA8C;;YAE9C,wCAAwC;;YAExC,wCAAwC;;YAExC,sDAAsD;;YAEtD,mDAAmD;;YAEnD,sCAAsC;;;QA8GtC,kBAAkB;;YAlGlB,uBAAuB;;gBAlFvB,sDAAsD;;gBAEtD,6CAA6C;;;YAkF7C,2BAA2B;;YAE3B,kCAAkC;;YAElC,kDAAkD;;;;CA6P5C,CAAC"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @packageDocumentation
|
|
16
16
|
*/
|
|
17
|
-
import { East, StructType, VariantType, OptionType,
|
|
17
|
+
import { East, StructType, VariantType, OptionType, IntegerType, FloatType, BooleanType, FunctionType, VectorType, } from "@elaraai/east";
|
|
18
18
|
// ===========================================
|
|
19
19
|
// State Types
|
|
20
20
|
// ===========================================
|
|
@@ -27,9 +27,9 @@ import { East, StructType, VariantType, OptionType, ArrayType, IntegerType, Floa
|
|
|
27
27
|
*/
|
|
28
28
|
export const DiscreteStateType = VariantType({
|
|
29
29
|
/** Integer array state (permutations, assignments) */
|
|
30
|
-
int_array:
|
|
30
|
+
int_array: VectorType(IntegerType),
|
|
31
31
|
/** Boolean array state (subset selection) */
|
|
32
|
-
bool_array:
|
|
32
|
+
bool_array: VectorType(BooleanType),
|
|
33
33
|
});
|
|
34
34
|
// ===========================================
|
|
35
35
|
// Function Types
|
|
@@ -53,13 +53,13 @@ export const MoveFunctionType = FunctionType([DiscreteStateType], DiscreteStateT
|
|
|
53
53
|
*
|
|
54
54
|
* Specialized for permutation-based optimization.
|
|
55
55
|
*/
|
|
56
|
-
export const PermutationEnergyType = FunctionType([
|
|
56
|
+
export const PermutationEnergyType = FunctionType([VectorType(IntegerType)], FloatType);
|
|
57
57
|
/**
|
|
58
58
|
* Subset energy function type.
|
|
59
59
|
*
|
|
60
60
|
* Specialized for subset selection optimization.
|
|
61
61
|
*/
|
|
62
|
-
export const SubsetEnergyType = FunctionType([
|
|
62
|
+
export const SubsetEnergyType = FunctionType([VectorType(BooleanType)], FloatType);
|
|
63
63
|
// ===========================================
|
|
64
64
|
// Configuration Types
|
|
65
65
|
// ===========================================
|
|
@@ -128,7 +128,7 @@ export const simanneal_optimize = East.platform("simanneal_optimize", [
|
|
|
128
128
|
* @returns Result with best permutation and energy
|
|
129
129
|
*/
|
|
130
130
|
export const simanneal_optimize_permutation = East.platform("simanneal_optimize_permutation", [
|
|
131
|
-
|
|
131
|
+
VectorType(IntegerType),
|
|
132
132
|
PermutationEnergyType,
|
|
133
133
|
AnnealConfigType,
|
|
134
134
|
], AnnealResultType);
|
|
@@ -144,7 +144,7 @@ export const simanneal_optimize_permutation = East.platform("simanneal_optimize_
|
|
|
144
144
|
* @returns Result with best selection and energy
|
|
145
145
|
*/
|
|
146
146
|
export const simanneal_optimize_subset = East.platform("simanneal_optimize_subset", [
|
|
147
|
-
|
|
147
|
+
VectorType(BooleanType),
|
|
148
148
|
SubsetEnergyType,
|
|
149
149
|
AnnealConfigType,
|
|
150
150
|
], AnnealResultType);
|
|
@@ -190,7 +190,7 @@ export const SimAnnealTypes = {
|
|
|
190
190
|
*
|
|
191
191
|
* // TSP: minimize total route distance
|
|
192
192
|
* const energy = East.function(
|
|
193
|
-
* [
|
|
193
|
+
* [VectorType(IntegerType)],
|
|
194
194
|
* FloatType,
|
|
195
195
|
* ($, route) => {
|
|
196
196
|
* // Calculate total route distance
|
|
@@ -213,14 +213,111 @@ export const SimAnnealTypes = {
|
|
|
213
213
|
export const SimAnneal = {
|
|
214
214
|
/**
|
|
215
215
|
* Run simulated annealing with custom energy and move functions.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* import { East, FloatType, IntegerType, VectorType, variant } from "@elaraai/east";
|
|
220
|
+
* import { SimAnneal, AnnealConfigType, DiscreteStateType } from "@elaraai/east-py-datascience";
|
|
221
|
+
*
|
|
222
|
+
* const solve = East.function([], SimAnneal.Types.ResultType, ($) => {
|
|
223
|
+
* const energy = East.function([DiscreteStateType], FloatType, ($, state) => {
|
|
224
|
+
* const cost = $.let(0.0);
|
|
225
|
+
* $.match(state, {
|
|
226
|
+
* int_array: ($, arr) => {
|
|
227
|
+
* const a0 = $.let(arr.get(0n));
|
|
228
|
+
* $.if(East.equal(a0, 2n), $ => {}).else($ => { $.assign(cost, cost.add(1.0)); });
|
|
229
|
+
* },
|
|
230
|
+
* bool_array: ($) => { $.assign(cost, 999.0); },
|
|
231
|
+
* });
|
|
232
|
+
* return $.return(cost);
|
|
233
|
+
* });
|
|
234
|
+
* const move = East.function([DiscreteStateType], DiscreteStateType, ($, state) => {
|
|
235
|
+
* const result = $.let(state);
|
|
236
|
+
* $.match(state, {
|
|
237
|
+
* int_array: ($, arr) => {
|
|
238
|
+
* const new_arr = $.let(East.Vector.fromArray([arr.get(0n).add(1n).remainder(3n), arr.get(1n), arr.get(2n)]));
|
|
239
|
+
* $.assign(result, variant("int_array", new_arr));
|
|
240
|
+
* },
|
|
241
|
+
* bool_array: ($, arr) => { $.assign(result, variant("bool_array", arr)); },
|
|
242
|
+
* });
|
|
243
|
+
* return $.return(result);
|
|
244
|
+
* });
|
|
245
|
+
* const initial = $.let(variant("int_array", new BigInt64Array([0n, 0n, 0n])), DiscreteStateType);
|
|
246
|
+
* const config = $.let({
|
|
247
|
+
* t_max: variant("some", 100.0), t_min: variant("some", 0.01),
|
|
248
|
+
* steps: variant("some", 1000n), updates: variant("none", null),
|
|
249
|
+
* auto_schedule: variant("none", null), random_state: variant("some", 42n),
|
|
250
|
+
* }, AnnealConfigType);
|
|
251
|
+
* return $.return(SimAnneal.optimize(initial, energy, move, config));
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
216
254
|
*/
|
|
217
255
|
optimize: simanneal_optimize,
|
|
218
256
|
/**
|
|
219
257
|
* Run simulated annealing on a permutation with swap moves.
|
|
258
|
+
*
|
|
259
|
+
* Convenience function for permutation-based problems (TSP, scheduling).
|
|
260
|
+
* Automatically uses swap moves to generate neighbors.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* import { East, FloatType, IntegerType, VectorType, variant } from "@elaraai/east";
|
|
265
|
+
* import { SimAnneal, AnnealConfigType } from "@elaraai/east-py-datascience";
|
|
266
|
+
*
|
|
267
|
+
* const solve = East.function([], SimAnneal.Types.ResultType, ($) => {
|
|
268
|
+
* const energy = East.function([VectorType(IntegerType)], FloatType, ($, route) => {
|
|
269
|
+
* const total = $.let(0.0);
|
|
270
|
+
* $.for(East.Array.range(0n, route.length()), ($, i) => {
|
|
271
|
+
* const from = $.let(route.get(i));
|
|
272
|
+
* const to = $.let(route.get(i.add(1n).remainder(route.length())));
|
|
273
|
+
* const diff = $.let(from.subtract(to).abs());
|
|
274
|
+
* $.if(East.equal(diff, 1n).or(() => East.equal(diff, 3n)), $ => {
|
|
275
|
+
* $.assign(total, total.add(1.0));
|
|
276
|
+
* }).else($ => { $.assign(total, total.add(1.414)); });
|
|
277
|
+
* });
|
|
278
|
+
* return $.return(total);
|
|
279
|
+
* });
|
|
280
|
+
* const initial = $.let(new BigInt64Array([0n, 1n, 2n, 3n]));
|
|
281
|
+
* const config = $.let({
|
|
282
|
+
* t_max: variant("some", 1000.0), t_min: variant("some", 0.1),
|
|
283
|
+
* steps: variant("some", 5000n), updates: variant("none", null),
|
|
284
|
+
* auto_schedule: variant("none", null), random_state: variant("some", 42n),
|
|
285
|
+
* }, AnnealConfigType);
|
|
286
|
+
* return $.return(SimAnneal.optimizePermutation(initial, energy, config));
|
|
287
|
+
* });
|
|
288
|
+
* ```
|
|
220
289
|
*/
|
|
221
290
|
optimizePermutation: simanneal_optimize_permutation,
|
|
222
291
|
/**
|
|
223
292
|
* Run simulated annealing on a subset selection with bit-flip moves.
|
|
293
|
+
*
|
|
294
|
+
* Convenience function for subset selection problems (feature selection, knapsack).
|
|
295
|
+
* Automatically uses bit-flip moves to generate neighbors.
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```ts
|
|
299
|
+
* import { East, FloatType, BooleanType, VectorType, variant } from "@elaraai/east";
|
|
300
|
+
* import { SimAnneal, AnnealConfigType } from "@elaraai/east-py-datascience";
|
|
301
|
+
*
|
|
302
|
+
* const solve = East.function([], SimAnneal.Types.ResultType, ($) => {
|
|
303
|
+
* const items = $.let(new Float64Array([3.0, 7.0, 1.0, 8.0, 4.0]));
|
|
304
|
+
* const target = $.let(12.0);
|
|
305
|
+
* const energy = East.function([VectorType(BooleanType)], FloatType, ($, selection) => {
|
|
306
|
+
* const sum = $.let(0.0);
|
|
307
|
+
* $.for(East.Array.range(0n, selection.length()), ($, i) => {
|
|
308
|
+
* $.if(selection.get(i), $ => { $.assign(sum, sum.add(items.get(i))); });
|
|
309
|
+
* });
|
|
310
|
+
* return $.return(sum.subtract(target).abs());
|
|
311
|
+
* });
|
|
312
|
+
* const initial = $.let(East.Vector.fromArray([true, true, true, true, true]));
|
|
313
|
+
* const config = $.let({
|
|
314
|
+
* t_max: variant("some", 500.0), t_min: variant("some", 0.1),
|
|
315
|
+
* steps: variant("some", 2000n), updates: variant("none", null),
|
|
316
|
+
* auto_schedule: variant("none", null), random_state: variant("some", 123n),
|
|
317
|
+
* }, AnnealConfigType);
|
|
318
|
+
* return $.return(SimAnneal.optimizeSubset(initial, energy, config));
|
|
319
|
+
* });
|
|
320
|
+
* ```
|
|
224
321
|
*/
|
|
225
322
|
optimizeSubset: simanneal_optimize_subset,
|
|
226
323
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simanneal.js","sourceRoot":"","sources":["../../../src/simanneal/simanneal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EACH,IAAI,EACJ,UAAU,EACV,WAAW,EACX,UAAU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B;IACzB,UAAU,EAAE,gBAAgB;IAC5B,kBAAkB;IAClB,UAAU,EAAE,gBAAgB;CACtB,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,QAAQ,EAAE,kBAAkB;IAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,mBAAmB,EAAE,8BAA8B;IAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,cAAc,EAAE,yBAAyB;IAEzC;;OAEG;IACH,KAAK,EAAE,cAAc;CACf,CAAC"}
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Discrete Event Simulation (DES) — Economic Ontology.
|
|
7
|
+
*
|
|
8
|
+
* Provides a generic priority-queue DES engine grounded in an economic ontology:
|
|
9
|
+
* - R (Resources): user-defined struct representing business state
|
|
10
|
+
* - E (Events): user-defined variant where each case is an economic activity
|
|
11
|
+
* - Process handler: defines how events affect resources (match dispatch)
|
|
12
|
+
*
|
|
13
|
+
* Two entry points:
|
|
14
|
+
* - `simulation_run`: single deterministic run
|
|
15
|
+
* - `simulation_run_trajectories`: Monte Carlo with multiple seeds
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { StructType, OptionType, ArrayType, IntegerType, DateTimeType, FunctionType } from "@elaraai/east";
|
|
20
|
+
/**
|
|
21
|
+
* Configuration for a single simulation run.
|
|
22
|
+
*/
|
|
23
|
+
export declare const SimulationConfigType: StructType<{
|
|
24
|
+
/** Safety limit on number of events processed (default: 100000) */
|
|
25
|
+
readonly max_events: OptionType<IntegerType>;
|
|
26
|
+
/** Stop processing events after this date */
|
|
27
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Result of a single simulation run.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SimulationResultType: StructType<{
|
|
33
|
+
/** Final resource state after all events processed */
|
|
34
|
+
readonly final_state: "R";
|
|
35
|
+
/** Number of events processed */
|
|
36
|
+
readonly events_processed: IntegerType;
|
|
37
|
+
/** Date of the last event processed */
|
|
38
|
+
readonly final_date: DateTimeType;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Configuration for Monte Carlo simulation trajectories.
|
|
42
|
+
*/
|
|
43
|
+
export declare const SimulationTrajectoriesConfigType: StructType<{
|
|
44
|
+
/** Number of trajectories to run (required) */
|
|
45
|
+
readonly trajectories: IntegerType;
|
|
46
|
+
/** Base RNG seed — trajectory i uses seed + i */
|
|
47
|
+
readonly seed: OptionType<IntegerType>;
|
|
48
|
+
/** Safety limit on events per trajectory (default: 100000) */
|
|
49
|
+
readonly max_events: OptionType<IntegerType>;
|
|
50
|
+
/** Stop processing events after this date */
|
|
51
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Result of Monte Carlo simulation trajectories.
|
|
55
|
+
*/
|
|
56
|
+
export declare const SimulationTrajectoriesResultType: StructType<{
|
|
57
|
+
/** Array of per-trajectory results */
|
|
58
|
+
readonly trajectories: ArrayType<StructType<{
|
|
59
|
+
/** Final resource state */
|
|
60
|
+
readonly final_state: "R";
|
|
61
|
+
/** Number of events processed */
|
|
62
|
+
readonly events_processed: IntegerType;
|
|
63
|
+
/** Date of last event processed */
|
|
64
|
+
readonly final_date: DateTimeType;
|
|
65
|
+
}>>;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Run a single deterministic discrete event simulation.
|
|
69
|
+
*
|
|
70
|
+
* Events are processed in chronological order from a priority queue.
|
|
71
|
+
* The handler function dispatches on event type (match) and can
|
|
72
|
+
* mutate state and schedule new events.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { East, StructType, VariantType, FloatType, DateTimeType, variant } from "@elaraai/east";
|
|
77
|
+
* import { Simulation } from "@elaraai/east-py-datascience";
|
|
78
|
+
*
|
|
79
|
+
* const Resources = StructType({ cash: FloatType });
|
|
80
|
+
* const Events = VariantType({ income: FloatType, expense: FloatType });
|
|
81
|
+
*
|
|
82
|
+
* const process = East.function(
|
|
83
|
+
* [Resources, DateTimeType, Events],
|
|
84
|
+
* StructType({ state: Resources, events: ArrayType(StructType({ date: DateTimeType, event: Events })) }),
|
|
85
|
+
* ($, state, date, event) => {
|
|
86
|
+
* return $.return(event.match({
|
|
87
|
+
* income: ($, amount) => $.return({ state: state.spread({ cash: state.cash.add(amount) }), events: [] }),
|
|
88
|
+
* expense: ($, amount) => $.return({ state: state.spread({ cash: state.cash.subtract(amount) }), events: [] }),
|
|
89
|
+
* }));
|
|
90
|
+
* }
|
|
91
|
+
* );
|
|
92
|
+
*
|
|
93
|
+
* const result = $.let(Simulation.run([Resources, Events], initialState, initialEvents, process, config));
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const simulation_run: import("@elaraai/east").GenericPlatformDefinition<readonly ["R", "E"], readonly ["R", ArrayType<StructType<{
|
|
97
|
+
readonly date: DateTimeType;
|
|
98
|
+
readonly event: "E";
|
|
99
|
+
}>>, FunctionType<["R", DateTimeType, "E"], StructType<{
|
|
100
|
+
readonly state: "R";
|
|
101
|
+
readonly events: ArrayType<StructType<{
|
|
102
|
+
readonly date: DateTimeType;
|
|
103
|
+
readonly event: "E";
|
|
104
|
+
}>>;
|
|
105
|
+
}>>, StructType<{
|
|
106
|
+
/** Safety limit on number of events processed (default: 100000) */
|
|
107
|
+
readonly max_events: OptionType<IntegerType>;
|
|
108
|
+
/** Stop processing events after this date */
|
|
109
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
110
|
+
}>], StructType<{
|
|
111
|
+
/** Final resource state after all events processed */
|
|
112
|
+
readonly final_state: "R";
|
|
113
|
+
/** Number of events processed */
|
|
114
|
+
readonly events_processed: IntegerType;
|
|
115
|
+
/** Date of the last event processed */
|
|
116
|
+
readonly final_date: DateTimeType;
|
|
117
|
+
}>>;
|
|
118
|
+
/**
|
|
119
|
+
* Run Monte Carlo simulation trajectories.
|
|
120
|
+
*
|
|
121
|
+
* Each trajectory runs the same DES engine with a different RNG seed
|
|
122
|
+
* (base_seed + trajectory_index), enabling stochastic scenario analysis.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const result = $.let(Simulation.runTrajectories(
|
|
127
|
+
* [Resources, Events],
|
|
128
|
+
* initialState, initialEvents, stochasticProcess,
|
|
129
|
+
* { trajectories: 100n, seed: variant('some', 42n), max_events: variant('none', null), end_date: variant('none', null) },
|
|
130
|
+
* ));
|
|
131
|
+
* result.trajectories.get(0n).final_state.cash
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare const simulation_run_trajectories: import("@elaraai/east").GenericPlatformDefinition<readonly ["R", "E"], readonly ["R", ArrayType<StructType<{
|
|
135
|
+
readonly date: DateTimeType;
|
|
136
|
+
readonly event: "E";
|
|
137
|
+
}>>, FunctionType<["R", DateTimeType, "E"], StructType<{
|
|
138
|
+
readonly state: "R";
|
|
139
|
+
readonly events: ArrayType<StructType<{
|
|
140
|
+
readonly date: DateTimeType;
|
|
141
|
+
readonly event: "E";
|
|
142
|
+
}>>;
|
|
143
|
+
}>>, StructType<{
|
|
144
|
+
/** Number of trajectories to run (required) */
|
|
145
|
+
readonly trajectories: IntegerType;
|
|
146
|
+
/** Base RNG seed — trajectory i uses seed + i */
|
|
147
|
+
readonly seed: OptionType<IntegerType>;
|
|
148
|
+
/** Safety limit on events per trajectory (default: 100000) */
|
|
149
|
+
readonly max_events: OptionType<IntegerType>;
|
|
150
|
+
/** Stop processing events after this date */
|
|
151
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
152
|
+
}>], StructType<{
|
|
153
|
+
/** Array of per-trajectory results */
|
|
154
|
+
readonly trajectories: ArrayType<StructType<{
|
|
155
|
+
/** Final resource state */
|
|
156
|
+
readonly final_state: "R";
|
|
157
|
+
/** Number of events processed */
|
|
158
|
+
readonly events_processed: IntegerType;
|
|
159
|
+
/** Date of last event processed */
|
|
160
|
+
readonly final_date: DateTimeType;
|
|
161
|
+
}>>;
|
|
162
|
+
}>>;
|
|
163
|
+
/**
|
|
164
|
+
* Type definitions for simulation functions.
|
|
165
|
+
*/
|
|
166
|
+
export declare const SimulationTypes: {
|
|
167
|
+
/** Single run configuration */
|
|
168
|
+
readonly ConfigType: StructType<{
|
|
169
|
+
/** Safety limit on number of events processed (default: 100000) */
|
|
170
|
+
readonly max_events: OptionType<IntegerType>;
|
|
171
|
+
/** Stop processing events after this date */
|
|
172
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
173
|
+
}>;
|
|
174
|
+
/** Single run result */
|
|
175
|
+
readonly ResultType: StructType<{
|
|
176
|
+
/** Final resource state after all events processed */
|
|
177
|
+
readonly final_state: "R";
|
|
178
|
+
/** Number of events processed */
|
|
179
|
+
readonly events_processed: IntegerType;
|
|
180
|
+
/** Date of the last event processed */
|
|
181
|
+
readonly final_date: DateTimeType;
|
|
182
|
+
}>;
|
|
183
|
+
/** Monte Carlo configuration */
|
|
184
|
+
readonly TrajectoriesConfigType: StructType<{
|
|
185
|
+
/** Number of trajectories to run (required) */
|
|
186
|
+
readonly trajectories: IntegerType;
|
|
187
|
+
/** Base RNG seed — trajectory i uses seed + i */
|
|
188
|
+
readonly seed: OptionType<IntegerType>;
|
|
189
|
+
/** Safety limit on events per trajectory (default: 100000) */
|
|
190
|
+
readonly max_events: OptionType<IntegerType>;
|
|
191
|
+
/** Stop processing events after this date */
|
|
192
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
193
|
+
}>;
|
|
194
|
+
/** Monte Carlo result */
|
|
195
|
+
readonly TrajectoriesResultType: StructType<{
|
|
196
|
+
/** Array of per-trajectory results */
|
|
197
|
+
readonly trajectories: ArrayType<StructType<{
|
|
198
|
+
/** Final resource state */
|
|
199
|
+
readonly final_state: "R";
|
|
200
|
+
/** Number of events processed */
|
|
201
|
+
readonly events_processed: IntegerType;
|
|
202
|
+
/** Date of last event processed */
|
|
203
|
+
readonly final_date: DateTimeType;
|
|
204
|
+
}>>;
|
|
205
|
+
}>;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Discrete Event Simulation (DES) — REA Economic Ontology.
|
|
209
|
+
*
|
|
210
|
+
* Generic over:
|
|
211
|
+
* - R: Resources (state struct — the economic resource ontology)
|
|
212
|
+
* - E: Events (variant type — the economic event ontology)
|
|
213
|
+
*
|
|
214
|
+
* The handler function uses match dispatch to define economic processes.
|
|
215
|
+
* Each match branch IS a separate economic process. Process-from-process
|
|
216
|
+
* triggering works by returning new events.
|
|
217
|
+
*/
|
|
218
|
+
export declare const Simulation: {
|
|
219
|
+
/**
|
|
220
|
+
* Run a single deterministic discrete event simulation.
|
|
221
|
+
*
|
|
222
|
+
* Events are processed chronologically from a priority queue.
|
|
223
|
+
* The handler function dispatches on event type via match and can
|
|
224
|
+
* mutate state and schedule new events (creating the directed
|
|
225
|
+
* cyclic economic graph).
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* import { East, StructType, VariantType, ArrayType, FloatType, DateTimeType, variant } from "@elaraai/east";
|
|
230
|
+
* import { Simulation, SimulationConfigType } from "@elaraai/east-py-datascience";
|
|
231
|
+
*
|
|
232
|
+
* const Resources = StructType({ cash: FloatType });
|
|
233
|
+
* const Events = VariantType({ income: FloatType, expense: FloatType });
|
|
234
|
+
* const ScheduledEvent = StructType({ date: DateTimeType, event: Events });
|
|
235
|
+
* const ProcessResult = StructType({ state: Resources, events: ArrayType(ScheduledEvent) });
|
|
236
|
+
*
|
|
237
|
+
* const simulate = East.function([], Simulation.Types.ResultType, ($) => {
|
|
238
|
+
* const process = East.function(
|
|
239
|
+
* [Resources, DateTimeType, Events],
|
|
240
|
+
* ProcessResult,
|
|
241
|
+
* ($, state, date, event) => {
|
|
242
|
+
* const empty = $.let([] as const, ArrayType(ScheduledEvent));
|
|
243
|
+
* return $.return(event.match({
|
|
244
|
+
* income: ($, amount) => ({
|
|
245
|
+
* state: { cash: state.cash.add(amount) },
|
|
246
|
+
* events: empty,
|
|
247
|
+
* }),
|
|
248
|
+
* expense: ($, amount) => ({
|
|
249
|
+
* state: { cash: state.cash.subtract(amount) },
|
|
250
|
+
* events: empty,
|
|
251
|
+
* }),
|
|
252
|
+
* }));
|
|
253
|
+
* }
|
|
254
|
+
* );
|
|
255
|
+
*
|
|
256
|
+
* const initialState = $.let({ cash: 1000.0 });
|
|
257
|
+
* const initialEvents = $.let([
|
|
258
|
+
* { date: $.let(new Date("2025-01-01")), event: $.let(variant("income", 500.0), Events) },
|
|
259
|
+
* { date: $.let(new Date("2025-01-15")), event: $.let(variant("expense", 200.0), Events) },
|
|
260
|
+
* ], ArrayType(ScheduledEvent));
|
|
261
|
+
* const config = $.let({
|
|
262
|
+
* max_events: variant("none", null),
|
|
263
|
+
* end_date: variant("none", null),
|
|
264
|
+
* }, SimulationConfigType);
|
|
265
|
+
*
|
|
266
|
+
* const result = $.let(Simulation.run(
|
|
267
|
+
* [Resources, Events],
|
|
268
|
+
* initialState, initialEvents, process, config,
|
|
269
|
+
* ));
|
|
270
|
+
* // result.final_state.cash => 1300.0
|
|
271
|
+
* // result.events_processed => 2n
|
|
272
|
+
* return $.return(result);
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
readonly run: import("@elaraai/east").GenericPlatformDefinition<readonly ["R", "E"], readonly ["R", ArrayType<StructType<{
|
|
277
|
+
readonly date: DateTimeType;
|
|
278
|
+
readonly event: "E";
|
|
279
|
+
}>>, FunctionType<["R", DateTimeType, "E"], StructType<{
|
|
280
|
+
readonly state: "R";
|
|
281
|
+
readonly events: ArrayType<StructType<{
|
|
282
|
+
readonly date: DateTimeType;
|
|
283
|
+
readonly event: "E";
|
|
284
|
+
}>>;
|
|
285
|
+
}>>, StructType<{
|
|
286
|
+
/** Safety limit on number of events processed (default: 100000) */
|
|
287
|
+
readonly max_events: OptionType<IntegerType>;
|
|
288
|
+
/** Stop processing events after this date */
|
|
289
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
290
|
+
}>], StructType<{
|
|
291
|
+
/** Final resource state after all events processed */
|
|
292
|
+
readonly final_state: "R";
|
|
293
|
+
/** Number of events processed */
|
|
294
|
+
readonly events_processed: IntegerType;
|
|
295
|
+
/** Date of the last event processed */
|
|
296
|
+
readonly final_date: DateTimeType;
|
|
297
|
+
}>>;
|
|
298
|
+
/**
|
|
299
|
+
* Run Monte Carlo simulation trajectories.
|
|
300
|
+
*
|
|
301
|
+
* Each trajectory runs the same DES engine with a different RNG seed
|
|
302
|
+
* (base_seed + trajectory_index), enabling stochastic scenario analysis.
|
|
303
|
+
* Use this when the process handler uses Random functions — each trajectory
|
|
304
|
+
* gets a deterministic but distinct seed.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```ts
|
|
308
|
+
* import { East, StructType, VariantType, ArrayType, FloatType, DateTimeType, variant } from "@elaraai/east";
|
|
309
|
+
* import { Simulation, SimulationTrajectoriesConfigType } from "@elaraai/east-py-datascience";
|
|
310
|
+
*
|
|
311
|
+
* const Resources = StructType({ cash: FloatType });
|
|
312
|
+
* const Events = VariantType({ income: FloatType, expense: FloatType });
|
|
313
|
+
* const ScheduledEvent = StructType({ date: DateTimeType, event: Events });
|
|
314
|
+
* const ProcessResult = StructType({ state: Resources, events: ArrayType(ScheduledEvent) });
|
|
315
|
+
*
|
|
316
|
+
* const simulate = East.function([], Simulation.Types.TrajectoriesResultType, ($) => {
|
|
317
|
+
* const process = East.function(
|
|
318
|
+
* [Resources, DateTimeType, Events],
|
|
319
|
+
* ProcessResult,
|
|
320
|
+
* ($, state, date, event) => {
|
|
321
|
+
* const empty = $.let([] as const, ArrayType(ScheduledEvent));
|
|
322
|
+
* return $.return(event.match({
|
|
323
|
+
* income: ($, amount) => ({
|
|
324
|
+
* state: { cash: state.cash.add(amount) },
|
|
325
|
+
* events: empty,
|
|
326
|
+
* }),
|
|
327
|
+
* expense: ($, amount) => ({
|
|
328
|
+
* state: { cash: state.cash.subtract(amount) },
|
|
329
|
+
* events: empty,
|
|
330
|
+
* }),
|
|
331
|
+
* }));
|
|
332
|
+
* }
|
|
333
|
+
* );
|
|
334
|
+
*
|
|
335
|
+
* const initialState = $.let({ cash: 1000.0 });
|
|
336
|
+
* const initialEvents = $.let([
|
|
337
|
+
* { date: $.let(new Date("2025-01-01")), event: $.let(variant("income", 500.0), Events) },
|
|
338
|
+
* { date: $.let(new Date("2025-01-15")), event: $.let(variant("expense", 200.0), Events) },
|
|
339
|
+
* ], ArrayType(ScheduledEvent));
|
|
340
|
+
* const config = $.let({
|
|
341
|
+
* trajectories: 100n,
|
|
342
|
+
* seed: variant("some", 42n),
|
|
343
|
+
* max_events: variant("none", null),
|
|
344
|
+
* end_date: variant("some", new Date("2025-12-31")),
|
|
345
|
+
* }, SimulationTrajectoriesConfigType);
|
|
346
|
+
*
|
|
347
|
+
* const result = $.let(Simulation.runTrajectories(
|
|
348
|
+
* [Resources, Events],
|
|
349
|
+
* initialState, initialEvents, process, config,
|
|
350
|
+
* ));
|
|
351
|
+
* // result.trajectories.length() => 100n
|
|
352
|
+
* // result.trajectories.get(0n).final_state.cash
|
|
353
|
+
* return $.return(result);
|
|
354
|
+
* });
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
readonly runTrajectories: import("@elaraai/east").GenericPlatformDefinition<readonly ["R", "E"], readonly ["R", ArrayType<StructType<{
|
|
358
|
+
readonly date: DateTimeType;
|
|
359
|
+
readonly event: "E";
|
|
360
|
+
}>>, FunctionType<["R", DateTimeType, "E"], StructType<{
|
|
361
|
+
readonly state: "R";
|
|
362
|
+
readonly events: ArrayType<StructType<{
|
|
363
|
+
readonly date: DateTimeType;
|
|
364
|
+
readonly event: "E";
|
|
365
|
+
}>>;
|
|
366
|
+
}>>, StructType<{
|
|
367
|
+
/** Number of trajectories to run (required) */
|
|
368
|
+
readonly trajectories: IntegerType;
|
|
369
|
+
/** Base RNG seed — trajectory i uses seed + i */
|
|
370
|
+
readonly seed: OptionType<IntegerType>;
|
|
371
|
+
/** Safety limit on events per trajectory (default: 100000) */
|
|
372
|
+
readonly max_events: OptionType<IntegerType>;
|
|
373
|
+
/** Stop processing events after this date */
|
|
374
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
375
|
+
}>], StructType<{
|
|
376
|
+
/** Array of per-trajectory results */
|
|
377
|
+
readonly trajectories: ArrayType<StructType<{
|
|
378
|
+
/** Final resource state */
|
|
379
|
+
readonly final_state: "R";
|
|
380
|
+
/** Number of events processed */
|
|
381
|
+
readonly events_processed: IntegerType;
|
|
382
|
+
/** Date of last event processed */
|
|
383
|
+
readonly final_date: DateTimeType;
|
|
384
|
+
}>>;
|
|
385
|
+
}>>;
|
|
386
|
+
/**
|
|
387
|
+
* Type definitions for simulation functions.
|
|
388
|
+
*/
|
|
389
|
+
readonly Types: {
|
|
390
|
+
/** Single run configuration */
|
|
391
|
+
readonly ConfigType: StructType<{
|
|
392
|
+
/** Safety limit on number of events processed (default: 100000) */
|
|
393
|
+
readonly max_events: OptionType<IntegerType>;
|
|
394
|
+
/** Stop processing events after this date */
|
|
395
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
396
|
+
}>;
|
|
397
|
+
/** Single run result */
|
|
398
|
+
readonly ResultType: StructType<{
|
|
399
|
+
/** Final resource state after all events processed */
|
|
400
|
+
readonly final_state: "R";
|
|
401
|
+
/** Number of events processed */
|
|
402
|
+
readonly events_processed: IntegerType;
|
|
403
|
+
/** Date of the last event processed */
|
|
404
|
+
readonly final_date: DateTimeType;
|
|
405
|
+
}>;
|
|
406
|
+
/** Monte Carlo configuration */
|
|
407
|
+
readonly TrajectoriesConfigType: StructType<{
|
|
408
|
+
/** Number of trajectories to run (required) */
|
|
409
|
+
readonly trajectories: IntegerType;
|
|
410
|
+
/** Base RNG seed — trajectory i uses seed + i */
|
|
411
|
+
readonly seed: OptionType<IntegerType>;
|
|
412
|
+
/** Safety limit on events per trajectory (default: 100000) */
|
|
413
|
+
readonly max_events: OptionType<IntegerType>;
|
|
414
|
+
/** Stop processing events after this date */
|
|
415
|
+
readonly end_date: OptionType<DateTimeType>;
|
|
416
|
+
}>;
|
|
417
|
+
/** Monte Carlo result */
|
|
418
|
+
readonly TrajectoriesResultType: StructType<{
|
|
419
|
+
/** Array of per-trajectory results */
|
|
420
|
+
readonly trajectories: ArrayType<StructType<{
|
|
421
|
+
/** Final resource state */
|
|
422
|
+
readonly final_state: "R";
|
|
423
|
+
/** Number of events processed */
|
|
424
|
+
readonly events_processed: IntegerType;
|
|
425
|
+
/** Date of last event processed */
|
|
426
|
+
readonly final_date: DateTimeType;
|
|
427
|
+
}>>;
|
|
428
|
+
}>;
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
//# sourceMappingURL=simulation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulation.d.ts","sourceRoot":"","sources":["../../../src/simulation/simulation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAEH,UAAU,EACV,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,YAAY,EACf,MAAM,eAAe,CAAC;AAmCvB;;GAEG;AACH,eAAO,MAAM,oBAAoB;IAC7B,mEAAmE;;IAEnE,6CAA6C;;EAE/C,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,oBAAoB;IAC7B,sDAAsD;;IAEtD,iCAAiC;;IAEjC,uCA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