N x 1
vector, denoted \(\psi\). Either
MyObjective
. In FiveO, MyObjective
is an Ox class
derived from one of the built-in classes derived from the base Objective. The objective ƒ()
is the column sum of MyObjective::vfunc()
, a user-provided function (method). The system would be the column itself, not the sum.
Unlike non-OOP approaches, the parameter vector \(\psi\) is not represented (simply) as a vector of real numbers. Instead, individual parameters are
members of MyObjective
and are objects derived from the Parameter class. So \(\psi\) is internally stored as a list (an OxArray
) of parameters, but in MyObjective
each parameter is simply a variable, like x or y. Parameters can be constrained and related to each other. A ParameterBlock will hold a vector of parameters to be treated together, like the coefficient vector β in a regression.
Optimization/root-finding is carried out by invoking one of several standard algorithms which are classes derived from the base Algorithm class.
The algorithm operating on MyModel
is denoted Alg
(to avoid repeatedly writing the algorithm applied to the objective/system ...). Multiple objectives and nested objectives can be handled by creating new objects (new instances of
MyObject
or different classes).
This is a major distinction between FiveO and DDP, which is designed to hold just one DP model at a time.
FiveO is designed to optimize over a handful, dozens, or a few hundred parameters, and problems of this scale do not tax
the memory capacity of computers. Thus, almost all members of Objective are automatic, specific to the new
object. (On the other hand, DDP is designed to represent very large state spaces so as many members of that class are declared static as possible.
Alg
begins, is denoted x.0
. Thus the first element of \(\psi\) is initially set to x0.0
. The current value of x at some point in the algorithms operation is x.v
. The open range of feasible values for x, for a parameter that an algorithm can vary, is an open interval denoted x.I
, where x.I
⊆ ℜ. For example, if x is a Free parameter it can take on values in the range x.I = (-∞,+∞)
. A Positive parameter has interval (0,∞)
. A key feature of FiveO is that the bounds of x.I
can be dynamic: they can depend on the current values of other elements of \(\psi\). This dependence must be forward: the range of a parameter can only depend on elements that come before it in \(\psi\). That is, for i > 0
, the interval can be written explicitly as xi.I(x0.v, …, xi‾.v). Using x0.v emphasizes that the interval can depend on the current values of preceding values, and then xi.v ∈ xi.I. For standard algorithms to work, the intervals must always be smooth functions of their arguments.
A parameter of class Determined will not be under the control of the algorithm. That is, a determined parameter is a point, or closed interval of the form x.I = [d,d].
. The value d
is determined by something else, usually a fixed constant or a function of other parameters in \(\psi\). For example, a determined parameter could be set equal to the average of two other parameters, z = (x+y)/2
. FiveO would ensure that restriction on z holds. The algorithm knows only about x and y. Two or more parameters can form a ParameterBlock, denoted as upper case Roman (X, Y, etc.). This allows MyModel
to refer to a single variable which is a vector not a scalar. Parameter blocks are, in effect, sub-vectors of the overall parameter vector.
The parameter vector, denoted \(\psi\), generically takes the form
$$\psi = \pmatrix{x_0& x_1 &\cdots& x_{N-1}},$$
where N‾ is shorthand for N-1. \(\psi\) is built up by adding parameters and parameter blocks to it. The number of dimensions, N, is also written \(\psi\).N. The parameter space, Ψ
, is the Cartesian product of the intervals for the elements of \(\psi\),
$$\Psi \equiv \times_{n=0}^{N-1}\psi_n.I.$$
MyObject
may tell Alg
not to vary some parameters in \(\psi\) directly. A Determined parameter does not have an interval, it has a point value, x.I ∈ ℜ. As with feasible intervals, x.I can be a function of the current value of preceding parameters. The feasible parameter space can only be defined implicitly:
$$\Psi \equiv \{\psi = (x_0 \cdots x_{N-1}) : x_0 \in x_0.I, x_1\in x_1.I(x_0), \dots ,x_{N-1}\in x_{N-1}.I(x_0,\dots,x_{N-2}) \}.$$
By using predefined parameter classes and parameter blocks this complex and very flexible parameter space emerges naturally from the parameters added to MyModel
.
Alg
, as a sequential algorithm, can be thought of as a function \(S: \Re^N\rightarrow \Re^N.\) S maps the starting vector \(\psi\).0, to a final value, \(\psi^S \approx \psi^\star\).
MyObject
should include these elements
compilationstage)
MyObject
as derived from the Objective classvfunc
new
objects derived from Parameter to the data members for \(\psi\) elementsL.optobj
, where L is the string label assigned to the objective (L).
MyObject
can save the current vector (whether best or not) using Save(). The format of the file is not simply a vector of numbers. It is a summary of the problem and the current state of the solution process. The .optobj
file is designed to be loaded back into FiveO using Load(). Load()
will check some aspects of the file for consistency, read in starting values, \(\psi\).O and ignore the other information. The parameter vector in the file can be edited to reset the values. MyObject
will always hard codestarting values for parameters when they are created. The code can be written so that these hard values are only used if the person wants to complete restart. Otherwise, the starting vector, \(\psi\).O, will be loaded from a file:
if (!Load(fn)) Encode();If
fn=-1
then Load()
will return FALSE and do nothing. Then Encode(0)
will use the hard-coded values for \(\psi\).0. On the other hand, if fn = "hello"
, Load() will try to load values from hello.oxobj
, returning TRUE if successful. Finally, if fn=0
it will do the same but using the default file name, L.optobj
. UseCheckPoint
to the algorithm's Iterate()
.
myobj
contains a 4x1 vector of parameters, \(x\). The following segments of code explain how the user would change their code while changing the objective and restarting the optimization.
x = new Coefficients("x",zeros(4,1)); myobj->Parameters(x); bfgs = new BFGS(myobj); bfgs -> Iterate();
.optobj
file to start at 15 instead of 15000. Other changes made to the objective will shift the optimum in other ways as well. The algorithm should restart with the initial Hessian because changes to the objective mean the old one is not appropriate given the rescaling.
x = new Coefficients("x",zeros(4,1)); myobj->Parameters(x); myobj->Load(); // new, read from the default .optobj file bfgs = new BFGS(myobj); bfgs -> Iterate();
Load()
could specify a different file to read from, but in this case the file that the previous attempt saved is used.
x = new Coefficients("x",zeros(4,1)); myobj->Parameters(x); myobj->Load(); bfgs = new BFGS(myobj); bfgs -> Iterate(UseCheckPoint); //restart the algorithm where it left off
Load()
still happens but reading the chkpt
file wipes out those values. They would be the same.
maximize
already.Item | In Ox::maximize | In FiveO |
---|---|---|
The objective ƒ() : ℜN→ℜ |
MyObj(x,v,G,H){ ··· } |
class MyObj : BlackBox { ··· vfunc(); } MyObj::vfunc() {···} method with a particular name of a class derived from Objective. |
The parameter vector
$$\psi \equiv \pmatrix{x_0& x_1 &\dots &x_{N-1}}$$
A single parameter x
Initial value x0. Current value: x |
psi = new matrix(N,1);A position in psi
Starting values sent to a function. Extracted by the user: |
x = new Parameter("x",0.0); Parameters(x); ⋮ CV(x); x.v |
Related Parameters (e.g. Coefficients β) |
beta = x[2:8]; yhat = x*beta; |
beta = new Coefficients("beta",7,0); ⋮ yhat = x*CV(beta); beta.v or CV(q) |
Open interval constraints For example, 0< q < 1 |
|
prob = new Probability("p",0.3); |
Restrictions Across Parameters |
p = x[0:4] | 1-sumc(x[0:4]); |
p = new Simplex("p",6); |
Algorithms | MaxBFGS(f,…) |
obj -> Quasi(BFGS,0,0); |
Objectives that are not a BlackBox \(f = \sum f_i(\psi_i)\) | Up to the user to program | Efficient and simple handling of Separable and Mixture objectives. |
Long execution times | Current best vector not saved automatically. | Automatic Save of current best, which can be Loaded to restart. |
Modelbase
already.maximize
are low level ones that leave a great deal of work for the user. However, Ox provides a class that provides a higher level function, Modelbase
. It would often be a better and more convenient way to develop an econometric application than a direct use of maximize
. And its approach can be better than FiveO for coding econometric models to account for variable selection, parameter definitions that are primarily coefficients on variables.
FiveO is not concerned with variables, observations and coefficients. Rather, it is concerned with parameterizing a model that involves optimization in a much more general sense than something related to linear econometric models. The fact that the objective may be related to data as well is not primary to FiveO.
In Modelbase
aspects of parameters are stored separately, at least from the user's perspective. Parameters can be fixed or free, but other kinds of constraints and relationships between parameters are left to the user. A key difference with FiveO is that parameters are represented as objects derived from built-in parameter types. Parameters are created using a class that captures the constraints on the parameter and its relation to other parameters. For example, with one line of code a user can add a vector of parameters that are guaranteed to be Increasing during optimization: x1 >x2 > ··· > xM.
Functions | ||
Explore | Take a random walk in the parameter space of a model. |
Public methods | ||
Estimate |
model | Object that has a Solve() method.
|
Ncalls | integer, number of calls, default=0, no end to calls |
Chol | Cholesky argument to send to Iterate(). Set to 0 to use default identity matrix. |
... | Parameters or arrays of Parameters to wander over.
This routine creates a NoObjective objective, which calls method->Solve() .
It creates a RandomSearch algorithm and then iterates on it. These objects are deleted if/when
the number of calls reaches Ncalls . |