pygsti.optimize.optimize
Optimization (minimization) functions
Module Contents
Functions
|
Minimizes the function fn starting at x0. |
|
Create a callback function that prints the value of an objective function. |
|
Checks a jacobian function using finite differences. |
- pygsti.optimize.optimize.minimize(fn, x0, method='cg', callback=None, tol=1e-10, maxiter=1000000, maxfev=None, stopval=None, jac=None, verbosity=0, **addl_kwargs)
Minimizes the function fn starting at x0.
This is a gateway function to all other minimization routines within this module, providing a common interface to many different minimization methods (including and extending beyond those available from scipy.optimize).
Parameters
- fnfunction
The function to minimize.
- x0numpy array
The starting point (argument to fn).
- methodstring, optional
Which minimization method to use. Allowed values are: “simplex” : uses _fmin_simplex “supersimplex” : uses _fmin_supersimplex “customcg” : uses fmax_cg (custom CG method) “brute” : uses scipy.optimize.brute “basinhopping” : uses scipy.optimize.basinhopping with L-BFGS-B “swarm” : uses _fmin_particle_swarm “evolve” : uses _fmin_evolutionary (which uses DEAP) < methods available from scipy.optimize.minimize >
- callbackfunction, optional
A callback function to be called in order to track optimizer progress. Should have signature: myCallback(x, f=None, accepted=None). Note that create_objfn_printer(…) function can be used to create a callback.
- tolfloat, optional
Tolerance value used for all types of tolerances available in a given method.
- maxiterint, optional
Maximum iterations.
- maxfevint, optional
Maximum function evaluations; used only when available, and defaults to maxiter.
- stopvalfloat, optional
For basinhopping method only. When f <= stopval then basinhopping outer loop will terminate. Useful when a bound on the minimum is known.
- jacfunction
Jacobian function.
- verbosityint
Level of detail to print to stdout.
- addl_kwargsdict
Additional arguments for the specific optimizer being used.
Returns
- scipy.optimize.Result object
Includes members ‘x’, ‘fun’, ‘success’, and ‘message’.
- pygsti.optimize.optimize.create_objfn_printer(obj_func, start_time=None)
Create a callback function that prints the value of an objective function.
Parameters
- obj_funcfunction
The objective function to print.
- start_timefloat , optional
A reference starting time to use when printing elapsed times. If None, then the system time when this function is called is used (which is often what you want).
Returns
- function
A callback function which prints obj_func.
- pygsti.optimize.optimize.check_jac(f, x0, jac_to_check, eps=1e-10, tol=1e-06, err_type='rel', verbosity=1)
Checks a jacobian function using finite differences.
Parameters
- ffunction
The function to check.
- x0numpy array
The point at which to check the jacobian.
- jac_to_checkfunction
A function which should compute the jacobian of f at x0.
- epsfloat, optional
Epsilon to use in finite difference calculations of jacobian.
- tolfloat, optional
The allowd tolerance on the relative differene between the values of the finite difference and jac_to_check jacobians if err_type == ‘rel’ or the absolute difference if err_type == ‘abs’.
- err_type{‘rel’, ‘abs’), optional
How to interpret tol (see above).
- verbosityint, optional
Controls how much detail is printed to stdout.
Returns
- errSumfloat
The total error between the jacobians.
- errslist
List of (row,col,err) tuples giving the error for each row and column.
- ffd_jacnumpy array
The computed forward-finite-difference jacobian.