Optimizers

Curve fitting is an iterative process of finding parameters of mathematical function that has the best fit to a series of experimental data points. In ESCAPE optimizer objects of type optimizer_obj do curve fitting in terms of several algorithms:

  • Levenberg-Marquardt [1], [2] which belongs to non-linear least-square algorithms,

  • Differential evolution [3] - stochastic evultionary based algorithm which optiizes a model by maintaining a population of candidate solutions, iteratively combining them with a simple formulae and keeping a candidate with the best fitness.

escape.core.optimizer.levmar(name, stack, ftol=1e-10, xtol=1e-10, gtol=1e-10, maxiter=300, maxfev=5000, nupdate=1)

Creates Levenberg-Marquardt optimizer.

Parameters:
stack: modelstack_obj, list of models or model_obj

Models to be optimized.

ftol: non-negative double value

Measures the relative error desired in the sum of squares, i.e. cost function.

xtol: non-negative double value

Measures the relative error desired in the approximate solution.

gtol: non-negative double value

Measures the orthogonality desired between the cost function vector and the columns of the jacobian.

maxiter: non-negative integer

Maximum number of iterations.

maxfev: non-negative integer

Maximum number of cost function evaluations.

nupdate: non-negative integer

Controls calling of ‘on_iterate’ slot.

Returns:

instance of optimizer_obj

escape.core.optimizer.diffevol(name, stack, popsize=5, strategy='best1bin', maxiter=300, mincost=1e-5, minconv=1e-3, mutation=0.5, crossover=0.5, polish_candidate_maxiter=0, polish_final_maxiter=300, nupdate=1)

Differential Evolution is stochastic algorithm to find the minimum of cost function. It can search large areas of candidate space, but often requires larger numbers of function evaluations than conventional gradient-based techniques.

Parameters:
stack: modelstack_obj, list of models or model_obj

Models to be optimized.

popsizeint, optional

A multiplier for setting the total population size. The population has popsize * num_params individuals.

strategystr, optional
The differential evolution strategy to use. Should be one of:
  • ‘best1bin’

  • ‘best1exp’

  • ‘rand1exp’

  • ‘randtobest1exp’

  • ‘best2exp’

  • ‘rand2exp’

  • ‘randtobest1bin’

  • ‘best2bin’

  • ‘rand2bin’

  • ‘rand1bin’

The default is ‘best1bin’.

maxiterint, optional

The maximum number of generations over which the entire population is evolved.

mincost: double, optional

When cost function reaches this value, optimizer will be terminated.

minconvfloat, optional

Relative tolerance for convergence.

mutationfloat or tuple(float, float), optional

The mutation constant. In the literature this is also known as differential weight, being denoted by F. If specified as a float it should be in the range [0, 2]. Larger values increase searching radius, but slow down convergence.

crossoverfloat, optional

The recombination constant, should be in the range [0, 1]. In the literature this is also known as the crossover probability, being denoted by CR. Increasing this value allows a larger number of mutants to progress into the next generation, but at the risk of population stability.

polish_candidate_maxiterint, optional

Maximum number of iterations for LM algorithm after every iteration. LM algorithm improves quality of candidates in the population matrix bringing them closer to the minimum. If zero, no polishing is applied for each candidate.

polish_final_maxiterint, optional

Maximum number of iterations for final polishing using LM optimizer.

nupdate: non-negative integer

Controls calling of ‘on_iterate’ slot.

Returns:

instance of optimizer_obj

class escape.core.optimizer.optimizer_obj

Wrapper class for ESCAPE optimizers.

best_cost
Returns:

Best cost for stochastic methods or final cost for levnar

cost_history

Returns cost history as a python list.

finalization_method

Used to set custom finalization method.

initial_parameters

Returns initial parameters values.

initialization_method

Used to set custom initialization method.

iteration_method

Used to set custom iteration method.

load_parameters(self, fn)

Load parameters from ASCII file with name ‘fn’.

modelstack
Returns:

Modelstack instance.

name
Returns:

Name of optimizer object.

num_of_evaluations
Returns:

Number of function evaluations used for curve fitting.

num_of_iterations
Returns:

Number of iterations used for curve fitting.

num_of_params
Returns:

Number of parameters.

on_finalized(self)

Slot which is activated after optimization.

on_initialized(self)

Slot which is activated during optimizer’s initialization.

on_iteration(self)

Slot which is activated every n-th iteration. Iteration number ‘n’ is set with ‘nupdates’ setting.

parameter(self, size_t i)
reset_to_initial(self)

Reset parameters values to initial values.

save_parameters(self, fn)

Saves parameters to ASCII file with name ‘fn’.

shake(self)

Sets random values to all non-fixed independent parameters.

status_code
Returns:

Status code.

status_msg
Returns:

Status message.

stop(self)

Interrupts optimization process.

wait(self)

Waits with blocking for the optimizer to finish optimization process. Works if optimizer has been started asynchronously.