Skip to content

Estimator Traits & Composition

This document explains Strata’s trait hierarchy and how compile-time parametric polymorphism enables type-safe, composable Machine Learning pipelines without runtime overhead.


Strata structures its Machine Learning interfaces around four fundamental traits inheriting from Estimator:

┌─────────────────────┐
│ Estimator │
│ var is_fitted: Bool│
└──────────┬──────────┘
┌──────────────┬────────┴────────┬──────────────┐
▼ ▼ ▼ ▼
┌─────────────┐ ┌───────────┐ ┌────────────┐ ┌───────────┐
│ Transformer │ │ Regressor │ │ Classifier │ │ Clusterer │
├─────────────┤ ├───────────┤ ├────────────┤ ├───────────┤
│ fit(X) │ │ fit(X, y) │ │ fit(X, y) │ │ fit(X) │
│ transform() │ │ predict() │ │ predict() │ │ predict() │
│ fit_trans() │ └───────────┘ │ pred_prob()│ │ fit_pred()│
└─────────────┘ └────────────┘ └───────────┘

2. Compile-Time Generics vs Runtime Virtual Tables

Section titled “2. Compile-Time Generics vs Runtime Virtual Tables”

In languages like C++ or Python, polymorphism typically uses virtual method tables (vtable) or dynamic method lookup. This prevents loop vectorization and function inlining across pipeline stages.

In Strata, pipelines are generic structs parameterizing the exact concrete types:

struct PipelineRegressor[
TransformerT: Transformer,
RegressorT: Regressor,
target_dtype: DType
](Copyable, Movable, Regressor):
var transformer: TransformerT
var regressor: RegressorT

Because TransformerT and RegressorT are known at compile time, the Mojo compiler directly inlines transformer.transform(X) and regressor.predict(X_trans) into a unified execution stream.