![]()
Optimize Command
Optimize: Minimize a function of several parameters
General form:Optimize creates a new current plot 'optimizeNN' and populates it with vectors as follows:
| npar | |||||||||
| Number of parameters to optimize.
Default: 1. Limits: 0 < npar. | |||||||||
| vertices[npar] | |||||||||
| Suggested starting values for parameters.
Default: 0.0 for all. | |||||||||
| vertices[npar+1][npar] | |||||||||
| Matrix of parameter values defining a simplex.
Default: Not applicable. | |||||||||
| steps[npar] | |||||||||
| Suggested initial step sizes. These are the semi-axes of a hyperellipsoid; the
vertices of the intial simplex will lie on its surface.
Default: 1.0 for all. | |||||||||
| maxeval | |||||||||
| The maximum number of function evaluations allowed during search.
Default: 50 × npar. Limits: npar ≤ maxeval. | |||||||||
| stoppar | |||||||||
|
Stop when stoppar × step[j] < Δvertices[j].
Default: 0.0, i.e. base stopping on cost function values (see below). Limits: 0.0 ≤ stoppar < 1.0 . | |||||||||
| stopcost | |||||||||
| Stop when this value is greater than the difference between the
highest and lowest values of the cost at the points of the simplex.
Default: 1.0 × 10−3. Limits: 0.0 ≤ stopcost. | |||||||||
| ntest | |||||||||
Stopping test is applied after every ntest iterations.
Normally, set ntest to
about npar. Setting ntest to zero prevents any convergence test
being made and hence maxeval stops the iteration.
Default: npar. Limits: 0 ≤ ntest ≤ maxeval. | |||||||||
| nofit | |||||||||
| = 0 a quadratic surface fit is required (default);
= 1 the nofit flag was on the command line.
| |||||||||
| report | |||||||||
Print control parameter:
| |||||||||
The restart argument causes the optimizer to ignore any command-line
and/or default specifications for npar, vertices and steps, and read the
values of these from the current plot.
If stopcost and stoppar are both specified, both conditions must be satisfied
before the optimization stops.
CostProcedure must read from the appropriate optimize plot:
| p[npar] | |
| The point, in parameter space, at which to evaluate the cost function; | |
and, having performed its calculations, write back to the same plot:
| cost | |
| The value of the cost function evaluated at p; | |
| accept | |
CostProcedure may signal that the current value of p
violates a constraint by assigning accept the value false (i.e. 0.0).
| |
Optimize returns results by storing them in vectors:
| neval | |||||||||||||||||||||||||||||||||||||
| the number of times the cost function was evaluated.
| |||||||||||||||||||||||||||||||||||||
| vertices[n][npar] | |||||||||||||||||||||||||||||||||||||
Simplex vertices, i.e. an array of
npar+1 parameter vectors. These are sorted into increasing-cost order so
vertices[0] contains the best p tried so far.
| |||||||||||||||||||||||||||||||||||||
| values[npar+1] | |||||||||||||||||||||||||||||||||||||
Values of the cost function at the simplex vertices with
values[0] containing the lowest value found so far.
| |||||||||||||||||||||||||||||||||||||
| ifail | |||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||
Optimize attempts to fit a quadratic hypersurface in the vicinity of a minimum it has found
unless the nofit option has been specified. For this process to succeed, the cost function
must be smooth in the minimum region.
| q[npar] | |
| The position, in parameter space, of the minimum of the
fitted surface. This should be close to p.
| |
| qmin | |
| The minimum value of the
fitted surface. This should be close to the minimum value of cost.
| |
| info[npar][npar] | |
| The information matrix.
| |
| invinfo[npar][npar] | |
| The 'inverse information matrix'. If the cost function
minimized was −LOG(LIKELIHOOD) this is the covariance matrix of the parameters. If the cost
function was the sum of squares of residuals, this matrix must be multiplied by twice the
(estimated) variance of the residuals to obtain the covariance matrix.
| |
| corr[npar][npar] | |
| The correlation matrix. | |
Sequence of Operations
Optimize looks for the information it needs to run in various places using the following
order of precedence:
- values specified on the command line;
- if restarting, values from the current optimize plot;
- default values specified in previous sections.
It then performs various checks for consistency. Provided that
the check is passed, the data structure is converted to vectors and are stored
in a new - or, in the case of restart jobs, an existing - plot of type
'optimization'.
Remarks
Constraints
As an alternative to the 'let accept = false' mechanism, constraints such as
'p[2] < 5' can be expressed as a function g(p) such that g < 0 when they are
satisfied, then add a penalty to the cost function as follows:
let optim.g = p[2] - 5
if (g>0)
let cost = cost + mu * g^lambda
end
where mu and lambda are positive constants. On exit, if
- g > 0 then mu and/or lambda need increasing,
- g = 0 then mu and/or lambda need decreasing,
- g < 0 the constraints were satisfied.
Cost Functions
CostProcedure will be evaluated many times, so it should normally be designed to be fast, and not 'leak' memory. For example, if CostProcedure creates a new plot every time it is evaluated, it should also destroy one before it terminates. A warning message will be printed if MacSpice suspects a leak.
The syntax plot.vector should be used to access these variables if the current plot is changed within CostProcedure because, for example, an analysis is run. Use alter to change the values of circuit elements.
The vector cost is given the value 'NaN' before each evaluation of the cost
function. It must be set to a valid value unless the point is rejected which
is signalled by 'let accept = 0' or 'let cost = 1/0'.
Reports
The number of digits used in reports defaults to 6, but can be changed by setting the numdgt variable.
Plot Locking
The plot created by optimize will be delete-locked while optimization
is being performed. This means that, although new vectors can be created and
existing vectors can have their values changed, vectors cannot be deleted or
re-dimensioned.