Class Simplex

Start, improve and interrogate an optimisation. Unlike fitSimplex, which does this in a single step, the Simplex class creates mutable state representing a (potentially) partially-completed optimisation process, which you are then responsible for pushing around in a loop. This means that if the optimisation is slow and you want to make it cancelleable, or if you want to report back anything about the progress of the optimsiation, you are free to do so as you'll only ever hit a method here for as long as it takes to call your target function a few times.

Example

var banana = function(x: number, y: number, a: number, b: number) {
return (a - x)**2 + b * (y - x * x)**2;
};
var obj = Simplex(
(loc: number[]) => banana(loc[0], loc[1], 1, 100),
[-2, -2]);
obj.result();
obj.step();
obj.run(10);

Hierarchy

  • Simplex

Constructors

Methods

Constructors

  • Parameters

    • target: TargetFn<number[]>

      The function to be minimised

    • location: number[]

      The initial location to start the search from

    • control: Partial<SimplexControlParam> = {}

      Control parameters, as an object

    Returns Simplex

Methods

  • result(): { converged: boolean; data: any; evaluations: number; iterations: number; location: number[]; value: number }
  • Return information about the best found point so far.

    Returns { converged: boolean; data: any; evaluations: number; iterations: number; location: number[]; value: number }

    • converged: boolean

      Has the algorithm converged?

    • data: any

      Any additional data returned by the target function, for this point

    • evaluations: number

      The number of times that target has been called so far

    • iterations: number

      The number of times that step has been called so far

    • location: number[]

      The best found location

    • value: number

      The value of target(location)

  • run(maxIterations: number): { converged: boolean; data: any; evaluations: number; iterations: number; location: number[]; value: number }
  • Helper function to run the algorithm until converged. This is very basic and not really intended to be used - you should probably build logic around step directly, or if you want a simple interface use the fitSimplex function.

    Returns

    The same object as result. Note that the algorithm may not have converged, so you should check the .converged field.

    Parameters

    • maxIterations: number

      The maximum number of iterations of the algorithm (calls to step to take. If we converge before hitting this number we will return early.

    Returns { converged: boolean; data: any; evaluations: number; iterations: number; location: number[]; value: number }

    • converged: boolean

      Has the algorithm converged?

    • data: any

      Any additional data returned by the target function, for this point

    • evaluations: number

      The number of times that target has been called so far

    • iterations: number

      The number of times that step has been called so far

    • location: number[]

      The best found location

    • value: number

      The value of target(location)

  • simplex(): { location: number[]; value: number }[]
  • Returns an array of the points that make up the Simplex. This is primarily provided for visualisation or debugging, but it could also be used to derive alternative early exit criteria.

    Returns

    An array of objects, sorted from best to worst. Each object has fields location and value.

    Returns { location: number[]; value: number }[]

  • step(): boolean
  • Advance the optimiser one "step" of the algorithm. This will usually evaluate target once or twice, depending on if proposal finds an improved point or not.

    Returns

    true if the algorithm has converged, false otherwise. For details about the best point so far, see result

    Returns boolean

Generated using TypeDoc