mixle.models.neural moduleΒΆ

Torch neural-network objective helpers.

class GaussianRegressionNeuralNetwork(module, noise=1.0, engine=None, precision=None)[source]

Bases: object

A 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.

Return type:

Iterable[Any]

property noise: float

Return the fitted observation standard deviation.

predict_tensor(x)[source]

Return module predictions as a Torch tensor on the configured engine.

Parameters:

x (Any)

Return type:

Any

log_likelihood(x, y)[source]

Return the summed Gaussian regression log likelihood.

Parameters:
Return type:

Any

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. Set return_result=True for the full objective diagnostics.

Parameters:
Return type:

Any

predict(x)[source]

Return mean predictions as a NumPy array.

Parameters:

x (Any)

Return type:

ndarray

class CategoricalClassificationNeuralNetwork(module, engine=None, precision=None)[source]

Bases: object

A 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_objective so 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.

Return type:

Iterable[Any]

logits_tensor(x)[source]

Return raw class logits for x as a Torch tensor.

Parameters:

x (Any)

Return type:

Any

log_likelihood(x, y)[source]

Return the summed categorical log likelihood for integer labels.

Parameters:
Return type:

Any

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.

Parameters:
Return type:

Any

predict_proba_tensor(x)[source]

Return class probabilities for x as a Torch tensor.

Parameters:

x (Any)

Return type:

Any

predict_proba(x)[source]

Return class probabilities for x as a NumPy array.

Parameters:

x (Any)

Return type:

ndarray

predict(x)[source]

Return maximum-probability class labels for x.

Parameters:

x (Any)

Return type:

ndarray

class PoissonRegressionNeuralNetwork(module, engine=None, precision=None)[source]

Bases: object

A 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.

Return type:

Iterable[Any]

log_rate_tensor(x)[source]

Return predicted log rates as a Torch tensor.

Parameters:

x (Any)

Return type:

Any

log_likelihood(x, y)[source]

Return the summed Poisson count log likelihood.

Parameters:
Return type:

Any

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.

Parameters:
Return type:

Any

predict_rate_tensor(x)[source]

Return predicted Poisson rates as a Torch tensor.

Parameters:

x (Any)

Return type:

Any

predict_rate(x)[source]

Return predicted Poisson rates as a NumPy array.

Parameters:

x (Any)

Return type:

ndarray

predict(x)[source]

Return rounded count predictions as integer NumPy values.

Parameters:

x (Any)

Return type:

ndarray

make_mlp(input_dim, hidden_dims, output_dim=1, activation='tanh')[source]

Create a simple fully connected Torch MLP.

Parameters:
Return type:

Any