Box constrained minimization and maximization with the L-BFGS-B algorithm.
The namespace wraps the Java implementation of L-BFGS-B bundled with the library. The algorithm is a limited-memory quasi-Newton method which works with lower and upper bounds on every variable and needs the gradient of the objective. The gradient can be given by the user or is approximated with finite differences.
The single optimizer function is lbfgsb. The algorithm settings (memory size, tolerances, line search) are built by parameters from the same options map.
Bounds are always required and are validated before the optimization starts (see fastmath.optimization.common/normalize-bounds). Infinite bounds are allowed when the initial point is given. The objective function is never evaluated outside of the bounds, also when the gradient is approximated numerically. A non-finite objective value or gradient stops the optimization with an exception.
Box constrained minimization and maximization with the L-BFGS-B algorithm. The namespace wraps the Java implementation of L-BFGS-B bundled with the library. The algorithm is a limited-memory quasi-Newton method which works with lower and upper bounds on every variable and needs the gradient of the objective. The gradient can be given by the user or is approximated with finite differences. The single optimizer function is [[lbfgsb]]. The algorithm settings (memory size, tolerances, line search) are built by [[parameters]] from the same options map. Bounds are always required and are validated before the optimization starts (see [[fastmath.optimization.common/normalize-bounds]]). Infinite bounds are allowed when the initial point is given. The objective function is never evaluated outside of the bounds, also when the gradient is approximated numerically. A non-finite objective value or gradient stops the optimization with an exception.
(lbfgsb f
{:keys [bounds initial goal vector-arg? gradient gradient-h stats?]
:as opts})Minimizes or maximizes a function within box constraints using the L-BFGS-B algorithm.
Parameters:
f (function): the objective. It receives the point as one sequence (a double[] here), or as separate arguments when :vector-arg? is false, and returns a number. It is never called outside of :bounds.opts (map): all keys of parameters (below) and:
:bounds (required) - sequence of [lo hi] pairs, one for each dimension. Infinite values are allowed when :initial is given. A flat [lo hi] is accepted for one dimension.:initial - initial point, default: the middle of the bounds. A point outside of the bounds is moved to the nearest bound.:goal - :minimize (default) or :maximize.:vector-arg? - when false, f takes separate arguments, default: true.:gradient - function of the point (always one sequence) returning the gradient of f as a sequence of numbers. It is the gradient of f itself, also when maximizing. Default: the gradient is approximated with finite differences.:gradient-h - step of the finite differences, default: 1.0e-6. Used only when :gradient is not given. Near a bound a one-sided difference is used.:stats? - return a map with additional information, default: false.parameters keys:
:m - number of stored correction pairs, the memory of the method, default: 6.:abs, :rel - absolute and relative tolerance of the projected gradient norm, default: 1.0e-8 each. The optimization stops when the norm is below :abs or below :rel times the norm of the point.:past - number of past iterations used by the stall test, default: 3. 0 disables the test.:delta - the optimization stops when the objective changed by less than this value (scaled by the objective magnitude, at least 1) over the last :past iterations, default: 1.0e-10.:max-iters - maximum number of iterations, default: 1000. 0 means unlimited.:max-submin - maximum number of iterations of the subspace minimization, default: 10.:max-linesearch - maximum number of line search iterations, default: 20.:linesearch - line search method, one of :more-thuente (or :orig, default), :more-thuente-lbfgspp (or :lbfgsb) and :lewis-overton (experimental).:xtol - relative tolerance of the line search interval, default: 1.0e-8.:min-step, :max-step - bounds on the line search step, default: 1.0e-20 and 1.0e20.:ftol - sufficient decrease parameter of the line search, default: 1.0e-4.:wolfe - curvature condition parameter of the line search, default: 0.9.:weak-wolfe? - use the weak Wolfe condition, default: true.:debug? - print the progress of the algorithm to the standard output, default: false. The setting is global and is applied on every call.Returns [point value], where point is a vector and value is the value of f. When :stats? is true, returns a map with:
:point and :value - as above,:iterations - number of iterations,:gradient - the gradient of f at the point,:status - why the optimization stopped: :converged (projected gradient norm below :abs or :rel), :stalled (the objective stopped changing, see :delta and :past) or :max-iterations.Reaching :max-iters is not an error and ends with status :max-iterations. :max-evals is not supported.
Throws ex-info for invalid bounds, options or gradient length, and an exception when the objective value or the gradient is not finite or when the line search fails.
See also parameters, fastmath.optimization/minimize, fastmath.optimization/maximize.
Minimizes or maximizes a function within box constraints using the L-BFGS-B algorithm. Parameters: - `f` (function): the objective. It receives the point as one sequence (a `double[]` here), or as separate arguments when `:vector-arg?` is `false`, and returns a number. It is never called outside of `:bounds`. - `opts` (map): all keys of [[parameters]] (below) and: - `:bounds` (required) - sequence of `[lo hi]` pairs, one for each dimension. Infinite values are allowed when `:initial` is given. A flat `[lo hi]` is accepted for one dimension. - `:initial` - initial point, default: the middle of the bounds. A point outside of the bounds is moved to the nearest bound. - `:goal` - `:minimize` (default) or `:maximize`. - `:vector-arg?` - when `false`, `f` takes separate arguments, default: `true`. - `:gradient` - function of the point (always one sequence) returning the gradient of `f` as a sequence of numbers. It is the gradient of `f` itself, also when maximizing. Default: the gradient is approximated with finite differences. - `:gradient-h` - step of the finite differences, default: `1.0e-6`. Used only when `:gradient` is not given. Near a bound a one-sided difference is used. - `:stats?` - return a map with additional information, default: `false`. [[parameters]] keys: - `:m` - number of stored correction pairs, the memory of the method, default: `6`. - `:abs`, `:rel` - absolute and relative tolerance of the projected gradient norm, default: `1.0e-8` each. The optimization stops when the norm is below `:abs` or below `:rel` times the norm of the point. - `:past` - number of past iterations used by the stall test, default: `3`. `0` disables the test. - `:delta` - the optimization stops when the objective changed by less than this value (scaled by the objective magnitude, at least 1) over the last `:past` iterations, default: `1.0e-10`. - `:max-iters` - maximum number of iterations, default: `1000`. `0` means unlimited. - `:max-submin` - maximum number of iterations of the subspace minimization, default: `10`. - `:max-linesearch` - maximum number of line search iterations, default: `20`. - `:linesearch` - line search method, one of `:more-thuente` (or `:orig`, default), `:more-thuente-lbfgspp` (or `:lbfgsb`) and `:lewis-overton` (experimental). - `:xtol` - relative tolerance of the line search interval, default: `1.0e-8`. - `:min-step`, `:max-step` - bounds on the line search step, default: `1.0e-20` and `1.0e20`. - `:ftol` - sufficient decrease parameter of the line search, default: `1.0e-4`. - `:wolfe` - curvature condition parameter of the line search, default: `0.9`. - `:weak-wolfe?` - use the weak Wolfe condition, default: `true`. - `:debug?` - print the progress of the algorithm to the standard output, default: `false`. The setting is global and is applied on every call. Returns `[point value]`, where `point` is a vector and `value` is the value of `f`. When `:stats?` is `true`, returns a map with: - `:point` and `:value` - as above, - `:iterations` - number of iterations, - `:gradient` - the gradient of `f` at the point, - `:status` - why the optimization stopped: `:converged` (projected gradient norm below `:abs` or `:rel`), `:stalled` (the objective stopped changing, see `:delta` and `:past`) or `:max-iterations`. Reaching `:max-iters` is not an error and ends with status `:max-iterations`. `:max-evals` is not supported. Throws `ex-info` for invalid bounds, options or gradient length, and an exception when the objective value or the gradient is not finite or when the line search fails. See also [[parameters]], [[fastmath.optimization/minimize]], [[fastmath.optimization/maximize]].
(parameters
{:keys [m rel abs past delta max-iters max-submin max-linesearch linesearch
xtol min-step max-step ftol wolfe weak-wolfe? debug?]
:or {ftol 1.0E-4
xtol 1.0E-8
rel 1.0E-8
max-linesearch 20
wolfe 0.9
max-iters 1000
past 3
m 6
min-step 1.0E-20
max-submin 10
max-step 1.0E20
linesearch :more-thuente
weak-wolfe? true
debug? false
abs 1.0E-8
delta 1.0E-10}})Creates the settings of the L-BFGS-B algorithm.
Parameters:
opts (map): all keys are optional.
:m - number of stored correction pairs, the memory of the method, default: 6.:abs, :rel - absolute and relative tolerance of the projected gradient norm, default: 1.0e-8 each. The optimization stops when the norm is below :abs or below :rel times the norm of the point.:past - number of past iterations used by the stall test, default: 3. 0 disables the test.:delta - the optimization stops when the objective changed by less than this value (scaled by the objective magnitude, at least 1) over the last :past iterations, default: 1.0e-10.:max-iters - maximum number of iterations, default: 1000. 0 means unlimited.:max-submin - maximum number of iterations of the subspace minimization, default: 10.:max-linesearch - maximum number of line search iterations, default: 20.:linesearch - line search method, one of :more-thuente (or :orig, default), :more-thuente-lbfgspp (or :lbfgsb) and :lewis-overton (experimental).:xtol - relative tolerance of the line search interval, default: 1.0e-8.:min-step, :max-step - bounds on the line search step, default: 1.0e-20 and 1.0e20.:ftol - sufficient decrease parameter of the line search, default: 1.0e-4.:wolfe - curvature condition parameter of the line search, default: 0.9.:weak-wolfe? - use the weak Wolfe condition, default: true.:debug? - print the progress of the algorithm to the standard output, default: false. The setting is global and is applied on every call.Returns a Parameters object.
Throws ex-info when :m, :abs, :rel, :max-linesearch or :min-step is not positive, when :past, :delta, :max-iters or :max-submin is negative, when :max-step is lower than :min-step, when 0 < :ftol < 0.5 and :ftol < :wolfe < 1 do not hold, and for an unknown :linesearch.
See also lbfgsb.
Creates the settings of the L-BFGS-B algorithm. Parameters: - `opts` (map): all keys are optional. - `:m` - number of stored correction pairs, the memory of the method, default: `6`. - `:abs`, `:rel` - absolute and relative tolerance of the projected gradient norm, default: `1.0e-8` each. The optimization stops when the norm is below `:abs` or below `:rel` times the norm of the point. - `:past` - number of past iterations used by the stall test, default: `3`. `0` disables the test. - `:delta` - the optimization stops when the objective changed by less than this value (scaled by the objective magnitude, at least 1) over the last `:past` iterations, default: `1.0e-10`. - `:max-iters` - maximum number of iterations, default: `1000`. `0` means unlimited. - `:max-submin` - maximum number of iterations of the subspace minimization, default: `10`. - `:max-linesearch` - maximum number of line search iterations, default: `20`. - `:linesearch` - line search method, one of `:more-thuente` (or `:orig`, default), `:more-thuente-lbfgspp` (or `:lbfgsb`) and `:lewis-overton` (experimental). - `:xtol` - relative tolerance of the line search interval, default: `1.0e-8`. - `:min-step`, `:max-step` - bounds on the line search step, default: `1.0e-20` and `1.0e20`. - `:ftol` - sufficient decrease parameter of the line search, default: `1.0e-4`. - `:wolfe` - curvature condition parameter of the line search, default: `0.9`. - `:weak-wolfe?` - use the weak Wolfe condition, default: `true`. - `:debug?` - print the progress of the algorithm to the standard output, default: `false`. The setting is global and is applied on every call. Returns a `Parameters` object. Throws `ex-info` when `:m`, `:abs`, `:rel`, `:max-linesearch` or `:min-step` is not positive, when `:past`, `:delta`, `:max-iters` or `:max-submin` is negative, when `:max-step` is lower than `:min-step`, when `0 < :ftol < 0.5` and `:ftol < :wolfe < 1` do not hold, and for an unknown `:linesearch`. See also [[lbfgsb]].
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |