@elaraai/east-py-datascience 0.0.2-beta.1

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 (56) hide show
  1. package/LICENSE.md +18 -0
  2. package/README.md +104 -0
  3. package/dist/gp/gp.d.ts +398 -0
  4. package/dist/gp/gp.d.ts.map +1 -0
  5. package/dist/gp/gp.js +170 -0
  6. package/dist/gp/gp.js.map +1 -0
  7. package/dist/index.d.ts +27 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +39 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/lightgbm/lightgbm.d.ts +494 -0
  12. package/dist/lightgbm/lightgbm.d.ts.map +1 -0
  13. package/dist/lightgbm/lightgbm.js +155 -0
  14. package/dist/lightgbm/lightgbm.js.map +1 -0
  15. package/dist/mads/mads.d.ts +413 -0
  16. package/dist/mads/mads.d.ts.map +1 -0
  17. package/dist/mads/mads.js +221 -0
  18. package/dist/mads/mads.js.map +1 -0
  19. package/dist/ngboost/ngboost.d.ts +433 -0
  20. package/dist/ngboost/ngboost.d.ts.map +1 -0
  21. package/dist/ngboost/ngboost.js +178 -0
  22. package/dist/ngboost/ngboost.js.map +1 -0
  23. package/dist/optuna/optuna.d.ts +797 -0
  24. package/dist/optuna/optuna.d.ts.map +1 -0
  25. package/dist/optuna/optuna.js +268 -0
  26. package/dist/optuna/optuna.js.map +1 -0
  27. package/dist/scipy/scipy.d.ts +954 -0
  28. package/dist/scipy/scipy.d.ts.map +1 -0
  29. package/dist/scipy/scipy.js +287 -0
  30. package/dist/scipy/scipy.js.map +1 -0
  31. package/dist/shap/shap.d.ts +657 -0
  32. package/dist/shap/shap.d.ts.map +1 -0
  33. package/dist/shap/shap.js +241 -0
  34. package/dist/shap/shap.js.map +1 -0
  35. package/dist/simanneal/simanneal.d.ts +531 -0
  36. package/dist/simanneal/simanneal.d.ts.map +1 -0
  37. package/dist/simanneal/simanneal.js +231 -0
  38. package/dist/simanneal/simanneal.js.map +1 -0
  39. package/dist/sklearn/sklearn.d.ts +1272 -0
  40. package/dist/sklearn/sklearn.d.ts.map +1 -0
  41. package/dist/sklearn/sklearn.js +307 -0
  42. package/dist/sklearn/sklearn.js.map +1 -0
  43. package/dist/torch/torch.d.ts +658 -0
  44. package/dist/torch/torch.d.ts.map +1 -0
  45. package/dist/torch/torch.js +233 -0
  46. package/dist/torch/torch.js.map +1 -0
  47. package/dist/tsconfig.tsbuildinfo +1 -0
  48. package/dist/types.d.ts +80 -0
  49. package/dist/types.d.ts.map +1 -0
  50. package/dist/types.js +81 -0
  51. package/dist/types.js.map +1 -0
  52. package/dist/xgboost/xgboost.d.ts +504 -0
  53. package/dist/xgboost/xgboost.d.ts.map +1 -0
  54. package/dist/xgboost/xgboost.js +177 -0
  55. package/dist/xgboost/xgboost.js.map +1 -0
  56. package/package.json +82 -0
@@ -0,0 +1,231 @@
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, ArrayType, IntegerType, FloatType, BooleanType, FunctionType, } 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: ArrayType(IntegerType),
31
+ /** Boolean array state (subset selection) */
32
+ bool_array: ArrayType(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([ArrayType(IntegerType)], FloatType);
57
+ /**
58
+ * Subset energy function type.
59
+ *
60
+ * Specialized for subset selection optimization.
61
+ */
62
+ export const SubsetEnergyType = FunctionType([ArrayType(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
+ ArrayType(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
+ ArrayType(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
+ * [ArrayType(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
+ optimize: simanneal_optimize,
218
+ /**
219
+ * Run simulated annealing on a permutation with swap moves.
220
+ */
221
+ optimizePermutation: simanneal_optimize_permutation,
222
+ /**
223
+ * Run simulated annealing on a subset selection with bit-flip moves.
224
+ */
225
+ optimizeSubset: simanneal_optimize_subset,
226
+ /**
227
+ * Type definitions for SimAnneal functions.
228
+ */
229
+ Types: SimAnnealTypes,
230
+ };
231
+ //# sourceMappingURL=simanneal.js.map
@@ -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,EACV,SAAS,EACT,WAAW,EACX,SAAS,EACT,WAAW,EACX,YAAY,GACf,MAAM,eAAe,CAAC;AAEvB,8CAA8C;AAC9C,cAAc;AACd,8CAA8C;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAC;IACzC,sDAAsD;IACtD,SAAS,EAAE,SAAS,CAAC,WAAW,CAAC;IACjC,6CAA6C;IAC7C,UAAU,EAAE,SAAS,CAAC,WAAW,CAAC;CACrC,CAAC,CAAC;AAEH,8CAA8C;AAC9C,iBAAiB;AACjB,8CAA8C;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,YAAY,CAC1C,CAAC,iBAAiB,CAAC,EACnB,SAAS,CACZ,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CACxC,CAAC,iBAAiB,CAAC,EACnB,iBAAiB,CACpB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAC7C,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,EACxB,SAAS,CACZ,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CACxC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,EACxB,SAAS,CACZ,CAAC;AAEF,8CAA8C;AAC9C,sBAAsB;AACtB,8CAA8C;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;IACvC,8CAA8C;IAC9C,KAAK,EAAE,U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