leaspy.models.utils.initialization.model_initialization

Attributes

Functions

initialize_parameters(model, dataset[, method])

Initialize the model's group parameters given its name & the scores of all subjects.

get_lme_results(df[, n_jobs, with_random_slope_age])

Fit a LME on univariate (per feature) time-series (feature vs. patients' ages with varying intercept & slope)

lme_init(model, df[, fact_std])

Initialize the model's group parameters.

Module Contents

XI_STD = 0.5
TAU_STD = 5.0
NOISE_STD = 0.1
SOURCES_STD = 1.0
initialize_parameters(model, dataset, method='default')[source]

Initialize the model’s group parameters given its name & the scores of all subjects.

Under-the-hood it calls an initialization function dedicated for the model:
  • initialize_linear() (including when univariate)

  • initialize_logistic() (including when univariate)

  • initialize_logistic_parallel()

It is automatically called during Leaspy.fit().

Parameters:
modelAbstractModel

The model to initialize.

datasetDataset

Contains the individual scores.

methodstr
Must be one of:
  • 'default': initialize at mean.

  • 'random': initialize with a gaussian realization with same mean and variance.

Returns:
parametersdict [str, torch.Tensor]

Contains the initialized model’s group parameters.

Raises:
LeaspyInputError

If no initialization method is known for model type / method

Return type:

tuple

get_lme_results(df, n_jobs=-1, *, with_random_slope_age=True, **lme_fit_kwargs)[source]

Fit a LME on univariate (per feature) time-series (feature vs. patients’ ages with varying intercept & slope)

Parameters:
dfpd.DataFrame

Contains all the data (with nans)

n_jobsint

Number of jobs in parallel when multiple features to init Not used for now, buggy

with_random_slope_agebool (default True)

Has LME model a random slope per age (otherwise only a random intercept).

**lme_fit_kwargs

Kwargs passed to ‘lme_fit’ (such as force_independent_random_effects, default True)

Returns:
dict

{param: str -> param_values_for_ft: torch.Tensor(nb_fts, *shape_param)}

Parameters:

df (DataFrame)

lme_init(model, df, fact_std=1.0, **kwargs)[source]

Initialize the model’s group parameters.

Parameters:
modelAbstractModel

The model to initialize (must be an univariate or multivariate linear or logistic manifold model).

dfpd.DataFrame

Contains the individual scores (with nans).

fact_stdfloat

Multiplicative factor to apply on std-dev (tau, xi, noise) found naively with LME

**kwargs

Additional kwargs passed to get_lme_results()

Returns:
parametersdict [str, torch.Tensor]

Contains the initialized model’s group parameters.

Raises:
LeaspyInputError

If model is not supported for this initialization

Parameters:

df (DataFrame)