next up previous contents
Next: 4.5.5 Example of a Up: 4.5 Integration into a Previous: 4.5.3 SIESTA Optimizer Module


4.5.4 Example of a Calibration Task

In this calibration task a quadratic function should be fitted to a given dataset. The model function

\begin{displaymath}
\hat{f}(a_1, a_2, a_3, x) = a_1 + a_2 \cdot x + a_3 \cdot x^2
\end{displaymath} (4.47)

depends on x, the input variable from the dataset. a1, a2, and a3 are the parameters of the model which have to be fitted. The measured data for which this model should be fitted is listed in Table 4.1.


Table 4.1: Table of the measured data.
x f(x)
-4.0 45.9
0.0 79.8
1.0 78.9
3.0 77.1
5.0 62.5

It should be noticed that this task can be solved using the methods described in Section 3.2.1. This short example should only show how the optimization task and the model function are defined.

The main file describing the calibration task is the experiment file listed in Figure 4.10. The file has a LISP like syntax where the first keyword describes the type of optimization (here a calibration task is chosen) followed by some parameter assignments. Here the three parameters model, free, and target are discussed, the others will be described later.

Figure 4.10: The experiment file describes the calibration task.
(calibration 
    (model     "lmmintest3.mod")
    (free       a1 a2 a3)
    (target     residuum)
    (gradient   1e-11)
    (tolerance  1e-6)
    (log        "lmmintest3.log")
    (dump       "lmmintest3.crv"))

The model value assigns a file, located in the same directory as the experiment file, containing the evaluation model. In free a list of input ports of the evaluation model is defined; these can be varied by the optimizer. The ranges and start values are defined in the model. In target the target vector is assigned. This must be an output port of the model function and of type vector. The dimension of this vector must be greater than the number of free parameters.

Figure 4.11: The submodel evaluates the fitted model function.
(arithmetic-model
 (inputs
  (a1      bound-float   0.0     -100.     100.)
  (a2      bound-float   0.0      -10.      10.)
  (a3      bound-float   0.0      -10.      10.)
  (x       float         1.0)
  (f       float         1.0))
 (outputs
  (error   float))
 (operators
  (error (- 
           (+ a1 
              (* a2 x) 
              (* a3 x x)) 
           f))))

Figure 4.12: The module file describes the model analyzed in the calibration task.
(network-model 
 (submodel calculate1 "lmmintest3calc.mod"
           (inputs 
            (private (x -4.) 
                     (f 45.9))))

 (submodel calculate2 "lmmintest3calc.mod"
           (inputs
            (private (x 0.) 
                     (f 79.8))))

 (submodel calculate3 "lmmintest3calc.mod"
           (inputs
            (private (x 1.) 
                     (f 78.9))))
 (submodel calculate4 "lmmintest3calc.mod"
           (inputs
            (private (x 3) 
                     (f 77.1))))
 (submodel calculate5 "lmmintest3calc.mod"
           (inputs
            (private (x 5.) 
                     (f 62.5))))

 (submodel merge 
           (float-to-vector-model
              (inputs  (vec1 float) 
                       (vec2 float)
                       (vec3 float)
                       (vec4 float)
                       (vec5 float)))
           (inputs 
            (connect (vec1 calculate1 error)
                     (vec2 calculate2 error)
                     (vec3 calculate3 error)
                     (vec4 calculate4 error)
                     (vec5 calculate5 error)))
           (outputs 
            (public  (vector residuum)))))

A model or submodel consists of input ports, output ports and the actions which produce the output data from the input. The actions are defined by the type of the model, the so called model class. In Figure 4.11 a submodel of the class arithmetic-model is shown. In the inputs part of the model declaration a list of input parameters is given. Here for each input parameter the name used inside the model is assigned (for instance a1), the parameter type is declared (here bound-float or float) and a value is set. The input parameters of the type bound-float also have a minimum and maximum value. In the outputs section (in this example only one output error is declared) the parameter value has to be omitted. The arithmetic-model has an operators part, where the algorithm for the calculation of the outputs is declared. Here the calculation of difference between the analytical function $\hat f$ from (4.47) and the measured value f is coded.

In Figure 4.12 the definition of the evaluation model is shown. A model can consist of several submodels declared in the same or obtained from a separate file. In this model the difference between the approximated model function and the measured data is calculated for several x values. The model function listed in Figure 4.11 is included in the submodels calculate1 to calculate5. In each submodel the measured data is subtracted from the fit function (4.47). The result is a scalar; the error. These scalar values are then merged into the vector residuum in the merge submodel which is of type float-to-vector-model.

In Figure 4.12 the values for x and f in the five evaluations of the submodel lmmintest3calc.mod are set according to the data from Table 4.1.

The optimization process needs 29 evaluations of the target function (including 7 gradient evaluations where each needs 3 evaluations). The values for a1, a2, and a3 chosen by the optimizer are shown in Figure 4.13 and Figure 4.14.

Figure 4.13: Values for a2 and a3.
\includegraphics[width=\linewidth]{graphics/lmminplot1.ps}

Figure 4.14: Values for a1.
\includegraphics[width=\linewidth]{graphics/lmminplot2.ps}

The exact result of can be calculated by solving (3.6) using the methods described in Section 3.2.2

\begin{displaymath}
\left (
\begin{array}{c}
45.9 \\ 79.8 \\ 78.9 \\ 77.1 \\...
...epsilon_3 \\ \epsilon_4 \\ \epsilon_5
\end{array} \right )
.
\end{displaymath} (4.48)

A comparison of the results found by the optimizer and by solving the linear system is listed in Table 4.2. In this example the difference between the exact result and the result found by the optimizer is less than six significant digits.


Table 4.2: Comparison of the results from the optimizer and the exact solution.
  optimizer solver
a1 78.61453 78.61453
a2 3.106243 3.106244
a3 -1.262821 -1.262821


next up previous contents
Next: 4.5.5 Example of a Up: 4.5 Integration into a Previous: 4.5.3 SIESTA Optimizer Module

R. Plasun