leaspy.algo.personalize ======================= .. py:module:: leaspy.algo.personalize Submodules ---------- .. toctree:: :maxdepth: 1 /reference/api/leaspy/algo/personalize/base/index /reference/api/leaspy/algo/personalize/constant_prediction_algo/index /reference/api/leaspy/algo/personalize/lme_personalize/index /reference/api/leaspy/algo/personalize/mcmc/index /reference/api/leaspy/algo/personalize/mean_posterior/index /reference/api/leaspy/algo/personalize/mode_posterior/index /reference/api/leaspy/algo/personalize/scipy_minimize/index Classes ------- .. autoapisummary:: leaspy.algo.personalize.PersonalizeAlgorithm leaspy.algo.personalize.ConstantPredictionAlgorithm leaspy.algo.personalize.LMEPersonalizeAlgorithm leaspy.algo.personalize.McmcPersonalizeAlgorithm leaspy.algo.personalize.MeanPosteriorAlgorithm leaspy.algo.personalize.ModePosteriorAlgorithm leaspy.algo.personalize.ScipyMinimizeAlgorithm Package Contents ---------------- .. py:class:: PersonalizeAlgorithm(settings) Bases: :py:obj:`leaspy.algo.base.IterativeAlgorithm`\ [\ :py:obj:`leaspy.algo.base.ModelType`\ , :py:obj:`leaspy.algo.base.ReturnType`\ ] Abstract class for `personalize` algorithm. Estimation of individual parameters of a given `Data` file with a frozen model (already estimated, or loaded from known parameters). :Parameters: **settings** : :class:`.AlgorithmSettings` Settings of the algorithm. :Attributes: **name** : :obj:`str` Algorithm's name. **seed** : :obj:`int`, optional Algorithm's seed (default None). **algo_parameters** : :obj:`dict` Algorithm's parameters. .. seealso:: :meth:`.Leaspy.personalize` .. .. !! processed by numpydoc !! .. py:attribute:: family :type: leaspy.algo.base.AlgorithmType .. py:method:: set_output_manager(output_settings) Set the output manager. This is currently not implemented for personalize. .. !! processed by numpydoc !! .. py:class:: ConstantPredictionAlgorithm(settings) Bases: :py:obj:`leaspy.algo.personalize.base.PersonalizeAlgorithm`\ [\ :py:obj:`leaspy.models.ConstantModel`\ , :py:obj:`leaspy.io.outputs.individual_parameters.IndividualParameters`\ ] ConstantPredictionAlgorithm is an algorithm that provides constant predictions. It is used with the :class:`~leaspy.models.ConstantModel`. :Parameters: **settings** : :class:`.AlgorithmSettings` The settings of constant prediction algorithm. It supports the following `prediction_type` values (str):: * ``'last'``: last value even if NaN, * ``'last_known'``: last non NaN value, * ``'max'``: maximum (=worst) value , * ``'mean'``: average of values depending on features, the `last_known` / `max` value may correspond to different visits. For a given feature, value will be NaN if and only if all values for this feature are NaN. :Raises: :exc:`.LeaspyAlgoInputError` If any invalid setting for the algorithm .. !! processed by numpydoc !! .. py:attribute:: name :type: leaspy.algo.base.AlgorithmName .. py:attribute:: deterministic :type: bool :value: True .. py:attribute:: prediction_type :type: PredictionType .. py:class:: LMEPersonalizeAlgorithm(settings) Bases: :py:obj:`leaspy.algo.personalize.base.PersonalizeAlgorithm`\ [\ :py:obj:`leaspy.models.LMEModel`\ , :py:obj:`leaspy.io.outputs.individual_parameters.IndividualParameters`\ ] Personalization algorithm associated to :class:`~leaspy.models.LMEModel`. :Parameters: **settings** : :class:`.AlgorithmSettings` Algorithm settings (none yet). Most LME parameters are defined within LME model and LME fit algorithm. :Attributes: **name** : ``'lme_personalize'`` .. .. !! processed by numpydoc !! .. py:attribute:: name :type: leaspy.algo.base.AlgorithmName .. py:attribute:: deterministic :type: bool :value: True .. py:method:: set_output_manager(output_settings) Not implemented. .. !! processed by numpydoc !! .. py:class:: McmcPersonalizeAlgorithm(settings) Bases: :py:obj:`leaspy.algo.algo_with_annealing.AlgorithmWithAnnealingMixin`, :py:obj:`leaspy.algo.algo_with_samplers.AlgorithmWithSamplersMixin`, :py:obj:`leaspy.algo.algo_with_device.AlgorithmWithDeviceMixin`, :py:obj:`leaspy.algo.personalize.base.PersonalizeAlgorithm`\ [\ :py:obj:`leaspy.models.McmcSaemCompatibleModel`\ , :py:obj:`leaspy.io.outputs.individual_parameters.IndividualParameters`\ ] Base class for MCMC-based personalization algorithms. Individual parameters are derived from values of individual variables of the model. :Parameters: **settings** : :class:`.AlgorithmSettings` Settings of the algorithm. .. !! processed by numpydoc !! .. py:class:: MeanPosteriorAlgorithm(settings) Bases: :py:obj:`leaspy.algo.personalize.mcmc.McmcPersonalizeAlgorithm` Sampler-based algorithm that derives individual parameters as the most frequent mean posterior value from `n_iter` samplings. :Parameters: **settings** : :class:`.AlgorithmSettings` Settings of the algorithm. .. !! processed by numpydoc !! .. py:attribute:: name :type: leaspy.algo.base.AlgorithmName .. py:class:: ModePosteriorAlgorithm(settings) Bases: :py:obj:`leaspy.algo.personalize.mcmc.McmcPersonalizeAlgorithm` Sampler-based algorithm that derives individual parameters as the most frequent mode posterior value from `n_iter` samplings. TODO? we could derive some confidence intervals on individual parameters thanks to this personalization algorithm... :Parameters: **settings** : :class:`.AlgorithmSettings` Settings of the algorithm. .. !! processed by numpydoc !! .. py:attribute:: name :type: leaspy.algo.base.AlgorithmName .. py:attribute:: regularity_factor :type: float :value: 1.0 Weighting of regularity term in the final loss to be minimized. .. !! processed by numpydoc !! .. py:class:: ScipyMinimizeAlgorithm(settings) Bases: :py:obj:`leaspy.algo.personalize.base.PersonalizeAlgorithm`\ [\ :py:obj:`leaspy.models.McmcSaemCompatibleModel`\ , :py:obj:`leaspy.io.outputs.individual_parameters.IndividualParameters`\ ] Gradient descent based algorithm to compute individual parameters, `i.e.` personalizing a model for a given set of subjects. :Parameters: **settings** : :class:`.AlgorithmSettings` Settings for the algorithm, including the `custom_scipy_minimize_params` parameter, which contains keyword arguments passed to :func:`scipy.optimize.minimize`. :Attributes: **scipy_minimize_params** : :obj:`dict` Keyword arguments for :func:`scipy.optimize.minimize`, with default values depending on the usage of a jacobian (cf. `ScipyMinimize.DEFAULT_SCIPY_MINIMIZE_PARAMS_WITH_JACOBIAN` and `ScipyMinimize.DEFAULT_SCIPY_MINIMIZE_PARAMS_WITHOUT_JACOBIAN`). Customization is possible via the `custom_scipy_minimize_params` in :class:`.AlgorithmSettings`. **format_convergence_issues** : :obj:`str` A format string for displaying convergence issues, which can use the following variables: - `patient_id`: :obj:`str` - `optimization_result_pformat`: :obj:`str` - `optimization_result_obj`: dict-like The default format is defined in `ScipyMinimize.DEFAULT_FORMAT_CONVERGENCE_ISSUES`, but it can be customized via the `custom_format_convergence_issues` parameter. **logger** : None or callable :obj:`str` -> None The function used to display convergence issues returned by :func:`scipy.optimize.minimize`. By default, convergence issues are printed only if the BFGS optimization method is not used. This can be customized by setting the `logger` attribute in :class:`.AlgorithmSettings`. .. !! processed by numpydoc !! .. py:attribute:: name :type: leaspy.algo.base.AlgorithmName .. py:attribute:: DEFAULT_SCIPY_MINIMIZE_PARAMS_WITH_JACOBIAN .. py:attribute:: DEFAULT_SCIPY_MINIMIZE_PARAMS_WITHOUT_JACOBIAN .. py:attribute:: DEFAULT_FORMAT_CONVERGENCE_ISSUES :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ {patient_id}: {optimization_result_pformat}""" .. raw:: html
.. py:attribute:: regularity_factor :type: float :value: 1.0 .. py:attribute:: scipy_minimize_params .. py:attribute:: format_convergence_issues .. py:attribute:: logger .. py:method:: obj_no_jac(x, state, scaling) Objective loss function to minimize in order to get patient's individual parameters. :Parameters: **x** : numpy.ndarray Individual standardized parameters At initialization x is full of zeros (mode of priors, scaled by std-dev) **state** : :class:`.State` The cloned model state that is dedicated to the current individual. In particular, individual data variables for the current individual are already loaded into it. **scaling** : _AffineScalings1D The scaling to be used for individual latent variables. :Returns: **objective** : :obj:`float` Value of the loss function (negative log-likelihood). .. !! processed by numpydoc !! .. py:method:: obj_with_jac(x, state, scaling) :abstractmethod: Objective loss function to minimize in order to get patient's individual parameters, together with its jacobian w.r.t to each of `x` dimension. :Parameters: **x** : numpy.ndarray Individual standardized parameters At initialization x is full of zeros (mode of priors, scaled by std-dev) **state** : :class:`.State` The cloned model state that is dedicated to the current individual. In particular, individual data variables for the current individual are already loaded into it. **scaling** : _AffineScalings1D The scaling to be used for individual latent variables. :Returns: 2-tuple (as expected by :func:`scipy.optimize.minimize` when ``jac=True``) * objective : :obj:`float` * gradient : array-like[float] with same length as `x` (= all dimensions of individual latent variables, concatenated) .. !! processed by numpydoc !! .. py:method:: is_jacobian_implemented(model) Check that the jacobian of model is implemented. .. !! processed by numpydoc !!