pcntoolkit.regression_model.regression_model

Abstract base class for regression models in the PCNToolkit.

This module provides the base class for all regression models, defining the common interface and shared functionality that all regression implementations must follow.

Notes

All regression model implementations should inherit from this base class and implement the abstract methods.

Classes

RegressionModel

This class defines the interface for all regression models in the toolkit,

Module Contents

class RegressionModel(name: str, is_fitted: bool = False, is_from_dict: bool = False)

Bases: abc.ABC

This class defines the interface for all regression models in the toolkit, providing common attributes and methods that must be implemented by concrete subclasses.

Parameters:
  • name (str) – Unique identifier for the regression model instance

  • reg_conf (RegConf) – Configuration object containing regression model parameters

  • is_fitted (bool, optional) – Flag indicating if the model has been fitted to data, by default False

  • is_from_dict (bool, optional) – Flag indicating if the model was instantiated from a dictionary, by default False

is_fitted

Indicates whether the model has been fitted to data

Type:

bool

abstractmethod backward(X: xarray.DataArray, be: xarray.DataArray, Z: xarray.DataArray) xarray.DataArray

Compute points in feature space for given z-scores

Parameters:
  • X (xr.DataArray containing covariates)

  • be (xr.DataArray containing batch effects)

  • Y (xr.DataArray containing covariates)

Returns:

Data with Y values derived from Z-scores

Return type:

xr.DataArray

compute_yhat(data, responsevar, X, be)
abstractmethod elemwise_logp(X: xarray.DataArray, be: xarray.DataArray, Y: xarray.DataArray) xarray.DataArray

Compute the log-probability of the data under the model.

abstractmethod fit(X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) None

Fit the model to the data.

Parameters:
  • X (xr.DataArray containing covariates)

  • be (xr.DataArray containing batch effects)

  • be_maps (dictionary of dictionaries mapping batch effect to indices)

  • Y (xr.DataArray containing covariates)

Return type:

Nothing

abstractmethod forward(X: xarray.DataArray, be: xarray.DataArray, Y: xarray.DataArray) xarray.DataArray

Compute Z-scores for provided Y values

Parameters:
  • X (xr.DataArray containing covariates)

  • be (xr.DataArray containing batch effects)

  • Y (xr.DataArray containing covariates)

Returns:

Data with Z-scores derived from Y values

Return type:

xr.DataArray

classmethod from_args(name: str, args: dict) RegressionModel
Abstractmethod:

Create model instance from arguments dictionary.

Used for instantiating models from the command line.

Parameters:
  • name (str) – Unique identifier for the model instance

  • args (dict) – Dictionary of model parameters and configuration

Returns:

New instance of the regression model

Return type:

RegressionModel

Raises:

NotImplementedError – Must be implemented by concrete subclasses

classmethod from_dict(my_dict: dict, path: str) RegressionModel
Abstractmethod:

Create model instance from dictionary representation.

Used for loading models from disk.

Parameters:
  • dct (dict) – Dictionary containing model parameters and configuration

  • path (str) – Path to load any associated files

Returns:

New instance of the regression model

Return type:

RegressionModel

Raises:

NotImplementedError – Must be implemented by concrete subclasses

model_specific_evaluation(path: str) None

Save model-specific evaluation metrics.

abstractmethod to_dict(path: str | None = None) dict

Convert model instance to dictionary representation.

Used for saving models to disk.

Parameters:

path (str | None, optional) – Path to save any associated files, by default None

Returns:

Dictionary containing model parameters and configuration

Return type:

dict

abstractmethod transfer(X: xarray.DataArray, be: xarray.DataArray, be_maps: dict[str, dict[str, int]], Y: xarray.DataArray) RegressionModel

Transfer the model to a new dataset.

Parameters:
  • X (xr.DataArray containing covariates)

  • be (xr.DataArray containing batch effects)

  • be_maps (dictionary of dictionaries mapping batch effect to indices)

  • Y (xr.DataArray containing covariates)

Returns:

New instance of the regression model, transfered to the new dataset

Return type:

RegressionModel

property has_batch_effect: bool
Abstractmethod:

Check if model includes batch effects.

Returns:

True if model includes batch effects, False otherwise

Return type:

bool

is_fitted: bool = False
is_from_dict: bool = False
property name: str

Get the model’s name.

Returns:

The unique identifier of the model

Return type:

str

property regmodel_dict: dict
transfered = False