leaspy.algo.base ================ .. py:module:: leaspy.algo.base .. autoapi-nested-parse:: This module defines the `AlgorithmType`, `AlgorithmName` and `AbstractAlgo` classes .. !! processed by numpydoc !! Attributes ---------- .. autoapisummary:: leaspy.algo.base.ModelType leaspy.algo.base.ReturnType Classes ------- .. autoapisummary:: leaspy.algo.base.AlgorithmType leaspy.algo.base.AlgorithmName leaspy.algo.base.BaseAlgorithm leaspy.algo.base.IterativeAlgorithm Functions --------- .. autoapisummary:: leaspy.algo.base.get_algorithm_type leaspy.algo.base.get_algorithm_class leaspy.algo.base.algorithm_factory Module Contents --------------- .. py:data:: ModelType .. py:data:: ReturnType .. py:class:: AlgorithmType Bases: :py:obj:`str`, :py:obj:`enum.Enum` The type of the algorithms. .. !! processed by numpydoc !! .. py:attribute:: FIT :value: 'fit' .. py:attribute:: PERSONALIZE :value: 'personalize' .. py:attribute:: SIMULATE :value: 'simulate' .. py:class:: AlgorithmName Bases: :py:obj:`str`, :py:obj:`enum.Enum` The available algorithms in Leaspy. .. !! processed by numpydoc !! .. py:attribute:: FIT_MCMC_SAEM :value: 'mcmc_saem' .. py:attribute:: FIT_LME :value: 'lme_fit' .. py:attribute:: PERSONALIZE_SCIPY_MINIMIZE :value: 'scipy_minimize' .. py:attribute:: PERSONALIZE_MEAN_POSTERIOR :value: 'mean_posterior' .. py:attribute:: PERSONALIZE_MODE_POSTERIOR :value: 'mode_posterior' .. py:attribute:: PERSONALIZE_CONSTANT :value: 'constant_prediction' .. py:attribute:: PERSONALIZE_LME :value: 'lme_personalize' .. py:attribute:: SIMULATE :value: 'simulate' .. py:class:: BaseAlgorithm(settings) Bases: :py:obj:`abc.ABC`, :py:obj:`Generic`\ [\ :py:obj:`ModelType`\ , :py:obj:`ReturnType`\ ] Base class containing common methods for all algorithm classes. :Parameters: **settings** : :class:`~leaspy.algo.AlgorithmSettings` The specifications of the algorithm as a :class:`~leaspy.algo.AlgorithmSettings` instance. :Attributes: **name** : :class:`~leaspy.algo.base.AlgorithmName` Name of the algorithm. **family** : :class:`~leaspy.algo.base.AlgorithmType` Family of the algorithm. **deterministic** : :obj:`bool` True, if and only if algorithm does not involve randomness. Setting a seed will have no effect on such algorithms. **algo_parameters** : :obj:`dict` Contains the algorithm's parameters. Those are controlled by the :attr:`leaspy.algo.AlgorithmSettings.parameters` class attribute. **seed** : :obj:`int`, optional Seed used by :mod:`numpy` and :mod:`torch`. .. !! processed by numpydoc !! .. py:attribute:: name :type: AlgorithmName :value: None .. py:attribute:: family :type: AlgorithmType :value: None .. py:attribute:: deterministic :type: bool :value: False .. py:attribute:: seed .. py:attribute:: algo_parameters .. py:attribute:: output_manager :value: None .. py:method:: set_output_manager(output_settings) :abstractmethod: .. py:method:: run(model, dataset = None, **kwargs) Main method, run the algorithm. :Parameters: **model** : :class:`~leaspy.models.BaseModel` The used model. **dataset** : :class:`~leaspy.io.data.Dataset` Contains all the subjects' observations with corresponding timepoints, in torch format to speed up computations. :Returns: ReturnType: Depends on algorithm class. .. seealso:: :class:`.AbstractFitAlgo` .. :class:`.AbstractPersonalizeAlgo` .. .. !! processed by numpydoc !! .. py:method:: load_parameters(parameters) 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** : :obj:`dict` Contains the pairs (key, value) of the requested parameters .. rubric:: 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}} .. !! processed by numpydoc !! .. py:class:: IterativeAlgorithm(settings) Bases: :py:obj:`BaseAlgorithm`\ [\ :py:obj:`ModelType`\ , :py:obj:`ReturnType`\ ] Base class containing common methods for all algorithm classes. :Parameters: **settings** : :class:`~leaspy.algo.AlgorithmSettings` The specifications of the algorithm as a :class:`~leaspy.algo.AlgorithmSettings` instance. :Attributes: **name** : :class:`~leaspy.algo.base.AlgorithmName` Name of the algorithm. **family** : :class:`~leaspy.algo.base.AlgorithmType` Family of the algorithm. **deterministic** : :obj:`bool` True, if and only if algorithm does not involve randomness. Setting a seed will have no effect on such algorithms. **algo_parameters** : :obj:`dict` Contains the algorithm's parameters. Those are controlled by the :attr:`leaspy.algo.AlgorithmSettings.parameters` class attribute. **seed** : :obj:`int`, optional Seed used by :mod:`numpy` and :mod:`torch`. .. !! processed by numpydoc !! .. py:attribute:: current_iteration :type: int :value: 0 .. py:function:: get_algorithm_type(name) Return the algorithm type. :Parameters: **name** : :obj:`str` or :class:`~leaspy.algo.base.AlgorithmName` The name of the algorithm. :Returns: algorithm type: :class:`leaspy.algo.AlgorithmType` .. .. !! processed by numpydoc !! .. py:function:: get_algorithm_class(name) Return the algorithm class. :Parameters: **name** : :obj:`str` or :class:`~leaspy.algo.base.AlgorithmName` The name of the algorithm. :Returns: algorithm class: :class:`~leaspy.algo.BaseAlgorithm` .. .. !! processed by numpydoc !! .. py:function:: algorithm_factory(settings) Return the requested algorithm based on the provided settings. :Parameters: **settings** : :class:`leaspy.algo.AlgorithmSettingss` The algorithm settings. :Returns: **algorithm** : child class of :class:`~leaspy.algo.BaseAlgorithm` The requested algorithm. If it exists, it will be compatible with algorithm family. .. !! processed by numpydoc !!