@elaraai/east-py-datascience 1.0.1 → 1.0.3

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.
Files changed (81) hide show
  1. package/dist/src/alns/alns.d.ts +528 -0
  2. package/dist/src/alns/alns.d.ts.map +1 -0
  3. package/dist/src/alns/alns.js +238 -0
  4. package/dist/src/alns/alns.js.map +1 -0
  5. package/dist/src/google_or/google_or.d.ts +2457 -0
  6. package/dist/src/google_or/google_or.d.ts.map +1 -0
  7. package/dist/src/google_or/google_or.js +547 -0
  8. package/dist/src/google_or/google_or.js.map +1 -0
  9. package/dist/src/gp/gp.d.ts +447 -0
  10. package/dist/src/gp/gp.d.ts.map +1 -0
  11. package/dist/src/gp/gp.js +222 -0
  12. package/dist/src/gp/gp.js.map +1 -0
  13. package/dist/src/index.d.ts +34 -0
  14. package/dist/src/index.d.ts.map +1 -0
  15. package/dist/src/index.js +57 -0
  16. package/dist/src/index.js.map +1 -0
  17. package/dist/src/lightgbm/lightgbm.d.ts +575 -0
  18. package/dist/src/lightgbm/lightgbm.d.ts.map +1 -0
  19. package/dist/src/lightgbm/lightgbm.js +241 -0
  20. package/dist/src/lightgbm/lightgbm.js.map +1 -0
  21. package/dist/src/lightning/lightning.d.ts +1594 -0
  22. package/dist/src/lightning/lightning.d.ts.map +1 -0
  23. package/dist/src/lightning/lightning.js +468 -0
  24. package/dist/src/lightning/lightning.js.map +1 -0
  25. package/dist/src/mads/mads.d.ts +410 -0
  26. package/dist/src/mads/mads.d.ts.map +1 -0
  27. package/dist/src/mads/mads.js +219 -0
  28. package/dist/src/mads/mads.js.map +1 -0
  29. package/dist/src/mapie/mapie.d.ts +3680 -0
  30. package/dist/src/mapie/mapie.d.ts.map +1 -0
  31. package/dist/src/mapie/mapie.js +616 -0
  32. package/dist/src/mapie/mapie.js.map +1 -0
  33. package/dist/src/ngboost/ngboost.d.ts +483 -0
  34. package/dist/src/ngboost/ngboost.d.ts.map +1 -0
  35. package/dist/src/ngboost/ngboost.js +231 -0
  36. package/dist/src/ngboost/ngboost.js.map +1 -0
  37. package/dist/src/optimization/optimization.d.ts +700 -0
  38. package/dist/src/optimization/optimization.d.ts.map +1 -0
  39. package/dist/src/optimization/optimization.js +411 -0
  40. package/dist/src/optimization/optimization.js.map +1 -0
  41. package/dist/src/optuna/optuna.d.ts +857 -0
  42. package/dist/src/optuna/optuna.d.ts.map +1 -0
  43. package/dist/src/optuna/optuna.js +270 -0
  44. package/dist/src/optuna/optuna.js.map +1 -0
  45. package/dist/src/pymc/pymc.d.ts +2932 -0
  46. package/dist/src/pymc/pymc.d.ts.map +1 -0
  47. package/dist/src/pymc/pymc.js +688 -0
  48. package/dist/src/pymc/pymc.js.map +1 -0
  49. package/dist/src/scipy/scipy.d.ts +2205 -0
  50. package/dist/src/scipy/scipy.d.ts.map +1 -0
  51. package/dist/src/scipy/scipy.js +884 -0
  52. package/dist/src/scipy/scipy.js.map +1 -0
  53. package/dist/src/shap/shap.d.ts +4611 -0
  54. package/dist/src/shap/shap.d.ts.map +1 -0
  55. package/dist/src/shap/shap.js +552 -0
  56. package/dist/src/shap/shap.js.map +1 -0
  57. package/dist/src/simanneal/simanneal.d.ts +628 -0
  58. package/dist/src/simanneal/simanneal.d.ts.map +1 -0
  59. package/dist/src/simanneal/simanneal.js +328 -0
  60. package/dist/src/simanneal/simanneal.js.map +1 -0
  61. package/dist/src/simulation/simulation.d.ts +224 -0
  62. package/dist/src/simulation/simulation.d.ts.map +1 -0
  63. package/dist/src/simulation/simulation.js +189 -0
  64. package/dist/src/simulation/simulation.js.map +1 -0
  65. package/dist/src/sklearn/sklearn.d.ts +6362 -0
  66. package/dist/src/sklearn/sklearn.d.ts.map +1 -0
  67. package/dist/src/sklearn/sklearn.js +1508 -0
  68. package/dist/src/sklearn/sklearn.js.map +1 -0
  69. package/dist/src/torch/torch.d.ts +1205 -0
  70. package/dist/src/torch/torch.d.ts.map +1 -0
  71. package/dist/src/torch/torch.js +440 -0
  72. package/dist/src/torch/torch.js.map +1 -0
  73. package/dist/src/types.d.ts +43 -0
  74. package/dist/src/types.d.ts.map +1 -0
  75. package/dist/src/types.js +44 -0
  76. package/dist/src/types.js.map +1 -0
  77. package/dist/src/xgboost/xgboost.d.ts +1424 -0
  78. package/dist/src/xgboost/xgboost.d.ts.map +1 -0
  79. package/dist/src/xgboost/xgboost.js +432 -0
  80. package/dist/src/xgboost/xgboost.js.map +1 -0
  81. package/package.json +3 -3
@@ -0,0 +1,328 @@
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 optimization using Simulated Annealing.
7
+ *
8
+ * Provides combinatorial optimization for discrete state spaces using the
9
+ * simanneal library. Ideal for:
10
+ * - Permutation problems (TSP, scheduling)
11
+ * - Subset selection (feature selection, knapsack)
12
+ * - Assignment problems
13
+ * - Any discrete optimization where gradient methods don't apply
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import { East, StructType, VariantType, OptionType, IntegerType, FloatType, BooleanType, FunctionType, VectorType, } from "@elaraai/east";
18
+ // ===========================================
19
+ // State Types
20
+ // ===========================================
21
+ /**
22
+ * Discrete state type for simulated annealing.
23
+ *
24
+ * Supports different representations for combinatorial problems:
25
+ * - int_array: Permutations, assignments, sequences of integers
26
+ * - bool_array: Subset selections, binary decisions
27
+ */
28
+ export const DiscreteStateType = VariantType({
29
+ /** Integer array state (permutations, assignments) */
30
+ int_array: VectorType(IntegerType),
31
+ /** Boolean array state (subset selection) */
32
+ bool_array: VectorType(BooleanType),
33
+ });
34
+ // ===========================================
35
+ // Function Types
36
+ // ===========================================
37
+ /**
38
+ * Energy function type: state -> score.
39
+ *
40
+ * Computes the objective value (energy) for a given state.
41
+ * Lower energy is better (minimization).
42
+ */
43
+ export const EnergyFunctionType = FunctionType([DiscreteStateType], FloatType);
44
+ /**
45
+ * Move function type: state -> neighbor state.
46
+ *
47
+ * Generates a random neighbor of the current state.
48
+ * Should make small, local changes (e.g., swap two elements).
49
+ */
50
+ export const MoveFunctionType = FunctionType([DiscreteStateType], DiscreteStateType);
51
+ /**
52
+ * Permutation energy function type.
53
+ *
54
+ * Specialized for permutation-based optimization.
55
+ */
56
+ export const PermutationEnergyType = FunctionType([VectorType(IntegerType)], FloatType);
57
+ /**
58
+ * Subset energy function type.
59
+ *
60
+ * Specialized for subset selection optimization.
61
+ */
62
+ export const SubsetEnergyType = FunctionType([VectorType(BooleanType)], FloatType);
63
+ // ===========================================
64
+ // Configuration Types
65
+ // ===========================================
66
+ /**
67
+ * Simulated annealing configuration.
68
+ */
69
+ export const AnnealConfigType = StructType({
70
+ /** Starting temperature (default: 25000.0) */
71
+ t_max: OptionType(FloatType),
72
+ /** Ending temperature (default: 2.5) */
73
+ t_min: OptionType(FloatType),
74
+ /** Total iterations (default: 50000) */
75
+ steps: OptionType(IntegerType),
76
+ /** Progress report frequency (default: 0 = silent) */
77
+ updates: OptionType(IntegerType),
78
+ /** Minutes for auto-calibration (default: none) */
79
+ auto_schedule: OptionType(FloatType),
80
+ /** Random seed for reproducibility */
81
+ random_state: OptionType(IntegerType),
82
+ });
83
+ // ===========================================
84
+ // Result Types
85
+ // ===========================================
86
+ /**
87
+ * Simulated annealing result.
88
+ */
89
+ export const AnnealResultType = StructType({
90
+ /** Best state found */
91
+ best_state: DiscreteStateType,
92
+ /** Energy of best state */
93
+ best_energy: FloatType,
94
+ /** Actual iterations performed */
95
+ steps_taken: IntegerType,
96
+ /** Whether optimization completed successfully */
97
+ success: BooleanType,
98
+ });
99
+ // ===========================================
100
+ // Platform Functions
101
+ // ===========================================
102
+ /**
103
+ * Run simulated annealing on a discrete state space.
104
+ *
105
+ * Uses custom energy and move functions for flexible optimization.
106
+ *
107
+ * @param initial_state - Starting state
108
+ * @param energy_fn - Function to compute state energy (lower is better)
109
+ * @param move_fn - Function to generate neighbor states
110
+ * @param config - Annealing schedule configuration
111
+ * @returns Result with best state and energy
112
+ */
113
+ export const simanneal_optimize = East.platform("simanneal_optimize", [
114
+ DiscreteStateType,
115
+ EnergyFunctionType,
116
+ MoveFunctionType,
117
+ AnnealConfigType,
118
+ ], AnnealResultType);
119
+ /**
120
+ * Run simulated annealing on a permutation with swap moves.
121
+ *
122
+ * Convenience function for permutation-based problems (TSP, scheduling).
123
+ * Automatically uses swap moves to generate neighbors.
124
+ *
125
+ * @param initial_perm - Starting permutation
126
+ * @param energy_fn - Function to compute permutation energy
127
+ * @param config - Annealing schedule configuration
128
+ * @returns Result with best permutation and energy
129
+ */
130
+ export const simanneal_optimize_permutation = East.platform("simanneal_optimize_permutation", [
131
+ VectorType(IntegerType),
132
+ PermutationEnergyType,
133
+ AnnealConfigType,
134
+ ], AnnealResultType);
135
+ /**
136
+ * Run simulated annealing on a subset selection with bit-flip moves.
137
+ *
138
+ * Convenience function for subset selection problems (feature selection, knapsack).
139
+ * Automatically uses bit-flip moves to generate neighbors.
140
+ *
141
+ * @param initial_selection - Starting selection (boolean array)
142
+ * @param energy_fn - Function to compute selection energy
143
+ * @param config - Annealing schedule configuration
144
+ * @returns Result with best selection and energy
145
+ */
146
+ export const simanneal_optimize_subset = East.platform("simanneal_optimize_subset", [
147
+ VectorType(BooleanType),
148
+ SubsetEnergyType,
149
+ AnnealConfigType,
150
+ ], AnnealResultType);
151
+ // ===========================================
152
+ // Grouped Export
153
+ // ===========================================
154
+ /**
155
+ * Type definitions for Simulated Annealing.
156
+ */
157
+ export const SimAnnealTypes = {
158
+ /** Discrete state type */
159
+ DiscreteStateType,
160
+ /** Energy function type */
161
+ EnergyFunctionType,
162
+ /** Move function type */
163
+ MoveFunctionType,
164
+ /** Permutation energy function type */
165
+ PermutationEnergyType,
166
+ /** Subset energy function type */
167
+ SubsetEnergyType,
168
+ /** Configuration type */
169
+ ConfigType: AnnealConfigType,
170
+ /** Result type */
171
+ ResultType: AnnealResultType,
172
+ };
173
+ /**
174
+ * Discrete optimization using Simulated Annealing.
175
+ *
176
+ * Provides combinatorial optimization for discrete state spaces.
177
+ * Simulated annealing is a probabilistic technique that can escape
178
+ * local minima by occasionally accepting worse solutions.
179
+ *
180
+ * Ideal for:
181
+ * - Permutation problems (TSP, job scheduling)
182
+ * - Subset selection (feature selection, knapsack)
183
+ * - Assignment problems
184
+ * - Any discrete optimization with many local minima
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * import { East, FloatType, variant } from "@elaraai/east";
189
+ * import { SimAnneal } from "@elaraai/east-py-datascience";
190
+ *
191
+ * // TSP: minimize total route distance
192
+ * const energy = East.function(
193
+ * [VectorType(IntegerType)],
194
+ * FloatType,
195
+ * ($, route) => {
196
+ * // Calculate total route distance
197
+ * return $.return(totalDistance);
198
+ * }
199
+ * );
200
+ *
201
+ * const config = $.let({
202
+ * t_max: variant("some", 10000.0),
203
+ * t_min: variant("some", 1.0),
204
+ * steps: variant("some", 50000n),
205
+ * updates: variant("none", null),
206
+ * auto_schedule: variant("none", null),
207
+ * random_state: variant("some", 42n),
208
+ * });
209
+ *
210
+ * const result = SimAnneal.optimizePermutation(initial, energy, config);
211
+ * ```
212
+ */
213
+ export const SimAnneal = {
214
+ /**
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
+ * ```
254
+ */
255
+ optimize: simanneal_optimize,
256
+ /**
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
+ * ```
289
+ */
290
+ optimizePermutation: simanneal_optimize_permutation,
291
+ /**
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
+ * ```
321
+ */
322
+ optimizeSubset: simanneal_optimize_subset,
323
+ /**
324
+ * Type definitions for SimAnneal functions.
325
+ */
326
+ Types: SimAnnealTypes,
327
+ };
328
+ //# sourceMappingURL=simanneal.js.map
@@ -0,0 +1 @@
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AAc,GAAG;IAC1B,0BAA0B;IAC1B,iBAAiB;IACjB,2BAA2B;IAC3B,kBAAkB;IAClB,yBAAyB;IACzB,gBAAgB;IAChB,uCAAuC;IACvC,qBAAqB;IACrB,kCAAkC;IAClC,gBAAgB;IAChB,yBAAyB;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,224 @@
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
+ * Entry point:
14
+ * - `simulation_run`: single deterministic run
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+ import { StructType, OptionType, ArrayType, IntegerType, DateTimeType, FunctionType } from "@elaraai/east";
19
+ /**
20
+ * Configuration for a single simulation run.
21
+ */
22
+ export declare const SimulationConfigType: StructType<{
23
+ /** Safety limit on number of events processed (default: 100000) */
24
+ readonly max_events: OptionType<IntegerType>;
25
+ /** Stop processing events after this date */
26
+ readonly end_date: OptionType<DateTimeType>;
27
+ }>;
28
+ /**
29
+ * Result of a single simulation run.
30
+ */
31
+ export declare const SimulationResultType: StructType<{
32
+ /** Final resource state after all events processed */
33
+ readonly final_state: "R";
34
+ /** Number of events processed */
35
+ readonly events_processed: IntegerType;
36
+ /** Date of the last event processed */
37
+ readonly final_date: DateTimeType;
38
+ }>;
39
+ /**
40
+ * Run a single deterministic discrete event simulation.
41
+ *
42
+ * Events are processed in chronological order from a priority queue.
43
+ * The handler function dispatches on event type (match) and can
44
+ * mutate state and schedule new events.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { East, StructType, VariantType, FloatType, DateTimeType, variant } from "@elaraai/east";
49
+ * import { Simulation } from "@elaraai/east-py-datascience";
50
+ *
51
+ * const Resources = StructType({ cash: FloatType });
52
+ * const Events = VariantType({ income: FloatType, expense: FloatType });
53
+ *
54
+ * const process = East.function(
55
+ * [Resources, DateTimeType, Events],
56
+ * StructType({ state: Resources, events: ArrayType(StructType({ date: DateTimeType, event: Events })) }),
57
+ * ($, state, date, event) => {
58
+ * return $.return(event.match({
59
+ * income: ($, amount) => $.return({ state: state.spread({ cash: state.cash.add(amount) }), events: [] }),
60
+ * expense: ($, amount) => $.return({ state: state.spread({ cash: state.cash.subtract(amount) }), events: [] }),
61
+ * }));
62
+ * }
63
+ * );
64
+ *
65
+ * const result = $.let(Simulation.run([Resources, Events], initialState, initialEvents, process, config));
66
+ * ```
67
+ */
68
+ export declare const simulation_run: import("@elaraai/east").GenericPlatformDefinition<readonly ["R", "E"], readonly ["R", ArrayType<StructType<{
69
+ readonly date: DateTimeType;
70
+ readonly event: "E";
71
+ }>>, FunctionType<["R", DateTimeType, "E"], StructType<{
72
+ readonly state: "R";
73
+ readonly events: ArrayType<StructType<{
74
+ readonly date: DateTimeType;
75
+ readonly event: "E";
76
+ }>>;
77
+ }>>, StructType<{
78
+ /** Safety limit on number of events processed (default: 100000) */
79
+ readonly max_events: OptionType<IntegerType>;
80
+ /** Stop processing events after this date */
81
+ readonly end_date: OptionType<DateTimeType>;
82
+ }>], StructType<{
83
+ /** Final resource state after all events processed */
84
+ readonly final_state: "R";
85
+ /** Number of events processed */
86
+ readonly events_processed: IntegerType;
87
+ /** Date of the last event processed */
88
+ readonly final_date: DateTimeType;
89
+ }>>;
90
+ /**
91
+ * Type definitions for simulation functions.
92
+ */
93
+ export declare const SimulationTypes: {
94
+ /** Single run configuration */
95
+ readonly ConfigType: StructType<{
96
+ /** Safety limit on number of events processed (default: 100000) */
97
+ readonly max_events: OptionType<IntegerType>;
98
+ /** Stop processing events after this date */
99
+ readonly end_date: OptionType<DateTimeType>;
100
+ }>;
101
+ /** Single run result */
102
+ readonly ResultType: StructType<{
103
+ /** Final resource state after all events processed */
104
+ readonly final_state: "R";
105
+ /** Number of events processed */
106
+ readonly events_processed: IntegerType;
107
+ /** Date of the last event processed */
108
+ readonly final_date: DateTimeType;
109
+ }>;
110
+ };
111
+ /**
112
+ * Discrete Event Simulation (DES) — REA Economic Ontology.
113
+ *
114
+ * Generic over:
115
+ * - R: Resources (state struct — the economic resource ontology)
116
+ * - E: Events (variant type — the economic event ontology)
117
+ *
118
+ * The handler function uses match dispatch to define economic processes.
119
+ * Each match branch IS a separate economic process. Process-from-process
120
+ * triggering works by returning new events.
121
+ */
122
+ export declare const Simulation: {
123
+ /**
124
+ * Run a single deterministic discrete event simulation.
125
+ *
126
+ * Events are processed chronologically from a priority queue.
127
+ * The handler function dispatches on event type via match and can
128
+ * mutate state and schedule new events (creating the directed
129
+ * cyclic economic graph).
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * import { East, StructType, VariantType, ArrayType, FloatType, DateTimeType, variant } from "@elaraai/east";
134
+ * import { Simulation, SimulationConfigType } from "@elaraai/east-py-datascience";
135
+ *
136
+ * const Resources = StructType({ cash: FloatType });
137
+ * const Events = VariantType({ income: FloatType, expense: FloatType });
138
+ * const ScheduledEvent = StructType({ date: DateTimeType, event: Events });
139
+ * const ProcessResult = StructType({ state: Resources, events: ArrayType(ScheduledEvent) });
140
+ *
141
+ * const simulate = East.function([], Simulation.Types.ResultType, ($) => {
142
+ * const process = East.function(
143
+ * [Resources, DateTimeType, Events],
144
+ * ProcessResult,
145
+ * ($, state, date, event) => {
146
+ * const empty = $.let([] as const, ArrayType(ScheduledEvent));
147
+ * return $.return(event.match({
148
+ * income: ($, amount) => ({
149
+ * state: { cash: state.cash.add(amount) },
150
+ * events: empty,
151
+ * }),
152
+ * expense: ($, amount) => ({
153
+ * state: { cash: state.cash.subtract(amount) },
154
+ * events: empty,
155
+ * }),
156
+ * }));
157
+ * }
158
+ * );
159
+ *
160
+ * const initialState = $.let({ cash: 1000.0 });
161
+ * const initialEvents = $.let([
162
+ * { date: $.let(new Date("2025-01-01")), event: $.let(variant("income", 500.0), Events) },
163
+ * { date: $.let(new Date("2025-01-15")), event: $.let(variant("expense", 200.0), Events) },
164
+ * ], ArrayType(ScheduledEvent));
165
+ * const config = $.let({
166
+ * max_events: variant("none", null),
167
+ * end_date: variant("none", null),
168
+ * }, SimulationConfigType);
169
+ *
170
+ * const result = $.let(Simulation.run(
171
+ * [Resources, Events],
172
+ * initialState, initialEvents, process, config,
173
+ * ));
174
+ * // result.final_state.cash => 1300.0
175
+ * // result.events_processed => 2n
176
+ * return $.return(result);
177
+ * });
178
+ * ```
179
+ */
180
+ readonly run: import("@elaraai/east").GenericPlatformDefinition<readonly ["R", "E"], readonly ["R", ArrayType<StructType<{
181
+ readonly date: DateTimeType;
182
+ readonly event: "E";
183
+ }>>, FunctionType<["R", DateTimeType, "E"], StructType<{
184
+ readonly state: "R";
185
+ readonly events: ArrayType<StructType<{
186
+ readonly date: DateTimeType;
187
+ readonly event: "E";
188
+ }>>;
189
+ }>>, StructType<{
190
+ /** Safety limit on number of events processed (default: 100000) */
191
+ readonly max_events: OptionType<IntegerType>;
192
+ /** Stop processing events after this date */
193
+ readonly end_date: OptionType<DateTimeType>;
194
+ }>], StructType<{
195
+ /** Final resource state after all events processed */
196
+ readonly final_state: "R";
197
+ /** Number of events processed */
198
+ readonly events_processed: IntegerType;
199
+ /** Date of the last event processed */
200
+ readonly final_date: DateTimeType;
201
+ }>>;
202
+ /**
203
+ * Type definitions for simulation functions.
204
+ */
205
+ readonly Types: {
206
+ /** Single run configuration */
207
+ readonly ConfigType: StructType<{
208
+ /** Safety limit on number of events processed (default: 100000) */
209
+ readonly max_events: OptionType<IntegerType>;
210
+ /** Stop processing events after this date */
211
+ readonly end_date: OptionType<DateTimeType>;
212
+ }>;
213
+ /** Single run result */
214
+ readonly ResultType: StructType<{
215
+ /** Final resource state after all events processed */
216
+ readonly final_state: "R";
217
+ /** Number of events processed */
218
+ readonly events_processed: IntegerType;
219
+ /** Date of the last event processed */
220
+ readonly final_date: DateTimeType;
221
+ }>;
222
+ };
223
+ };
224
+ //# 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;;;;;;;;;;;;GAYG;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,uCAAuC;;EAEzC,CAAC;AAMH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;IAnDvB,mEAAmE;;IAEnE,6CAA6C;;;IAQ7C,sDAAsD;;IAEtD,iCAAiC;;IAEjC,uCAAuC;;GA+C1C,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,eAAe;IACxB,+BAA+B;;QAvE/B,mEAAmE;;QAEnE,6CAA6C;;;IAuE7C,wBAAwB;;QA/DxB,sDAAsD;;QAEtD,iCAAiC;;QAEjC,uCAAuC;;;CA6DjC,CAAC;AAEX;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU;IACnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwDG;;;;;;;;;;;QAjJH,mEAAmE;;QAEnE,6CAA6C;;;QAQ7C,sDAAsD;;QAEtD,iCAAiC;;QAEjC,uCAAuC;;;IAsIvC;;OAEG;;QA/EH,+BAA+B;;YAvE/B,mEAAmE;;YAEnE,6CAA6C;;;QAuE7C,wBAAwB;;YA/DxB,sDAAsD;;YAEtD,iCAAiC;;YAEjC,uCAAuC;;;;CA0IjC,CAAC"}