@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,688 @@
|
|
|
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
|
+
* PyMC Bayesian inference platform functions for East.
|
|
7
|
+
*
|
|
8
|
+
* Provides Bayesian linear regression, hierarchical models, and multi-layer
|
|
9
|
+
* joint estimation with full posterior analysis using PyMC.
|
|
10
|
+
* Uses cloudpickle for model serialization.
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
*/
|
|
14
|
+
import { East, StructType, VariantType, OptionType, ArrayType, IntegerType, FloatType, BooleanType, BlobType, StringType, NullType, } from "@elaraai/east";
|
|
15
|
+
import { VectorType, MatrixType } from "../types.js";
|
|
16
|
+
// Re-export shared types for convenience
|
|
17
|
+
export { VectorType, MatrixType } from "../types.js";
|
|
18
|
+
// ============================================================================
|
|
19
|
+
// Enum Types
|
|
20
|
+
// ============================================================================
|
|
21
|
+
/**
|
|
22
|
+
* Prior distribution type for PyMC parameters.
|
|
23
|
+
*/
|
|
24
|
+
export const PyMCPriorDistributionType = VariantType({
|
|
25
|
+
/** Half-normal distribution (positive only) */
|
|
26
|
+
halfnormal: NullType,
|
|
27
|
+
/** Log-normal distribution */
|
|
28
|
+
lognormal: NullType,
|
|
29
|
+
/** Normal (Gaussian) distribution */
|
|
30
|
+
normal: NullType,
|
|
31
|
+
/** Half-Cauchy distribution (heavy tails, positive only) */
|
|
32
|
+
halfcauchy: NullType,
|
|
33
|
+
/** Exponential distribution */
|
|
34
|
+
exponential: NullType,
|
|
35
|
+
/** Uniform distribution */
|
|
36
|
+
uniform: NullType,
|
|
37
|
+
/** Horseshoe prior (sparsity-inducing) */
|
|
38
|
+
horseshoe: NullType,
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Likelihood function type.
|
|
42
|
+
*/
|
|
43
|
+
export const PyMCLikelihoodType = VariantType({
|
|
44
|
+
/** Normal (Gaussian) likelihood */
|
|
45
|
+
normal: NullType,
|
|
46
|
+
/** Student-t likelihood (robust to outliers) */
|
|
47
|
+
studentt: NullType,
|
|
48
|
+
/** Poisson likelihood (count data) */
|
|
49
|
+
poisson: NullType,
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Pooling type for hierarchical models.
|
|
53
|
+
*/
|
|
54
|
+
export const PyMCPoolingType = VariantType({
|
|
55
|
+
/** No pooling (independent per group) */
|
|
56
|
+
none: NullType,
|
|
57
|
+
/** Partial pooling (shared hyperpriors) */
|
|
58
|
+
partial: NullType,
|
|
59
|
+
/** Full pooling (all groups share same parameters) */
|
|
60
|
+
full: NullType,
|
|
61
|
+
});
|
|
62
|
+
// ============================================================================
|
|
63
|
+
// Config Types
|
|
64
|
+
// ============================================================================
|
|
65
|
+
/**
|
|
66
|
+
* Prior distribution parameters.
|
|
67
|
+
*/
|
|
68
|
+
export const PyMCPriorParamsType = StructType({
|
|
69
|
+
/** Mean (for normal/lognormal) */
|
|
70
|
+
mu: OptionType(MatrixType(FloatType)),
|
|
71
|
+
/** Standard deviation */
|
|
72
|
+
sigma: OptionType(MatrixType(FloatType)),
|
|
73
|
+
/** Precision (for exponential rate) */
|
|
74
|
+
tau: OptionType(FloatType),
|
|
75
|
+
/** Lower bound (for uniform) */
|
|
76
|
+
lower: OptionType(FloatType),
|
|
77
|
+
/** Upper bound (for uniform) */
|
|
78
|
+
upper: OptionType(FloatType),
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Prior specification combining distribution and parameters.
|
|
82
|
+
*/
|
|
83
|
+
export const PyMCPriorSpecType = StructType({
|
|
84
|
+
/** Distribution type */
|
|
85
|
+
distribution: PyMCPriorDistributionType,
|
|
86
|
+
/** Distribution parameters */
|
|
87
|
+
params: PyMCPriorParamsType,
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* Configuration for Bayesian linear regression.
|
|
91
|
+
*/
|
|
92
|
+
export const PyMCRegressionConfigType = StructType({
|
|
93
|
+
/** Prior specification for coefficients */
|
|
94
|
+
prior: OptionType(PyMCPriorSpecType),
|
|
95
|
+
/** Likelihood function */
|
|
96
|
+
likelihood: OptionType(PyMCLikelihoodType),
|
|
97
|
+
/** Whether to include intercept term (default true) */
|
|
98
|
+
include_intercept: OptionType(BooleanType),
|
|
99
|
+
/** Number of posterior samples (default 1000) */
|
|
100
|
+
samples: OptionType(IntegerType),
|
|
101
|
+
/** Number of tuning steps (default 1000) */
|
|
102
|
+
tune: OptionType(IntegerType),
|
|
103
|
+
/** Number of MCMC chains (default 2) */
|
|
104
|
+
chains: OptionType(IntegerType),
|
|
105
|
+
/** Target acceptance rate (default 0.8) */
|
|
106
|
+
target_accept: OptionType(FloatType),
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Configuration for hierarchical models.
|
|
110
|
+
*/
|
|
111
|
+
export const PyMCHierarchicalConfigType = StructType({
|
|
112
|
+
/** Prior specification for coefficients */
|
|
113
|
+
prior: OptionType(PyMCPriorSpecType),
|
|
114
|
+
/** Likelihood function */
|
|
115
|
+
likelihood: OptionType(PyMCLikelihoodType),
|
|
116
|
+
/** Pooling type (default partial) */
|
|
117
|
+
pooling: OptionType(PyMCPoolingType),
|
|
118
|
+
/** Number of posterior samples (default 1000) */
|
|
119
|
+
samples: OptionType(IntegerType),
|
|
120
|
+
/** Number of tuning steps (default 1000) */
|
|
121
|
+
tune: OptionType(IntegerType),
|
|
122
|
+
/** Number of MCMC chains (default 2) */
|
|
123
|
+
chains: OptionType(IntegerType),
|
|
124
|
+
/** Target acceptance rate (default 0.8) */
|
|
125
|
+
target_accept: OptionType(FloatType),
|
|
126
|
+
});
|
|
127
|
+
/**
|
|
128
|
+
* Layer specification for multi-layer models.
|
|
129
|
+
*/
|
|
130
|
+
export const PyMCLayerSpecType = StructType({
|
|
131
|
+
/** Layer name */
|
|
132
|
+
name: StringType,
|
|
133
|
+
/** Input data name */
|
|
134
|
+
input: StringType,
|
|
135
|
+
/** Output data name */
|
|
136
|
+
output: StringType,
|
|
137
|
+
/** Parameter name for coefficients */
|
|
138
|
+
parameter: StringType,
|
|
139
|
+
/** Likelihood function */
|
|
140
|
+
likelihood: OptionType(PyMCLikelihoodType),
|
|
141
|
+
});
|
|
142
|
+
/**
|
|
143
|
+
* Named prior specification.
|
|
144
|
+
*/
|
|
145
|
+
export const PyMCNamedPriorType = StructType({
|
|
146
|
+
/** Parameter name this prior applies to */
|
|
147
|
+
name: StringType,
|
|
148
|
+
/** Prior specification */
|
|
149
|
+
prior: PyMCPriorSpecType,
|
|
150
|
+
});
|
|
151
|
+
/**
|
|
152
|
+
* Named boolean mask.
|
|
153
|
+
*/
|
|
154
|
+
export const PyMCNamedMaskType = StructType({
|
|
155
|
+
/** Parameter name this mask applies to */
|
|
156
|
+
name: StringType,
|
|
157
|
+
/** Boolean mask matrix (true = estimate, false = fix to zero) */
|
|
158
|
+
mask: MatrixType(BooleanType),
|
|
159
|
+
});
|
|
160
|
+
/**
|
|
161
|
+
* Configuration for multi-layer joint estimation.
|
|
162
|
+
*/
|
|
163
|
+
export const PyMCMultiLayerConfigType = StructType({
|
|
164
|
+
/** Layer specifications */
|
|
165
|
+
layers: ArrayType(PyMCLayerSpecType),
|
|
166
|
+
/** Named priors for parameters */
|
|
167
|
+
priors: OptionType(ArrayType(PyMCNamedPriorType)),
|
|
168
|
+
/** Named masks for parameter sparsity */
|
|
169
|
+
masks: OptionType(ArrayType(PyMCNamedMaskType)),
|
|
170
|
+
/** Number of posterior samples (default 1000) */
|
|
171
|
+
samples: OptionType(IntegerType),
|
|
172
|
+
/** Number of tuning steps (default 1000) */
|
|
173
|
+
tune: OptionType(IntegerType),
|
|
174
|
+
/** Number of MCMC chains (default 2) */
|
|
175
|
+
chains: OptionType(IntegerType),
|
|
176
|
+
/** Target acceptance rate (default 0.8) */
|
|
177
|
+
target_accept: OptionType(FloatType),
|
|
178
|
+
/** Force full MCMC even for large models (default false) */
|
|
179
|
+
force_full_mcmc: OptionType(BooleanType),
|
|
180
|
+
/** L1 regularization alpha for fallback (default 0.01) */
|
|
181
|
+
fallback_l1_alpha: OptionType(FloatType),
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* Named data for multi-layer models.
|
|
185
|
+
*/
|
|
186
|
+
export const PyMCNamedDataType = StructType({
|
|
187
|
+
/** Data name */
|
|
188
|
+
name: StringType,
|
|
189
|
+
/** Data matrix */
|
|
190
|
+
data: MatrixType(FloatType),
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* Prediction configuration.
|
|
194
|
+
*/
|
|
195
|
+
export const PyMCPredictConfigType = StructType({
|
|
196
|
+
/** Layer name to predict from (for multi-layer models) */
|
|
197
|
+
layer: OptionType(StringType),
|
|
198
|
+
/** Number of posterior samples to use for prediction (default 100) */
|
|
199
|
+
n_samples: OptionType(IntegerType),
|
|
200
|
+
});
|
|
201
|
+
// ============================================================================
|
|
202
|
+
// Result Types
|
|
203
|
+
// ============================================================================
|
|
204
|
+
/**
|
|
205
|
+
* Individual parameter estimate with diagnostics.
|
|
206
|
+
*/
|
|
207
|
+
export const PyMCParameterEstimateType = StructType({
|
|
208
|
+
/** Row index in parameter matrix */
|
|
209
|
+
index_row: IntegerType,
|
|
210
|
+
/** Column index in parameter matrix */
|
|
211
|
+
index_col: IntegerType,
|
|
212
|
+
/** Posterior mean */
|
|
213
|
+
mean: FloatType,
|
|
214
|
+
/** Posterior median */
|
|
215
|
+
median: FloatType,
|
|
216
|
+
/** Posterior standard deviation */
|
|
217
|
+
sd: FloatType,
|
|
218
|
+
/** Lower 95% credible interval */
|
|
219
|
+
ci_lower: FloatType,
|
|
220
|
+
/** Upper 95% credible interval */
|
|
221
|
+
ci_upper: FloatType,
|
|
222
|
+
/** R-hat convergence diagnostic */
|
|
223
|
+
rhat: FloatType,
|
|
224
|
+
/** Effective sample size */
|
|
225
|
+
ess: FloatType,
|
|
226
|
+
});
|
|
227
|
+
/**
|
|
228
|
+
* Summary for one named parameter.
|
|
229
|
+
*/
|
|
230
|
+
export const PyMCParameterSummaryType = StructType({
|
|
231
|
+
/** Parameter name */
|
|
232
|
+
parameter: StringType,
|
|
233
|
+
/** Number of rows */
|
|
234
|
+
shape_rows: IntegerType,
|
|
235
|
+
/** Number of columns */
|
|
236
|
+
shape_cols: IntegerType,
|
|
237
|
+
/** Per-element estimates */
|
|
238
|
+
estimates: ArrayType(PyMCParameterEstimateType),
|
|
239
|
+
});
|
|
240
|
+
/**
|
|
241
|
+
* Diagnostics for one parameter.
|
|
242
|
+
*/
|
|
243
|
+
export const PyMCParameterDiagType = StructType({
|
|
244
|
+
/** Parameter name */
|
|
245
|
+
parameter: StringType,
|
|
246
|
+
/** Maximum R-hat across elements */
|
|
247
|
+
rhat_max: FloatType,
|
|
248
|
+
/** Minimum ESS across elements */
|
|
249
|
+
ess_min: FloatType,
|
|
250
|
+
/** Number of divergent transitions */
|
|
251
|
+
n_divergent: IntegerType,
|
|
252
|
+
});
|
|
253
|
+
/**
|
|
254
|
+
* Overall diagnostics result.
|
|
255
|
+
*/
|
|
256
|
+
export const PyMCDiagnosticsResultType = StructType({
|
|
257
|
+
/** Whether all diagnostics indicate convergence */
|
|
258
|
+
converged: BooleanType,
|
|
259
|
+
/** Total number of divergent transitions */
|
|
260
|
+
n_divergences: IntegerType,
|
|
261
|
+
/** Per-parameter diagnostics */
|
|
262
|
+
parameters: ArrayType(PyMCParameterDiagType),
|
|
263
|
+
/** Warning messages */
|
|
264
|
+
warnings: ArrayType(StringType),
|
|
265
|
+
});
|
|
266
|
+
/**
|
|
267
|
+
* Observed fit metrics for posterior predictive checks.
|
|
268
|
+
*/
|
|
269
|
+
export const PyMCObservedFitType = StructType({
|
|
270
|
+
/** Target column name or index */
|
|
271
|
+
name: StringType,
|
|
272
|
+
/** Mean absolute error */
|
|
273
|
+
mae: FloatType,
|
|
274
|
+
/** Pearson correlation */
|
|
275
|
+
correlation: FloatType,
|
|
276
|
+
/** 95% credible interval coverage */
|
|
277
|
+
coverage_95: FloatType,
|
|
278
|
+
});
|
|
279
|
+
// ============================================================================
|
|
280
|
+
// Model Blob Types
|
|
281
|
+
// ============================================================================
|
|
282
|
+
/**
|
|
283
|
+
* Model blob type for serialized PyMC models.
|
|
284
|
+
*/
|
|
285
|
+
export const PyMCModelBlobType = VariantType({
|
|
286
|
+
/** Bayesian linear regression model */
|
|
287
|
+
pymc_regression: StructType({
|
|
288
|
+
/** Cloudpickle serialized model data */
|
|
289
|
+
data: BlobType,
|
|
290
|
+
/** Number of input features */
|
|
291
|
+
n_features: IntegerType,
|
|
292
|
+
/** Number of target columns */
|
|
293
|
+
n_targets: IntegerType,
|
|
294
|
+
/** Whether intercept is included */
|
|
295
|
+
include_intercept: BooleanType,
|
|
296
|
+
}),
|
|
297
|
+
/** Hierarchical Bayesian model */
|
|
298
|
+
pymc_hierarchical: StructType({
|
|
299
|
+
/** Cloudpickle serialized model data */
|
|
300
|
+
data: BlobType,
|
|
301
|
+
/** Number of input features */
|
|
302
|
+
n_features: IntegerType,
|
|
303
|
+
/** Number of target columns */
|
|
304
|
+
n_targets: IntegerType,
|
|
305
|
+
/** Number of groups */
|
|
306
|
+
n_groups: IntegerType,
|
|
307
|
+
}),
|
|
308
|
+
/** Multi-layer joint estimation model */
|
|
309
|
+
pymc_multi_layer: StructType({
|
|
310
|
+
/** Cloudpickle serialized model data */
|
|
311
|
+
data: BlobType,
|
|
312
|
+
/** Layer names */
|
|
313
|
+
layer_names: ArrayType(StringType),
|
|
314
|
+
/** Parameter names */
|
|
315
|
+
parameter_names: ArrayType(StringType),
|
|
316
|
+
}),
|
|
317
|
+
});
|
|
318
|
+
// ============================================================================
|
|
319
|
+
// Platform Functions
|
|
320
|
+
// ============================================================================
|
|
321
|
+
/**
|
|
322
|
+
* Train a Bayesian linear regression model.
|
|
323
|
+
*
|
|
324
|
+
* @param X - Feature matrix (n_samples x n_features)
|
|
325
|
+
* @param Y - Target matrix (n_samples x n_targets)
|
|
326
|
+
* @param config - Regression configuration
|
|
327
|
+
* @returns Trained PyMC model blob
|
|
328
|
+
*/
|
|
329
|
+
export const pymc_train_regression = East.platform("pymc_train_regression", [MatrixType(FloatType), MatrixType(FloatType), PyMCRegressionConfigType], PyMCModelBlobType);
|
|
330
|
+
/**
|
|
331
|
+
* Train a hierarchical Bayesian model.
|
|
332
|
+
*
|
|
333
|
+
* @param X - Feature matrix (n_samples x n_features)
|
|
334
|
+
* @param Y - Target matrix (n_samples x n_targets)
|
|
335
|
+
* @param groups - Group assignments per sample
|
|
336
|
+
* @param config - Hierarchical configuration
|
|
337
|
+
* @returns Trained PyMC model blob
|
|
338
|
+
*/
|
|
339
|
+
export const pymc_train_hierarchical = East.platform("pymc_train_hierarchical", [MatrixType(FloatType), MatrixType(FloatType), VectorType(IntegerType), PyMCHierarchicalConfigType], PyMCModelBlobType);
|
|
340
|
+
/**
|
|
341
|
+
* Train a multi-layer joint estimation model.
|
|
342
|
+
*
|
|
343
|
+
* @param data - Array of named data matrices
|
|
344
|
+
* @param config - Multi-layer configuration
|
|
345
|
+
* @returns Trained PyMC model blob
|
|
346
|
+
*/
|
|
347
|
+
export const pymc_train_multi_layer = East.platform("pymc_train_multi_layer", [ArrayType(PyMCNamedDataType), PyMCMultiLayerConfigType], PyMCModelBlobType);
|
|
348
|
+
/**
|
|
349
|
+
* Make point predictions (posterior mean).
|
|
350
|
+
*
|
|
351
|
+
* @param model - Trained PyMC model blob
|
|
352
|
+
* @param X - Feature matrix
|
|
353
|
+
* @param config - Prediction configuration
|
|
354
|
+
* @returns Predicted values matrix
|
|
355
|
+
*/
|
|
356
|
+
export const pymc_predict = East.platform("pymc_predict", [PyMCModelBlobType, MatrixType(FloatType), PyMCPredictConfigType], MatrixType(FloatType));
|
|
357
|
+
/**
|
|
358
|
+
* Make predictions returning full posterior distribution.
|
|
359
|
+
*
|
|
360
|
+
* Returns matrix where each row is a posterior sample prediction.
|
|
361
|
+
*
|
|
362
|
+
* @param model - Trained PyMC model blob
|
|
363
|
+
* @param X - Feature matrix
|
|
364
|
+
* @param config - Prediction configuration
|
|
365
|
+
* @returns Posterior predictive samples matrix
|
|
366
|
+
*/
|
|
367
|
+
export const pymc_predict_distribution = East.platform("pymc_predict_distribution", [PyMCModelBlobType, MatrixType(FloatType), PyMCPredictConfigType], MatrixType(FloatType));
|
|
368
|
+
/**
|
|
369
|
+
* Get posterior parameter summaries.
|
|
370
|
+
*
|
|
371
|
+
* @param model - Trained PyMC model blob
|
|
372
|
+
* @returns Array of parameter summaries
|
|
373
|
+
*/
|
|
374
|
+
export const pymc_posterior_summary = East.platform("pymc_posterior_summary", [PyMCModelBlobType], ArrayType(PyMCParameterSummaryType));
|
|
375
|
+
/**
|
|
376
|
+
* Extract raw posterior samples for a named parameter.
|
|
377
|
+
*
|
|
378
|
+
* @param model - Trained PyMC model blob
|
|
379
|
+
* @param param_name - Parameter name
|
|
380
|
+
* @param n_samples - Number of samples to return
|
|
381
|
+
* @returns Matrix of posterior samples
|
|
382
|
+
*/
|
|
383
|
+
export const pymc_posterior_samples = East.platform("pymc_posterior_samples", [PyMCModelBlobType, StringType, IntegerType], MatrixType(FloatType));
|
|
384
|
+
/**
|
|
385
|
+
* Run convergence diagnostics on a trained model.
|
|
386
|
+
*
|
|
387
|
+
* @param model - Trained PyMC model blob
|
|
388
|
+
* @returns Diagnostics result
|
|
389
|
+
*/
|
|
390
|
+
export const pymc_diagnostics = East.platform("pymc_diagnostics", [PyMCModelBlobType], PyMCDiagnosticsResultType);
|
|
391
|
+
/**
|
|
392
|
+
* Posterior predictive check against observed data.
|
|
393
|
+
*
|
|
394
|
+
* @param model - Trained PyMC model blob
|
|
395
|
+
* @param X - Feature matrix
|
|
396
|
+
* @param Y_observed - Observed target matrix
|
|
397
|
+
* @returns Array of fit metrics per target
|
|
398
|
+
*/
|
|
399
|
+
export const pymc_posterior_predictive_check = East.platform("pymc_posterior_predictive_check", [PyMCModelBlobType, MatrixType(FloatType), MatrixType(FloatType)], ArrayType(PyMCObservedFitType));
|
|
400
|
+
// ============================================================================
|
|
401
|
+
// Grouped Export
|
|
402
|
+
// ============================================================================
|
|
403
|
+
/**
|
|
404
|
+
* Type definitions for PyMC functions.
|
|
405
|
+
*/
|
|
406
|
+
export const PyMCTypes = {
|
|
407
|
+
/** Prior distribution type */
|
|
408
|
+
PyMCPriorDistributionType,
|
|
409
|
+
/** Likelihood type */
|
|
410
|
+
PyMCLikelihoodType,
|
|
411
|
+
/** Pooling type */
|
|
412
|
+
PyMCPoolingType,
|
|
413
|
+
/** Prior parameters */
|
|
414
|
+
PyMCPriorParamsType,
|
|
415
|
+
/** Prior specification */
|
|
416
|
+
PyMCPriorSpecType,
|
|
417
|
+
/** Regression configuration */
|
|
418
|
+
PyMCRegressionConfigType,
|
|
419
|
+
/** Hierarchical configuration */
|
|
420
|
+
PyMCHierarchicalConfigType,
|
|
421
|
+
/** Layer specification */
|
|
422
|
+
PyMCLayerSpecType,
|
|
423
|
+
/** Named prior */
|
|
424
|
+
PyMCNamedPriorType,
|
|
425
|
+
/** Named mask */
|
|
426
|
+
PyMCNamedMaskType,
|
|
427
|
+
/** Multi-layer configuration */
|
|
428
|
+
PyMCMultiLayerConfigType,
|
|
429
|
+
/** Named data */
|
|
430
|
+
PyMCNamedDataType,
|
|
431
|
+
/** Prediction configuration */
|
|
432
|
+
PyMCPredictConfigType,
|
|
433
|
+
/** Parameter estimate */
|
|
434
|
+
PyMCParameterEstimateType,
|
|
435
|
+
/** Parameter summary */
|
|
436
|
+
PyMCParameterSummaryType,
|
|
437
|
+
/** Parameter diagnostics */
|
|
438
|
+
PyMCParameterDiagType,
|
|
439
|
+
/** Diagnostics result */
|
|
440
|
+
PyMCDiagnosticsResultType,
|
|
441
|
+
/** Observed fit metrics */
|
|
442
|
+
PyMCObservedFitType,
|
|
443
|
+
/** Model blob type */
|
|
444
|
+
ModelBlobType: PyMCModelBlobType,
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* PyMC Bayesian inference.
|
|
448
|
+
*
|
|
449
|
+
* Provides Bayesian linear regression, hierarchical models, and multi-layer
|
|
450
|
+
* joint estimation with full posterior analysis.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```ts
|
|
454
|
+
* import { East, variant } from "@elaraai/east";
|
|
455
|
+
* import { PyMC } from "@elaraai/east-py-datascience";
|
|
456
|
+
*
|
|
457
|
+
* const train = East.function([], PyMC.Types.ModelBlobType, $ => {
|
|
458
|
+
* const X = $.let([[1.0], [2.0], [3.0], [4.0]]);
|
|
459
|
+
* const Y = $.let([[2.0], [4.0], [6.0], [8.0]]);
|
|
460
|
+
* const config = $.let({
|
|
461
|
+
* prior: variant('none', null),
|
|
462
|
+
* likelihood: variant('none', null),
|
|
463
|
+
* include_intercept: variant('some', true),
|
|
464
|
+
* samples: variant('some', 100n),
|
|
465
|
+
* tune: variant('some', 50n),
|
|
466
|
+
* chains: variant('some', 1n),
|
|
467
|
+
* target_accept: variant('none', null),
|
|
468
|
+
* });
|
|
469
|
+
* return $.return(PyMC.trainRegression(X, Y, config));
|
|
470
|
+
* });
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
export const PyMC = {
|
|
474
|
+
/**
|
|
475
|
+
* Train a Bayesian linear regression model.
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* import { East, FloatType, variant } from "@elaraai/east";
|
|
480
|
+
* import { PyMC, PyMCRegressionConfigType, MatrixType } from "@elaraai/east-py-datascience";
|
|
481
|
+
*
|
|
482
|
+
* const train = East.function(
|
|
483
|
+
* [MatrixType(FloatType), MatrixType(FloatType)],
|
|
484
|
+
* PyMC.Types.ModelBlobType,
|
|
485
|
+
* ($, X, Y) => {
|
|
486
|
+
* const config = $.let({
|
|
487
|
+
* prior: variant("none", null),
|
|
488
|
+
* likelihood: variant("none", null),
|
|
489
|
+
* include_intercept: variant("some", true),
|
|
490
|
+
* samples: variant("some", 1000n),
|
|
491
|
+
* tune: variant("some", 1000n),
|
|
492
|
+
* chains: variant("some", 2n),
|
|
493
|
+
* target_accept: variant("none", null),
|
|
494
|
+
* }, PyMCRegressionConfigType);
|
|
495
|
+
* return $.return(PyMC.trainRegression(X, Y, config));
|
|
496
|
+
* }
|
|
497
|
+
* );
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
trainRegression: pymc_train_regression,
|
|
501
|
+
/**
|
|
502
|
+
* Train a hierarchical Bayesian model.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```ts
|
|
506
|
+
* import { East, FloatType, IntegerType, variant } from "@elaraai/east";
|
|
507
|
+
* import { PyMC, PyMCHierarchicalConfigType, MatrixType, VectorType } from "@elaraai/east-py-datascience";
|
|
508
|
+
*
|
|
509
|
+
* const train = East.function(
|
|
510
|
+
* [MatrixType(FloatType), MatrixType(FloatType), VectorType(IntegerType)],
|
|
511
|
+
* PyMC.Types.ModelBlobType,
|
|
512
|
+
* ($, X, Y, groups) => {
|
|
513
|
+
* const config = $.let({
|
|
514
|
+
* prior: variant("none", null),
|
|
515
|
+
* likelihood: variant("none", null),
|
|
516
|
+
* pooling: variant("some", variant("partial", null)),
|
|
517
|
+
* samples: variant("some", 1000n),
|
|
518
|
+
* tune: variant("some", 1000n),
|
|
519
|
+
* chains: variant("some", 2n),
|
|
520
|
+
* target_accept: variant("none", null),
|
|
521
|
+
* }, PyMCHierarchicalConfigType);
|
|
522
|
+
* return $.return(PyMC.trainHierarchical(X, Y, groups, config));
|
|
523
|
+
* }
|
|
524
|
+
* );
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
trainHierarchical: pymc_train_hierarchical,
|
|
528
|
+
/**
|
|
529
|
+
* Train a multi-layer joint estimation model.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```ts
|
|
533
|
+
* import { East, ArrayType, variant } from "@elaraai/east";
|
|
534
|
+
* import { PyMC, PyMCMultiLayerConfigType, PyMCNamedDataType } from "@elaraai/east-py-datascience";
|
|
535
|
+
*
|
|
536
|
+
* const train = East.function(
|
|
537
|
+
* [ArrayType(PyMCNamedDataType)],
|
|
538
|
+
* PyMC.Types.ModelBlobType,
|
|
539
|
+
* ($, data) => {
|
|
540
|
+
* const config = $.let({
|
|
541
|
+
* layers: [{
|
|
542
|
+
* name: "layer1",
|
|
543
|
+
* input: "X",
|
|
544
|
+
* output: "Y",
|
|
545
|
+
* parameter: "beta",
|
|
546
|
+
* likelihood: variant("none", null),
|
|
547
|
+
* }],
|
|
548
|
+
* priors: variant("none", null),
|
|
549
|
+
* masks: variant("none", null),
|
|
550
|
+
* samples: variant("some", 1000n),
|
|
551
|
+
* tune: variant("some", 1000n),
|
|
552
|
+
* chains: variant("some", 2n),
|
|
553
|
+
* target_accept: variant("none", null),
|
|
554
|
+
* force_full_mcmc: variant("none", null),
|
|
555
|
+
* fallback_l1_alpha: variant("none", null),
|
|
556
|
+
* }, PyMCMultiLayerConfigType);
|
|
557
|
+
* return $.return(PyMC.trainMultiLayer(data, config));
|
|
558
|
+
* }
|
|
559
|
+
* );
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
trainMultiLayer: pymc_train_multi_layer,
|
|
563
|
+
/**
|
|
564
|
+
* Make point predictions (posterior mean).
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
567
|
+
* ```ts
|
|
568
|
+
* import { East, FloatType, variant } from "@elaraai/east";
|
|
569
|
+
* import { PyMC, PyMCPredictConfigType, MatrixType } from "@elaraai/east-py-datascience";
|
|
570
|
+
*
|
|
571
|
+
* const predict = East.function(
|
|
572
|
+
* [PyMC.Types.ModelBlobType, MatrixType(FloatType)],
|
|
573
|
+
* MatrixType(FloatType),
|
|
574
|
+
* ($, model, X) => {
|
|
575
|
+
* const config = $.let({
|
|
576
|
+
* layer: variant("none", null),
|
|
577
|
+
* n_samples: variant("some", 100n),
|
|
578
|
+
* }, PyMCPredictConfigType);
|
|
579
|
+
* return $.return(PyMC.predict(model, X, config));
|
|
580
|
+
* }
|
|
581
|
+
* );
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
predict: pymc_predict,
|
|
585
|
+
/**
|
|
586
|
+
* Make predictions returning full posterior distribution.
|
|
587
|
+
*
|
|
588
|
+
* Returns matrix where each row is a posterior sample prediction.
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```ts
|
|
592
|
+
* import { East, FloatType, variant } from "@elaraai/east";
|
|
593
|
+
* import { PyMC, PyMCPredictConfigType, MatrixType } from "@elaraai/east-py-datascience";
|
|
594
|
+
*
|
|
595
|
+
* const predictDist = East.function(
|
|
596
|
+
* [PyMC.Types.ModelBlobType, MatrixType(FloatType)],
|
|
597
|
+
* MatrixType(FloatType),
|
|
598
|
+
* ($, model, X) => {
|
|
599
|
+
* const config = $.let({
|
|
600
|
+
* layer: variant("none", null),
|
|
601
|
+
* n_samples: variant("some", 200n),
|
|
602
|
+
* }, PyMCPredictConfigType);
|
|
603
|
+
* return $.return(PyMC.predictDistribution(model, X, config));
|
|
604
|
+
* }
|
|
605
|
+
* );
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
predictDistribution: pymc_predict_distribution,
|
|
609
|
+
/**
|
|
610
|
+
* Get posterior parameter summaries.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```ts
|
|
614
|
+
* import { East, ArrayType } from "@elaraai/east";
|
|
615
|
+
* import { PyMC } from "@elaraai/east-py-datascience";
|
|
616
|
+
*
|
|
617
|
+
* const getSummary = East.function(
|
|
618
|
+
* [PyMC.Types.ModelBlobType],
|
|
619
|
+
* ArrayType(PyMC.Types.PyMCParameterSummaryType),
|
|
620
|
+
* ($, model) => {
|
|
621
|
+
* return $.return(PyMC.posteriorSummary(model));
|
|
622
|
+
* }
|
|
623
|
+
* );
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
posteriorSummary: pymc_posterior_summary,
|
|
627
|
+
/**
|
|
628
|
+
* Extract raw posterior samples for a named parameter.
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```ts
|
|
632
|
+
* import { East, FloatType, IntegerType, StringType } from "@elaraai/east";
|
|
633
|
+
* import { PyMC, MatrixType } from "@elaraai/east-py-datascience";
|
|
634
|
+
*
|
|
635
|
+
* const getSamples = East.function(
|
|
636
|
+
* [PyMC.Types.ModelBlobType, StringType, IntegerType],
|
|
637
|
+
* MatrixType(FloatType),
|
|
638
|
+
* ($, model, paramName, nSamples) => {
|
|
639
|
+
* return $.return(PyMC.posteriorSamples(model, paramName, nSamples));
|
|
640
|
+
* }
|
|
641
|
+
* );
|
|
642
|
+
* ```
|
|
643
|
+
*/
|
|
644
|
+
posteriorSamples: pymc_posterior_samples,
|
|
645
|
+
/**
|
|
646
|
+
* Run convergence diagnostics on a trained model.
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```ts
|
|
650
|
+
* import { East } from "@elaraai/east";
|
|
651
|
+
* import { PyMC } from "@elaraai/east-py-datascience";
|
|
652
|
+
*
|
|
653
|
+
* const diagnose = East.function(
|
|
654
|
+
* [PyMC.Types.ModelBlobType],
|
|
655
|
+
* PyMC.Types.PyMCDiagnosticsResultType,
|
|
656
|
+
* ($, model) => {
|
|
657
|
+
* const result = $.let(PyMC.diagnostics(model));
|
|
658
|
+
* // result.converged, result.n_divergences, result.warnings
|
|
659
|
+
* return $.return(result);
|
|
660
|
+
* }
|
|
661
|
+
* );
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
diagnostics: pymc_diagnostics,
|
|
665
|
+
/**
|
|
666
|
+
* Posterior predictive check against observed data.
|
|
667
|
+
*
|
|
668
|
+
* @example
|
|
669
|
+
* ```ts
|
|
670
|
+
* import { East, FloatType, ArrayType } from "@elaraai/east";
|
|
671
|
+
* import { PyMC, MatrixType } from "@elaraai/east-py-datascience";
|
|
672
|
+
*
|
|
673
|
+
* const check = East.function(
|
|
674
|
+
* [PyMC.Types.ModelBlobType, MatrixType(FloatType), MatrixType(FloatType)],
|
|
675
|
+
* ArrayType(PyMC.Types.PyMCObservedFitType),
|
|
676
|
+
* ($, model, X, Y_observed) => {
|
|
677
|
+
* const result = $.let(PyMC.posteriorPredictiveCheck(model, X, Y_observed));
|
|
678
|
+
* // Each element has: name, mae, correlation, coverage_95
|
|
679
|
+
* return $.return(result);
|
|
680
|
+
* }
|
|
681
|
+
* );
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
posteriorPredictiveCheck: pymc_posterior_predictive_check,
|
|
685
|
+
/** Type definitions */
|
|
686
|
+
Types: PyMCTypes,
|
|
687
|
+
};
|
|
688
|
+
//# sourceMappingURL=pymc.js.map
|