mot.library_functions package¶
Subpackages¶
Submodules¶
mot.library_functions.base module¶
-
class
mot.library_functions.base.
SimpleCLLibrary
(cl_code, **kwargs)[source]¶ Bases:
mot.library_functions.base.CLLibrary
,mot.lib.cl_function.SimpleCLFunction
-
class
mot.library_functions.base.
SimpleCLLibraryFromFile
(return_type, cl_function_name, parameter_list, cl_code_file, var_replace_dict=None, **kwargs)[source]¶ Bases:
mot.library_functions.base.CLLibrary
,mot.lib.cl_function.SimpleCLFunction
Create a CL function for a library function.
These functions are not meant to be optimized, but can be used a helper functions in models.
Parameters: - cl_function_name (str) – The name of the CL function
- cl_code_file (str) – The location of the code file
- var_replace_dict (dict) – In the cl_code file these replacements will be made (using the % format function of Python)
mot.library_functions.error_functions module¶
-
class
mot.library_functions.error_functions.
CerfImWOfX
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibraryFromFile
Calculate the cerf.
-
class
mot.library_functions.error_functions.
erfi
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Calculate the imaginary error function for a real argument (special case).
Compute erfi(x) = -i erf(ix), the imaginary error function.
mot.library_functions.lanczos module¶
-
class
mot.library_functions.lanczos.
lanczos_sum_expg_scaled
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Copied from Scipy (https://github.com/scipy/scipy/blob/master/scipy/special/cephes/lanczos.c), 2018-05-07.
mot.library_functions.polynomial_evaluations module¶
mot.library_functions.unity module¶
-
class
mot.library_functions.unity.
lgam1p
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Compute lgam(x + 1).
This is a simplification of the corresponding function in scipy https://github.com/scipy/scipy/blob/master/scipy/special/cephes/unity.c 2018-05-14
-
class
mot.library_functions.unity.
log1pmx
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
log(1 + x) - x
Module contents¶
-
class
mot.library_functions.
Besseli0
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Return the zeroth-order modified Bessel function of the first kind
Original author of C code: M.G.R. Vogelaar
-
class
mot.library_functions.
EuclidianNormFunction
(memspace='private', memtype='mot_float_type')[source]¶ Bases:
mot.library_functions.base.SimpleCLLibraryFromFile
A CL functions for calculating the Euclidian distance between n values.
Parameters: - memspace (str) – The memory space of the memtyped array (private, constant, global).
- memtype (str) – the memory type to use, double, float, mot_float_type, …
-
class
mot.library_functions.
LevenbergMarquardt
(eval_func, nmr_parameters, nmr_observations, patience=250, step_bound=100.0, scale_diag=1, usertol_mult=30, jacobian_func=None, **kwargs)[source]¶ Bases:
mot.library_functions.base.SimpleCLLibraryFromFile
The Powell CL implementation.
Parameters: - eval_func (mot.lib.cl_function.CLFunction) – the function we want to optimize, Should be of signature:
void evaluate(local mot_float_type* x, void* data_void, local mot_float_type* result);
- nmr_parameters (int) – the number of parameters in the model, this will be hardcoded in the method
- patience (int) – the patience of the Powell algorithm
- patience_line_search (int) – the patience of the line search algorithm
- reset_method (str) – one of
RESET_TO_IDENTITY
orEXTRAPOLATED_POINT
. The method used to reset the search directions every iteration. - jacobian_func (mot.lib.cl_function.CLFunction or None) – the function used to compute the Jacobian. If not given, we will use a numerical differentiation
- eval_func (mot.lib.cl_function.CLFunction) – the function we want to optimize, Should be of signature:
-
class
mot.library_functions.
LibNMSimplex
(function_name)[source]¶ Bases:
mot.library_functions.base.SimpleCLLibraryFromFile
The NMSimplex algorithm as a reusable library component.
Parameters: function_name (str) – the name of the evaluation function to call, defaults to ‘evaluate’. This should point to a function with signature:
double evaluate(local mot_float_type* x, void* data_void);
-
class
mot.library_functions.
LogBesseli0
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Return the log of the zeroth-order modified Bessel function of the first kind.
-
class
mot.library_functions.
LogCosh
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Computes \(log(cosh(x))\)
For large x this will try to estimate it without overflow. For small x we use the opencl functions log and cos. The estimation for large numbers has been taken from: https://github.com/JaneliaSciComp/tmt/blob/master/basics/logcosh.m
-
class
mot.library_functions.
NMSimplex
(function_name, nmr_parameters, patience=200, alpha=1.0, beta=0.5, gamma=2.0, delta=0.5, scale=0.1, adaptive_scales=True, **kwargs)[source]¶
-
class
mot.library_functions.
Powell
(eval_func, nmr_parameters, patience=2, patience_line_search=None, reset_method='EXTRAPOLATED_POINT', **kwargs)[source]¶ Bases:
mot.library_functions.base.SimpleCLLibraryFromFile
The Powell CL implementation.
Parameters: - eval_func (mot.lib.cl_function.CLFunction) – the function we want to optimize, Should be of signature:
double evaluate(local mot_float_type* x, void* data_void);
- nmr_parameters (int) – the number of parameters in the model, this will be hardcoded in the method
- patience (int) – the patience of the Powell algorithm
- patience_line_search (int) – the patience of the line search algorithm. If None, we set it equal to the patience.
- reset_method (str) – one of
RESET_TO_IDENTITY
orEXTRAPOLATED_POINT
. The method used to reset the search directions every iteration.
- eval_func (mot.lib.cl_function.CLFunction) – the function we want to optimize, Should be of signature:
-
class
mot.library_functions.
Subplex
(eval_func, nmr_parameters, patience=10, patience_nmsimplex=100, alpha=1.0, beta=0.5, gamma=2.0, delta=0.5, scale=1.0, psi=0.001, omega=0.01, adaptive_scales=True, min_subspace_length='auto', max_subspace_length='auto', **kwargs)[source]¶ Bases:
mot.library_functions.base.SimpleCLLibraryFromFile
The Subplex optimization routines.
-
class
mot.library_functions.
eigenvalues_3x3_symmetric
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Calculate the eigenvalues of a symmetric 3x3 matrix.
This simple algorithm only works in case of a real and symmetric matrix.
The input to this function is an array with the upper triangular elements of the matrix. The output are the eigenvalues such that eig1 >= eig2 >= eig3, i.e. from large to small.
Parameters: - A – the upper triangle of an 3x3 matrix
- v – the output eigenvalues as a vector of three elements.
References
[1]: https://en.wikipedia.org/wiki/Eigenvalue_algorithm#3.C3.973_matrices [2]: Smith, Oliver K. (April 1961), “Eigenvalues of a symmetric 3 × 3 matrix.”, Communications of the ACM,
4 (4): 168, doi:10.1145/355578.366316
-
class
mot.library_functions.
linear_cubic_interpolation
[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Cubic interpolation for a one-dimensional grid.
This uses the theory of Cubic Hermite splines for interpolating a one-dimensional grid of values.
At the borders, it will clip the values to the nearest border.
For more information on this method, see https://en.wikipedia.org/wiki/Cubic_Hermite_spline.
- Example usage:
- constant float data[] = {1.0, 2.0, 5.0, 6.0}; linear_cubic_interpolation(1.5, 4, data);
-
class
mot.library_functions.
simpsons_rule
(function_name)[source]¶ Bases:
mot.library_functions.base.SimpleCLLibrary
Create a CL function for integrating a function using Simpson’s rule.
This creates a CL function specifically meant for integrating the function of the given name. The name of the generated CL function will be ‘simpsons_rule_<function_name>’.
Parameters: function_name (str) – the name of the function to integrate, accepting the arguments: - a: the lower bound of the integral - b: the upper bound of the integral - n: the number of steps, i.e. the number of approximations to make - data: a pointer to some data, this is passed on to the function we are integrating.