leaspy.algo.base¶
This module defines the AlgorithmType, AlgorithmName and AbstractAlgo classes
Attributes¶
Classes¶
The type of the algorithms. |
|
The available algorithms in Leaspy. |
|
Base class containing common methods for all algorithm classes. |
|
Base class containing common methods for all algorithm classes. |
Functions¶
|
Return the algorithm type. |
|
Return the algorithm class. |
|
Return the requested algorithm based on the provided settings. |
Module Contents¶
- ModelType¶
- ReturnType¶
- class AlgorithmType[source]¶
-
The type of the algorithms.
- FIT = 'fit'¶
- PERSONALIZE = 'personalize'¶
- SIMULATE = 'simulate'¶
- class AlgorithmName[source]¶
-
The available algorithms in Leaspy.
- FIT_MCMC_SAEM = 'mcmc_saem'¶
- FIT_LME = 'lme_fit'¶
- PERSONALIZE_SCIPY_MINIMIZE = 'scipy_minimize'¶
- PERSONALIZE_MEAN_POSTERIOR = 'mean_posterior'¶
- PERSONALIZE_MODE_POSTERIOR = 'mode_posterior'¶
- PERSONALIZE_CONSTANT = 'constant_prediction'¶
- PERSONALIZE_LME = 'lme_personalize'¶
- SIMULATE = 'simulate'¶
- class BaseAlgorithm(settings)[source]¶
Bases:
abc.ABC,Generic[ModelType,ReturnType]Base class containing common methods for all algorithm classes.
- Parameters:
- settings
AlgorithmSettings The specifications of the algorithm as a
AlgorithmSettingsinstance.
- settings
- Attributes:
- name
AlgorithmName Name of the algorithm.
- family
AlgorithmType Family of the algorithm.
- deterministic
bool True, if and only if algorithm does not involve randomness. Setting a seed will have no effect on such algorithms.
- algo_parameters
dict Contains the algorithm’s parameters. Those are controlled by the
leaspy.algo.AlgorithmSettings.parametersclass attribute.- seed
int, optional
- name
- Parameters:
settings (AlgorithmSettings)
- name: AlgorithmName = None¶
- family: AlgorithmType = None¶
- seed¶
- algo_parameters¶
- output_manager = None¶
- abstractmethod set_output_manager(output_settings)[source]¶
- Parameters:
output_settings (OutputsSettings)
- Return type:
None
- run(model, dataset=None, **kwargs)[source]¶
Main method, run the algorithm.
- Parameters:
- Returns:
- ReturnType:
Depends on algorithm class.
- Parameters:
- Return type:
See also
AbstractFitAlgoAbstractPersonalizeAlgo
- load_parameters(parameters)[source]¶
Update the algorithm’s parameters by the ones in the given dictionary.
The keys in the input which does not belong to the algorithm’s parameters are ignored.
- Parameters:
- parameters
dict Contains the pairs (key, value) of the requested parameters
- parameters
- Parameters:
parameters (dict)
Examples
>>> from leaspy.algo import AlgorithmSettings, algorithm_factory, OutputsSettings >>> my_algo = algorithm_factory(AlgorithmSettings("mcmc_saem")) >>> my_algo.algo_parameters {'progress_bar': True, 'n_iter': 10000, 'n_burn_in_iter': 9000, 'n_burn_in_iter_frac': 0.9, 'burn_in_step_power': 0.8, 'random_order_variables': True, 'sampler_ind': 'Gibbs', 'sampler_ind_params': {'acceptation_history_length': 25, 'mean_acceptation_rate_target_bounds': [0.2, 0.4], 'adaptive_std_factor': 0.1}, 'sampler_pop': 'Gibbs', 'sampler_pop_params': {'random_order_dimension': True, 'acceptation_history_length': 25, 'mean_acceptation_rate_target_bounds': [0.2, 0.4], 'adaptive_std_factor': 0.1}, 'annealing': {'do_annealing': False, 'initial_temperature': 10, 'n_plateau': 10, 'n_iter': None, 'n_iter_frac': 0.5}} >>> parameters = {'n_iter': 5000, 'n_burn_in_iter': 4000} >>> my_algo.load_parameters(parameters) >>> my_algo.algo_parameters {'progress_bar': True, 'n_iter': 5000, 'n_burn_in_iter': 4000, 'n_burn_in_iter_frac': 0.9, 'burn_in_step_power': 0.8, 'random_order_variables': True, 'sampler_ind': 'Gibbs', 'sampler_ind_params': {'acceptation_history_length': 25, 'mean_acceptation_rate_target_bounds': [0.2, 0.4], 'adaptive_std_factor': 0.1}, 'sampler_pop': 'Gibbs', 'sampler_pop_params': {'random_order_dimension': True, 'acceptation_history_length': 25, 'mean_acceptation_rate_target_bounds': [0.2, 0.4], 'adaptive_std_factor': 0.1}, 'annealing': {'do_annealing': False, 'initial_temperature': 10, 'n_plateau': 10, 'n_iter': None, 'n_iter_frac': 0.5}}
- class IterativeAlgorithm(settings)[source]¶
Bases:
BaseAlgorithm[ModelType,ReturnType]Base class containing common methods for all algorithm classes.
- Parameters:
- settings
AlgorithmSettings The specifications of the algorithm as a
AlgorithmSettingsinstance.
- settings
- Attributes:
- name
AlgorithmName Name of the algorithm.
- family
AlgorithmType Family of the algorithm.
- deterministic
bool True, if and only if algorithm does not involve randomness. Setting a seed will have no effect on such algorithms.
- algo_parameters
dict Contains the algorithm’s parameters. Those are controlled by the
leaspy.algo.AlgorithmSettings.parametersclass attribute.- seed
int, optional
- name
- Parameters:
settings (AlgorithmSettings)
- get_algorithm_type(name)[source]¶
Return the algorithm type.
- Parameters:
- name
strorAlgorithmName The name of the algorithm.
- name
- Returns:
- algorithm type:
leaspy.algo.AlgorithmType
- algorithm type:
- Parameters:
name (Union[str, AlgorithmName])
- Return type:
- get_algorithm_class(name)[source]¶
Return the algorithm class.
- Parameters:
- name
strorAlgorithmName The name of the algorithm.
- name
- Returns:
- algorithm class:
BaseAlgorithm
- algorithm class:
- Parameters:
name (Union[str, AlgorithmName])
- Return type:
Type[BaseAlgorithm]
- algorithm_factory(settings)[source]¶
Return the requested algorithm based on the provided settings.
- Parameters:
- settings
leaspy.algo.AlgorithmSettingss The algorithm settings.
- settings
- Returns:
- algorithmchild class of
BaseAlgorithm The requested algorithm. If it exists, it will be compatible with algorithm family.
- algorithmchild class of
- Parameters:
settings (AlgorithmSettings)
- Return type: