b311480e |
1 | -- Created on: 1991-05-14 |
2 | -- Created by: Laurent PAINNOT |
3 | -- Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
4 | -- Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | -- |
973c2be1 |
6 | -- This file is part of Open CASCADE Technology software library. |
b311480e |
7 | -- |
d5f74e42 |
8 | -- This library is free software; you can redistribute it and/or modify it under |
9 | -- the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | -- by the Free Software Foundation, with special exception defined in the file |
11 | -- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | -- distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | -- |
973c2be1 |
14 | -- Alternatively, this file may be used under the terms of Open CASCADE |
15 | -- commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | class BFGS from math |
18 | ---Purpose: |
19 | -- This class implements the Broyden-Fletcher-Goldfarb-Shanno variant of |
20 | -- Davidson-Fletcher-Powell minimization algorithm of a function of |
21 | -- multiple variables.Knowledge of the function's gradient is required. |
22 | |
23 | uses Vector from math, Matrix from math, |
24 | MultipleVarFunctionWithGradient from math, |
25 | Status from math, |
26 | OStream from Standard |
27 | |
28 | raises NotDone from StdFail, |
29 | DimensionError from Standard |
30 | |
31 | is |
7fd59977 |
32 | |
07f1a2e6 |
33 | Create(NbVariables: Integer; |
34 | Tolerance: Real = 1.0e-8; |
35 | NbIterations: Integer = 200; |
36 | ZEPS: Real = 1.0e-12) |
37 | ---Purpose: Initializes the computation of the minimum of a function with |
38 | -- NbVariables. |
39 | -- Tolerance, ZEPS and NbIterations are described in the method Perform. |
40 | -- Warning: |
41 | -- A call to the Perform method must be made after this |
42 | -- initialization to effectively compute the minimum of the |
43 | -- function F. |
7fd59977 |
44 | returns BFGS; |
45 | |
46 | |
47 | Delete(me:out) is virtual; |
48 | ---C++: alias "Standard_EXPORT virtual ~math_BFGS(){Delete() ; }" |
49 | |
50 | Perform(me: in out; F: in out MultipleVarFunctionWithGradient; |
07f1a2e6 |
51 | StartingPoint: Vector) |
52 | ---Purpose: Given the starting point StartingPoint, |
53 | -- minimization is done on the function F. |
54 | -- The solution F = Fi is found when : |
55 | -- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS). |
56 | -- Tolerance, ZEPS and maximum number of iterations are given |
57 | -- in the constructor. |
7fd59977 |
58 | |
59 | is static; |
60 | |
61 | |
62 | IsSolutionReached(me; F: in out MultipleVarFunctionWithGradient) |
63 | ---Purpose: |
64 | -- This method is called at the end of each iteration to check if the |
65 | -- solution is found. |
66 | -- It can be redefined in a sub-class to implement a specific test to |
67 | -- stop the iterations. |
68 | |
69 | returns Boolean |
70 | is virtual; |
71 | |
72 | |
73 | IsDone(me) |
74 | ---Purpose: Returns true if the computations are successful, otherwise returns false. |
75 | ---C++: inline |
76 | |
77 | returns Boolean |
78 | is static; |
79 | |
80 | |
81 | Location(me) |
82 | ---Purpose: returns the location vector of the minimum. |
83 | -- Exception NotDone is raised if the minimum was not found. |
84 | ---C++: inline |
85 | ---C++: return const& |
86 | returns Vector |
87 | raises NotDone |
88 | is static; |
89 | |
90 | |
91 | Location(me; Loc: out Vector) |
92 | ---Purpose: outputs the location vector of the minimum in Loc. |
93 | -- Exception NotDone is raised if the minimum was not found. |
94 | -- Exception DimensionError is raised if the range of Loc is not |
95 | -- equal to the range of the StartingPoint. |
96 | ---C++: inline |
97 | |
98 | raises DimensionError, |
99 | NotDone |
100 | is static; |
101 | |
102 | |
103 | Minimum(me) |
104 | ---Purpose: returns the value of the minimum. |
105 | -- Exception NotDone is raised if the minimum was not found. |
106 | ---C++: inline |
107 | |
108 | returns Real |
109 | raises NotDone |
110 | is static; |
111 | |
112 | |
113 | Gradient(me) |
114 | ---Purpose: Returns the gradient vector at the minimum. |
115 | -- Exception NotDone is raised if the minimum was not found. |
116 | ---C++: inline |
117 | ---C++: return const& |
118 | returns Vector |
119 | raises NotDone |
120 | is static; |
121 | |
122 | |
123 | Gradient(me; Grad: out Vector) |
124 | ---Purpose: Returns the value of the gradient vector at the minimum in Grad. |
125 | -- Exception NotDone is raised if the minimum was not found. |
126 | -- Exception DimensionError is raised if the range of Grad is not |
127 | -- equal to the range of the StartingPoint. |
128 | ---C++: inline |
129 | raises DimensionError, |
130 | NotDone |
131 | is static; |
132 | |
133 | |
134 | NbIterations(me) |
135 | ---Purpose: Returns the number of iterations really done in the |
136 | -- calculation of the minimum. |
137 | -- The exception NotDone is raised if the minimum was not found. |
138 | ---C++: inline |
139 | returns Integer |
140 | raises NotDone |
141 | is static; |
142 | |
143 | |
144 | Dump(me; o: in out OStream) |
145 | ---Purpose: Prints on the stream o information on the current state |
146 | -- of the object. |
147 | -- Is used to redefine the operator <<. |
148 | |
149 | is static; |
150 | |
151 | |
152 | fields |
153 | |
154 | Done: Boolean; |
155 | TheStatus: Status is protected; |
156 | TheLocation: Vector is protected; |
157 | TheGradient: Vector is protected; |
158 | PreviousMinimum: Real is protected; |
159 | TheMinimum: Real is protected; |
160 | XTol: Real is protected; |
161 | EPSZ: Real is protected; |
162 | nbiter: Integer is protected; |
163 | Itermax: Integer; |
164 | |
165 | end BFGS; |