scxpand.mlp.mlp_model#

Functions

load_nn_model(results_path, device)

Load a trained MLP model using unified loading utilities.

Classes

CategoricalHead(in_dim, n_classes[, ...])

Neural network head for categorical feature prediction.

FC_Net(in_dim, out_dim, hid_layers[, ...])

Fully connected neural network with layer normalization and dropout.

MLPModel(prm, data_format[, device])

Multi-layer perceptron model for single-cell expansion prediction.

ModelOutput(main_logit[, categorical_logits])

class scxpand.mlp.mlp_model.CategoricalHead(in_dim, n_classes, hidden_dims=(16,), dropout_rate=0.3, feature_name=None)#

Neural network head for categorical feature prediction.

Parameters:
  • in_dim (int) – Input dimension

  • n_classes (int) – Number of output classes

  • hidden_dims (tuple (default: (16,))) – Tuple of hidden layer dimensions

  • dropout_rate (float (default: 0.3)) – Dropout probability

  • feature_name (str | None (default: None)) – Name of the feature being predicted

__init__(in_dim, n_classes, hidden_dims=(16,), dropout_rate=0.3, feature_name=None)#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor

class scxpand.mlp.mlp_model.FC_Net(in_dim, out_dim, hid_layers, dropout_rate=0.3)#

Fully connected neural network with layer normalization and dropout.

Parameters:
  • in_dim (int) – Input dimension

  • out_dim (int) – Output dimension

  • hid_layers (tuple) – Tuple of hidden layer dimensions

  • dropout_rate (float (default: 0.3)) – Dropout probability

__init__(in_dim, out_dim, hid_layers, dropout_rate=0.3)#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class scxpand.mlp.mlp_model.MLPModel(prm, data_format, device=None)#

Multi-layer perceptron model for single-cell expansion prediction.

Parameters:
  • prm (MLPParam) – MLP parameters including layer dimensions and training config

  • data_format (DataFormat) – Data format specification with gene information

  • device (str | None (default: None)) – Device to place the model on (cuda/cpu)

__init__(prm, data_format, device=None)#

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)#

Forward pass of the model.

Parameters:

x (Tensor) – torch.Tensor with shape [batch_size, n_features], input data

Return type:

ModelOutput

Returns:

ModelOutput containing logits and optional categorical_logits

class scxpand.mlp.mlp_model.ModelOutput(main_logit, categorical_logits=None)#
__init__(main_logit, categorical_logits=None)#
categorical_logits: dict[str, Tensor] | None = None#
main_logit: Tensor#
scxpand.mlp.mlp_model.load_nn_model(results_path, device)#

Load a trained MLP model using unified loading utilities.

Parameters:
  • results_path (Path) – Path to directory containing model files

  • device (device | str) – Device to load model on

Return type:

MLPModel

Returns:

Loaded MLP model ready for inference

Raises: