(best-of & pairs)
Default selection function for the best possible point. This function chooses the point out of (a, l, r, b) with the minimum function value.
Default selection function for the best possible point. This function chooses the point out of (a, l, r, b) with the minimum function value.
(convergence-fn {:keys [converged? fn-tolerance arg-tolerance]})
Returns a fn that returns true if any of the following are true:
fn-tolerance
of the smallest bound,convergence?
(if supplied) returns truearg-tolerance
absolute distance,false otherwise.
Returns a fn that returns true if any of the following are true: - the max interior value is within `fn-tolerance` of the smallest bound, - `convergence?` (if supplied) returns true - the bounds are within `arg-tolerance` absolute distance, false otherwise.
(extend-pt x away-from)
generate a new point by extending x away from away-from
. The invariant is
that x
sits between the new point and away-from
at the golden ratio
point.
generate a new point by extending x away from `away-from`. The invariant is that `x` sits between the new point and `away-from` at the golden ratio point.
(golden-cut from to)
Returns the point between from
and to
that cuts the region between the two
into two sections in golden-ratioed proportion to each other.
For example, depending on the ordering of from
and to
, x
would be
either:
from------x1---to
to---x2------from
Such that from->x1 / from->to == to->x2 / from->x1
.
Returns the point between `from` and `to` that cuts the region between the two into two sections in golden-ratioed proportion to each other. For example, depending on the ordering of `from` and `to`, `x` would be either: `from------x1---to` `to---x2------from` Such that `from->x1 / from->to == to->x2 / from->x1`.
(golden-section-max f xa xb)
(golden-section-max f xa xb opts)
For convenience, we also provide the sister-procedure for finding the maximum of a unimodal function using the golden section method.
Negate the function, minimize, negate the result.
For convenience, we also provide the sister-procedure for finding the maximum of a unimodal function using the golden section method. Negate the function, minimize, negate the result.
(golden-section-min f xa xb)
(golden-section-min f
xa
xb
{:keys [choose callback]
:or {choose best-of callback (constantly nil)}
:as opts})
Golden Section search attempts to locate the minimum of the supplied function
f
by evaluating points located at golden-ratioed intervals between the two
starting endpoints a
and b
. This method is slow, steady and reliable.
Supports the following optional keyword arguments:
:converged?
is an optional predicate accepting five arguments:
[a fa]
[l fl]
[r fr]
[b fb]
current-iteration
If the supplied fn
returns true, it will signal convergence and the
optimizer will return. Returning false will continue.
:choose
is called at the final step of optimization with all 4 points and
their fn values (see the first four arguments to :converged?
), and returns
the final choice.
:callback
receives all 5 arguments on every iteration.
:maxiter
Maximum number of iterations allowed for the minimizer. Defaults to
1000.
:maxfun
Maximum number of times the function can be evaluated before exiting.
Defaults to 1000.
:fn-tolerance
check that the minimal value of any of the checked points is
within the maximum of f(a) or f(b).
:arg-tolerance
check that a
and b
are within this supplied absolute
distance.
Golden Section search attempts to locate the minimum of the supplied function `f` by evaluating points located at golden-ratioed intervals between the two starting endpoints `a` and `b`. This method is slow, steady and reliable. Supports the following optional keyword arguments: `:converged?` is an optional predicate accepting five arguments: `[a fa]` `[l fl]` `[r fr]` `[b fb]` `current-iteration` If the supplied `fn` returns true, it will signal convergence and the optimizer will return. Returning false will continue. `:choose` is called at the final step of optimization with all 4 points and their fn values (see the first four arguments to `:converged?`), and returns the final choice. `:callback` receives all 5 arguments on every iteration. `:maxiter` Maximum number of iterations allowed for the minimizer. Defaults to 1000. `:maxfun` Maximum number of times the function can be evaluated before exiting. Defaults to 1000. `:fn-tolerance` check that the minimal value of any of the checked points is within the maximum of f(a) or f(b). `:arg-tolerance` check that `a` and `b` are within this supplied absolute distance.
(stop-fn {:keys [maxiter maxfun fn-counter]})
Returns a fn that returns true if any of the following are true::
fn-counter
atom contains a value > maxfun
maxiter
iterationsfalse otherwise.
Returns a fn that returns true if any of the following are true:: - the supplied `fn-counter` atom contains a value > `maxfun` - the loop has exceeded `maxiter` iterations false otherwise.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close