mot.optimize package

Submodules

mot.optimize.base module

class mot.optimize.base.OptimizeResults[source]

Bases: dict

Represents the optimization results.

x

ndarray – the optimized parameter maps, an (d, p) array with for d problems a value for every p parameters

status

ndarray – the return codes, an (d,) vector with for d problems the status return code

Module contents

mot.optimize.get_minimizer_options(method)[source]

Return a dictionary with the default options for the given minimization method.

Parameters:method (str) – the name of the method we want the options off
Returns:a dictionary with the default options
Return type:dict
mot.optimize.maximize(func, x0, nmr_observations, **kwargs)[source]

Maximization of a function.

This wraps the objective function to take the negative of the computed values and passes it then on to one of the minimization routines.

Parameters:
  • func (mot.lib.cl_function.CLFunction) –

    A CL function with the signature:

    double <func_name>(local const mot_float_type* const x,
                       void* data,
                       local mot_float_type* objective_list);
    

    The objective list needs to be filled when the provided pointer is not null. It should contain the function values for each observation. This list is used by non-linear least-squares routines, and will be squared by the least-square optimizer. This is only used by the Levenberg-Marquardt routine.

  • x0 (ndarray) – Initial guess. Array of real elements of size (n, p), for ‘n’ problems and ‘p’ independent variables.
  • nmr_observations (int) – the number of observations returned by the optimization function.
  • **kwargs – see minimize().
mot.optimize.minimize(func, x0, data=None, method=None, lower_bounds=None, upper_bounds=None, nmr_observations=None, cl_runtime_info=None, options=None, jacobian_func=None)[source]

Minimization of one or more variables.

For an easy wrapper of function maximization, see maximize().

Parameters:
  • func (mot.lib.cl_function.CLFunction) –

    A CL function with the signature:

    double <func_name>(local const mot_float_type* const x,
                       void* data,
                       local mot_float_type* objective_list);
    

    The objective list needs to be filled when the provided pointer is not null. It should contain the function values for each observation. This list is used by non-linear least-squares routines, and will be squared by the least-square optimizer. This is only used by the Levenberg-Marquardt routine.

  • x0 (ndarray) – Initial guess. Array of real elements of size (n, p), for ‘n’ problems and ‘p’ independent variables.
  • data (mot.lib.kernel_data.KernelData) – the kernel data we will load. This is returned to the likelihood function as the void* data pointer.
  • method (str) –

    Type of solver. Should be one of: - ‘Levenberg-Marquardt’ - ‘Nelder-Mead’ - ‘Powell’ - ‘Subplex’

    If not given, defaults to ‘Powell’.

  • lower_bounds (tuple) – per parameter a lower bound, if given, the optimizer ensures a <= x with a the lower bound and x the parameter. If not given, -infinity is assumed for all parameters. Each tuple element can either be a scalar or a vector. If a vector is given the first dimension length should match that of the parameters.
  • upper_bounds (tuple) – per parameter an upper bound, if given, the optimizer ensures x >= b with b the upper bound and x the parameter. If not given, +infinity is assumed for all parameters. Each tuple element can either be a scalar or a vector. If a vector is given the first dimension length should match that of the parameters.
  • nmr_observations (int) – the number of observations returned by the optimization function. This is only needed for the Levenberg-Marquardt method.
  • cl_runtime_info (mot.configuration.CLRuntimeInfo) – the CL runtime information
  • options (dict) – A dictionary of solver options. All methods accept the following generic options: - patience (int): Maximum number of iterations to perform.
  • jacobian_func (mot.lib.cl_function.CLFunction) –

    a CL function to compute the Jacobian of the objective function. This should have the signature:

    void compute_jacobian(local mot_float_type* model_parameters,
                          void* data,
                          local mot_float_type* fvec,
                          global mot_float_type* const fjac);
    

    With as input:

    • model_parameters: (nmr_params,) the current point around which we want to know the Jacobian
    • data: the current modeling data, used by the objective function
    • fvec: (nmr_observations,), the function values corresponding to the current model parameters
    • fjac: (nmr_parameters, nmr_observations), the memory location for the Jacobian

    This function is only used by the Levenberg-Marquardt algorithm. If not given, we will use a numerical derivative.

Returns:

The optimization result represented as a OptimizeResult object. Important attributes are: x the solution array.

Return type:

mot.optimize.base.OptimizeResults