|
a |
|
b/OptimLib3.def |
|
|
1 |
DEFINITION MODULE OptimLib3;
|
|
|
2 |
|
|
|
3 |
(*------------------------------------------------------------------------*)
|
|
|
4 |
(* Minimirungsroutinen fuer Funktionen mit bekannter 1. Ableitung. *)
|
|
|
5 |
(* Minimization of a function of several variables with derivative *)
|
|
|
6 |
(*------------------------------------------------------------------------*)
|
|
|
7 |
(* Please not that there is not OptimLib2 at the moment, this is reserved *)
|
|
|
8 |
(* for Michael Powells "bobyqa" routine (in preparation, a goto free *)
|
|
|
9 |
(* Fortran 90 version is already available). *)
|
|
|
10 |
(*------------------------------------------------------------------------*)
|
|
|
11 |
(* Implementation : Michael Riedl *)
|
|
|
12 |
(* Licence : GNU Lesser General Public License (LGPL) *)
|
|
|
13 |
(*------------------------------------------------------------------------*)
|
|
|
14 |
|
|
|
15 |
(* $Id: OptimLib3.def,v 1.4 2018/04/26 10:17:19 mriedl Exp mriedl $ *)
|
|
|
16 |
|
|
|
17 |
FROM Deklera IMPORT PMATRIX;
|
|
|
18 |
FROM LMathLib IMPORT Funktion1,FunktionN;
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
TYPE TGradient = PROCEDURE(VAR ARRAY OF LONGREAL,
|
|
|
22 |
CARDINAL,
|
|
|
23 |
VAR ARRAY OF LONGREAL);
|
|
|
24 |
|
|
|
25 |
(*----------------------------------------------------------------*)
|
|
|
26 |
(* A procedure of type "TGradient" calculates the gradient of a *)
|
|
|
27 |
(* given function of N parameters at point(s) X and returns the *)
|
|
|
28 |
(* result in vector G and will be called as "Gradient(X,N,G)" *)
|
|
|
29 |
(*----------------------------------------------------------------*)
|
|
|
30 |
|
|
|
31 |
PROCEDURE MinInDer(VAR a,b : LONGREAL;
|
|
|
32 |
f : Funktion1;
|
|
|
33 |
df : Funktion1;
|
|
|
34 |
ftol : Funktion1;
|
|
|
35 |
VAR x,y : LONGREAL;
|
|
|
36 |
VAR xmin : LONGREAL;
|
|
|
37 |
VAR cnt : CARDINAL);
|
|
|
38 |
|
|
|
39 |
(*----------------------------------------------------------------*)
|
|
|
40 |
(* MinInDer delivers the calculated minimum value of the *)
|
|
|
41 |
(* function, defined by f(x), on the interval with end points *)
|
|
|
42 |
(* a and b. The function is approximated by a cubic as given by *)
|
|
|
43 |
(* Davidon [1], the structure is similar to the structure of the *)
|
|
|
44 |
(* program given by Brent [2] *)
|
|
|
45 |
(* *)
|
|
|
46 |
(* The meaning of the formal parameters is: *)
|
|
|
47 |
(* *)
|
|
|
48 |
(* a,b : The start and end point of the interval on which the *)
|
|
|
49 |
(* function has to be minimized *)
|
|
|
50 |
(* fx : the function is given by the actual parameter fx *)
|
|
|
51 |
(* which depends on x *)
|
|
|
52 |
(* dfx : the derivative of the function is given by the actual *)
|
|
|
53 |
(* parameter dfx which depends on x, fx and dfx are *)
|
|
|
54 |
(* evaluated successively for a certain value of x *)
|
|
|
55 |
(* tolx : the tolerance is given by the actual parameter tolx, *)
|
|
|
56 |
(* which may depend on x, a suitable tolerance function *)
|
|
|
57 |
(* is: abs(x) * re + ae, where re is the relative *)
|
|
|
58 |
(* precision desired and ae is an absolute precision *)
|
|
|
59 |
(* which should not be chosen equal to zero. *)
|
|
|
60 |
(* x : On exit the calculated approximation of the position *)
|
|
|
61 |
(* of the minimum *)
|
|
|
62 |
(* y : On exit a value such that abs(x - y) <= 3*tol(x) *)
|
|
|
63 |
(* xmin : On exit the function value at position x *)
|
|
|
64 |
(* cnt : On exit the number of function evaluations *)
|
|
|
65 |
(* *)
|
|
|
66 |
(* Data and results: *)
|
|
|
67 |
(* *)
|
|
|
68 |
(* The user should be aware of the fact that the choice of tol(x) *)
|
|
|
69 |
(* may highly affect the behaviour of the algorithm, although *)
|
|
|
70 |
(* convergence to a point for which the given function is *)
|
|
|
71 |
(* minimal on the given interval is assured. The asymptotic *)
|
|
|
72 |
(* behaviour will usually be fine as long as the numerical *)
|
|
|
73 |
(* function is strictly delta-unimodal on the given interval *)
|
|
|
74 |
(* (see [1]) and the tolerance function satisfies *)
|
|
|
75 |
(* tol(x) >= delta, for all x in the given interval, let the *)
|
|
|
76 |
(* value of dfx at the begin and end point of the initial *)
|
|
|
77 |
(* interval be denoted by dfa and dfb, respectively, then, *)
|
|
|
78 |
(* finding a global minimum is only guaranteed if the function *)
|
|
|
79 |
(* is convex and dfa <= 0 and dfb >= 0. If these conditions are *)
|
|
|
80 |
(* not satisfied, then a local minimum or a minimum at one of *)
|
|
|
81 |
(* the end points might be found. *)
|
|
|
82 |
(* *)
|
|
|
83 |
(* [1] Brent, R.P.: "Algorithms for minimization without *)
|
|
|
84 |
(* derivatives": Chap. 5: Prentice Hall (1973) *)
|
|
|
85 |
(* [2] Davidon, W.C.: "Variable metric methods for minimization": *)
|
|
|
86 |
(* A.E.C. Research and Development Report ANL-5990 *)
|
|
|
87 |
(* (Rev. TID-4500, 14th ed.) (1959) *)
|
|
|
88 |
(*----------------------------------------------------------------*)
|
|
|
89 |
(* This routine is a translation of the Algol 60 procedure *)
|
|
|
90 |
(* mininder from the NUMAL Algol library (Stichting CWI) *)
|
|
|
91 |
(* *)
|
|
|
92 |
(* Diese Routine ist eine Modula-2 Uebersetzung der Algol 60 *)
|
|
|
93 |
(* Prozedur "mininder" aus der NUMAL Numerical Algol library *)
|
|
|
94 |
(* (Stichting CWI) Teil 2 (numal5p2) *)
|
|
|
95 |
(*----------------------------------------------------------------*)
|
|
|
96 |
|
|
|
97 |
PROCEDURE VMMin( Func : FunktionN;
|
|
|
98 |
n : CARDINAL;
|
|
|
99 |
Gradient : TGradient;
|
|
|
100 |
VAR X : ARRAY OF LONGREAL;
|
|
|
101 |
VAR Bvec : ARRAY OF LONGREAL;
|
|
|
102 |
VAR Fmin : LONGREAL;
|
|
|
103 |
VAR funcount : CARDINAL;
|
|
|
104 |
VAR gradcount : CARDINAL;
|
|
|
105 |
VAR iFehl : INTEGER);
|
|
|
106 |
|
|
|
107 |
(*----------------------------------------------------------------*)
|
|
|
108 |
(* Variable metric function minimiser *)
|
|
|
109 |
(* *)
|
|
|
110 |
(* Unlike Fletcher-Reeves no quadratic interpolation is used *)
|
|
|
111 |
(* since the search is often approximately a Newton step *)
|
|
|
112 |
(* *)
|
|
|
113 |
(* Func : Function of n variables to be minimized *)
|
|
|
114 |
(* n : number of variables *)
|
|
|
115 |
(* Gradient : Gradient of function to be minimized *)
|
|
|
116 |
(* X : vector of final function parameters *)
|
|
|
117 |
(* Bvec : vector of initial function parameters *)
|
|
|
118 |
(* Fmin : value of Funx(X,n) *)
|
|
|
119 |
(* funcount : number of evaluations of Func *)
|
|
|
120 |
(* gradcount : number of evaluations of Gradient *)
|
|
|
121 |
(* iFehl : -1 = Function cannot be evaluated at initial *)
|
|
|
122 |
(* parameters *)
|
|
|
123 |
(* *)
|
|
|
124 |
(* This routine is an adopted version of the Pascal routine *)
|
|
|
125 |
(* vmmin found in ref [2]. It is published under the GPL with *)
|
|
|
126 |
(* written permission of the author. *)
|
|
|
127 |
(* *)
|
|
|
128 |
(* [1] Fletcher, R.; "A new approach to variable metric *)
|
|
|
129 |
(* algorithms", Computer Journal, 13/3 pp. 317-322 (1970) *)
|
|
|
130 |
(* [2] Nash, J.C.; "Compact Numerical Methods for Computers", *)
|
|
|
131 |
(* Second Edition, Adam Hilger, Bristol, UK (1990) *)
|
|
|
132 |
(*----------------------------------------------------------------*)
|
|
|
133 |
|
|
|
134 |
PROCEDURE CGMin( Func : FunktionN;
|
|
|
135 |
n : CARDINAL;
|
|
|
136 |
Gradient : TGradient;
|
|
|
137 |
VAR X : ARRAY OF LONGREAL;
|
|
|
138 |
VAR Bvec : ARRAY OF LONGREAL;
|
|
|
139 |
VAR Fmin : LONGREAL;
|
|
|
140 |
VAR funcount : CARDINAL;
|
|
|
141 |
VAR gradcount : CARDINAL;
|
|
|
142 |
VAR intol : LONGREAL;
|
|
|
143 |
setstep : LONGREAL;
|
|
|
144 |
methode : CARDINAL;
|
|
|
145 |
VAR iFehl : INTEGER);
|
|
|
146 |
|
|
|
147 |
(*----------------------------------------------------------------*)
|
|
|
148 |
(* Conjugate gradients function minimiser *)
|
|
|
149 |
(* *)
|
|
|
150 |
(* Func : Function of n variables to be minimized *)
|
|
|
151 |
(* n : number of variables *)
|
|
|
152 |
(* Gradient : Gradient of function to be minimized *)
|
|
|
153 |
(* X : vector of final function parameters *)
|
|
|
154 |
(* Bvec : vector of initial function parameters *)
|
|
|
155 |
(* Fmin : value of Funx(X,n) *)
|
|
|
156 |
(* funcount : number of evaluations of Func *)
|
|
|
157 |
(* gradcount : number of evaluations of Gradient *)
|
|
|
158 |
(* intol : Tolerance for the evaluation of Func. *)
|
|
|
159 |
(* Tolerance used is then tol = ntol*n*sqrt(intol) *)
|
|
|
160 |
(* If Func(X,n) is not lowered by more than tol *)
|
|
|
161 |
(* within one cycle of the minimization process *)
|
|
|
162 |
(* the process is regarded as beeing converged. *)
|
|
|
163 |
(* Set the tolerance negative to indicate that *)
|
|
|
164 |
(* procedure must obtain an appropriate value. *)
|
|
|
165 |
(* setstep : steplength saving factor *)
|
|
|
166 |
(* *)
|
|
|
167 |
(* methode : 1 = Fletcher Reeves *)
|
|
|
168 |
(* 2 = Polak Ribiere *)
|
|
|
169 |
(* 3 = Beale Sorenson *)
|
|
|
170 |
(* *)
|
|
|
171 |
(* iFehl : -1 = Function cannot be evaluated at initial *)
|
|
|
172 |
(* parameters *)
|
|
|
173 |
(* -99 = Wrong parameter "methode" *)
|
|
|
174 |
(* 99 = At least one result is either INF of NAN *)
|
|
|
175 |
(* *)
|
|
|
176 |
(* This routine is an adopted version of the Pascal routine *)
|
|
|
177 |
(* cgmin found in ref [2]. It is published under the GPL with *)
|
|
|
178 |
(* written permission of the author. *)
|
|
|
179 |
(* *)
|
|
|
180 |
(* [1] Fletcher,R; Reeves,C.M.; Computer Journal 7/7, *)
|
|
|
181 |
(* pp. 149-154 (1964) *)
|
|
|
182 |
(* [2] Nash, J.C.; "Compact Numerical Methods for Computers", *)
|
|
|
183 |
(* Second Edition, Adam Hilger, Bristol, UK (1990) *)
|
|
|
184 |
(*----------------------------------------------------------------*)
|
|
|
185 |
|
|
|
186 |
END OptimLib3.
|