ForceBalance API
1.3
Automated optimization of force fields and empirical potentials
|
Functions | |
def | f1d2p (f, h, f0=None) |
A two-point finite difference stencil. More... | |
def | f1d5p (f, h) |
A highly accurate five-point finite difference stencil for computing derivatives of a function. More... | |
def | f1d7p (f, h) |
A highly accurate seven-point finite difference stencil for computing derivatives of a function. More... | |
def | f12d7p (f, h) |
def | f12d3p (f, h, f0=None) |
A three-point finite difference stencil. More... | |
def | f2var (f, h) |
A finite difference stencil for a function of two variables. More... | |
def | in_fd () |
Invoking this function from anywhere will tell us whether we're being called by a finite-difference function. More... | |
def | in_fd_srch () |
Invoking this function from anywhere will tell us whether we're being called by a finite-difference function. More... | |
def | fdwrap (func, mvals0, pidx, key=None, kwargs) |
A function wrapper for finite difference designed for differentiating 'get'-type functions. More... | |
def | fdwrap_G (tgt, mvals0, pidx) |
A driver to fdwrap for gradients (see documentation for fdwrap) Inputs: tgt = The Target containing the objective function that we want to differentiate mvals0 = The 'central' values of the mathematical parameters - i.e. More... | |
def | fdwrap_H (tgt, mvals0, pidx) |
A driver to fdwrap for Hessians (see documentation for fdwrap) Inputs: tgt = The Target containing the objective function that we want to differentiate mvals0 = The 'central' values of the mathematical parameters - i.e. More... | |
Variables | |
logger = getLogger(__name__) | |
def src.finite_difference.f12d3p | ( | f, | |
h, | |||
f0 = None |
|||
) |
A three-point finite difference stencil.
This function does either two computations or three, depending on whether the 'center' value is supplied. This is done in order to avoid recomputing the center value many times.
The first derivative is evaluated using central difference. One advantage of using central difference (as opposed to forward difference) is that we get zero at the bottom of a parabola.
Using this formula we also get an approximate second derivative, which can then be inserted into the diagonal of the Hessian. This is very useful for optimizations like BFGS where the diagonal determines how far we step in the parameter space.
How to use: use fdwrap or something similar to generate a one-variable function from the (usually) much more complicated function that we wish to differentate. Then pass it to this function.
Inputs: f = The one-variable function f(x) that we're differentiating h = The finite difference step size, usually a small number
Outputs: fp = The finite difference derivative of the function f(x) around x=0.
Definition at line 110 of file finite_difference.py.
def src.finite_difference.f12d7p | ( | f, | |
h | |||
) |
Definition at line 76 of file finite_difference.py.
def src.finite_difference.f1d2p | ( | f, | |
h, | |||
f0 = None |
|||
) |
A two-point finite difference stencil.
This function does either two computations or one, depending on whether the 'center' value is supplied. This is done in order to avoid recomputing the center value many times when we repeat this function for each index of the gradient.
How to use: use fdwrap or something similar to generate a one-variable function from the (usually) much more complicated function that we wish to differentate. Then pass it to this function.
Inputs: f = The one-variable function f(x) that we're differentiating h = The finite difference step size, usually a small number
Outputs: fp = The finite difference derivative of the function f(x) around x=0.
Definition at line 30 of file finite_difference.py.
def src.finite_difference.f1d5p | ( | f, | |
h | |||
) |
A highly accurate five-point finite difference stencil for computing derivatives of a function.
It works on both scalar and vector functions (i.e. functions that return arrays). Since the function does four computations, it's costly but recommended if we really need an accurate reference value.
The function is evaluated at points -2h, -h, +h and +2h and these values are combined to make the derivative according to: http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/central-differences/
How to use: use fdwrap or something similar to generate a one-variable function from the (usually) much more complicated function that we wish to differentate. Then pass it to this function.
Inputs: f = The one-variable function f(x) that we're differentiating h = The finite difference step size, usually a small number
Outputs: fp = The finite difference derivative of the function f(x) around x=0.
Definition at line 61 of file finite_difference.py.
def src.finite_difference.f1d7p | ( | f, | |
h | |||
) |
A highly accurate seven-point finite difference stencil for computing derivatives of a function.
Definition at line 71 of file finite_difference.py.
def src.finite_difference.f2var | ( | f, | |
h | |||
) |
A finite difference stencil for a function of two variables.
Definition at line 121 of file finite_difference.py.
def src.finite_difference.fdwrap | ( | func, | |
mvals0, | |||
pidx, | |||
key = None , |
|||
kwargs | |||
) |
A function wrapper for finite difference designed for differentiating 'get'-type functions.
Since our finite difference stencils take single-variable functions and differentiate them around zero, and our objective function is quite a complicated function, we need a wrapper to serve as a middleman. The alternative would be to copy the finite difference formula to wherever we're taking the derivative, and that is prone to mistakes.
Inputs: func = Either get_X or get_G; these functions return dictionaries. ['X'] = 1.23, ['G'] = [0.12, 3,45, ...] mvals0 = The 'central' values of the mathematical parameters - i.e. the wrapped function's origin is here. pidx = The index of the parameter that we're differentiating key = either 'G' or 'X', the value we wish to take out of the dictionary kwargs = Anything else we want to pass to the objective function (for instance, Project.Objective takes Order as an argument)
Outputs: func1 = Wrapped version of func, which takes a single float argument.
Definition at line 161 of file finite_difference.py.
def src.finite_difference.fdwrap_G | ( | tgt, | |
mvals0, | |||
pidx | |||
) |
A driver to fdwrap for gradients (see documentation for fdwrap) Inputs: tgt = The Target containing the objective function that we want to differentiate mvals0 = The 'central' values of the mathematical parameters - i.e.
the wrapped function's origin is here. pidx = The index of the parameter that we're differentiating
Definition at line 180 of file finite_difference.py.
def src.finite_difference.fdwrap_H | ( | tgt, | |
mvals0, | |||
pidx | |||
) |
A driver to fdwrap for Hessians (see documentation for fdwrap) Inputs: tgt = The Target containing the objective function that we want to differentiate mvals0 = The 'central' values of the mathematical parameters - i.e.
the wrapped function's origin is here. pidx = The index of the parameter that we're differentiating
Definition at line 191 of file finite_difference.py.
def src.finite_difference.in_fd | ( | ) |
Invoking this function from anywhere will tell us whether we're being called by a finite-difference function.
This is mainly useful for deciding when to update the 'qualitative indicators' and when not to.
Definition at line 128 of file finite_difference.py.
def src.finite_difference.in_fd_srch | ( | ) |
Invoking this function from anywhere will tell us whether we're being called by a finite-difference function.
This is mainly useful for deciding when to update the 'qualitative indicators' and when not to.
Definition at line 135 of file finite_difference.py.
src.finite_difference.logger = getLogger(__name__) |
Definition at line 8 of file finite_difference.py.