GOFit Algorithms
The GOFit module contains the following three optimization algorithms for parameter fitting nonlinear least-squares problems. The first two are global optimization algorithms and the third is an interface to the local optimization algorithm that is used within the global algorithms. Note that all algorithms expect numpy arrays for vector and matrix inputs.
Multistart Algorithm
- gofit.multistart(m, n, xl, xu, res [, jac=None, samples=100, maxit=200, eps_r=1e-05, eps_g=1e-04, eps_s=1e-08, scaling=True]) -> (x, status)
Multistart global optimization algorithm. Starts multiple regularisation local optimization algorithms from a given number of randomly generated Latin Hypercube starting points.
- Parameters:
m (int) – number of residuals (number of data points)
n (int) – number of parameters (dimension of the problem)
xl (numpy.ndarray) – lower bounds of the parameters to optimize
xu (numpy.ndarray) – upper bounds of the parameters to optimize
res (callable) – function that evaluates the residual, must have the signature
r = res(x)whereris the residual (a numpy.ndarray of size m) evaluated atx(a numpy.ndarray of size n)jac (None or callable, optional) – optional function that evaluates the Jacobian, must have the signature
J = jac(x)whereJis the Jacobian (a numpy.ndarray of size (m,n)) of the residual evaluated atx(a numpy.ndarray of size n). If not given computes the Jacobian using finite-differencessamples (int, optional) – number of Latin Hypercube starting points for the local solver
maxit (int, optional) – maximum number of iterations for each local solver run
eps_r (float, optional) – residual stopping tolerance
eps_g (float, optional) – norm of gradient stopping tolerance
eps_s (float, optional) – norm of step stopping tolerance
scaling (bool, optional) – whether to scale the optimization parameters (recommended)
- Returns:
optimal parameters, status code
- Return type:
(numpy.ndarray,int)
Alternating Algorithm
- gofit.alternating(m, n, n_split, x0, xl, xu, res [, samples=100, maxit=200, eps_r=1e-05, eps_g=1e-04, eps_s=1e-08]) -> (x, status)
Alternating multistart global optimization algorithm. Assumes the parameters split into
n_splitmodel parameters andn-n_splitshape parameters. Then proceeds as follows: 1. fix initial shape params, globally optimize model params; 2. fix model params, locally optimize shape params; 3. locally optimize over model params again; 4. locally optimize over shape params again. Please note that the optimization parameters are scaled by default.- Parameters:
m (int) – number of residuals (number of data points)
n (int) – number of parameters (dimension of the problem)
n_split (int) – parameter split point for alternating optimization (<n)
x0 (numpy.ndarray) – initial guess for the parameters
xl (numpy.ndarray) – lower bounds of the parameters to optimize
xu (numpy.ndarray) – upper bounds of the parameters to optimize
res (callable) – function that evaluates the residual, must have the signature
r = res(x)whereris the residual (a numpy.ndarray of size m) evaluated atx(a numpy.ndarray of size n)samples (int, optional) – number of Latin Hypercube starting points for the local solver
maxit (int, optional) – maximum number of iterations for each local solver run
eps_r (float, optional) – residual stopping tolerance
eps_g (float, optional) – norm of gradient stopping tolerance
eps_s (float, optional) – norm of step stopping tolerance
- Returns:
optimal parameters, status code
- Return type:
(numpy.ndarray,int)
Regularisation Algorithm
- gofit.regularisation(m, n, x, res [, jac=None, maxit=200, eps_g=1e-04, eps_s=1e-08]) -> (x, status)
Adaptive quadratic regularisation local optimization algorithm. Included for completeness.
- Parameters:
m (int) – number of residuals (number of data points)
n (int) – number of parameters (dimension of the problem)
x0 (numpy.ndarray) – initial guess for the parameters
res (callable) – function that evaluates the residual, must have the signature
r = res(x)whereris the residual (a numpy.ndarray of size m) evaluated atx(a numpy.ndarray of size n)jac (None or callable, optional) – optional function that evaluates the Jacobian, must have the signature
J = jac(x)whereJis the Jacobian (a numpy.ndarray of size (m,n)) of the residual evaluated atx(a numpy.ndarray of size n). If not given computes the Jacobian using finite-differencesmaxit (int, optional) – maximum number of iterations for each local solver run
eps_g (float, optional) – norm of gradient stopping tolerance
eps_s (float, optional) – norm of step stopping tolerance
- Returns:
optimal parameters, status code
- Return type:
(numpy.ndarray,int)