mixle.task.regress module¶
solve_regression – replace rigid code that returns NUMBERS, with coverage-guaranteed honesty.
The regression shape of the solve loop. teacher(x) -> float is the scorer/pricer/estimator being
replaced; a small student learns it, and calibration is split conformal for regression: on a held-out
slice the absolute-residual quantile qhat is set so the interval [yhat - qhat, yhat + qhat] covers
the teacher’s answer with probability >= 1 - alpha (finite-sample, distribution-free, exchangeable
inputs). The escalate-or-answer rule becomes a precision rule: answer locally only when the guaranteed
interval is tight enough for the caller’s purpose (qhat <= tol); otherwise run the real code. So a
locally-answered value is never silently worse than ±tol at the calibrated confidence — and if the
student simply cannot achieve that precision, EVERY request escalates (an honest failure, priced as such).
def price(item): … # the rigid pricing routine sol = solve_regression(price, items, tol=5.0) # dataset <- price(i); train; calibrate sol(item) # a float: local (±tol guaranteed) or teacher sol.interval(item) # (yhat, lo, hi) with 1 - alpha coverage sol.improve(); sol.report() # the same compounding loop
Note qhat is one global width (standard split conformal); locally-adaptive widths are a later rung.
- class RecordRegressionFeaturizer(dim=256, seed=0)[source]
Bases:
objectRecords for REGRESSION: numeric fields pass through standardized, categoricals hash.
HashedRecord(built for classification) squashes numerics throughtanh, which saturates and erases the magnitude signal a regressor needs. Here numeric keys (learned from the fit sample) map to dedicated standardized columns; everything else uses the hashing trick.
- featurizer_spec(f)[source]
Tagged, artifact-ready spec for the featurizers the solve shapes use.
- class RegressionSolution(net, featurizer, teacher, qhat, alpha, tol, holdout_mae, y_mean, y_scale, train_inputs=<factory>, train_ys=<factory>, cal_inputs=<factory>, cal_ys=<factory>, hidden=(64, ), epochs=300, lr=0.01, seed=0, n_requests=0, n_escalated=0, harvested_inputs=<factory>, harvested_ys=<factory>)[source]
Bases:
objectA calibrated numeric student in front of the routine it replaces.
- Parameters:
net (Any)
featurizer (Any)
qhat (float)
alpha (float)
tol (float)
holdout_mae (float)
y_mean (float)
y_scale (float)
train_inputs (list)
train_ys (list)
cal_inputs (list)
cal_ys (list)
hidden (tuple)
epochs (int)
lr (float)
seed (int)
n_requests (int)
n_escalated (int)
harvested_inputs (list)
harvested_ys (list)
- net: Any
- featurizer: Any
- qhat: float
- alpha: float
- tol: float
- holdout_mae: float
- y_mean: float
- y_scale: float
- train_inputs: list
- train_ys: list
- cal_inputs: list
- cal_ys: list
- hidden: tuple = (64,)
- epochs: int = 300
- lr: float = 0.01
- seed: int = 0
- n_requests: int = 0
- n_escalated: int = 0
- harvested_inputs: list
- harvested_ys: list
- interval(x)[source]
(yhat, lo, hi)with calibrated>= 1 - alphacoverage of the teacher’s answer.
- property answers_locally: bool
Whether the calibrated precision meets the tolerance at all (else everything escalates).
- save(path)[source]
Persist net (safetensors via the mixle.mlp builder) + featurizer + calibration;
load()restores.
- classmethod load(path, teacher, *, device='cpu')[source]
Reconstitute a serving RegressionSolution (no training/calibration data; improve() raises).
- solve_regression(teacher, inputs, *, tol, alpha=0.1, holdout=0.25, kind=None, hidden=(64,), epochs=300, lr=1e-2, dim=256, prelabeled=None, seed=0)[source]
Replace a numeric routine with a conformally-calibrated student (see module docstring).
- Parameters:
teacher (Callable[[...], Any]) – the numeric routine (
teacher(x) -> float); labels the dataset, remains the fallback.inputs (Sequence[Any]) – example inputs (text or dict/tuple records).
tol (float) – the caller’s precision requirement — answer locally only when the calibrated
qhat <= tol.alpha (float) – interval miscoverage level (
1 - alphacoverage of the teacher’s answer).prelabeled (tuple[Sequence[Any], Sequence[float]] | None) – already-teacher-labeled
(inputs, values)— typically harvested escalations from a serving deployment — folded into the TRAINING split only, never calibration (which stays a fresh split ofinputs, soqhatkeeps its finite-sample guarantee). The re-solve half of the serving loop.holdout (float)
kind (str | None)
epochs (int)
lr (float)
dim (int)
seed (int)
- Return type:
RegressionSolution