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()
│
├─ ALNS (adaptive large neighborhood search)
│ └─ .optimize([SolutionType], initial, objective, destroys, repairs, config)
│ └─ Generic over solution type S - define your own struct
│
├─ 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()
│
├─ MAPIE (conformal prediction intervals)
│ ├─ Regression → .trainConformalRegressor(), .trainCQR()
│ ├─ Classification → .trainConformalClassifier()
│ ├─ Predict → .predictInterval(), .predictSet()
│ └─ SHAP integration → .uncertaintyPredictorRegressor(), .uncertaintyPredictorClassifier()
│
├─ Sklearn (preprocessing & metrics)
│ ├─ Splitting (with stratification and rare class filtering) → .trainTestSplit(), .trainValTestSplit()
│ ├─ Scaling → .standardScalerFit/Transform(), .minMaxScalerFit/Transform(), .robustScalerFit/Transform()
│ ├─ Encoding → .labelEncoderFit/Transform/InverseTransform(), .ordinalEncoderFit/Transform()
│ ├─ Class weights → .computeClassWeight()
│ ├─ Regression metrics → .computeMetrics(), .computeMetricsMulti()
│ ├─ Classification metrics → .computeClassificationMetrics(), .computeClassificationMetricsMulti()
│ ├─ Probability metrics → .rocAucScore(), .logLoss(), .confusionMatrix()
│ └─ 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, MAPIE
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) |
| ALNS |
import { ALNS } from "@elaraai/east-py-datascience" |
Adaptive Large Neighborhood Search (generic over solution type) |
| 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 |
| MAPIE |
import { MAPIE } from "@elaraai/east-py-datascience" |
Conformal prediction intervals |
| 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, ALNS } 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
ALNS.Types.ConfigType // ALNS configuration
ALNS.Types.ResultType // Result with "S" placeholder for solution type
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-datascience-23description: 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), conformal prediction (MAPIE), 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) Conformal prediction intervals with MAPIE, (10) Model explainability with Shap.4---56# East Data Science78Data science and machine learning platform functions for the East language. Provides optimization, ML models, preprocessing, and explainability.910## Quick Start1112```typescript13import { East, FloatType, variant } from "@elaraai/east";14import { MADS } from "@elaraai/east-py-datascience";1516// Define objective function17const objective = East.function([MADS.Types.VectorType], FloatType, ($, x) => {18 const x0 = $.let(x.get(0n));19 const x1 = $.let(x.get(1n));20 return $.return(x0.multiply(x0).add(x1.multiply(x1)));21});2223// Optimize24const optimize = East.function([], MADS.Types.ResultType, $ => {25 const x0 = $.let([0.5, 0.5]);26 const bounds = $.let({ lower: [-1.0, -1.0], upper: [1.0, 1.0] });27 const config = $.let({28 max_bb_eval: variant('some', 100n),29 display_degree: variant('some', 0n),30 direction_type: variant('none', null),31 initial_mesh_size: variant('none', null),32 min_mesh_size: variant('none', null),33 seed: variant('some', 42n),34 });35 return $.return(MADS.optimize(objective, x0, bounds, variant('none', null), config));36});37```3839## Decision Tree: Which Module to Use4041```42Task → What do you need?43 │44 ├─ MADS (derivative-free continuous optimization)45 │ └─ .optimize()46 │47 ├─ Optuna (Bayesian hyperparameter tuning)48 │ └─ .optimize()49 │50 ├─ SimAnneal (discrete/combinatorial optimization)51 │ └─ .optimize(), .optimizePermutation(), .optimizeSubset()52 │53 ├─ ALNS (adaptive large neighborhood search)54 │ └─ .optimize([SolutionType], initial, objective, destroys, repairs, config)55 │ └─ Generic over solution type S - define your own struct56 │57 ├─ Scipy58 │ ├─ Optimization → .optimizeMinimize(), .optimizeMinimizeQuadratic(), .optimizeDualAnnealing()59 │ ├─ Statistics → .statsDescribe(), .statsPearsonr(), .statsSpearmanr(), .statsPercentile(), .statsIqr(), .statsMedian(), .statsMad(), .statsRobust()60 │ ├─ Curve Fitting → .curveFit()61 │ └─ Interpolation → .interpolate1dFit(), .interpolate1dPredict()62 │63 ├─ XGBoost (gradient boosting)64 │ ├─ Train → .trainRegressor(), .trainClassifier(), .trainQuantile()65 │ └─ Predict → .predict(), .predictClass(), .predictProba(), .predictQuantile()66 │67 ├─ LightGBM (fast gradient boosting)68 │ ├─ Train → .trainRegressor(), .trainClassifier()69 │ └─ Predict → .predict(), .predictClass(), .predictProba()70 │71 ├─ NGBoost (probabilistic gradient boosting)72 │ ├─ Train → .trainRegressor()73 │ └─ Predict → .predict(), .predictDist()74 │75 ├─ Torch (neural networks)76 │ ├─ Train → .mlpTrain(), .mlpTrainMulti()77 │ ├─ Predict → .mlpPredict(), .mlpPredictMulti()78 │ └─ Embeddings → .mlpEncode(), .mlpDecode()79 │80 ├─ Lightning (PyTorch Lightning neural networks)81 │ ├─ Train → .train(X, y, config, masks, group_weights, conditions)82 │ ├─ Predict → .predict(model, X, masks, conditions)83 │ ├─ Embeddings → .encode(), .decode(), .decodeConditional() (autoencoder only)84 │ ├─ Architectures:85 │ │ ├─ mlp: simple feedforward86 │ │ ├─ autoencoder: encoder → latent → decoder87 │ │ ├─ conv1d: 1D convolutional autoencoder (temporal)88 │ │ ├─ sequential: LSTM/GRU autoencoder (temporal)89 │ │ └─ transformer: attention-based autoencoder (temporal)90 │ ├─ Output modes:91 │ │ ├─ regression: MSE loss92 │ │ ├─ binary: BCE loss, per-position pos_weights (VectorType), masks93 │ │ └─ multi_head: N independent CE heads, per-head class_weights, masks94 │ ├─ Conditional generation: condition_dim in temporal architectures95 │ └─ Features: early stopping, gradient clipping, epoch callbacks, group_weights96 │97 ├─ GP (Gaussian Process regression)98 │ ├─ Train → .train()99 │ └─ Predict → .predict(), .predictStd()100 │101 ├─ MAPIE (conformal prediction intervals)102 │ ├─ Regression → .trainConformalRegressor(), .trainCQR()103 │ ├─ Classification → .trainConformalClassifier()104 │ ├─ Predict → .predictInterval(), .predictSet()105 │ └─ SHAP integration → .uncertaintyPredictorRegressor(), .uncertaintyPredictorClassifier()106 │107 ├─ Sklearn (preprocessing & metrics)108 │ ├─ Splitting (with stratification and rare class filtering) → .trainTestSplit(), .trainValTestSplit()109 │ ├─ Scaling → .standardScalerFit/Transform(), .minMaxScalerFit/Transform(), .robustScalerFit/Transform()110 │ ├─ Encoding → .labelEncoderFit/Transform/InverseTransform(), .ordinalEncoderFit/Transform()111 │ ├─ Class weights → .computeClassWeight()112 │ ├─ Regression metrics → .computeMetrics(), .computeMetricsMulti()113 │ ├─ Classification metrics → .computeClassificationMetrics(), .computeClassificationMetricsMulti()114 │ ├─ Probability metrics → .rocAucScore(), .logLoss(), .confusionMatrix()115 │ └─ Multi-target → .regressorChainTrain(), .regressorChainPredict()116 │117 └─ Shap (model explainability)118 ├─ Create → .treeExplainerCreate() (XGBoost only), .kernelExplainerCreate() (any model)119 ├─ Compute → .computeValues(), .featureImportance()120 └─ Supports → TreeExplainer: XGBoost; KernelExplainer: XGBoost, LightGBM, NGBoost, GP, Torch, RegressorChain, MAPIE121```122123## Common Types124125| Type | Definition | Description |126|------|------------|-------------|127| `VectorType` | `ArrayType(FloatType)` | 1D array of floats (e.g., `[1.0, 2.0, 3.0]`) |128| `MatrixType` | `ArrayType(ArrayType(FloatType))` | 2D array of floats (e.g., `[[1.0, 2.0], [3.0, 4.0]]`) |129| `LabelVectorType` | `ArrayType(IntegerType)` | Class labels as integers (e.g., `[0n, 1n, 0n, 2n]`) |130| `ModelBlobType` | `BlobType` | Serialized model (opaque, pass to predict functions) |131132## Reference Documentation133134- **[API Reference](./reference/api.md)** - Complete function signatures, types, and config options135- **[Examples](./reference/examples.md)** - Working code examples by use case136137## Available Modules138139| Module | Import | Purpose |140|--------|--------|---------|141| MADS | `import { MADS } from "@elaraai/east-py-datascience"` | Derivative-free blackbox optimization |142| Optuna | `import { Optuna } from "@elaraai/east-py-datascience"` | Bayesian optimization (hyperparameter tuning) |143| SimAnneal | `import { SimAnneal } from "@elaraai/east-py-datascience"` | Simulated annealing (permutation/subset) |144| ALNS | `import { ALNS } from "@elaraai/east-py-datascience"` | Adaptive Large Neighborhood Search (generic over solution type) |145| Scipy | `import { Scipy } from "@elaraai/east-py-datascience"` | Statistics, optimization, interpolation |146| XGBoost | `import { XGBoost } from "@elaraai/east-py-datascience"` | Gradient boosting (regression/classification/quantile) |147| LightGBM | `import { LightGBM } from "@elaraai/east-py-datascience"` | Fast gradient boosting |148| NGBoost | `import { NGBoost } from "@elaraai/east-py-datascience"` | Probabilistic gradient boosting |149| Torch | `import { Torch } from "@elaraai/east-py-datascience"` | Neural networks (MLP) |150| Lightning | `import { Lightning } from "@elaraai/east-py-datascience"` | PyTorch Lightning neural networks |151| GP | `import { GP } from "@elaraai/east-py-datascience"` | Gaussian Process regression |152| MAPIE | `import { MAPIE } from "@elaraai/east-py-datascience"` | Conformal prediction intervals |153| Sklearn | `import { Sklearn } from "@elaraai/east-py-datascience"` | Preprocessing, metrics, data splitting |154| Shap | `import { Shap } from "@elaraai/east-py-datascience"` | Model explainability (SHAP values) |155156## Accessing Types157158```typescript159import { MADS, Optuna, Sklearn, XGBoost, ALNS } from "@elaraai/east-py-datascience";160161// Access types via Module.Types.TypeName162MADS.Types.VectorType // ArrayType(FloatType)163MADS.Types.BoundsType // StructType({ lower, upper })164MADS.Types.ResultType // StructType({ x_best, f_best, ... })165166Optuna.Types.ParamSpaceType // Parameter definition167Optuna.Types.StudyResultType // Optimization result168169ALNS.Types.ConfigType // ALNS configuration170ALNS.Types.ResultType // Result with "S" placeholder for solution type171172Sklearn.Types.SplitConfigType // Train/test split config173XGBoost.Types.ModelBlobType // Trained model174```175176## Common Patterns177178### Train and Predict179180```typescript181// 1. Prepare data182const X = $.let([[...], [...], ...]);183const y = $.let([...]);184185// 2. Configure and train186const config = $.let({ /* options with variant('some', value) or variant('none', null) */ });187const model = $.let(Module.train(X, y, config));188189// 3. Predict190const predictions = $.let(Module.predict(model, X_test));191```192193### Optimization194195```typescript196// 1. Define objective function197const objective = East.function([VectorType], FloatType, ($, x) => {198 // compute and return objective value199});200201// 2. Set bounds and config202const bounds = $.let({ lower: [...], upper: [...] });203const config = $.let({ /* options */ });204205// 3. Optimize206const result = $.let(Module.optimize(objective, x0, bounds, config));207// result.x_best, result.f_best208```