leaspy.algo.fit.abstract_mcmc
.AbstractFitMCMC
- class AbstractFitMCMC(settings)
Bases:
AlgoWithAnnealingMixin
,AlgoWithSamplersMixin
,AbstractFitAlgo
Abstract class containing common method for all fit algorithm classes based on Monte-Carlo Markov Chains (MCMC).
- Parameters:
- settings
AlgorithmSettings
MCMC fit algorithm settings
- settings
See also
leaspy.algo.utils.samplers
- Attributes:
- samplersdict[ str,
AbstractSampler
] Dictionary of samplers per each variable
- random_order_variablesbool (default True)
This attribute controls whether we randomize the order of variables at each iteration. Article https://proceedings.neurips.cc/paper/2016/hash/e4da3b7fbbce2345d7772b0674a318d5-Abstract.html gives a rationale on why we should activate this flag.
- temperaturefloat
- temperature_invfloat
Temperature and its inverse (modified during algorithm when using annealing)
- samplersdict[ str,
Methods
iteration
(dataset, model, realizations)MCMC-SAEM iteration.
load_parameters
(parameters)Update the algorithm's parameters by the ones in the given dictionary.
run
(model, *args[, return_loss])Main method, run the algorithm.
run_impl
(model, dataset)Main method, run the algorithm.
set_output_manager
(output_settings)Set a
FitOutputManager
object for the run of the algorithm- iteration(dataset: Dataset, model: AbstractModel, realizations: CollectionRealization) None
MCMC-SAEM iteration.
Sample : MC sample successively of the population and individual variables
Maximization step : update model parameters from current population/individual variables values.
- Parameters:
- dataset
Dataset
- model
AbstractModel
- realizations
CollectionRealization
- dataset
- load_parameters(parameters: dict)
Update the algorithm’s parameters by the ones in the given dictionary. The keys in the io which does not belong to the algorithm’s parameters keys are ignored.
- Parameters:
- parametersdict
Contains the pairs (key, value) of the wanted parameters
Examples
>>> settings = leaspy.io.settings.algorithm_settings.AlgorithmSettings("mcmc_saem") >>> my_algo = leaspy.algo.fit.tensor_mcmcsaem.TensorMCMCSAEM(settings) >>> my_algo.algo_parameters {'n_iter': 10000, 'n_burn_in_iter': 9000, 'eps': 0.001, 'L': 10, 'sampler_ind': 'Gibbs', 'sampler_pop': 'Gibbs', 'annealing': {'do_annealing': False, 'initial_temperature': 10, 'n_plateau': 10, 'n_iter': 200}} >>> parameters = {'n_iter': 5000, 'n_burn_in_iter': 4000} >>> my_algo.load_parameters(parameters) >>> my_algo.algo_parameters {'n_iter': 5000, 'n_burn_in_iter': 4000, 'eps': 0.001, 'L': 10, 'sampler_ind': 'Gibbs', 'sampler_pop': 'Gibbs', 'annealing': {'do_annealing': False, 'initial_temperature': 10, 'n_plateau': 10, 'n_iter': 200}}
- run(model: AbstractModel, *args, return_loss: bool = False, **extra_kwargs) Any
Main method, run the algorithm.
TODO fix proper abstract class method: input depends on algorithm… (esp. simulate != from others…)
- Parameters:
- model
AbstractModel
The used model.
- dataset
Dataset
Contains all the subjects’ observations with corresponding timepoints, in torch format to speed up computations.
- return_lossbool (default False), keyword only
Should the algorithm return main output and optional loss output as a 2-tuple?
- model
- Returns:
- Depends on algorithm class: TODO change?
- run_impl(model: AbstractModel, dataset: Dataset)
Main method, run the algorithm.
Basically, it initializes the
CollectionRealization
object, updates it using the iteration method then returns it.TODO fix proper abstract class
- Parameters:
- model
AbstractModel
The used model.
- dataset
Dataset
Contains the subjects’ observations in torch format to speed up computation.
- model
- Returns:
- 2-tuple:
- realizations
CollectionRealization
The optimized parameters.
- realizations
None : placeholder for noise-std
- set_output_manager(output_settings: OutputsSettings) None
Set a
FitOutputManager
object 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
Examples
>>> from leaspy import AlgorithmSettings >>> from leaspy.io.settings.outputs_settings import OutputsSettings >>> from leaspy.algo.fit.tensor_mcmcsaem import TensorMCMCSAEM >>> algo_settings = AlgorithmSettings("mcmc_saem") >>> my_algo = TensorMCMCSAEM(algo_settings) >>> settings = {'path': 'brouillons', 'console_print_periodicity': 50, 'plot_periodicity': 100, 'save_periodicity': 50 } >>> my_algo.set_output_manager(OutputsSettings(settings))