tdm.model.Model#

class tdm.model.Model(dataset: Dataset, fit_cell_types: list[str] | None = None, death_estimation: Literal['mean'] = 'mean', truncate_division_rate: bool = True, **kwargs)[source]#

Base class for all models.

A Model fits two models per cell_type, one for division and one for death.

__init__(dataset: Dataset, fit_cell_types: list[str] | None = None, death_estimation: Literal['mean'] = 'mean', truncate_division_rate: bool = True, **kwargs) None[source]#

Base class for models.

Parameters:
  • dataset (Dataset) – Dataset used to fit the model.

  • fit_cell_types (list[str] | None, optional) – fit a model to this subset. Defaults to all cell types.

  • death_estimation (Literal["mean", "fit"], optional) – method for death rate estimation. Defaults to “mean”.

  • truncate_division_rate (bool, optional) – truncate division rates at the maximal rate for cells in the data. Prevents extreme values in extrapolated regions. Defaults to False.

cell_types()[source]#

The cell types the model has been fitted to.

death_prob(cell_type: str) float[source]#
delta_cells(cell_counts: Mapping[str, float | ndarray], return_order: list[str], mode: Literal['cells', 'rates'] = 'cells') list[ndarray] | ndarray[source]#

Uses division and death rate to compute the absolute number of cells gained / lost.

Note: This method works with ACTUAL CELL NUMBERS! Do not perform any transformation to cell vals. The dataset object used to fit the model is responsible for performing the transformation.

Parameters:
  • cell_counts (dict) – maps a cell type to an array or single integer value of non-transformed cell counts. Note: cell_counts must contain a value for every cell type the model was fit to.

  • return_order (list[str]) – determines the order of cells for returning results as a tuple

abstract fit(features: DataFrame, obs: Series, cell_type: str) object[source]#

Fits a single model to X=features, y=obs

get_delta_cells_func(predicted_cell_types: list[str], fixed_cell_counts: dict[str, float] | None = None) Callable[source]#

Return the dynamics function f, such that dx/dt = f(x). Useful for numerical ode solvers.

Parameters:
  • predicted_cell_types (list[str]) – return order of predictions.

  • fixed_cell_counts (dict[str, float] | None, optional) – provide these in the case of 2D dynamics with fixed cell counts for other cells. Defaults to None.

Returns:

the dynamics function

Return type:

Callable

parameter_names(cell_type: str, obs: Literal['death', 'division']) ndarray[source]#

Returns the parameter names associated with the death / division model for cells of type cell_type.

parameter_pvalues(cell_type: str, obs: Literal['death', 'division']) ndarray[source]#

Returns parameter pvalues.

parameter_stds(cell_type: str, obs: Literal['death', 'division']) ndarray[source]#

Returns standard deviation of parameters.

parameters(cell_type: str, obs: Literal['death', 'division']) ndarray[source]#

Returns parameter values.

parameters_df(cell_type: str, obs: Literal['death', 'division']) DataFrame[source]#
predict(cell_type: str, obs: Literal['death', 'division', 'division_minus_death'], features: DataFrame) ndarray[source]#

Uses the model fit on cell_type data to predict death / division rates.

predict() implements shared logic for all Model classes. Classes inheriting Model should implement the _predict function

reset_maximal_density_enforcement()[source]#
sample_observations(cell_type: str, cell_counts: dict | DataFrame, obs: Literal['death', 'division', 'both']) ndarray[source]#

Sample death or division according to modeled probabilities. Useful for Monte Carlo methods.

set_death_prob(cell_type: str, val: float)[source]#
set_maximal_density_enforcement(enforcer)[source]#

Initializes a maximal density enforcer model that corrects for positive fluxes at maximal density.