mixle.ppl.neural module

Neural conditional models for mixle.ppl – a Net predictor in a slot.

The nonlinear sibling of mixle.ppl.regression. A Net in an outer family’s slot makes a neural conditional model; the outer family sets the link:

Categorical(logits=Net(out=K)).fit(y, given={"x": X})   # softmax link  -> classification  (SoftmaxNeuralLeaf)
Normal(Net(out=1), free).fit(y, given={"x": X})         # identity link -> neural mean + learned noise (the blend)

The objective is the leaf’s own log-density; fitting routes to the standard mixle.inference.estimate() loop – there is no loss function and no training loop in user code.

class NeuralResult(dist, field, kind)[source]

Bases: object

A fitted neural conditional model. predict(given={"x": X}) returns class labels (Categorical) or the conditional mean (Normal) at new covariates – the same shape of interface as RegressionResult.predict. .dist is the underlying mixle leaf (composes into mixtures / composites like any distribution).

Parameters:
  • dist (Any)

  • field (str)

  • kind (str)

predict(given)[source]

Class labels (Categorical) or the conditional mean (Normal) at covariates given.

Parameters:

given (dict)

Return type:

ndarray

score(data, given)[source]

Held-out accuracy (Categorical) or R^2 (Normal) on (data, given).

Parameters:
Return type:

float

neural_fit(rv, data, *, given=None, epochs=200, lr=0.01, batch_size=None, device='cpu', init=None, weights=None, ewc=None, **_)[source]

Fit a neural-headed conditional RV. data is the response y; given carries the covariates.

epochs is the number of passes; batch_size (None = full batch) + device (“mps”/”cuda”) let a conv net train on a real image set on the GPU. The input keeps its natural shape – (N, D) or (N, C, H, W).

Multi-stage pipeline (one module across stages): init= continues a previous fit’s module (CPT/SFT) instead of building a fresh one; weights= are per-observation loss weights (e.g. an SFT prompt mask: 0 on prompt tokens, 1 on the completion); ewc= is an (anchor, fisher, lambda) EWC penalty for continued pretraining without forgetting.

Parameters:
Return type:

NeuralResult