leaspy.algo.fit¶
Submodules¶
Classes¶
Abstract class containing common method for all fit algorithm classes. |
|
Class used by |
|
Fitting algorithm associated to |
|
Main algorithm for MCMC-SAEM. |
Package Contents¶
- class FitAlgorithm(settings)[source]¶
Bases:
leaspy.algo.base.IterativeAlgorithm[leaspy.algo.base.ModelType,leaspy.algo.base.ReturnType]Abstract class containing common method for all fit algorithm classes.
The algorithm is proven to converge if the sequence burn_in_step is positive, with an infinite sum \(\sum_k \epsilon_k = +\infty\) and a finite sum of the squares \(\sum_k \epsilon_k^2 < \infty\) (see following paper).
- Parameters:
- settings
AlgorithmSettings The specifications of the algorithm as a
AlgorithmSettingsinstance.
- settings
- Attributes:
- algorithm_device
str Valid
torch.device- current_iteration
int, default 0 The number of the current iteration. The first iteration will be 1 and the last one n_iter.
- sufficient_statistics
dict[str,torch.Tensor] or None Sufficient statistics of the previous step. It is None during all the burn-in phase.
- output_manager
FitOutputManager Optional output manager of the algorithm
- Inherited attributes
From
AbstractAlgo
- algorithm_device
- Parameters:
settings (AlgorithmSettings)
See also
leaspy.api.Leaspy.fit()
- family¶
- logs¶
- sufficient_statistics: DictParamsTorch | None = None¶
- set_output_manager(output_settings)[source]¶
Set a
FitOutputManagerobject for the run of the algorithm.- Parameters:
- output_settings
OutputsSettings Contains the logs settings for the computation run (console print periodicity, plot periodicity …)
- output_settings
- Parameters:
output_settings (OutputsSettings)
- Return type:
None
Examples
>>> from leaspy.algo import AlgorithmSettings, algorithm_factory, OutputsSettings >>> algo_settings = AlgorithmSettings("mcmc_saem") >>> my_algo = algorithm_factory(algo_settings) >>> settings = { 'path': 'brouillons', 'print_periodicity': 50, 'plot_periodicity': 100, 'save_periodicity': 50 } >>> my_algo.set_output_manager(OutputsSettings(settings))
- class FitOutputManager(outputs)[source]¶
Class used by
AbstractAlgo(and its child classes) to display & save plots and statistics during algorithm execution.- Parameters:
- outputs
OutputsSettings Initialize the FitOutputManager class attributes, like the logs paths, the console print periodicity and so forth.
- outputs
- Attributes:
- path_output
str Path of the folder containing all the outputs
- path_plot
str Path of the subfolder of path_output containing the logs plots
- path_plot_convergence_model_parameters
str Path of the first plot of the convergence of the model’s parameters (in the subfolder path_plot)
- path_plot_patients
str Path of the subfolder of path_plot containing the plot of the reconstruction of the patients’ longitudinal trajectory by the model
- nb_of_patients_to_plot
int Number of patients for whom the reconstructions will be plotted.
- path_save_model_parameters_convergence
str Path of the subfolder of path_output containing the progression of the model’s parameters convergence
- periodicity_plot
int(default 100) Set the frequency of the display of the plots
- periodicity_print
int Set the frequency of the display of the statistics
- periodicity_save
int Set the frequency of the saves of the model’s parameters
- periodicity_plot_patients
int Set the frequency of the saves of the patients’ reconstructions
- plot_sourcewise
bool If True, plots will be generated for each source separately.
- path_output
- periodicity_print¶
- periodicity_save¶
- periodicity_plot¶
- nb_of_patients_to_plot¶
- periodicity_plot_patients¶
- plot_sourcewise¶
- time¶
- iteration(algo, model, data)[source]¶
Call methods to save state of the running computation, display statistics & plots if the current iteration is a multiple of periodicity_print, periodicity_plot or periodicity_save
- Parameters:
- algo
FitAlgo A fitting algorithm.
- model
McmcSaemCompatibleModel The model used by the computation.
- data
Dataset The data used by the computation
- algo
- Parameters:
algo (FitAlgorithm)
model (McmcSaemCompatibleModel)
data (Dataset)
- Return type:
None
- print_model_statistics(model)[source]¶
Prints model’s statistics.
- Parameters:
- model
McmcSaemCompatibleModel The model used by the computation
- model
- Parameters:
model (McmcSaemCompatibleModel)
- print_algo_statistics(algo)[source]¶
Prints algorithm’s statistics
- Parameters:
- algo
FitAlgo A fitting algorithm.
- algo
- Parameters:
algo (FitAlgorithm)
- save_model_parameters_convergence(iteration, model)[source]¶
Saves the current state of the model’s parameters
- Parameters:
- iteration
int The current iteration.
- model
McmcSaemCompatibleModel The model used by the computation
- iteration
- Parameters:
iteration (int)
model (McmcSaemCompatibleModel)
- Return type:
None
- save_plot_convergence_model_parameters(model)[source]¶
Saves figures of the model parameters’ convergence in multiple pages of a PDF.
- Parameters:
- model
McmcSaemCompatibleModel The model used by the computation
- model
- Parameters:
model (McmcSaemCompatibleModel)
- save_plot_patient_reconstructions(iteration, model, data)[source]¶
Saves figures of real longitudinal values and their reconstructions computed by the model for maximum 5 patients during each iteration.
- Parameters:
- iteration
int The current iteration
- model
McmcSaemCompatibleModel The model used by the computation
- data
Dataset The dataset used by the computation
- iteration
- Parameters:
iteration (int)
model (McmcSaemCompatibleModel)
data (Dataset)
- Return type:
None
- class LMEFitAlgorithm(settings)[source]¶
Bases:
leaspy.algo.fit.base.FitAlgorithm[leaspy.models.LMEModel,tuple]Fitting algorithm associated to
LMEModel.- Parameters:
- settings
AlgorithmSettings - force_independent_random_effects
bool Force independence of random intercept & random slope
- force_independent_random_effects
other keyword arguments passed to
statsmodels.regression.mixed_linear_model.MixedLM.fit()
- settings
- Parameters:
settings (AlgorithmSettings)
- name: AlgorithmName¶
- force_independent_random_effects¶
- sm_fit_parameters¶
- set_output_manager(output_settings)[source]¶
Not implemented.
- Parameters:
output_settings (OutputsSettings)
- Return type:
None
- class TensorMcmcSaemAlgorithm(settings)[source]¶
Bases:
leaspy.algo.algo_with_device.AlgorithmWithDeviceMixin,leaspy.algo.algo_with_annealing.AlgorithmWithAnnealingMixin,leaspy.algo.algo_with_samplers.AlgorithmWithSamplersMixin,leaspy.algo.fit.base.FitAlgorithm[leaspy.models.McmcSaemCompatibleModel,leaspy.variables.state.State]Main algorithm for MCMC-SAEM.
- Parameters:
- settings
AlgorithmSettings MCMC fit algorithm settings
- settings
- Attributes:
- samplers
dict[str,AbstractSampler] Dictionary of samplers per each variable
- random_order_variables
bool(default True) This attribute controls whether we randomize the order of variables at each iteration. Article gives a reason on why we should activate this flag.
- temperature
float - temperature_inv
float Temperature and its inverse are modified during algorithm if annealing is used
- samplers
- Parameters:
settings (AlgorithmSettings)
See also
- name: AlgorithmName¶