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
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.ABCThis 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 instancereg_conf (
RegConf) – Configuration object containing regression model parametersis_fitted (
bool, optional) – Flag indicating if the model has been fitted to data, by default Falseis_from_dict (
bool, optional) – Flag indicating if the model was instantiated from a dictionary, by default False
- 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 (
dictionaryofdictionaries mapping batch effecttoindices)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:
- Returns:
New instance of the regression model
- Return type:
- 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:
- Returns:
New instance of the regression model
- Return type:
- Raises:
NotImplementedError – Must be implemented by concrete subclasses
- 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:
- 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 (
dictionaryofdictionaries mapping batch effecttoindices)Y (
xr.DataArray containing covariates)
- Returns:
New instance of the regression model, transfered to the new dataset
- Return type:
- property has_batch_effect: bool
- Abstractmethod:
Check if model includes batch effects.
- Returns:
True if model includes batch effects, False otherwise
- Return type:
- transfered = False