Optimizing a ModelΒΆ

The optimization procedure will vary specified regression coefficients to minimize the value in the last period of the simulation of a specified objective function variable.

For example, to optimize the fit of the model as measured by the sum of the squares of percentage errors in the simulated value of real GDP (gdpR) and nominal GDP (gdp), we can define in the model the objective function as the last value of misses defined by

fex gdpRX = gdpR
fex gdpDX = gdpD
f miss = @sq((gdpR-gdpRX)/gdpRX)+@sq((gdpD-gdpDX)/gdpDX)
f misses = @cum(misses, miss, 0.0)

We then need to convey to the simulation program which of the many equations in the model is the objective function and which of the many regression coefficients can be varied to minimize the last value of this variable. Both of these tasks are done by the optimization specification file. By convention, its name should have the extension .OPT and it should have the form illustrated below.

misses : Name of objective function
20 : Maximum number of coefficients to be varied.
# 1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25
0.1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.1
# 1      2    3    4    5   6     7    8    9   10   11   12   13    14   15   16
0.10 0.001 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.005 0.00 1.00

The first line of the file gives the name of variable whose last value is to be minimized. The second line specifies the maximum number of parameters which will be varied in the course of the optimization. It does not hurt if it is larger than the number actually used. Here we have set the maximum at 20 but will only use 6.

The next line says that some parameters will come from the equation for vfnreR. The third line begins with a # which marks it as simply a comment to be ignored by the program. For us, however, it is very useful since it numbers the 25 regression coefficients which occur in the equation for vfnreR. The line below it gives the step sizes for each of these 25 coefficients. A coefficient given a step size of 0 is not involved in the optimization. Thus we see that coefficient 1, the intercept, is given a step size of 0.1 and that the coefficient for the 25th variable also is given a step size of 0.1. The next triplet of lines does the same for three coefficients in the cRpc equation.

The step sizes determine an initial simplex of points which are then varied by the downhill simplex downhill simplex method to find the optimum. (See Wm. Press et al., Numerical Recipies in C.) Choice of these step sizes can matter. If they are too large, some steps may take the model into regions where it does not converge. If they are too small, the algorithm may conclude that it has converged before it really gets started.

To run an optimizing simulation, click Model | Run and in the “Type of Simulation” panel, click on the button for “Optimizing.” Fill in the dates, fix file name, and results file name as usual. Also give the name of the optimization specification file. Then click OK. As usual, you will get a command prompt window and a ] prompt. You may add any sort of fix command and give a title to the run. Then give the command run.

Running the optimizing simulation will create a file with the optimized values of all regression coefficients in the model. It will have the same root name as the Optimization file but with the extension .DAT. If the optimization file was OPTSPEC.OPT, this file will be OPTSPEC.DAT. This file has exactly the same format as the HEART.DAT file created when you originally built the model. If you now wish to run the optimized model, you need only copy the OPTSPEC.DAT file to HEART.DAT and run the model. You probably first should save the original HEART.DAT file, so after optimizing the model, in G7 you should do

dos copy heart.dat original.dat
dos copy optspec.dat heart.dat

and then run the model again.

Previous topic

Running a Model - Deterministic Simulation

Next topic

Stochastic Simulation

This Page