mixle.models.neural module¶
Torch neural-network wrappers trained through Mixle objective utilities.
The wrappers expose Gaussian regression and categorical classification models with consistent log-likelihood objectives, convergence diagnostics, precision handling, and prediction helpers.
- class GaussianRegressionNeuralNetwork(module, noise=1.0, engine=None, precision=None)[source]
Bases:
objectA Torch module trained with a Gaussian regression log likelihood.
The wrapped module predicts the response mean and this helper learns a scalar observation noise alongside module weights. It uses the same generic Torch objective optimizer as the distribution objective helpers.
- Parameters:
module (Any)
noise (float)
engine (Any | None)
precision (Any | None)
- parameters()[source]
Return trainable module parameters plus the raw noise parameter.
- property noise: float
Return the fitted observation standard deviation.
- predict_tensor(x)[source]
Return module predictions as a Torch tensor on the configured engine.
- log_likelihood(x, y)[source]
Return the summed Gaussian regression log likelihood.
- fit(x, y, max_its=500, lr=0.01, optimizer='adam', tol=1.0e-7, out=None, print_iter=100, return_result=False, restore_best=True)[source]
Maximize the Gaussian regression log likelihood.
The default return shape is the historical
(value, iterations)tuple. Setreturn_result=Truefor the full objective diagnostics.
- class CategoricalClassificationNeuralNetwork(module, engine=None, precision=None)[source]
Bases:
objectA Torch classifier wrapper optimized by summed categorical log likelihood.
The wrapped module must return one logits row per observation. Fitting is delegated to
optimize_torch_objectiveso classification examples get the same convergence diagnostics and best-state restoration as distribution objectives.- Parameters:
module (Any)
engine (Any | None)
precision (Any | None)
- parameters()[source]
Return trainable parameters of the wrapped classification module.
- logits_tensor(x)[source]
Return raw class logits for
xas a Torch tensor.
- log_likelihood(x, y)[source]
Return the summed categorical log likelihood for integer labels.
- fit(x, y, max_its=500, lr=0.01, optimizer='adam', tol=1.0e-7, out=None, print_iter=100, return_result=False, restore_best=True)[source]
Maximize the categorical classification log likelihood.
- predict_proba_tensor(x)[source]
Return class probabilities for
xas a Torch tensor.
- predict_proba(x)[source]
Return class probabilities for
xas a NumPy array.
- class PoissonRegressionNeuralNetwork(module, engine=None, precision=None)[source]
Bases:
objectA Torch count-regression wrapper optimized by Poisson log likelihood.
The wrapped module predicts log rates. Observed counts must be non-negative and match the module output shape after one-dimensional inputs are promoted to column vectors.
- Parameters:
module (Any)
engine (Any | None)
precision (Any | None)
- parameters()[source]
Return trainable parameters of the wrapped log-rate module.
- log_rate_tensor(x)[source]
Return predicted log rates as a Torch tensor.
- log_likelihood(x, y)[source]
Return the summed Poisson count log likelihood.
- fit(x, y, max_its=500, lr=0.01, optimizer='adam', tol=1.0e-7, out=None, print_iter=100, return_result=False, restore_best=True)[source]
Maximize the Poisson count log likelihood.
- predict_rate_tensor(x)[source]
Return predicted Poisson rates as a Torch tensor.
- predict_rate(x)[source]
Return predicted Poisson rates as a NumPy array.
- make_mlp(input_dim, hidden_dims, output_dim=1, activation='tanh')[source]
Create a simple fully connected Torch MLP.
- make_monotonic_mlp(input_dim, hidden_dims, output_dim=1, *, increasing=True)[source]
A fully connected Torch MLP that is monotonic in every input dimension jointly, BY CONSTRUCTION.
Each layer’s weight matrix is reparameterized through
softplusbefore use, so every weight is strictly non-negative; composed with the (smooth, strictly increasing)Softplusactivation, a non-negative-weight affine map followed by an increasing activation is itself increasing, and that property is closed under composition – so the whole network is provably non-decreasing in every input coordinate, with no penalty term and no post-hoc check needed.increasing=Falsenegates the output, giving a network non-increasing in every coordinate instead.This is a hard architectural constraint (unlike
PINNRegression’s soft residual penalty): the guarantee holds at every point in input space, not just where training data landed. Drops into the same wrappers asmake_mlp()–NeuralGaussianfor regression,NeuralCategoricalfor classification – no other changes needed. Only jointly monotonic in ALL inputs; a network monotonic in some coordinates and free in others needs a two-path (monotonic + unconstrained) variant, not built here.
- make_deep_set(element_dim, phi_hidden, latent_dim, rho_hidden, output_dim=1, *, pooling='mean')[source]
A Deep Sets network (Zaheer et al. 2017): invariant to any permutation of the set axis, by construction.
Input shape
(..., set_size, element_dim): a per-element MLPphi(shared weights, applied identically to every element –torch.nn.Linearalready broadcasts over all leading dims, so reusingmake_mlp()forphigives exactly that) maps each element to alatent_dimcode; a permutation-invariant pool (pooling="mean"/"sum"/"max", taken over the set axis) aggregates the codes into one order-independent summary; a second MLPrhomaps the summary to the output. Becausephiis applied identically per element and the pool is a symmetric function, the output is exactly unchanged by any permutation of the set axis – true for any weights, trained or not, unlike e.g. training on many random orderings and hoping the network learns invariance.The returned module is a plain
torch.nn.Module, trainable with any ordinary Torch optimizer loop over(set_size, element_dim)-shaped inputs. Note:NeuralGaussian’s accumulator flattens each observation to a 1-D feature vector (reshape(n, -1)) before the M-step, which destroys the set axis this module needs – so it is not a drop-in wrapper for set-shaped data asmake_mlp()/make_monotonic_mlp()are for flat feature vectors. Use this module directly with a custom training loop (or through a wrapper that preserves the set axis) for a fixed set size.