name: east-py-datascience
description: Data science and machine learning platform functions for the East language (TypeScript types). Use when writing East programs that need optimization (MADS, Optuna, SimAnneal, Scipy), machine learning (XGBoost, LightGBM, NGBoost, Torch MLP, Lightning, GP), ML utilities (Sklearn preprocessing, metrics, splits), or model explainability (SHAP). Triggers for: (1) Writing East programs with @elaraai/east-py-datascience, (2) Derivative-free optimization with MADS, (3) Bayesian optimization with Optuna, (4) Discrete/combinatorial optimization with SimAnneal, (5) Gradient boosting with XGBoost or LightGBM, (6) Probabilistic predictions with NGBoost or GP, (7) Neural networks with Torch MLP or Lightning, (8) Data preprocessing and metrics with Sklearn, (9) Model explainability with Shap.
East Data Science
Data science and machine learning platform functions for the East language. Provides optimization, ML models, preprocessing, and explainability.
Quick Start
import { East, FloatType, variant } from "@elaraai/east";
import { MADS } from "@elaraai/east-py-datascience";
// Define objective function
const objective = East.function([MADS.Types.VectorType], FloatType, ($, x) => {
const x0 = $.let(x.get(0n));
const x1 = $.let(x.get(1n));
return $.return(x0.multiply(x0).add(x1.multiply(x1)));
});
// Optimize
const optimize = East.function([], MADS.Types.ResultType, $ => {
const x0 = $.let([0.5, 0.5]);
const bounds = $.let({ lower: [-1.0, -1.0], upper: [1.0, 1.0] });
const config = $.let({
max_bb_eval: variant('some', 100n),
display_degree: variant('some', 0n),
direction_type: variant('none', null),
initial_mesh_size: variant('none', null),
min_mesh_size: variant('none', null),
seed: variant('some', 42n),
});
return $.return(MADS.optimize(objective, x0, bounds, variant('none', null), config));
});
Decision Tree: Which Module to Use
Task → What do you need?
│
├─ MADS (derivative-free continuous optimization)
│ └─ .optimize()
│
├─ Optuna (Bayesian hyperparameter tuning)
│ └─ .optimize()
│
├─ SimAnneal (discrete/combinatorial optimization)
│ └─ .optimize(), .optimizePermutation(), .optimizeSubset()
│
├─ Scipy
│ ├─ Optimization → .optimizeMinimize(), .optimizeMinimizeQuadratic(), .optimizeDualAnnealing()
│ ├─ Statistics → .statsDescribe(), .statsPearsonr(), .statsSpearmanr(), .statsPercentile(), .statsIqr(), .statsMedian(), .statsMad(), .statsRobust()
│ ├─ Curve Fitting → .curveFit()
│ └─ Interpolation → .interpolate1dFit(), .interpolate1dPredict()
│
├─ XGBoost (gradient boosting)
│ ├─ Train → .trainRegressor(), .trainClassifier(), .trainQuantile()
│ └─ Predict → .predict(), .predictClass(), .predictProba(), .predictQuantile()
│
├─ LightGBM (fast gradient boosting)
│ ├─ Train → .trainRegressor(), .trainClassifier()
│ └─ Predict → .predict(), .predictClass(), .predictProba()
│
├─ NGBoost (probabilistic gradient boosting)
│ ├─ Train → .trainRegressor()
│ └─ Predict → .predict(), .predictDist()
│
├─ Torch (neural networks)
│ ├─ Train → .mlpTrain(), .mlpTrainMulti()
│ ├─ Predict → .mlpPredict(), .mlpPredictMulti()
│ └─ Embeddings → .mlpEncode(), .mlpDecode()
│
├─ Lightning (PyTorch Lightning neural networks)
│ ├─ Train → .train(X, y, config, masks, group_weights, conditions)
│ ├─ Predict → .predict(model, X, masks, conditions)
│ ├─ Embeddings → .encode(), .decode(), .decodeConditional() (autoencoder only)
│ ├─ Architectures:
│ │ ├─ mlp: simple feedforward
│ │ ├─ autoencoder: encoder → latent → decoder
│ │ ├─ conv1d: 1D convolutional autoencoder (temporal)
│ │ ├─ sequential: LSTM/GRU autoencoder (temporal)
│ │ └─ transformer: attention-based autoencoder (temporal)
│ ├─ Output modes:
│ │ ├─ regression: MSE loss
│ │ ├─ binary: BCE loss, per-position pos_weights (VectorType), masks
│ │ └─ multi_head: N independent CE heads, per-head class_weights, masks
│ ├─ Conditional generation: condition_dim in temporal architectures
│ └─ Features: early stopping, gradient clipping, epoch callbacks, group_weights
│
├─ GP (Gaussian Process regression)
│ ├─ Train → .train()
│ └─ Predict → .predict(), .predictStd()
│
├─ Sklearn (preprocessing & metrics)
│ ├─ Splitting → .trainTestSplit(), .trainValTestSplit()
│ ├─ Scaling → .standardScalerFit(), .standardScalerTransform(), .minMaxScalerFit(), .minMaxScalerTransform()
│ ├─ Metrics → .computeMetrics(), .computeMetricsMulti(), .computeClassificationMetrics(), .computeClassificationMetricsMulti()
│ └─ Multi-target → .regressorChainTrain(), .regressorChainPredict()
│
└─ Shap (model explainability)
├─ Create → .treeExplainerCreate() (XGBoost only), .kernelExplainerCreate() (any model)
├─ Compute → .computeValues(), .featureImportance()
└─ Supports → TreeExplainer: XGBoost; KernelExplainer: XGBoost, LightGBM, NGBoost, GP, Torch, RegressorChain
Common Types
| Type |
Definition |
Description |
VectorType |
ArrayType(FloatType) |
1D array of floats (e.g., [1.0, 2.0, 3.0]) |
MatrixType |
ArrayType(ArrayType(FloatType)) |
2D array of floats (e.g., [[1.0, 2.0], [3.0, 4.0]]) |
LabelVectorType |
ArrayType(IntegerType) |
Class labels as integers (e.g., [0n, 1n, 0n, 2n]) |
ModelBlobType |
BlobType |
Serialized model (opaque, pass to predict functions) |
Reference Documentation
- API Reference - Complete function signatures, types, and config options
- Examples - Working code examples by use case
Available Modules
| Module |
Import |
Purpose |
| MADS |
import { MADS } from "@elaraai/east-py-datascience" |
Derivative-free blackbox optimization |
| Optuna |
import { Optuna } from "@elaraai/east-py-datascience" |
Bayesian optimization (hyperparameter tuning) |
| SimAnneal |
import { SimAnneal } from "@elaraai/east-py-datascience" |
Simulated annealing (permutation/subset) |
| Scipy |
import { Scipy } from "@elaraai/east-py-datascience" |
Statistics, optimization, interpolation |
| XGBoost |
import { XGBoost } from "@elaraai/east-py-datascience" |
Gradient boosting (regression/classification/quantile) |
| LightGBM |
import { LightGBM } from "@elaraai/east-py-datascience" |
Fast gradient boosting |
| NGBoost |
import { NGBoost } from "@elaraai/east-py-datascience" |
Probabilistic gradient boosting |
| Torch |
import { Torch } from "@elaraai/east-py-datascience" |
Neural networks (MLP) |
| Lightning |
import { Lightning } from "@elaraai/east-py-datascience" |
PyTorch Lightning neural networks |
| GP |
import { GP } from "@elaraai/east-py-datascience" |
Gaussian Process regression |
| Sklearn |
import { Sklearn } from "@elaraai/east-py-datascience" |
Preprocessing, metrics, data splitting |
| Shap |
import { Shap } from "@elaraai/east-py-datascience" |
Model explainability (SHAP values) |
Accessing Types
import { MADS, Optuna, Sklearn, XGBoost } from "@elaraai/east-py-datascience";
// Access types via Module.Types.TypeName
MADS.Types.VectorType // ArrayType(FloatType)
MADS.Types.BoundsType // StructType({ lower, upper })
MADS.Types.ResultType // StructType({ x_best, f_best, ... })
Optuna.Types.ParamSpaceType // Parameter definition
Optuna.Types.StudyResultType // Optimization result
Sklearn.Types.SplitConfigType // Train/test split config
XGBoost.Types.ModelBlobType // Trained model
Common Patterns
Train and Predict
// 1. Prepare data
const X = $.let([[...], [...], ...]);
const y = $.let([...]);
// 2. Configure and train
const config = $.let({ /* options with variant('some', value) or variant('none', null) */ });
const model = $.let(Module.train(X, y, config));
// 3. Predict
const predictions = $.let(Module.predict(model, X_test));
Optimization
// 1. Define objective function
const objective = East.function([VectorType], FloatType, ($, x) => {
// compute and return objective value
});
// 2. Set bounds and config
const bounds = $.let({ lower: [...], upper: [...] });
const config = $.let({ /* options */ });
// 3. Optimize
const result = $.let(Module.optimize(objective, x0, bounds, config));
// result.x_best, result.f_best
1---2name: east-py-datascience3description: Data science and machine learning platform functions for the East language (TypeScript types). Use when writing East programs that need optimization (MADS, Optuna, SimAnneal, Scipy), machine learning4---5
6---
7name: east-py-datascience
8description: Data science and machine learning platform functions for the East language (TypeScript types). Use when writing East programs that need optimization (MADS, Optuna, SimAnneal, Scipy), machine learning (XGBoost, LightGBM, NGBoost, Torch MLP, Lightning, GP), ML utilities (Sklearn preprocessing, metrics, splits), or model explainability (SHAP). Triggers for: (1) Writing East programs with @elaraai/east-py-datascience, (2) Derivative-free optimization with MADS, (3) Bayesian optimization with Optuna, (4) Discrete/combinatorial optimization with SimAnneal, (5) Gradient boosting with XGBoost or LightGBM, (6) Probabilistic predictions with NGBoost or GP, (7) Neural networks with Torch MLP or Lightning, (8) Data preprocessing and metrics with Sklearn, (9) Model explainability with Shap.
9---
10
11# East Data Science
12
13Data science and machine learning platform functions for the East language. Provides optimization, ML models, preprocessing, and explainability.
14
15## Quick Start
16
17```typescript
18import { East, FloatType, variant } from "@elaraai/east";
19import { MADS } from "@elaraai/east-py-datascience";
20
21// Define objective function
22const objective = East.function([MADS.Types.VectorType], FloatType, ($, x) => {
23 const x0 = $.let(x.get(0n));
24 const x1 = $.let(x.get(1n));
25 return $.return(x0.multiply(x0).add(x1.multiply(x1)));
26});
27
28// Optimize
29const optimize = East.function([], MADS.Types.ResultType, $ => {
30 const x0 = $.let([0.5, 0.5]);
31 const bounds = $.let({ lower: [-1.0, -1.0], upper: [1.0, 1.0] });
32 const config = $.let({
33 max_bb_eval: variant('some', 100n),
34 display_degree: variant('some', 0n),
35 direction_type: variant('none', null),
36 initial_mesh_size: variant('none', null),
37 min_mesh_size: variant('none', null),
38 seed: variant('some', 42n),
39 });
40 return $.return(MADS.optimize(objective, x0, bounds, variant('none', null), config));
41});
42```
43
44## Decision Tree: Which Module to Use
45
46```
47Task → What do you need?
48 │
49 ├─ MADS (derivative-free continuous optimization)
50 │ └─ .optimize()
51 │
52 ├─ Optuna (Bayesian hyperparameter tuning)
53 │ └─ .optimize()
54 │
55 ├─ SimAnneal (discrete/combinatorial optimization)
56 │ └─ .optimize(), .optimizePermutation(), .optimizeSubset()
57 │
58 ├─ Scipy
59 │ ├─ Optimization → .optimizeMinimize(), .optimizeMinimizeQuadratic(), .optimizeDualAnnealing()
60 │ ├─ Statistics → .statsDescribe(), .statsPearsonr(), .statsSpearmanr(), .statsPercentile(), .statsIqr(), .statsMedian(), .statsMad(), .statsRobust()
61 │ ├─ Curve Fitting → .curveFit()
62 │ └─ Interpolation → .interpolate1dFit(), .interpolate1dPredict()
63 │
64 ├─ XGBoost (gradient boosting)
65 │ ├─ Train → .trainRegressor(), .trainClassifier(), .trainQuantile()
66 │ └─ Predict → .predict(), .predictClass(), .predictProba(), .predictQuantile()
67 │
68 ├─ LightGBM (fast gradient boosting)
69 │ ├─ Train → .trainRegressor(), .trainClassifier()
70 │ └─ Predict → .predict(), .predictClass(), .predictProba()
71 │
72 ├─ NGBoost (probabilistic gradient boosting)
73 │ ├─ Train → .trainRegressor()
74 │ └─ Predict → .predict(), .predictDist()
75 │
76 ├─ Torch (neural networks)
77 │ ├─ Train → .mlpTrain(), .mlpTrainMulti()
78 │ ├─ Predict → .mlpPredict(), .mlpPredictMulti()
79 │ └─ Embeddings → .mlpEncode(), .mlpDecode()
80 │
81 ├─ Lightning (PyTorch Lightning neural networks)
82 │ ├─ Train → .train(X, y, config, masks, group_weights, conditions)
83 │ ├─ Predict → .predict(model, X, masks, conditions)
84 │ ├─ Embeddings → .encode(), .decode(), .decodeConditional() (autoencoder only)
85 │ ├─ Architectures:
86 │ │ ├─ mlp: simple feedforward
87 │ │ ├─ autoencoder: encoder → latent → decoder
88 │ │ ├─ conv1d: 1D convolutional autoencoder (temporal)
89 │ │ ├─ sequential: LSTM/GRU autoencoder (temporal)
90 │ │ └─ transformer: attention-based autoencoder (temporal)
91 │ ├─ Output modes:
92 │ │ ├─ regression: MSE loss
93 │ │ ├─ binary: BCE loss, per-position pos_weights (VectorType), masks
94 │ │ └─ multi_head: N independent CE heads, per-head class_weights, masks
95 │ ├─ Conditional generation: condition_dim in temporal architectures
96 │ └─ Features: early stopping, gradient clipping, epoch callbacks, group_weights
97 │
98 ├─ GP (Gaussian Process regression)
99 │ ├─ Train → .train()
100 │ └─ Predict → .predict(), .predictStd()
101 │
102 ├─ Sklearn (preprocessing & metrics)
103 │ ├─ Splitting → .trainTestSplit(), .trainValTestSplit()
104 │ ├─ Scaling → .standardScalerFit(), .standardScalerTransform(), .minMaxScalerFit(), .minMaxScalerTransform()
105 │ ├─ Metrics → .computeMetrics(), .computeMetricsMulti(), .computeClassificationMetrics(), .computeClassificationMetricsMulti()
106 │ └─ Multi-target → .regressorChainTrain(), .regressorChainPredict()
107 │
108 └─ Shap (model explainability)
109 ├─ Create → .treeExplainerCreate() (XGBoost only), .kernelExplainerCreate() (any model)
110 ├─ Compute → .computeValues(), .featureImportance()
111 └─ Supports → TreeExplainer: XGBoost; KernelExplainer: XGBoost, LightGBM, NGBoost, GP, Torch, RegressorChain
112```
113
114## Common Types
115
116| Type | Definition | Description |
117|------|------------|-------------|
118| `VectorType` | `ArrayType(FloatType)` | 1D array of floats (e.g., `[1.0, 2.0, 3.0]`) |
119| `MatrixType` | `ArrayType(ArrayType(FloatType))` | 2D array of floats (e.g., `[[1.0, 2.0], [3.0, 4.0]]`) |
120| `LabelVectorType` | `ArrayType(IntegerType)` | Class labels as integers (e.g., `[0n, 1n, 0n, 2n]`) |
121| `ModelBlobType` | `BlobType` | Serialized model (opaque, pass to predict functions) |
122
123## Reference Documentation
124
125- **[API Reference](./reference/api.md)** - Complete function signatures, types, and config options
126- **[Examples](./reference/examples.md)** - Working code examples by use case
127
128## Available Modules
129
130| Module | Import | Purpose |
131|--------|--------|---------|
132| MADS | `import { MADS } from "@elaraai/east-py-datascience"` | Derivative-free blackbox optimization |
133| Optuna | `import { Optuna } from "@elaraai/east-py-datascience"` | Bayesian optimization (hyperparameter tuning) |
134| SimAnneal | `import { SimAnneal } from "@elaraai/east-py-datascience"` | Simulated annealing (permutation/subset) |
135| Scipy | `import { Scipy } from "@elaraai/east-py-datascience"` | Statistics, optimization, interpolation |
136| XGBoost | `import { XGBoost } from "@elaraai/east-py-datascience"` | Gradient boosting (regression/classification/quantile) |
137| LightGBM | `import { LightGBM } from "@elaraai/east-py-datascience"` | Fast gradient boosting |
138| NGBoost | `import { NGBoost } from "@elaraai/east-py-datascience"` | Probabilistic gradient boosting |
139| Torch | `import { Torch } from "@elaraai/east-py-datascience"` | Neural networks (MLP) |
140| Lightning | `import { Lightning } from "@elaraai/east-py-datascience"` | PyTorch Lightning neural networks |
141| GP | `import { GP } from "@elaraai/east-py-datascience"` | Gaussian Process regression |
142| Sklearn | `import { Sklearn } from "@elaraai/east-py-datascience"` | Preprocessing, metrics, data splitting |
143| Shap | `import { Shap } from "@elaraai/east-py-datascience"` | Model explainability (SHAP values) |
144
145## Accessing Types
146
147```typescript
148import { MADS, Optuna, Sklearn, XGBoost } from "@elaraai/east-py-datascience";
149
150// Access types via Module.Types.TypeName
151MADS.Types.VectorType // ArrayType(FloatType)
152MADS.Types.BoundsType // StructType({ lower, upper })
153MADS.Types.ResultType // StructType({ x_best, f_best, ... })
154
155Optuna.Types.ParamSpaceType // Parameter definition
156Optuna.Types.StudyResultType // Optimization result
157
158Sklearn.Types.SplitConfigType // Train/test split config
159XGBoost.Types.ModelBlobType // Trained model
160```
161
162## Common Patterns
163
164### Train and Predict
165
166```typescript
167// 1. Prepare data
168const X = $.let([[...], [...], ...]);
169const y = $.let([...]);
170
171// 2. Configure and train
172const config = $.let({ /* options with variant('some', value) or variant('none', null) */ });
173const model = $.let(Module.train(X, y, config));
174
175// 3. Predict
176const predictions = $.let(Module.predict(model, X_test));
177```
178
179### Optimization
180
181```typescript
182// 1. Define objective function
183const objective = East.function([VectorType], FloatType, ($, x) => {
184 // compute and return objective value
185});
186
187// 2. Set bounds and config
188const bounds = $.let({ lower: [...], upper: [...] });
189const config = $.let({ /* options */ });
190
191// 3. Optimize
192const result = $.let(Module.optimize(objective, x0, bounds, config));
193// result.x_best, result.f_best
194```