Liking cljdoc? Tell your friends :D

fastmath.optimization.common

Internal helpers shared by fastmath.optimization, fastmath.optimization.acm and fastmath.optimization.lbfgsb.

The namespace is not part of the public API and may change without notice. It collects the option handling that every optimizer backend needs, so that each backend validates its input in exactly the same way.

Option parsing: parse-goal, resolve-vector-arg?, throw-unknown, throw-invalid-option, positive-integer-option, nonnegative-number-option.

Input validation: normalize-bounds checks and normalizes search bounds according to the capabilities of the given method; bounds-midpoint gives the default initial point.

Function adaptation: ->vector-fn turns a multi-arity function into a function of a single sequence.

Apache Commons Math glue used by the ACM backends and by linear optimization: goal-type, max-eval, max-iter, optimization-data, multivariate-optimize.

Internal helpers shared by [[fastmath.optimization]], [[fastmath.optimization.acm]] and [[fastmath.optimization.lbfgsb]].

The namespace is not part of the public API and may change without notice. It collects the option handling that every optimizer backend needs, so that each backend validates its input in exactly the same way.

Option parsing: [[parse-goal]], [[resolve-vector-arg?]], [[throw-unknown]], [[throw-invalid-option]], [[positive-integer-option]], [[nonnegative-number-option]].

Input validation: [[normalize-bounds]] checks and normalizes search bounds according to the capabilities of the given method; [[bounds-midpoint]] gives the default initial point.

Function adaptation: [[->vector-fn]] turns a multi-arity function into a function of a single sequence.

Apache Commons Math glue used by the ACM backends and by linear optimization: [[goal-type]], [[max-eval]], [[max-iter]], [[optimization-data]], [[multivariate-optimize]].
raw docstring

->vector-fnclj

(->vector-fn f vector-arg?)

Adapts a function to the single sequence calling convention.

Parameters:

  • f (function): the function to adapt.
  • vector-arg? (boolean): true when f already takes one sequence.

Returns f itself when vector-arg? is true, otherwise a function of one sequence which applies f to the elements.

Adapts a function to the single sequence calling convention.

Parameters:

- `f` (function): the function to adapt.
- `vector-arg?` (boolean): `true` when `f` already takes one sequence.

Returns `f` itself when `vector-arg?` is `true`, otherwise a function of one sequence which applies `f` to the elements.
raw docstring

bounds-midpointclj

(bounds-midpoint bounds)

Returns the middle of the bounds, the default initial point of the optimizers.

Parameters:

Returns a double[]. The middle is computed as half of the lower bound plus half of the upper bound, so it does not overflow for huge bounds. Infinite bounds give an infinite or NaN result; normalize-bounds rejects them when no initial point is given.

Returns the middle of the bounds, the default initial point of the optimizers.

Parameters:

- `bounds`: a vector of finite `[lo hi]` pairs, as returned by [[normalize-bounds]].

Returns a `double[]`. The middle is computed as half of the lower bound plus half of the upper bound, so it does not overflow for huge bounds. Infinite bounds give an infinite or NaN result; [[normalize-bounds]] rejects them when no initial point is given.
raw docstring

goal-typeclj

(goal-type goal)

Converts an optimization goal to the Apache Commons Math GoalType.

Parameters:

  • goal: :minimize, :maximize or nil (minimize), see parse-goal.

Throws ex-info for any other value.

Converts an optimization goal to the Apache Commons Math `GoalType`.

Parameters:

- `goal`: `:minimize`, `:maximize` or `nil` (minimize), see [[parse-goal]].

Throws `ex-info` for any other value.
raw docstring

max-evalclj

(max-eval max-evals)

Creates the Apache Commons Math limit on the number of function evaluations.

Parameters:

  • max-evals: maximum number of evaluations; nil means 10000.

Exceeding the limit during optimization throws an exception.

Creates the Apache Commons Math limit on the number of function evaluations.

Parameters:

- `max-evals`: maximum number of evaluations; `nil` means 10000.

Exceeding the limit during optimization throws an exception.
raw docstring

max-iterclj

(max-iter max-iters)

Creates the Apache Commons Math limit on the number of iterations.

Parameters:

  • max-iters: maximum number of iterations; nil means 10000.

Exceeding the limit during optimization throws an exception.

Creates the Apache Commons Math limit on the number of iterations.

Parameters:

- `max-iters`: maximum number of iterations; `nil` means 10000.

Exceeding the limit during optimization throws an exception.
raw docstring

multivariate-optimizeclj

(multivariate-optimize opt data stats?)

Runs an Apache Commons Math optimizer which returns a point and a value.

Parameters:

  • opt: a BaseOptimizer returning a PointValuePair.
  • data (collection): optimization data, see optimization-data.
  • stats? (boolean): return statistics along with the result.

Returns [point value] where point is a vector. When stats? is true, returns a map with :point, :value, :evaluations and :iterations.

Runs an Apache Commons Math optimizer which returns a point and a value.

Parameters:

- `opt`: a `BaseOptimizer` returning a `PointValuePair`.
- `data` (collection): optimization data, see [[optimization-data]].
- `stats?` (boolean): return statistics along with the result.

Returns `[point value]` where `point` is a vector. When `stats?` is `true`, returns a map with `:point`, `:value`, `:evaluations` and `:iterations`.
raw docstring

nonnegative-number-optionclj

(nonnegative-number-option options option default)

Reads an option which has to be a finite number not less than 0.

Parameters:

  • options (map): the options of an optimizer.
  • option (keyword): the key to read.
  • default (number): the value used when the option is missing or nil.

Returns a double. Throws ex-info (see throw-invalid-option) for a negative, infinite or NaN value, and for a value which is not a number.

See also positive-integer-option.

Reads an option which has to be a finite number not less than `0`.

Parameters:

- `options` (map): the options of an optimizer.
- `option` (keyword): the key to read.
- `default` (number): the value used when the option is missing or `nil`.

Returns a `double`. Throws `ex-info` (see [[throw-invalid-option]]) for a negative, infinite or `NaN` value, and for a value which is not a number.

See also [[positive-integer-option]].
raw docstring

normalize-boundsclj

(normalize-bounds method bounds initial)

Validates search bounds for the given optimization method and returns them in the canonical form.

Parameters:

  • method (keyword): :brent, :bobyqa, :cmaes, :sceua, :nelder-mead, :multidirectional-simplex, :lbfgsb, :powell, :conjugate-gradient or :non-linear-conjugate-gradient.
  • bounds: a sequence of [lo hi] pairs, one per dimension, or nil. A flat [lo hi] is accepted for one dimension.
  • initial: the initial point (a number for one dimension or a sequence) or nil.

Rules for all methods: no nil or NaN, lo <= hi, lo is not +Inf and hi is not -Inf, the number of pairs equals the length of initial when it is given, and infinite bounds require initial (no midpoint can be defined).

Rules per method:

  • :brent - bounds are required, exactly one pair, finite with lo < hi.
  • :bobyqa and :cmaes - bounds are required and finite (lo = hi is allowed).
  • :sceua - bounds are required and finite with lo < hi, since the whole population is sampled from them.
  • :nelder-mead and :multidirectional-simplex - bounds are optional (they only size the initial simplex); when given they are finite with lo < hi.
  • :lbfgsb - bounds are required, infinite values are allowed.
  • :powell, :conjugate-gradient and :non-linear-conjugate-gradient - bounds are optional and only checked structurally.

Returns a vector of [lo hi] pairs of doubles, or nil when the method accepts missing bounds and bounds is nil.

Throws ex-info with {:method :bounds :initial :reason} when a rule is violated, and with {:method method, :allowed ...} for an unknown method.

Validates search bounds for the given optimization method and returns them in the canonical form.

Parameters:

- `method` (keyword): `:brent`, `:bobyqa`, `:cmaes`, `:sceua`, `:nelder-mead`, `:multidirectional-simplex`, `:lbfgsb`, `:powell`, `:conjugate-gradient` or `:non-linear-conjugate-gradient`.
- `bounds`: a sequence of `[lo hi]` pairs, one per dimension, or `nil`. A flat `[lo hi]` is accepted for one dimension.
- `initial`: the initial point (a number for one dimension or a sequence) or `nil`.

Rules for all methods: no `nil` or NaN, `lo <= hi`, `lo` is not `+Inf` and `hi` is not `-Inf`, the number of pairs equals the length of `initial` when it is given, and infinite bounds require `initial` (no midpoint can be defined).

Rules per method:

- `:brent` - bounds are required, exactly one pair, finite with `lo < hi`.
- `:bobyqa` and `:cmaes` - bounds are required and finite (`lo = hi` is allowed).
- `:sceua` - bounds are required and finite with `lo < hi`, since the whole population is sampled from them.
- `:nelder-mead` and `:multidirectional-simplex` - bounds are optional (they only size the initial simplex); when given they are finite with `lo < hi`.
- `:lbfgsb` - bounds are required, infinite values are allowed.
- `:powell`, `:conjugate-gradient` and `:non-linear-conjugate-gradient` - bounds are optional and only checked structurally.

Returns a vector of `[lo hi]` pairs of doubles, or `nil` when the method accepts missing bounds and `bounds` is `nil`.

Throws `ex-info` with `{:method :bounds :initial :reason}` when a rule is violated, and with `{:method method, :allowed ...}` for an unknown method.
raw docstring

optimization-dataclj

(optimization-data data)

Converts a collection of Apache Commons Math optimization data (goal, limits, objective, bounds, initial guess, ...) to the array expected by optimizers.

Converts a collection of Apache Commons Math optimization data (goal, limits, objective, bounds, initial guess, ...) to the array expected by optimizers.
raw docstring

parse-goalclj

(parse-goal goal)

Validates an optimization goal.

Parameters:

  • goal: :minimize, :maximize or nil.

Returns the goal keyword; nil means :minimize. Throws ex-info for any other value.

See also goal-type.

Validates an optimization goal.

Parameters:

- `goal`: `:minimize`, `:maximize` or `nil`.

Returns the goal keyword; `nil` means `:minimize`. Throws `ex-info` for any other value.

See also [[goal-type]].
raw docstring

positive-integer-optionclj

(positive-integer-option options option default)

Reads an option which has to be an integer not less than 1.

Parameters:

  • options (map): the options of an optimizer.
  • option (keyword): the key to read.
  • default (long): the value used when the option is missing or nil.

Returns a long. Any fixed-size integer type is accepted (long, int, short, byte), a double, a ratio or a big integer is not. Throws ex-info (see throw-invalid-option) for any other value.

See also nonnegative-number-option.

Reads an option which has to be an integer not less than `1`.

Parameters:

- `options` (map): the options of an optimizer.
- `option` (keyword): the key to read.
- `default` (long): the value used when the option is missing or `nil`.

Returns a `long`. Any fixed-size integer type is accepted (`long`, `int`, `short`, `byte`), a double, a ratio or a big integer is not. Throws `ex-info` (see [[throw-invalid-option]]) for any other value.

See also [[nonnegative-number-option]].
raw docstring

resolve-vector-arg?clj

(resolve-vector-arg? method vector-arg?)

Resolves whether the optimized function receives its arguments as a single sequence.

Parameters:

  • method (keyword): optimization method.
  • vector-arg?: true, false or nil (not given).

An explicit boolean is returned as given. When vector-arg? is nil, the default is false for :brent (the function receives a number) and true for every other method (the function receives a sequence).

Returns a boolean.

Resolves whether the optimized function receives its arguments as a single sequence.

Parameters:

- `method` (keyword): optimization method.
- `vector-arg?`: `true`, `false` or `nil` (not given).

An explicit boolean is returned as given. When `vector-arg?` is `nil`, the default is `false` for `:brent` (the function receives a number) and `true` for every other method (the function receives a sequence).

Returns a boolean.
raw docstring

throw-invalid-optionclj

(throw-invalid-option option value reason)

Throws ex-info reporting an invalid value of an option.

Parameters:

  • option (keyword): name of the option, for example :complexes.
  • value: the rejected value.
  • reason (string): what the value has to satisfy.

The exception data is {:option option :value value :reason reason}. Never returns.

See also throw-unknown, positive-integer-option, nonnegative-number-option.

Throws `ex-info` reporting an invalid value of an option.

Parameters:

- `option` (keyword): name of the option, for example `:complexes`.
- `value`: the rejected value.
- `reason` (string): what the value has to satisfy.

The exception data is `{:option option :value value :reason reason}`. Never returns.

See also [[throw-unknown]], [[positive-integer-option]], [[nonnegative-number-option]].
raw docstring

throw-unknownclj

(throw-unknown what value allowed)

Throws ex-info reporting an option value which is not one of the allowed ones.

Parameters:

  • what (keyword): name of the option, for example :goal.
  • value: the rejected value.
  • allowed (collection): the accepted values.

The exception data is {what value, :allowed allowed}. Never returns.

Throws `ex-info` reporting an option value which is not one of the allowed ones.

Parameters:

- `what` (keyword): name of the option, for example `:goal`.
- `value`: the rejected value.
- `allowed` (collection): the accepted values.

The exception data is `{what value, :allowed allowed}`. Never returns.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close