leaspy.algo.personalize.scipy_minimize

This module defines the ScipyMinimize class.

Classes

ScipyMinimizeAlgorithm

Gradient descent based algorithm to compute individual parameters, i.e. personalizing a model for a given set of subjects.

Module Contents

class ScipyMinimizeAlgorithm(settings)[source]

Bases: leaspy.algo.personalize.base.PersonalizeAlgorithm[leaspy.models.McmcSaemCompatibleModel, 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:
settingsAlgorithmSettings

Settings for the algorithm, including the custom_scipy_minimize_params parameter, which contains keyword arguments passed to scipy.optimize.minimize().

Attributes:
scipy_minimize_paramsdict

Keyword arguments for 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 AlgorithmSettings.

format_convergence_issuesstr
A format string for displaying convergence issues, which can use the
following variables:
  • patient_id: str

  • optimization_result_pformat: 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.

loggerNone or callable str -> None

The function used to display convergence issues returned by 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 AlgorithmSettings.

Parameters:

settings (AlgorithmSettings)

name: AlgorithmName
DEFAULT_SCIPY_MINIMIZE_PARAMS_WITH_JACOBIAN
DEFAULT_SCIPY_MINIMIZE_PARAMS_WITHOUT_JACOBIAN
DEFAULT_FORMAT_CONVERGENCE_ISSUES = Multiline-String
Show Value
"""<!> {patient_id}:
{optimization_result_pformat}"""
regularity_factor: float = 1.0
scipy_minimize_params
format_convergence_issues
logger
obj_no_jac(x, state, scaling)[source]

Objective loss function to minimize in order to get patient’s individual parameters.

Parameters:
xnumpy.ndarray

Individual standardized parameters At initialization x is full of zeros (mode of priors, scaled by std-dev)

stateState

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:
objectivefloat

Value of the loss function (negative log-likelihood).

Parameters:
Return type:

float

abstractmethod obj_with_jac(x, state, scaling)[source]

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:
xnumpy.ndarray

Individual standardized parameters At initialization x is full of zeros (mode of priors, scaled by std-dev)

stateState

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 scipy.optimize.minimize() when jac=True)
  • objective : float

  • gradient : array-like[float] with same length as x (= all dimensions of individual latent variables, concatenated)

Parameters:
Return type:

tuple[float, Tensor]

is_jacobian_implemented(model)[source]

Check that the jacobian of model is implemented.

Parameters:

model (McmcSaemCompatibleModel)

Return type:

bool