mot.optimize package¶
Submodules¶
mot.optimize.base module¶
-
class
mot.optimize.base.OptimizeResults[source]¶ Bases:
dictRepresents 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-Marquardtroutine. - 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().
- func (mot.lib.cl_function.CLFunction) –
-
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-Marquardtroutine. - 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* datapointer. - 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 <= xwith 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 >= bwith 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-Marquardtmethod. - 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
OptimizeResultobject. Important attributes are:xthe solution array.Return type: - func (mot.lib.cl_function.CLFunction) –