42cf5bc1 |
1 | // Created on: 1996-02-28 |
2 | // Created by: Philippe MANGIN |
3 | // Copyright (c) 1996-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
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 |
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. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _math_NewtonMinimum_HeaderFile |
18 | #define _math_NewtonMinimum_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
f79b19a1 |
24 | #include <Precision.hxx> |
42cf5bc1 |
25 | #include <Standard_Boolean.hxx> |
26 | #include <math_Status.hxx> |
27 | #include <math_Vector.hxx> |
28 | #include <math_Matrix.hxx> |
29 | #include <Standard_Real.hxx> |
30 | #include <Standard_Integer.hxx> |
31 | #include <Standard_OStream.hxx> |
32 | class StdFail_NotDone; |
33 | class Standard_DimensionError; |
34 | class math_MultipleVarFunctionWithHessian; |
35 | |
36 | |
37 | |
38 | class math_NewtonMinimum |
39 | { |
40 | public: |
41 | |
42 | DEFINE_STANDARD_ALLOC |
43 | |
44 | |
45 | |
46 | //! The tolerance required on the solution is given by Tolerance. |
47 | //! Iteration are stopped if (!WithSingularity) and H(F(Xi)) is not definite |
48 | //! positive (if the smaller eigenvalue of H < Convexity) |
49 | //! or IsConverged() returns True for 2 successives Iterations. |
50 | //! Warning: This constructor does not perform computation. |
f79b19a1 |
51 | Standard_EXPORT math_NewtonMinimum(const math_MultipleVarFunctionWithHessian& theFunction, |
52 | const Standard_Real theTolerance = Precision::Confusion(), |
53 | const Standard_Integer theNbIterations = 40, |
54 | const Standard_Real theConvexity = 1.0e-6, |
55 | const Standard_Boolean theWithSingularity = Standard_True); |
42cf5bc1 |
56 | |
57 | //! Search the solution. |
58 | Standard_EXPORT void Perform (math_MultipleVarFunctionWithHessian& theFunction, const math_Vector& theStartingPoint); |
59 | |
e6f550da |
60 | //! Destructor |
42cf5bc1 |
61 | Standard_EXPORT virtual ~math_NewtonMinimum(); |
62 | |
63 | |
64 | //! This method is called at the end of each iteration to check the convergence: |
65 | //! || Xi+1 - Xi || < Tolerance or || F(Xi+1) - F(Xi)|| < Tolerance * || F(Xi) || |
66 | //! It can be redefined in a sub-class to implement a specific test. |
67 | virtual Standard_Boolean IsConverged() const; |
68 | |
69 | //! Tests if an error has occured. |
70 | Standard_Boolean IsDone() const; |
71 | |
72 | //! Tests if the Function is convexe during optimization. |
73 | Standard_Boolean IsConvex() const; |
74 | |
75 | //! returns the location vector of the minimum. |
76 | //! Exception NotDone is raised if an error has occured. |
77 | const math_Vector& Location() const; |
78 | |
79 | //! outputs the location vector of the minimum in Loc. |
80 | //! Exception NotDone is raised if an error has occured. |
81 | //! Exception DimensionError is raised if the range of Loc is not |
82 | //! equal to the range of the StartingPoint. |
83 | void Location (math_Vector& Loc) const; |
84 | |
85 | //! Set boundaries. |
86 | Standard_EXPORT void SetBoundary (const math_Vector& theLeftBorder, const math_Vector& theRightBorder); |
87 | |
88 | //! returns the value of the minimum. |
89 | //! Exception NotDone is raised if the minimum was not found. |
90 | Standard_Real Minimum() const; |
91 | |
92 | //! returns the gradient vector at the minimum. |
93 | //! Exception NotDone is raised if an error has occured.the minimum was not found. |
94 | const math_Vector& Gradient() const; |
95 | |
96 | //! outputs the gradient vector at the minimum in Grad. |
97 | //! Exception NotDone is raised if the minimum was not found. |
98 | //! Exception DimensionError is raised if the range of Grad is not |
99 | //! equal to the range of the StartingPoint. |
100 | void Gradient (math_Vector& Grad) const; |
101 | |
102 | //! returns the number of iterations really done in the |
103 | //! calculation of the minimum. |
104 | //! The exception NotDone is raised if an error has occured. |
105 | Standard_Integer NbIterations() const; |
243505b8 |
106 | |
107 | //! Returns the Status of computation. |
108 | //! The exception NotDone is raised if an error has occured. |
109 | math_Status GetStatus() const; |
110 | |
42cf5bc1 |
111 | |
112 | //! Prints on the stream o information on the current state |
113 | //! of the object. |
114 | //! Is used to redefine the operator <<. |
115 | Standard_EXPORT void Dump (Standard_OStream& o) const; |
116 | |
117 | |
118 | |
119 | |
120 | protected: |
121 | |
122 | |
123 | |
124 | math_Status TheStatus; |
125 | math_Vector TheLocation; |
126 | math_Vector TheGradient; |
127 | math_Vector TheStep; |
128 | math_Matrix TheHessian; |
129 | Standard_Real PreviousMinimum; |
130 | Standard_Real TheMinimum; |
131 | Standard_Real MinEigenValue; |
132 | Standard_Real XTol; |
133 | Standard_Real CTol; |
134 | Standard_Integer nbiter; |
135 | Standard_Boolean NoConvexTreatement; |
136 | Standard_Boolean Convex; |
137 | Standard_Boolean myIsBoundsDefined; |
138 | math_Vector myLeft; |
139 | math_Vector myRight; |
140 | |
141 | |
142 | private: |
143 | |
144 | |
145 | |
146 | Standard_Boolean Done; |
147 | Standard_Integer Itermax; |
148 | |
149 | |
150 | }; |
151 | |
152 | |
153 | #include <math_NewtonMinimum.lxx> |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | #endif // _math_NewtonMinimum_HeaderFile |