LogisticInitializationMixin#

Module: leaspy.models.logistic

Note: This is a helper component for LogisticModel. You rarely need to interact with it directly unless you are customizing how the model estimates its starting parameters.

The LogisticInitializationMixin class is responsible for the “cold start” problem. Before we can run complex optimization algorithms (like MCMC-SAEM), we need a reasonable starting point for our parameters (\(g, v_0, \tau, \xi\)). Random initialization often leads to poor convergence in non-linear models, so this class provides smart heuristics.

Why Separate Initialization?#

We separate this logic from the main LogisticModel class for two reasons:

  1. Code Organization: Keeps the mathematical definition of the model separate from the estimation heuristics.

  2. Modularity: Different initialization strategies (Default vs. Random) can be swapped or extended without changing the core model physics.

Key Methods#

  • _compute_initial_values_for_model_parameters(self, dataset): This is the workhorse method. It performs a lightweight analysis of your dataset to guess likely parameter values, each calculation is made thanks to some functions in src/leaspy/models/utilities.py, which are a set of loose functions:

    1. Slopes \(\to\) Velocity (\(v_0\)): It computes linear regression slopes for each patient to estimate the average progression speed.

    2. Values \(\to\) Shift (\(g\)): It looks at the value distribution to estimate where the curve sits (the \(g\) parameter).

    3. Times \(\to\) Time Shift (\(\tau\)): It uses the mean age of patients to center the time shifts.

    4. Variability \(\to\) Sources: If sources are enabled, it initializes the mixing matrix (betas) accordingly.

This heuristic step is crucial: a good initialization can reduce convergence time by orders of magnitude.