mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-19 13:40:49 +03:00
0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
The calling of virtual methods has been removed from constructors & destructors: math_BissecNewton math_BrentMinimum math_FRPR math_FunctionSetRoot math_NewtonFunctionSetRoot math_NewtonMinimum math_Powell
This commit is contained in:
@@ -30,41 +30,34 @@ raises NotDone from StdFail
|
||||
|
||||
is
|
||||
|
||||
Create(theXTolerance: in Real) returns BissecNewton;
|
||||
---Purpose: Constructor.
|
||||
-- @param theXTolerance - algorithm tolerance.
|
||||
|
||||
Perform(me: in out; F: out FunctionWithDerivative;
|
||||
Bound1, Bound2: Real;
|
||||
NbIterations: Integer)
|
||||
Bound1, Bound2: Real;
|
||||
NbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- A combination of Newton-Raphson and bissection methods is done to find
|
||||
-- the root of the function F between the bounds Bound1 and Bound2
|
||||
-- on the function F.
|
||||
-- The tolerance required on the root is given by TolX.
|
||||
-- The solution is found when:
|
||||
-- abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
is static;
|
||||
|
||||
is static protected;
|
||||
|
||||
|
||||
Create(F: in out FunctionWithDerivative;
|
||||
Bound1, Bound2, TolX: Real;
|
||||
NbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- A combination of Newton-Raphson and bissection methods is done to find
|
||||
-- the root of the function F between the bounds Bound1 and Bound2.
|
||||
-- on the function F.
|
||||
-- The tolerance required on the root is given by TolX.
|
||||
-- The solution is found when :
|
||||
-- abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
IsSolutionReached(me: in out; theFunction: out FunctionWithDerivative)
|
||||
---Purpose:
|
||||
-- This method is called at the end of each iteration to check if the
|
||||
-- solution has been found.
|
||||
-- It can be redefined in a sub-class to implement a specific test to
|
||||
-- stop the iterations.
|
||||
---C++: inline
|
||||
returns Boolean is virtual;
|
||||
|
||||
returns BissecNewton;
|
||||
|
||||
---C++: alias " Standard_EXPORT virtual ~math_BissecNewton();"
|
||||
|
||||
IsSolutionReached(me: in out; F: out FunctionWithDerivative)
|
||||
---Purpose:
|
||||
-- This method is called at the end of each iteration to check if the
|
||||
-- solution has been found.
|
||||
-- It can be redefined in a sub-class to implement a specific test to
|
||||
-- stop the iterations.
|
||||
|
||||
returns Boolean
|
||||
is virtual;
|
||||
|
||||
|
||||
IsDone(me)
|
||||
---Purpose: Tests is the root has been successfully found.
|
||||
---C++: inline
|
||||
@@ -99,7 +92,7 @@ is
|
||||
raises NotDone
|
||||
is static;
|
||||
|
||||
|
||||
|
||||
Dump(me; o: in out OStream)
|
||||
---Purpose: Prints on the stream o information on the current state
|
||||
-- of the object.
|
||||
@@ -108,6 +101,12 @@ is
|
||||
is static;
|
||||
|
||||
|
||||
Delete(me) is static;
|
||||
---Purpose: Destructor alias.
|
||||
---C++: inline
|
||||
---C++: alias " Standard_EXPORT virtual ~math_BissecNewton();"
|
||||
|
||||
|
||||
fields
|
||||
|
||||
Done: Boolean;
|
||||
|
@@ -15,14 +15,37 @@
|
||||
#include <math_BissecNewton.ixx>
|
||||
#include <math_FunctionWithDerivative.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : math_BissecNewton
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_BissecNewton::math_BissecNewton(const Standard_Real theXTolerance)
|
||||
: TheStatus(math_NotBracketed),
|
||||
XTol (theXTolerance),
|
||||
x (0.0),
|
||||
dx (0.0),
|
||||
f (0.0),
|
||||
df (0.0),
|
||||
Done (Standard_False)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~math_BissecNewton
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
math_BissecNewton::~math_BissecNewton()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_BissecNewton::Perform(math_FunctionWithDerivative& F,
|
||||
const Standard_Real Bound1,
|
||||
const Standard_Real Bound2,
|
||||
const Standard_Integer NbIterations)
|
||||
const Standard_Real Bound1,
|
||||
const Standard_Real Bound2,
|
||||
const Standard_Integer NbIterations)
|
||||
{
|
||||
Standard_Boolean GOOD;
|
||||
Standard_Integer j;
|
||||
@@ -125,25 +148,10 @@ void math_BissecNewton::Perform(math_FunctionWithDerivative& F,
|
||||
return;
|
||||
}
|
||||
|
||||
Standard_Boolean math_BissecNewton::IsSolutionReached
|
||||
//(math_FunctionWithDerivative& F)
|
||||
(math_FunctionWithDerivative& )
|
||||
{
|
||||
return Abs(dx) <= XTol;
|
||||
}
|
||||
|
||||
|
||||
math_BissecNewton::math_BissecNewton(math_FunctionWithDerivative& F,
|
||||
const Standard_Real Bound1,
|
||||
const Standard_Real Bound2,
|
||||
const Standard_Real TolX,
|
||||
const Standard_Integer NbIterations) {
|
||||
|
||||
XTol = TolX;
|
||||
Perform(F, Bound1, Bound2, NbIterations);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_BissecNewton::Dump(Standard_OStream& o) const {
|
||||
|
||||
o << "math_BissecNewton ";
|
||||
|
@@ -14,6 +14,16 @@
|
||||
|
||||
#include <StdFail_NotDone.hxx>
|
||||
|
||||
inline void math_BissecNewton::Delete() const
|
||||
{
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_BissecNewton::IsSolutionReached(math_FunctionWithDerivative&)
|
||||
{
|
||||
return Abs(dx) <= XTol;
|
||||
}
|
||||
|
||||
|
||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||
const math_BissecNewton& Bi)
|
||||
{
|
||||
|
@@ -32,63 +32,46 @@ is
|
||||
Create(TolX: Real;
|
||||
NbIterations: Integer = 100;
|
||||
ZEPS: Real = 1.0e-12)
|
||||
---Purpose:
|
||||
-- This constructor should be used in a sub-class to initialize
|
||||
-- correctly all the fields of this class.
|
||||
|
||||
---Purpose:
|
||||
-- This constructor should be used in a sub-class to initialize
|
||||
-- correctly all the fields of this class.
|
||||
returns BrentMinimum;
|
||||
|
||||
|
||||
Create(TolX: Real; Fbx: Real;
|
||||
NbIterations: Integer = 100;
|
||||
ZEPS: Real = 1.0e-12)
|
||||
---Purpose:
|
||||
-- This constructor should be used in a sub-class to initialize
|
||||
-- correctly all the fields of this class.
|
||||
-- It has to be used if F(Bx) is known.
|
||||
|
||||
---Purpose:
|
||||
-- This constructor should be used in a sub-class to initialize
|
||||
-- correctly all the fields of this class.
|
||||
-- It has to be used if F(Bx) is known.
|
||||
returns BrentMinimum;
|
||||
|
||||
|
||||
|
||||
Create(F: in out Function; Ax, Bx, Cx, TolX: Real;
|
||||
NbIterations: Integer = 100; ZEPS: Real=1.0e-12)
|
||||
---Purpose:
|
||||
-- Given a bracketing triplet of abscissae Ax, Bx, Cx
|
||||
-- (such as Bx is between Ax and Cx, F(Bx) is
|
||||
-- less than both F(Bx) and F(Cx)) the Brent minimization is done
|
||||
-- on the function F.
|
||||
-- The tolerance required on F is given by Tolerance.
|
||||
-- The solution is found when :
|
||||
-- abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS;
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
|
||||
returns BrentMinimum;
|
||||
|
||||
Delete(me) is static;
|
||||
---Purpose: Destructor alias.
|
||||
---C++: inline
|
||||
---C++: alias " Standard_EXPORT virtual ~math_BrentMinimum();"
|
||||
|
||||
Perform(me: in out; F: in out Function;
|
||||
Ax, Bx, Cx: Real)
|
||||
---Purpose:
|
||||
-- Brent minimization is performed on function F from a given
|
||||
-- bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is
|
||||
-- between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx))
|
||||
-- Warning
|
||||
-- The initialization constructors must have been called
|
||||
-- before the call to the Perform method.
|
||||
|
||||
Perform(me: in out; F: in out Function;
|
||||
Ax, Bx, Cx: Real)
|
||||
---Purpose:
|
||||
-- Brent minimization is performed on function F from a given
|
||||
-- bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is
|
||||
-- between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx))
|
||||
-- The solution is found when: abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS;
|
||||
is static;
|
||||
|
||||
|
||||
IsSolutionReached(me: in out; F: in out Function)
|
||||
---Purpose:
|
||||
-- This method is called at the end of each iteration to check if the
|
||||
-- solution is found.
|
||||
-- It can be redefined in a sub-class to implement a specific test to
|
||||
-- stop the iterations.
|
||||
|
||||
returns Boolean
|
||||
is virtual;
|
||||
IsSolutionReached(me: in out; theFunction: in out Function)
|
||||
---Purpose:
|
||||
-- This method is called at the end of each iteration to check if the
|
||||
-- solution is found.
|
||||
-- It can be redefined in a sub-class to implement a specific test to
|
||||
-- stop the iterations.
|
||||
---C++:inline
|
||||
returns Boolean is virtual;
|
||||
|
||||
|
||||
IsDone(me)
|
||||
@@ -137,7 +120,6 @@ is
|
||||
is static;
|
||||
|
||||
|
||||
|
||||
fields
|
||||
|
||||
Done: Boolean;
|
||||
|
@@ -23,15 +23,68 @@
|
||||
#define SIGN(a,b) ((b) > 0.0 ? fabs(a) : -fabs(a))
|
||||
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d)
|
||||
|
||||
//=======================================================================
|
||||
//function : math_BrentMinimum
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_BrentMinimum::math_BrentMinimum(const Standard_Real theTolX,
|
||||
const Standard_Integer theNbIterations,
|
||||
const Standard_Real theZEPS)
|
||||
: a (0.0),
|
||||
b (0.0),
|
||||
x (0.0),
|
||||
fx (0.0),
|
||||
fv (0.0),
|
||||
fw (0.0),
|
||||
XTol(theTolX),
|
||||
EPSZ(theZEPS),
|
||||
Done (Standard_False),
|
||||
iter (0),
|
||||
Itermax(theNbIterations),
|
||||
myF (Standard_False)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : math_BrentMinimum
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_BrentMinimum::math_BrentMinimum(const Standard_Real theTolX,
|
||||
const Standard_Real theFbx,
|
||||
const Standard_Integer theNbIterations,
|
||||
const Standard_Real theZEPS)
|
||||
: a (0.0),
|
||||
b (0.0),
|
||||
x (0.0),
|
||||
fx (theFbx),
|
||||
fv (0.0),
|
||||
fw (0.0),
|
||||
XTol(theTolX),
|
||||
EPSZ(theZEPS),
|
||||
Done (Standard_False),
|
||||
iter (0),
|
||||
Itermax(theNbIterations),
|
||||
myF (Standard_True)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~math_BrentMinimum
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
math_BrentMinimum::~math_BrentMinimum()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_BrentMinimum::Perform(math_Function& F,
|
||||
const Standard_Real ax,
|
||||
const Standard_Real bx,
|
||||
const Standard_Real cx) {
|
||||
|
||||
const Standard_Real ax,
|
||||
const Standard_Real bx,
|
||||
const Standard_Real cx)
|
||||
{
|
||||
Standard_Boolean OK;
|
||||
Standard_Real etemp, fu, p, q, r;
|
||||
Standard_Real tol1, tol2, u, v, w, xm;
|
||||
@@ -104,70 +157,20 @@ void math_BrentMinimum::Perform(math_Function& F,
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
math_BrentMinimum::math_BrentMinimum(math_Function& F,
|
||||
const Standard_Real Ax,
|
||||
const Standard_Real Bx,
|
||||
const Standard_Real Cx,
|
||||
const Standard_Real TolX,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real ZEPS) {
|
||||
|
||||
XTol = TolX;
|
||||
EPSZ = ZEPS;
|
||||
Itermax = NbIterations;
|
||||
myF = Standard_False;
|
||||
Perform(F, Ax, Bx, Cx);
|
||||
}
|
||||
|
||||
|
||||
// Constructeur d'initialisation des champs.
|
||||
|
||||
math_BrentMinimum::math_BrentMinimum(const Standard_Real TolX,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real ZEPS) {
|
||||
myF = Standard_False;
|
||||
XTol = TolX;
|
||||
EPSZ = ZEPS;
|
||||
Itermax = NbIterations;
|
||||
}
|
||||
|
||||
math_BrentMinimum::math_BrentMinimum(const Standard_Real TolX,
|
||||
const Standard_Real Fbx,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real ZEPS) {
|
||||
|
||||
fx = Fbx;
|
||||
myF = Standard_True;
|
||||
XTol = TolX;
|
||||
EPSZ = ZEPS;
|
||||
Itermax = NbIterations;
|
||||
}
|
||||
|
||||
|
||||
// Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function& F) {
|
||||
Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function& ) {
|
||||
|
||||
// Standard_Real xm = 0.5 * (a + b);
|
||||
// modified by NIZHNY-MKK Mon Oct 3 17:45:57 2005.BEGIN
|
||||
// Standard_Real tol = XTol * fabs(x) + EPSZ;
|
||||
// return fabs(x - xm) <= 2.0 * tol - 0.5 * (b - a);
|
||||
Standard_Real TwoTol = 2.0 *(XTol * fabs(x) + EPSZ);
|
||||
return ((x <= (TwoTol + a)) && (x >= (b - TwoTol)));
|
||||
// modified by NIZHNY-MKK Mon Oct 3 17:46:00 2005.END
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_BrentMinimum::Dump(Standard_OStream& o) const
|
||||
{
|
||||
o << "math_BrentMinimum ";
|
||||
if(Done) {
|
||||
o << " Status = Done \n";
|
||||
o << " Location value = " << x <<"\n";
|
||||
o << " Minimum value = " << fx << "\n";
|
||||
o << " Number of iterations = " << iter <<"\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void math_BrentMinimum::Dump(Standard_OStream& o) const {
|
||||
o << "math_BrentMinimum ";
|
||||
if(Done) {
|
||||
o << " Status = Done \n";
|
||||
o << " Location value = " << x <<"\n";
|
||||
o << " Minimum value = " << fx << "\n";
|
||||
o << " Number of iterations = " << iter <<"\n";
|
||||
}
|
||||
else {
|
||||
o << " Status = not Done \n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
o << " Status = not Done \n";
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,23 @@
|
||||
|
||||
#include <StdFail_NotDone.hxx>
|
||||
|
||||
inline Standard_Boolean math_BrentMinimum::IsDone() const { return Done; }
|
||||
inline void math_BrentMinimum::Delete() const
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function&)
|
||||
{
|
||||
const Standard_Real TwoTol = 2.0 * (XTol * fabs(x) + EPSZ);
|
||||
return (x <= (TwoTol + a)) && (x >= (b - TwoTol));
|
||||
}
|
||||
|
||||
|
||||
inline Standard_Boolean math_BrentMinimum::IsDone() const
|
||||
{
|
||||
return Done;
|
||||
}
|
||||
|
||||
|
||||
inline Standard_OStream& operator<< (Standard_OStream& o,
|
||||
const math_BrentMinimum& Br)
|
||||
|
@@ -30,53 +30,40 @@ raises DimensionError from Standard,
|
||||
|
||||
is
|
||||
|
||||
Create(F: in out MultipleVarFunctionWithGradient;
|
||||
StartingPoint: Vector; Tolerance: Real;
|
||||
NbIterations: Integer=200; ZEPS: Real=1.0e-12)
|
||||
---Purpose: Computes FRPR minimization function F from input vector
|
||||
-- StartingPoint. The solution F = Fi is found when 2.0 *
|
||||
-- abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) +
|
||||
-- ZEPS). The maximum number of iterations allowed is given
|
||||
-- by NbIterations.
|
||||
returns FRPR;
|
||||
|
||||
|
||||
Create(F: in out MultipleVarFunctionWithGradient;
|
||||
Tolerance: Real;
|
||||
NbIterations: Integer = 200;
|
||||
ZEPS: Real = 1.0e-12)
|
||||
---Purpose: Purpose
|
||||
-- Initializes the computation of the minimum of F.
|
||||
-- Warning
|
||||
-- A call to the Perform method must be made after this
|
||||
-- initialization to compute the minimum of the function.
|
||||
Create(theFunction: in MultipleVarFunctionWithGradient;
|
||||
theTolerance: Real;
|
||||
theNbIterations: Integer = 200;
|
||||
theZEPS: Real = 1.0e-12)
|
||||
---Purpose:
|
||||
-- Initializes the computation of the minimum of F.
|
||||
-- Warning: constructor does not perform computations.
|
||||
returns FRPR;
|
||||
|
||||
Delete(me) is static;
|
||||
---Purpose: Destructor alias.
|
||||
---C++: alias " Standard_EXPORT virtual ~math_FRPR();"
|
||||
|
||||
Perform(me: in out; F: in out MultipleVarFunctionWithGradient;
|
||||
StartingPoint: Vector)
|
||||
---Purpose: Use this method after a call to the initialization constructor
|
||||
-- to compute the minimum of function F.
|
||||
-- Warning
|
||||
-- The initialization constructor must have been called before
|
||||
-- the Perform method is called
|
||||
|
||||
Perform(me: in out;
|
||||
theFunction: in out MultipleVarFunctionWithGradient;
|
||||
theStartingPoint: Vector)
|
||||
---Purpose:
|
||||
-- The solution F = Fi is found when
|
||||
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
|
||||
is static;
|
||||
|
||||
|
||||
IsSolutionReached(me: in out; F: in out MultipleVarFunctionWithGradient)
|
||||
---Purpose:
|
||||
-- The solution F = Fi is found when :
|
||||
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
|
||||
returns Boolean
|
||||
is virtual;
|
||||
|
||||
|
||||
IsSolutionReached(me: in out; theFunction: in out MultipleVarFunctionWithGradient)
|
||||
---Purpose:
|
||||
-- The solution F = Fi is found when:
|
||||
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
---C++:inline
|
||||
returns Boolean is virtual;
|
||||
|
||||
|
||||
IsDone(me)
|
||||
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
||||
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
||||
---C++: inline
|
||||
returns Boolean
|
||||
is static;
|
||||
@@ -158,6 +145,7 @@ is
|
||||
|
||||
|
||||
fields
|
||||
|
||||
Done: Boolean;
|
||||
TheLocation: Vector is protected;
|
||||
TheGradient: Vector is protected;
|
||||
|
@@ -88,8 +88,9 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
||||
math_BracketMinimum Bracket(F, 0.0, 1.0);
|
||||
if(Bracket.IsDone()) {
|
||||
Bracket.Values(ax, xx, bx);
|
||||
math_BrentMinimum Sol(F, ax, xx, bx, 1.0e-10, 100);
|
||||
if(Sol.IsDone()) {
|
||||
math_BrentMinimum Sol(1.e-10);
|
||||
Sol.Perform(F, ax, xx, bx);
|
||||
if (Sol.IsDone()) {
|
||||
Standard_Real Scale = Sol.Location();
|
||||
Result = Sol.Minimum();
|
||||
Dir.Multiply(Scale);
|
||||
@@ -100,10 +101,45 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : math_FRPR
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_FRPR::math_FRPR(const math_MultipleVarFunctionWithGradient& theFunction,
|
||||
const Standard_Real theTolerance,
|
||||
const Standard_Integer theNbIterations,
|
||||
const Standard_Real theZEPS)
|
||||
|
||||
: TheLocation(1, theFunction.NbVariables()),
|
||||
TheGradient(1, theFunction.NbVariables()),
|
||||
TheMinimum (0.0),
|
||||
PreviousMinimum(0.0),
|
||||
XTol (theTolerance),
|
||||
EPSZ (theZEPS),
|
||||
Done (Standard_False),
|
||||
Iter (0),
|
||||
State (0),
|
||||
TheStatus (math_NotBracketed),
|
||||
Itermax (theNbIterations)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~math_FRPR
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
math_FRPR::~math_FRPR()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
|
||||
const math_Vector& StartingPoint) {
|
||||
|
||||
const math_Vector& StartingPoint)
|
||||
{
|
||||
Standard_Boolean Good;
|
||||
Standard_Integer n = TheLocation.Length();
|
||||
Standard_Integer j, its;
|
||||
@@ -140,7 +176,7 @@ void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
|
||||
}
|
||||
if(IsSolutionReached(F)) {
|
||||
Done = Standard_True;
|
||||
State = F.GetStateNumber();
|
||||
State = F.GetStateNumber();
|
||||
TheStatus = math_OK;
|
||||
return;
|
||||
}
|
||||
@@ -175,64 +211,25 @@ void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
|
||||
Done = Standard_False;
|
||||
TheStatus = math_TooManyIterations;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Standard_Boolean math_FRPR::IsSolutionReached(
|
||||
// math_MultipleVarFunctionWithGradient& F) {
|
||||
math_MultipleVarFunctionWithGradient& ) {
|
||||
|
||||
return (2.0 * fabs(TheMinimum - PreviousMinimum)) <=
|
||||
XTol * (fabs(TheMinimum) + fabs(PreviousMinimum) + EPSZ);
|
||||
}
|
||||
|
||||
math_FRPR::math_FRPR(math_MultipleVarFunctionWithGradient& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const Standard_Real Tolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real ZEPS)
|
||||
: TheLocation(1, StartingPoint.Length()),
|
||||
TheGradient(1, StartingPoint.Length()) {
|
||||
|
||||
XTol = Tolerance;
|
||||
EPSZ = ZEPS;
|
||||
Itermax = NbIterations;
|
||||
Perform(F, StartingPoint);
|
||||
}
|
||||
|
||||
|
||||
math_FRPR::math_FRPR(math_MultipleVarFunctionWithGradient& F,
|
||||
const Standard_Real Tolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real ZEPS)
|
||||
: TheLocation(1, F.NbVariables()),
|
||||
TheGradient(1, F.NbVariables()) {
|
||||
|
||||
XTol = Tolerance;
|
||||
EPSZ = ZEPS;
|
||||
Itermax = NbIterations;
|
||||
}
|
||||
|
||||
|
||||
math_FRPR::~math_FRPR()
|
||||
{
|
||||
}
|
||||
|
||||
void math_FRPR::Dump(Standard_OStream& o) const {
|
||||
|
||||
o << "math_FRPR ";
|
||||
if(Done) {
|
||||
o << " Status = Done \n";
|
||||
o << " Location Vector = "<< TheLocation << "\n";
|
||||
o << " Minimum value = " << TheMinimum <<"\n";
|
||||
o << " Number of iterations = " << Iter <<"\n";
|
||||
}
|
||||
else {
|
||||
o << " Status = not Done because " << (Standard_Integer)TheStatus << "\n";
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FRPR::Dump(Standard_OStream& o) const
|
||||
{
|
||||
o << "math_FRPR ";
|
||||
if(Done) {
|
||||
o << " Status = Done \n";
|
||||
o << " Location Vector = "<< TheLocation << "\n";
|
||||
o << " Minimum value = " << TheMinimum <<"\n";
|
||||
o << " Number of iterations = " << Iter <<"\n";
|
||||
}
|
||||
else {
|
||||
o << " Status = not Done because " << (Standard_Integer)TheStatus << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -15,8 +15,21 @@
|
||||
#include <StdFail_NotDone.hxx>
|
||||
#include <math_Vector.hxx>
|
||||
|
||||
inline void math_FRPR::Delete() const
|
||||
{
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_FRPR::IsDone() const { return Done; }
|
||||
inline Standard_Boolean math_FRPR::IsSolutionReached(math_MultipleVarFunctionWithGradient&)
|
||||
{
|
||||
return 2.0 * fabs(TheMinimum - PreviousMinimum) <=
|
||||
XTol * (fabs(TheMinimum) + fabs(PreviousMinimum) + EPSZ);
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_FRPR::IsDone() const
|
||||
{
|
||||
return Done;
|
||||
|
||||
}
|
||||
|
||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||
const math_FRPR& Fr)
|
||||
|
@@ -76,7 +76,8 @@ class math_MyFunctionSetWithDerivatives : public math_FunctionSetWithDerivatives
|
||||
math_MyFunctionSetWithDerivatives Ff(F);
|
||||
V(1)=Guess;
|
||||
Tol(1) = Tolerance;
|
||||
math_FunctionSetRoot Sol(Ff,V,Tol,NbIterations);
|
||||
math_FunctionSetRoot Sol(Ff, Tol, NbIterations);
|
||||
Sol.Perform(Ff, V);
|
||||
Done = Sol.IsDone();
|
||||
if (Done) {
|
||||
F.GetStateNumber();
|
||||
@@ -98,7 +99,8 @@ class math_MyFunctionSetWithDerivatives : public math_FunctionSetWithDerivatives
|
||||
Tol(1) = Tolerance;
|
||||
Aa(1)=A;
|
||||
Bb(1)=B;
|
||||
math_FunctionSetRoot Sol(Ff,V,Tol,Aa,Bb,NbIterations);
|
||||
math_FunctionSetRoot Sol(Ff, Tol, NbIterations);
|
||||
Sol.Perform(Ff, V, Aa, Bb);
|
||||
Done = Sol.IsDone();
|
||||
if (Done) {
|
||||
F.GetStateNumber();
|
||||
|
@@ -57,66 +57,52 @@ is
|
||||
-- constructor.
|
||||
|
||||
returns FunctionSetRoot from math;
|
||||
|
||||
|
||||
|
||||
Create(F: in out FunctionSetWithDerivatives; StartingPoint: Vector;
|
||||
Tolerance: Vector; NbIterations: Integer = 100)
|
||||
---Purpose: is used to improve the root of the function F
|
||||
-- from the initial guess StartingPoint.
|
||||
-- The maximum number of iterations allowed is given by
|
||||
-- NbIterations.
|
||||
-- In this case, the solution is found when:
|
||||
-- abs(Xi - Xi-1)(j) <= Tolerance(j) for all unknowns.
|
||||
|
||||
returns FunctionSetRoot from math;
|
||||
|
||||
|
||||
|
||||
Create(F: in out FunctionSetWithDerivatives; StartingPoint: Vector;
|
||||
Tolerance: Vector; infBound, supBound: Vector;
|
||||
NbIterations: Integer = 100; theStopOnDivergent : Boolean from Standard = Standard_False)
|
||||
---Purpose: is used to improve the root of the function F
|
||||
-- from the initial guess StartingPoint.
|
||||
-- The maximum number of iterations allowed is given
|
||||
-- by NbIterations.
|
||||
-- In this case, the solution is found when:
|
||||
-- abs(Xi - Xi-1) <= Tolerance for all unknowns.
|
||||
|
||||
returns FunctionSetRoot from math;
|
||||
|
||||
Delete(me) is static;
|
||||
---Purpose: Destructor alias.
|
||||
---C++: alias " Standard_EXPORT virtual ~math_FunctionSetRoot();"
|
||||
|
||||
|
||||
SetTolerance(me: in out; Tolerance: Vector)
|
||||
---Purpose: Initializes the tolerance values.
|
||||
|
||||
---Purpose: Initializes the tolerance values.
|
||||
is static;
|
||||
|
||||
|
||||
|
||||
Perform(me: in out; F: in out FunctionSetWithDerivatives;
|
||||
StartingPoint: Vector;
|
||||
infBound, supBound: Vector; theStopOnDivergent : Boolean from Standard = Standard_False)
|
||||
---Purpose: Improves the root of function F from the initial guess
|
||||
-- StartingPoint. infBound and supBound may be given to constrain the solution.
|
||||
-- Warning
|
||||
-- This method is called when computation of the solution is
|
||||
-- not performed by the constructors.
|
||||
|
||||
is static;
|
||||
|
||||
|
||||
IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
|
||||
---Purpose: This routine is called at the end of each iteration
|
||||
-- to check if the solution was found. It can be redefined
|
||||
-- in a sub-class to implement a specific test to stop the
|
||||
-- iterations.
|
||||
-- In this case, the solution is found when:
|
||||
-- abs(Xi - Xi-1) <= Tolerance for all unknowns.
|
||||
|
||||
---Purpose: This routine is called at the end of each iteration
|
||||
-- to check if the solution was found. It can be redefined
|
||||
-- in a sub-class to implement a specific test to stop the iterations.
|
||||
-- In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance
|
||||
-- for all unknowns.
|
||||
---C++: inline
|
||||
returns Boolean is virtual;
|
||||
|
||||
|
||||
Perform(me: in out;
|
||||
theFunction: in out FunctionSetWithDerivatives;
|
||||
theStartingPoint: Vector;
|
||||
theStopOnDivergent: Boolean from Standard = Standard_False)
|
||||
---Purpose:
|
||||
-- Improves the root of function from the initial guess point.
|
||||
-- The infinum and supremum may be given to constrain the solution.
|
||||
-- In this case, the solution is found when: abs(Xi - Xi-1)(j) <= Tolerance(j)
|
||||
-- for all unknowns.
|
||||
is static;
|
||||
|
||||
|
||||
Perform(me: in out;
|
||||
theFunction: in out FunctionSetWithDerivatives;
|
||||
theStartingPoint: Vector;
|
||||
theInfBound, theSupBound: Vector;
|
||||
theStopOnDivergent: Boolean from Standard = Standard_False)
|
||||
---Purpose:
|
||||
-- Improves the root of function from the initial guess point.
|
||||
-- The infinum and supremum may be given to constrain the solution.
|
||||
-- In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance
|
||||
-- for all unknowns.
|
||||
is static;
|
||||
|
||||
|
||||
IsDone(me)
|
||||
---Purpose:
|
||||
-- Returns true if the computations are successful, otherwise returns false.
|
||||
|
@@ -228,8 +228,12 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P0,
|
||||
FSR_DEBUG (" minimisation dans la direction")
|
||||
ax = -1; bx = 0;
|
||||
cx = (P2-P1).Norm()*invnorme;
|
||||
if (cx < 1.e-2) return Standard_False;
|
||||
math_BrentMinimum Sol(F, ax, bx, cx, tol1d, 100, tol1d);
|
||||
if (cx < 1.e-2)
|
||||
return Standard_False;
|
||||
|
||||
math_BrentMinimum Sol(tol1d, 100, tol1d);
|
||||
Sol.Perform(F, ax, bx, cx);
|
||||
|
||||
if(Sol.IsDone()) {
|
||||
tsol = Sol.Location();
|
||||
if (Sol.Minimum() < F1) {
|
||||
@@ -322,7 +326,10 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P,
|
||||
ax = 0.0; bx = tsol; cx = 1.0;
|
||||
}
|
||||
FSR_DEBUG(" minimisation dans la direction");
|
||||
math_BrentMinimum Sol(F, ax, bx, cx, tol1d, 100, tol1d);
|
||||
|
||||
math_BrentMinimum Sol(tol1d, 100, tol1d);
|
||||
Sol.Perform(F, ax, bx, cx);
|
||||
|
||||
if(Sol.IsDone()) {
|
||||
if (Sol.Minimum() <= Result) {
|
||||
tsol = Sol.Location();
|
||||
@@ -551,155 +558,109 @@ Standard_Boolean Bounds(const math_Vector& InfBound,
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : math_FunctionSetRoot
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_FunctionSetRoot::math_FunctionSetRoot(
|
||||
math_FunctionSetWithDerivatives& theFunction,
|
||||
const math_Vector& theTolerance,
|
||||
const Standard_Integer theNbIterations)
|
||||
|
||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& Tolerance,
|
||||
const Standard_Integer NbIterations) :
|
||||
Delta(1, F.NbVariables()),
|
||||
Sol(1, F.NbVariables()),
|
||||
DF(1, F.NbEquations(),
|
||||
1, F.NbVariables()),
|
||||
Tol(1,F.NbVariables()),
|
||||
|
||||
InfBound(1, F.NbVariables()),
|
||||
SupBound(1, F.NbVariables()),
|
||||
|
||||
SolSave(1, F.NbVariables()),
|
||||
GH(1, F.NbVariables()),
|
||||
DH(1, F.NbVariables()),
|
||||
DHSave(1, F.NbVariables()),
|
||||
FF(1, F.NbEquations()),
|
||||
PreviousSolution(1, F.NbVariables()),
|
||||
Save(0, NbIterations),
|
||||
Constraints(1, F.NbVariables()),
|
||||
Temp1(1, F.NbVariables()),
|
||||
Temp2(1, F.NbVariables()),
|
||||
Temp3(1, F.NbVariables()),
|
||||
Temp4(1, F.NbEquations())
|
||||
|
||||
: Delta(1, theFunction.NbVariables()),
|
||||
Sol (1, theFunction.NbVariables()),
|
||||
DF (1, theFunction.NbEquations() , 1, theFunction.NbVariables()),
|
||||
Tol (1, theFunction.NbVariables()),
|
||||
Done (Standard_False),
|
||||
Kount (0),
|
||||
State (0),
|
||||
Itermax (theNbIterations),
|
||||
InfBound(1, theFunction.NbVariables(), RealFirst()),
|
||||
SupBound(1, theFunction.NbVariables(), RealLast ()),
|
||||
SolSave (1, theFunction.NbVariables()),
|
||||
GH (1, theFunction.NbVariables()),
|
||||
DH (1, theFunction.NbVariables()),
|
||||
DHSave (1, theFunction.NbVariables()),
|
||||
FF (1, theFunction.NbEquations()),
|
||||
PreviousSolution(1, theFunction.NbVariables()),
|
||||
Save (0, theNbIterations),
|
||||
Constraints(1, theFunction.NbVariables()),
|
||||
Temp1 (1, theFunction.NbVariables()),
|
||||
Temp2 (1, theFunction.NbVariables()),
|
||||
Temp3 (1, theFunction.NbVariables()),
|
||||
Temp4 (1, theFunction.NbEquations()),
|
||||
myIsDivergent(Standard_False)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
||||
Tol(i) =Tolerance(i);
|
||||
}
|
||||
Itermax = NbIterations;
|
||||
SetTolerance(theTolerance);
|
||||
}
|
||||
|
||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
||||
const Standard_Integer NbIterations) :
|
||||
Delta(1, F.NbVariables()),
|
||||
Sol(1, F.NbVariables()),
|
||||
DF(1, F.NbEquations(),
|
||||
1, F.NbVariables()),
|
||||
Tol(1, F.NbVariables()),
|
||||
|
||||
InfBound(1, F.NbVariables()),
|
||||
SupBound(1, F.NbVariables()),
|
||||
|
||||
SolSave(1, F.NbVariables()),
|
||||
GH(1, F.NbVariables()),
|
||||
DH(1, F.NbVariables()),
|
||||
DHSave(1, F.NbVariables()),
|
||||
FF(1, F.NbEquations()),
|
||||
PreviousSolution(1, F.NbVariables()),
|
||||
Save(0, NbIterations),
|
||||
Constraints(1, F.NbVariables()),
|
||||
Temp1(1, F.NbVariables()),
|
||||
Temp2(1, F.NbVariables()),
|
||||
Temp3(1, F.NbVariables()),
|
||||
Temp4(1, F.NbEquations())
|
||||
//=======================================================================
|
||||
//function : math_FunctionSetRoot
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& theFunction,
|
||||
const Standard_Integer theNbIterations)
|
||||
|
||||
: Delta(1, theFunction.NbVariables()),
|
||||
Sol (1, theFunction.NbVariables()),
|
||||
DF (1, theFunction.NbEquations() , 1, theFunction.NbVariables()),
|
||||
Tol (1, theFunction.NbVariables()),
|
||||
Done (Standard_False),
|
||||
Kount (0),
|
||||
State (0),
|
||||
Itermax (theNbIterations),
|
||||
InfBound(1, theFunction.NbVariables(), RealFirst()),
|
||||
SupBound(1, theFunction.NbVariables(), RealLast ()),
|
||||
SolSave (1, theFunction.NbVariables()),
|
||||
GH (1, theFunction.NbVariables()),
|
||||
DH (1, theFunction.NbVariables()),
|
||||
DHSave (1, theFunction.NbVariables()),
|
||||
FF (1, theFunction.NbEquations()),
|
||||
PreviousSolution(1, theFunction.NbVariables()),
|
||||
Save (0, theNbIterations),
|
||||
Constraints(1, theFunction.NbVariables()),
|
||||
Temp1 (1, theFunction.NbVariables()),
|
||||
Temp2 (1, theFunction.NbVariables()),
|
||||
Temp3 (1, theFunction.NbVariables()),
|
||||
Temp4 (1, theFunction.NbEquations()),
|
||||
myIsDivergent(Standard_False)
|
||||
{
|
||||
Itermax = NbIterations;
|
||||
}
|
||||
|
||||
|
||||
|
||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Vector& Tolerance,
|
||||
const math_Vector& infBound,
|
||||
const math_Vector& supBound,
|
||||
const Standard_Integer NbIterations,
|
||||
Standard_Boolean theStopOnDivergent) :
|
||||
Delta(1, F.NbVariables()),
|
||||
Sol(1, F.NbVariables()),
|
||||
DF(1, F.NbEquations(),
|
||||
1, F.NbVariables()),
|
||||
Tol(1,F.NbVariables()),
|
||||
|
||||
|
||||
InfBound(1, F.NbVariables()),
|
||||
SupBound(1, F.NbVariables()),
|
||||
|
||||
SolSave(1, F.NbVariables()),
|
||||
GH(1, F.NbVariables()),
|
||||
DH(1, F.NbVariables()),
|
||||
DHSave(1, F.NbVariables()),
|
||||
FF(1, F.NbEquations()),
|
||||
PreviousSolution(1, F.NbVariables()),
|
||||
Save(0, NbIterations),
|
||||
Constraints(1, F.NbVariables()),
|
||||
Temp1(1, F.NbVariables()),
|
||||
Temp2(1, F.NbVariables()),
|
||||
Temp3(1, F.NbVariables()),
|
||||
Temp4(1, F.NbEquations())
|
||||
|
||||
{
|
||||
|
||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
||||
Tol(i) =Tolerance(i);
|
||||
}
|
||||
Itermax = NbIterations;
|
||||
Perform(F, StartingPoint, infBound, supBound, theStopOnDivergent);
|
||||
}
|
||||
|
||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Vector& Tolerance,
|
||||
const Standard_Integer NbIterations) :
|
||||
Delta(1, F.NbVariables()),
|
||||
Sol(1, F.NbVariables()),
|
||||
DF(1, F.NbEquations(),
|
||||
1, StartingPoint.Length()),
|
||||
Tol(1,F.NbVariables()),
|
||||
|
||||
InfBound(1, F.NbVariables()),
|
||||
SupBound(1, F.NbVariables()),
|
||||
|
||||
SolSave(1, F.NbVariables()),
|
||||
GH(1, F.NbVariables()),
|
||||
DH(1, F.NbVariables()),
|
||||
DHSave(1, F.NbVariables()),
|
||||
FF(1, F.NbEquations()),
|
||||
PreviousSolution(1, F.NbVariables()),
|
||||
Save(0, NbIterations),
|
||||
Constraints(1, F.NbVariables()),
|
||||
Temp1(1, F.NbVariables()),
|
||||
Temp2(1, F.NbVariables()),
|
||||
Temp3(1, F.NbVariables()),
|
||||
Temp4(1, F.NbEquations())
|
||||
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
||||
Tol(i) = Tolerance(i);
|
||||
}
|
||||
Itermax = NbIterations;
|
||||
InfBound.Init(RealFirst());
|
||||
SupBound.Init(RealLast());
|
||||
Perform(F, StartingPoint, InfBound, SupBound);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~math_FunctionSetRoot
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
math_FunctionSetRoot::~math_FunctionSetRoot()
|
||||
{
|
||||
Delete();
|
||||
}
|
||||
|
||||
void math_FunctionSetRoot::SetTolerance(const math_Vector& Tolerance)
|
||||
//=======================================================================
|
||||
//function : SetTolerance
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FunctionSetRoot::SetTolerance(const math_Vector& theTolerance)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
||||
Tol(i) = Tolerance(i);
|
||||
}
|
||||
for (Standard_Integer i = 1; i <= Tol.Length(); ++i)
|
||||
Tol(i) = theTolerance(i);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& theFunction,
|
||||
const math_Vector& theStartingPoint,
|
||||
const Standard_Boolean theStopOnDivergent)
|
||||
{
|
||||
Perform(theFunction, theStartingPoint, InfBound, SupBound, theStopOnDivergent);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Vector& theInfBound,
|
||||
@@ -1232,38 +1193,40 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Standard_Boolean math_FunctionSetRoot::IsSolutionReached(math_FunctionSetWithDerivatives& ) {
|
||||
for(Standard_Integer i = 1; i<= Sol.Length(); i++) {
|
||||
if(Abs(Delta(i)) > Tol(i)) {return Standard_False;}
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
|
||||
void math_FunctionSetRoot::Dump(Standard_OStream& o) const {
|
||||
o<<" math_FunctionSetRoot";
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FunctionSetRoot::Dump(Standard_OStream& o) const
|
||||
{
|
||||
o << " math_FunctionSetRoot";
|
||||
if (Done) {
|
||||
o << " Status = Done\n";
|
||||
o << " Location value = " << Sol << "\n";
|
||||
o << " Number of iterations = " << Kount << "\n";
|
||||
}
|
||||
else {
|
||||
o<<"Status = Not Done\n";
|
||||
o << "Status = Not Done\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void math_FunctionSetRoot::Root(math_Vector& Root) const{
|
||||
//=======================================================================
|
||||
//function : Root
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FunctionSetRoot::Root(math_Vector& Root) const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!Done, " ");
|
||||
Standard_DimensionError_Raise_if(Root.Length() != Sol.Length(), " ");
|
||||
Root = Sol;
|
||||
}
|
||||
|
||||
|
||||
void math_FunctionSetRoot::FunctionSetErrors(math_Vector& Err) const{
|
||||
//=======================================================================
|
||||
//function : FunctionSetErrors
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_FunctionSetRoot::FunctionSetErrors(math_Vector& Err) const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!Done, " ");
|
||||
Standard_DimensionError_Raise_if(Err.Length() != Sol.Length(), " ");
|
||||
Err = Delta;
|
||||
|
@@ -15,8 +15,26 @@
|
||||
#include <StdFail_NotDone.hxx>
|
||||
#include <Standard_DimensionError.hxx>
|
||||
|
||||
inline void math_FunctionSetRoot::Delete() const
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline Standard_Boolean math_FunctionSetRoot::IsSolutionReached(math_FunctionSetWithDerivatives&)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= Sol.Length(); ++i)
|
||||
if ( Abs(Delta(i)) > Tol(i) )
|
||||
return Standard_False;
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
|
||||
inline Standard_Boolean math_FunctionSetRoot::IsDone() const
|
||||
{
|
||||
return Done;
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_FunctionSetRoot::IsDone() const { return Done; }
|
||||
|
||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||
const math_FunctionSetRoot& F)
|
||||
|
@@ -247,7 +247,9 @@ Standard_Boolean math_GlobOptMin::computeLocalExtremum(const math_Vector& thePnt
|
||||
math_MultipleVarFunctionWithHessian* myTmp =
|
||||
dynamic_cast<math_MultipleVarFunctionWithHessian*> (myFunc);
|
||||
|
||||
math_NewtonMinimum newtonMinimum(*myTmp, thePnt);
|
||||
math_NewtonMinimum newtonMinimum(*myTmp);
|
||||
newtonMinimum.Perform(*myTmp, thePnt);
|
||||
|
||||
if (newtonMinimum.IsDone())
|
||||
{
|
||||
newtonMinimum.Location(theOutPnt);
|
||||
@@ -278,7 +280,8 @@ Standard_Boolean math_GlobOptMin::computeLocalExtremum(const math_Vector& thePnt
|
||||
for(i = 1; i <= myN; i++)
|
||||
m(1, 1) = 1.0;
|
||||
|
||||
math_Powell powell(*myFunc, thePnt, m, 1e-10);
|
||||
math_Powell powell(*myFunc, 1e-10);
|
||||
powell.Perform(*myFunc, thePnt, m);
|
||||
|
||||
if (powell.IsDone())
|
||||
{
|
||||
|
@@ -30,96 +30,66 @@ raises NotDone from StdFail,
|
||||
|
||||
is
|
||||
|
||||
Create(F: in out FunctionSetWithDerivatives;
|
||||
XTol: Vector; FTol: Real;
|
||||
NbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- This constructor should be used in a sub-class to initialize
|
||||
-- correctly all the fields of this class.
|
||||
-- The range (1, F.NbVariables()) must be especially respected for
|
||||
-- all vectors and matrix declarations.
|
||||
|
||||
returns NewtonFunctionSetRoot;
|
||||
|
||||
|
||||
Create(F: in out FunctionSetWithDerivatives;
|
||||
FTol: Real; NbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- This constructor should be used in a sub-class to initialize
|
||||
-- correctly all the fields of this class.
|
||||
-- The range (1, F.NbVariables()) must be especially respected for
|
||||
-- all vectors and matrix declarations.
|
||||
-- The method SetTolerance must be called before performing the
|
||||
-- algorithm.
|
||||
|
||||
returns NewtonFunctionSetRoot;
|
||||
|
||||
|
||||
|
||||
Create(F: in out FunctionSetWithDerivatives;
|
||||
StartingPoint: Vector;
|
||||
XTol: Vector; FTol: Real;
|
||||
NbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- The Newton method is done to improve the root of the function F
|
||||
-- from the initial guess StartingPoint.
|
||||
-- The tolerance required on the root is given by Tolerance.
|
||||
-- The solution is found when :
|
||||
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
|
||||
returns NewtonFunctionSetRoot;
|
||||
|
||||
Create(theFunction: in out FunctionSetWithDerivatives;
|
||||
theXTolerance: Vector; theFTolerance: Real;
|
||||
tehNbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- Initialize correctly all the fields of this class.
|
||||
-- The range (1, F.NbVariables()) must be especially respected for
|
||||
-- all vectors and matrix declarations.
|
||||
returns NewtonFunctionSetRoot;
|
||||
|
||||
|
||||
Create(F: in out FunctionSetWithDerivatives;
|
||||
StartingPoint: Vector;
|
||||
InfBound, SupBound: Vector;
|
||||
XTol: Vector; FTol: Real;
|
||||
NbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- The Newton method is done to improve the root of the function F
|
||||
-- from the initial guess StartingPoint.
|
||||
-- The tolerance required on the root is given by Tolerance.
|
||||
-- The solution is found when :
|
||||
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
|
||||
returns NewtonFunctionSetRoot;
|
||||
Create(theFunction: in out FunctionSetWithDerivatives;
|
||||
theFTolerance: Real; theNbIterations: Integer = 100)
|
||||
---Purpose:
|
||||
-- This constructor should be used in a sub-class to initialize
|
||||
-- correctly all the fields of this class.
|
||||
-- The range (1, F.NbVariables()) must be especially respected for
|
||||
-- all vectors and matrix declarations.
|
||||
-- The method SetTolerance must be called before performing the algorithm.
|
||||
returns NewtonFunctionSetRoot;
|
||||
|
||||
|
||||
Delete(me) is static;
|
||||
---Purpose: Destructor alias.
|
||||
---C++: alias " Standard_EXPORT virtual ~math_NewtonFunctionSetRoot();"
|
||||
|
||||
|
||||
|
||||
SetTolerance(me: in out; XTol: Vector)
|
||||
---Purpose: Initializes the tolerance values for the unknowns.
|
||||
|
||||
is static;
|
||||
|
||||
|
||||
Perform(me: in out; F:in out FunctionSetWithDerivatives;
|
||||
StartingPoint: Vector;
|
||||
InfBound, SupBound: Vector)
|
||||
---Purpose: Improves the root of function F from the initial guess
|
||||
-- StartingPoint. infBound and supBound may be given, to constrain the solution.
|
||||
-- Warning
|
||||
-- This method must be called when the solution is not computed by the constructors.
|
||||
|
||||
---Purpose: Initializes the tolerance values for the unknowns.
|
||||
is static;
|
||||
|
||||
|
||||
Perform(me: in out; theFunction: in out FunctionSetWithDerivatives; theStartingPoint: Vector)
|
||||
---Purpose:
|
||||
-- The Newton method is done to improve the root of the function
|
||||
-- from the initial guess point. The solution is found when:
|
||||
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
||||
is static;
|
||||
|
||||
|
||||
Perform(me: in out; theFunction: in out FunctionSetWithDerivatives;
|
||||
theStartingPoint: Vector; theInfBound, theSupBound: Vector)
|
||||
---Purpose:
|
||||
-- The Newton method is done to improve the root of the function
|
||||
-- from the initial guess point. Bounds may be given, to constrain the solution.
|
||||
-- The solution is found when:
|
||||
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
||||
is static;
|
||||
|
||||
|
||||
|
||||
IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
|
||||
---Purpose:
|
||||
-- This method is called at the end of each iteration to check if the
|
||||
-- solution is found.
|
||||
-- Vectors DeltaX, Fvalues and Jacobian Matrix are consistent with the
|
||||
-- possible solution Vector Sol and can be inspected to decide whether
|
||||
-- the solution is reached or not.
|
||||
---Purpose:
|
||||
-- This method is called at the end of each iteration to check if the
|
||||
-- solution is found.
|
||||
-- Vectors DeltaX, Fvalues and Jacobian Matrix are consistent with the
|
||||
-- possible solution Vector Sol and can be inspected to decide whether
|
||||
-- the solution is reached or not.
|
||||
---C++: inline
|
||||
returns Boolean is virtual;
|
||||
|
||||
|
||||
returns Boolean
|
||||
is virtual;
|
||||
|
||||
|
||||
IsDone(me)
|
||||
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
||||
---C++: inline
|
||||
|
@@ -22,128 +22,93 @@
|
||||
#include <math_Recipes.hxx>
|
||||
#include <math_FunctionSetWithDerivatives.hxx>
|
||||
|
||||
Standard_Boolean math_NewtonFunctionSetRoot::IsSolutionReached
|
||||
// (math_FunctionSetWithDerivatives& F)
|
||||
(math_FunctionSetWithDerivatives& )
|
||||
{
|
||||
|
||||
for(Standard_Integer i = DeltaX.Lower(); i <= DeltaX.Upper(); i++) {
|
||||
if(Abs(DeltaX(i)) > TolX(i) || Abs(FValues(i)) > TolF) return Standard_False;
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
|
||||
// Constructeurs d'initialisation des champs (pour utiliser Perform)
|
||||
|
||||
//=======================================================================
|
||||
//function : math_NewtonFunctionSetRoot
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
|
||||
math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& XTol,
|
||||
const Standard_Real FTol,
|
||||
const Standard_Integer NbIterations):
|
||||
TolX(1, F.NbVariables()),
|
||||
TolF(FTol),
|
||||
Indx(1, F.NbVariables()),
|
||||
Scratch(1, F.NbVariables()),
|
||||
Sol(1, F.NbVariables()),
|
||||
DeltaX(1, F.NbVariables()),
|
||||
FValues(1, F.NbVariables()),
|
||||
Jacobian(1, F.NbVariables(),
|
||||
1, F.NbVariables()),
|
||||
Itermax(NbIterations)
|
||||
math_FunctionSetWithDerivatives& theFunction,
|
||||
const math_Vector& theXTolerance,
|
||||
const Standard_Real theFTolerance,
|
||||
const Standard_Integer theNbIterations)
|
||||
|
||||
: TolX (1, theFunction.NbVariables()),
|
||||
TolF (theFTolerance),
|
||||
Indx (1, theFunction.NbVariables()),
|
||||
Scratch (1, theFunction.NbVariables()),
|
||||
Sol (1, theFunction.NbVariables()),
|
||||
DeltaX (1, theFunction.NbVariables()),
|
||||
FValues (1, theFunction.NbVariables()),
|
||||
Jacobian(1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||
Done (Standard_False),
|
||||
State (0),
|
||||
Iter (0),
|
||||
Itermax (theNbIterations)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
||||
TolX(i) = XTol(i);
|
||||
}
|
||||
SetTolerance(theXTolerance);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : math_NewtonFunctionSetRoot
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
|
||||
math_FunctionSetWithDerivatives& F,
|
||||
const Standard_Real FTol,
|
||||
const Standard_Integer NbIterations):
|
||||
TolX(1, F.NbVariables()),
|
||||
TolF(FTol),
|
||||
Indx(1, F.NbVariables()),
|
||||
Scratch(1, F.NbVariables()),
|
||||
Sol(1, F.NbVariables()),
|
||||
DeltaX(1, F.NbVariables()),
|
||||
FValues(1, F.NbVariables()),
|
||||
Jacobian(1, F.NbVariables(),
|
||||
1, F.NbVariables()),
|
||||
Itermax(NbIterations)
|
||||
math_FunctionSetWithDerivatives& theFunction,
|
||||
const Standard_Real theFTolerance,
|
||||
const Standard_Integer theNbIterations)
|
||||
|
||||
: TolX (1, theFunction.NbVariables()),
|
||||
TolF (theFTolerance),
|
||||
Indx (1, theFunction.NbVariables()),
|
||||
Scratch (1, theFunction.NbVariables()),
|
||||
Sol (1, theFunction.NbVariables()),
|
||||
DeltaX (1, theFunction.NbVariables()),
|
||||
FValues (1, theFunction.NbVariables()),
|
||||
Jacobian(1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||
Done (Standard_False),
|
||||
State (0),
|
||||
Iter (0),
|
||||
Itermax (theNbIterations)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot
|
||||
(math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Vector& XTol,
|
||||
const Standard_Real FTol,
|
||||
const Standard_Integer NbIterations) :
|
||||
|
||||
TolX(1, F.NbVariables()),
|
||||
TolF(FTol),
|
||||
Indx (1, F.NbVariables()),
|
||||
Scratch (1, F.NbVariables()),
|
||||
Sol (1, F.NbVariables()),
|
||||
DeltaX (1, F.NbVariables()),
|
||||
FValues (1, F.NbVariables()),
|
||||
Jacobian(1, F.NbVariables(),
|
||||
1, F.NbVariables()),
|
||||
Itermax(NbIterations)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
||||
TolX(i) = XTol(i);
|
||||
}
|
||||
math_Vector UFirst(1, F.NbVariables()),
|
||||
ULast(1, F.NbVariables());
|
||||
UFirst.Init(RealFirst());
|
||||
ULast.Init(RealLast());
|
||||
Perform(F, StartingPoint, UFirst, ULast);
|
||||
}
|
||||
|
||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot
|
||||
(math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Vector& InfBound,
|
||||
const math_Vector& SupBound,
|
||||
const math_Vector& XTol,
|
||||
const Standard_Real FTol,
|
||||
const Standard_Integer NbIterations) :
|
||||
|
||||
TolX(1, F.NbVariables()),
|
||||
TolF(FTol),
|
||||
Indx (1, F.NbVariables()),
|
||||
Scratch (1, F.NbVariables()),
|
||||
Sol (1, F.NbVariables()),
|
||||
DeltaX (1, F.NbVariables()),
|
||||
FValues (1, F.NbVariables()),
|
||||
Jacobian(1, F.NbVariables(),
|
||||
1, F.NbVariables()),
|
||||
Itermax(NbIterations)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
||||
TolX(i) = XTol(i);
|
||||
}
|
||||
Perform(F, StartingPoint, InfBound, SupBound);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~math_NewtonFunctionSetRoot
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
math_NewtonFunctionSetRoot::~math_NewtonFunctionSetRoot()
|
||||
{
|
||||
}
|
||||
|
||||
void math_NewtonFunctionSetRoot::SetTolerance
|
||||
(const math_Vector& XTol)
|
||||
//=======================================================================
|
||||
//function : SetTolerance
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_NewtonFunctionSetRoot::SetTolerance(const math_Vector& theXTolerance)
|
||||
{
|
||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
||||
TolX(i) = XTol(i);
|
||||
}
|
||||
for (Standard_Integer i = 1; i <= TolX.Length(); ++i)
|
||||
TolX(i) = theXTolerance(i);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_NewtonFunctionSetRoot::Perform(
|
||||
math_FunctionSetWithDerivatives& theFunction,
|
||||
const math_Vector& theStartingPoint)
|
||||
{
|
||||
const math_Vector anInf(1, theFunction.NbVariables(), RealFirst());
|
||||
const math_Vector aSup (1, theFunction.NbVariables(), RealLast ());
|
||||
|
||||
Perform(theFunction, theStartingPoint, anInf, aSup);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_NewtonFunctionSetRoot::Perform(
|
||||
math_FunctionSetWithDerivatives& F,
|
||||
const math_Vector& StartingPoint,
|
||||
@@ -184,6 +149,10 @@ void math_NewtonFunctionSetRoot::Perform(
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_NewtonFunctionSetRoot::Dump(Standard_OStream& o) const
|
||||
{
|
||||
o <<"math_NewtonFunctionSetRoot ";
|
||||
|
@@ -14,8 +14,23 @@
|
||||
|
||||
#include <StdFail_NotDone.hxx>
|
||||
|
||||
inline Standard_Boolean math_NewtonFunctionSetRoot::IsDone() const
|
||||
{ return Done;}
|
||||
inline void math_NewtonFunctionSetRoot::Delete() const
|
||||
{
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_NewtonFunctionSetRoot::IsSolutionReached(math_FunctionSetWithDerivatives&)
|
||||
{
|
||||
for (Standard_Integer i = DeltaX.Lower(); i <= DeltaX.Upper(); ++i)
|
||||
if ( Abs(DeltaX(i)) > TolX(i) || Abs(FValues(i)) > TolF )
|
||||
return Standard_False;
|
||||
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_NewtonFunctionSetRoot::IsDone() const
|
||||
{
|
||||
return Done;
|
||||
}
|
||||
|
||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||
const math_NewtonFunctionSetRoot& N)
|
||||
|
@@ -28,57 +28,41 @@ raises NotDone, DimensionError
|
||||
|
||||
is
|
||||
|
||||
Create(F: in out MultipleVarFunctionWithHessian;
|
||||
StartingPoint: Vector;
|
||||
Tolerance: Real=1.0e-7;
|
||||
NbIterations: Integer=40;
|
||||
Convexity: Real=1.0e-6;
|
||||
WithSingularity : Boolean = Standard_True)
|
||||
---Purpose: -- Given the starting point StartingPoint,
|
||||
-- The tolerance required on the solution is given by
|
||||
-- Tolerance.
|
||||
-- Iteration are stopped if
|
||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||
-- or IsConverged() returns True for 2 successives Iterations.
|
||||
-- Warning: Obsolete Constructor (because IsConverged can not be redefined
|
||||
-- with this. )
|
||||
Create(theFunction: in MultipleVarFunctionWithHessian;
|
||||
theTolerance: Real=1.0e-7;
|
||||
theNbIterations: Integer=40;
|
||||
theConvexity: Real=1.0e-6;
|
||||
theWithSingularity: Boolean = Standard_True)
|
||||
---Purpose:
|
||||
-- The tolerance required on the solution is given by Tolerance.
|
||||
-- Iteration are stopped if (!WithSingularity) and H(F(Xi)) is not definite
|
||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||
-- or IsConverged() returns True for 2 successives Iterations.
|
||||
-- Warning: This constructor does not perform computation.
|
||||
returns NewtonMinimum;
|
||||
|
||||
Create(F: in out MultipleVarFunctionWithHessian;
|
||||
Tolerance: Real=1.0e-7;
|
||||
NbIterations: Integer=40;
|
||||
Convexity: Real=1.0e-6;
|
||||
WithSingularity : Boolean = Standard_True)
|
||||
---Purpose:
|
||||
-- The tolerance required on the solution is given by
|
||||
-- Tolerance.
|
||||
-- Iteration are stopped if
|
||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||
-- or IsConverged() returns True for 2 successives Iterations.
|
||||
-- Warning: This constructor do not computation
|
||||
returns NewtonMinimum;
|
||||
|
||||
---C++: alias " Standard_EXPORT virtual ~math_NewtonMinimum();"
|
||||
|
||||
Perform(me: in out; F: in out MultipleVarFunctionWithHessian;
|
||||
StartingPoint: Vector)
|
||||
---Purpose: Search the solution.
|
||||
|
||||
Perform(me: in out; theFunction: in out MultipleVarFunctionWithHessian;
|
||||
theStartingPoint: Vector)
|
||||
---Purpose: Search the solution.
|
||||
is static;
|
||||
|
||||
|
||||
|
||||
Delete(me) is static;
|
||||
---Purpose: Destructor alias.
|
||||
---C++: inline
|
||||
---C++: alias " Standard_EXPORT virtual ~math_NewtonMinimum();"
|
||||
|
||||
|
||||
IsConverged(me)
|
||||
---Purpose: This method is called at the end of each
|
||||
-- iteration to check the convergence :
|
||||
-- || Xi+1 - Xi || < Tolerance
|
||||
-- or || F(Xi+1) - F(Xi)|| < Tolerance * || F(Xi) ||
|
||||
-- It can be redefined in a sub-class to implement a specific test.
|
||||
|
||||
returns Boolean
|
||||
is virtual;
|
||||
|
||||
|
||||
---Purpose:
|
||||
-- This method is called at the end of each iteration to check the convergence:
|
||||
-- || Xi+1 - Xi || < Tolerance or || F(Xi+1) - F(Xi)|| < Tolerance * || F(Xi) ||
|
||||
-- It can be redefined in a sub-class to implement a specific test.
|
||||
---C++: inline
|
||||
returns Boolean is virtual;
|
||||
|
||||
|
||||
IsDone(me)
|
||||
---Purpose: Tests if an error has occured.
|
||||
---C++: inline
|
||||
|
@@ -25,58 +25,49 @@
|
||||
#include <math_Gauss.hxx>
|
||||
#include <math_Jacobi.hxx>
|
||||
|
||||
//============================================================================
|
||||
math_NewtonMinimum::math_NewtonMinimum(math_MultipleVarFunctionWithHessian& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const Standard_Real Tolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real Convexity,
|
||||
const Standard_Boolean WithSingularity)
|
||||
//============================================================================
|
||||
: TheLocation(1, F.NbVariables()),
|
||||
TheGradient(1, F.NbVariables()),
|
||||
TheStep(1, F.NbVariables(), 10*Tolerance),
|
||||
TheHessian(1, F.NbVariables(), 1, F.NbVariables() )
|
||||
//=======================================================================
|
||||
//function : math_NewtonMinimum
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_NewtonMinimum::math_NewtonMinimum(
|
||||
const math_MultipleVarFunctionWithHessian& theFunction,
|
||||
const Standard_Real theTolerance,
|
||||
const Standard_Integer theNbIterations,
|
||||
const Standard_Real theConvexity,
|
||||
const Standard_Boolean theWithSingularity
|
||||
)
|
||||
: TheStatus (math_NotBracketed),
|
||||
TheLocation(1, theFunction.NbVariables()),
|
||||
TheGradient(1, theFunction.NbVariables()),
|
||||
TheStep (1, theFunction.NbVariables(), 10.0 * theTolerance),
|
||||
TheHessian (1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||
PreviousMinimum (0.0),
|
||||
TheMinimum (0.0),
|
||||
MinEigenValue (0.0),
|
||||
XTol (theTolerance),
|
||||
CTol (theConvexity),
|
||||
nbiter (0),
|
||||
NoConvexTreatement(theWithSingularity),
|
||||
Convex (Standard_True),
|
||||
Done (Standard_False),
|
||||
Itermax (theNbIterations)
|
||||
{
|
||||
XTol = Tolerance;
|
||||
CTol = Convexity;
|
||||
Itermax = NbIterations;
|
||||
NoConvexTreatement = WithSingularity;
|
||||
Convex = Standard_True;
|
||||
// Done = Standard_True;
|
||||
// TheStatus = math_OK;
|
||||
Perform ( F, StartingPoint);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
math_NewtonMinimum::math_NewtonMinimum(math_MultipleVarFunctionWithHessian& F,
|
||||
const Standard_Real Tolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real Convexity,
|
||||
const Standard_Boolean WithSingularity)
|
||||
//============================================================================
|
||||
: TheLocation(1, F.NbVariables()),
|
||||
TheGradient(1, F.NbVariables()),
|
||||
TheStep(1, F.NbVariables(), 10*Tolerance),
|
||||
TheHessian(1, F.NbVariables(), 1, F.NbVariables() )
|
||||
{
|
||||
XTol = Tolerance;
|
||||
CTol = Convexity;
|
||||
Itermax = NbIterations;
|
||||
NoConvexTreatement = WithSingularity;
|
||||
Convex = Standard_True;
|
||||
Done = Standard_False;
|
||||
TheStatus = math_NotBracketed;
|
||||
}
|
||||
//============================================================================
|
||||
//=======================================================================
|
||||
//function : ~math_NewtonMinimum
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
math_NewtonMinimum::~math_NewtonMinimum()
|
||||
{
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_NewtonMinimum::Perform(math_MultipleVarFunctionWithHessian& F,
|
||||
const math_Vector& StartingPoint)
|
||||
//============================================================================
|
||||
const math_Vector& StartingPoint)
|
||||
{
|
||||
math_Vector Point1 (1, F.NbVariables());
|
||||
Point1 = StartingPoint;
|
||||
@@ -191,26 +182,20 @@ void math_NewtonMinimum::Perform(math_MultipleVarFunctionWithHessian& F,
|
||||
TheLocation = *precedent;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
Standard_Boolean math_NewtonMinimum::IsConverged() const
|
||||
//============================================================================
|
||||
{
|
||||
return ( (TheStep.Norm() <= XTol ) ||
|
||||
( Abs(TheMinimum-PreviousMinimum) <= XTol*Abs(PreviousMinimum) ));
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_NewtonMinimum::Dump(Standard_OStream& o) const
|
||||
//============================================================================
|
||||
{
|
||||
o<< "math_Newton Optimisation: ";
|
||||
o << " Done =" << Done << endl;
|
||||
o << " Status = " << (Standard_Integer)TheStatus << endl;
|
||||
o <<" Location Vector = " << Location() << endl;
|
||||
o <<" Minimum value = "<< Minimum()<< endl;
|
||||
o <<" Previous value = "<< PreviousMinimum << endl;
|
||||
o <<" Number of iterations = " <<NbIterations() << endl;
|
||||
o <<" Convexity = " << Convex << endl;
|
||||
o <<" Eigen Value = " << MinEigenValue << endl;
|
||||
o<< "math_Newton Optimisation: ";
|
||||
o << " Done =" << Done << endl;
|
||||
o << " Status = " << (Standard_Integer)TheStatus << endl;
|
||||
o << " Location Vector = " << Location() << endl;
|
||||
o << " Minimum value = "<< Minimum()<< endl;
|
||||
o << " Previous value = "<< PreviousMinimum << endl;
|
||||
o << " Number of iterations = " <<NbIterations() << endl;
|
||||
o << " Convexity = " << Convex << endl;
|
||||
o << " Eigen Value = " << MinEigenValue << endl;
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,16 @@
|
||||
|
||||
#include <StdFail_NotDone.hxx>
|
||||
|
||||
inline void math_NewtonMinimum::Delete() const
|
||||
{
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_NewtonMinimum::IsConverged() const
|
||||
{
|
||||
return ( (TheStep.Norm() <= XTol ) ||
|
||||
( Abs(TheMinimum-PreviousMinimum) <= XTol * Abs(PreviousMinimum) ));
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_NewtonMinimum::IsDone() const
|
||||
{
|
||||
return Done;
|
||||
|
@@ -27,52 +27,37 @@ raises NotDone from StdFail,
|
||||
|
||||
is
|
||||
|
||||
Create(F: in out MultipleVarFunction; StartingPoint: Vector;
|
||||
StartingDirections: Matrix; Tolerance: Real;
|
||||
NbIterations: Integer=200; ZEPS: Real=1.0e-12)
|
||||
---Purpose:
|
||||
-- Computes Powell minimization on the function F given
|
||||
-- StartingPoint, and an initial matrix StartingDirection
|
||||
-- whose columns contain the initial set of directions. The
|
||||
-- solution F = Fi is found when 2.0 * abs(Fi - Fi-1) =
|
||||
-- <Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS). The maximum
|
||||
-- number of iterations allowed is given by NbIterations.
|
||||
returns Powell;
|
||||
|
||||
|
||||
Create(F: in out MultipleVarFunction;
|
||||
Tolerance: Real;
|
||||
NbIterations: Integer = 200;
|
||||
ZEPS: Real = 1.0e-12)
|
||||
---Purpose: is used in a sub-class to initialize correctly all the fields
|
||||
-- of this class.
|
||||
|
||||
Create(theFunction: in MultipleVarFunction;
|
||||
theTolerance: Real; theNbIterations: Integer = 200; theZEPS: Real = 1.0e-12)
|
||||
---Purpose: Constructor. Initialize new entity.
|
||||
returns Powell;
|
||||
|
||||
|
||||
Delete(me) is static;
|
||||
---Purpose: Destructor alias
|
||||
---C++: inline
|
||||
---C++: alias " Standard_EXPORT virtual ~math_Powell();"
|
||||
|
||||
Perform(me: in out;F: in out MultipleVarFunction;
|
||||
StartingPoint: Vector;
|
||||
StartingDirections: Matrix)
|
||||
---Purpose: Use this method after a call to the initialization constructor
|
||||
-- to compute the minimum of function F.
|
||||
-- Warning
|
||||
-- The initialization constructor must have been called before
|
||||
-- the Perform method is called.
|
||||
|
||||
|
||||
Perform(me: in out; theFunction: in out MultipleVarFunction; theStartingPoint: Vector; theStartingDirections: Matrix)
|
||||
---Purpose:
|
||||
-- Computes Powell minimization on the function F given
|
||||
-- theStartingPoint, and an initial matrix theStartingDirection
|
||||
-- whose columns contain the initial set of directions.
|
||||
-- The solution F = Fi is found when:
|
||||
-- 2.0 * abs(Fi - Fi-1) =< Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
|
||||
is static;
|
||||
|
||||
|
||||
IsSolutionReached(me: in out; F: in out MultipleVarFunction)
|
||||
---Purpose:
|
||||
-- solution F = Fi is found when :
|
||||
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
|
||||
returns Boolean
|
||||
is virtual;
|
||||
|
||||
|
||||
IsSolutionReached(me: in out; theFunction: in out MultipleVarFunction)
|
||||
---Purpose:
|
||||
-- Solution F = Fi is found when:
|
||||
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
||||
-- The maximum number of iterations allowed is given by NbIterations.
|
||||
---C++: inline
|
||||
returns Boolean is virtual;
|
||||
|
||||
|
||||
IsDone(me)
|
||||
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
||||
---C++: inline
|
||||
@@ -150,4 +135,3 @@ State: Integer;
|
||||
Itermax: Integer;
|
||||
|
||||
end Powell;
|
||||
|
||||
|
@@ -92,7 +92,8 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
||||
math_BracketMinimum Bracket(F, 0.0, 1.0);
|
||||
if (Bracket.IsDone()) {
|
||||
Bracket.Values(ax, xx, bx);
|
||||
math_BrentMinimum Sol(F, ax, xx, bx, 1.0e-10, 100);
|
||||
math_BrentMinimum Sol(1.0e-10);
|
||||
Sol.Perform(F, ax, xx, bx);
|
||||
if (Sol.IsDone()) {
|
||||
Standard_Real Scale = Sol.Location();
|
||||
Result = Sol.Minimum();
|
||||
@@ -104,15 +105,45 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : math_Powell
|
||||
//purpose : Constructor
|
||||
//=======================================================================
|
||||
math_Powell::math_Powell(const math_MultipleVarFunction& theFunction,
|
||||
const Standard_Real theTolerance,
|
||||
const Standard_Integer theNbIterations,
|
||||
const Standard_Real theZEPS)
|
||||
: TheLocation (1, theFunction.NbVariables()),
|
||||
TheMinimum (RealLast()),
|
||||
TheLocationError(RealLast()),
|
||||
PreviousMinimum (RealLast()),
|
||||
XTol (theTolerance),
|
||||
EPSZ (theZEPS),
|
||||
Done (Standard_False),
|
||||
Iter (0),
|
||||
TheStatus (math_NotBracketed),
|
||||
TheDirections (1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||
State (0),
|
||||
Itermax (theNbIterations)
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ~math_Powell
|
||||
//purpose : Destructor
|
||||
//=======================================================================
|
||||
math_Powell::~math_Powell()
|
||||
{
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_Powell::Perform(math_MultipleVarFunction& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Matrix& StartingDirections) {
|
||||
|
||||
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Matrix& StartingDirections)
|
||||
{
|
||||
Done = Standard_False;
|
||||
Standard_Integer i, ibig, j;
|
||||
Standard_Real t, fptt, del;
|
||||
@@ -195,48 +226,13 @@ void math_Powell::Perform(math_MultipleVarFunction& F,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Standard_Boolean math_Powell::IsSolutionReached(
|
||||
// math_MultipleVarFunction& F) {
|
||||
math_MultipleVarFunction& ) {
|
||||
|
||||
return 2.0*fabs(PreviousMinimum - TheMinimum) <=
|
||||
XTol*(fabs(PreviousMinimum)+fabs(TheMinimum) + EPSZ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
math_Powell::math_Powell(math_MultipleVarFunction& F,
|
||||
const math_Vector& StartingPoint,
|
||||
const math_Matrix& StartingDirections,
|
||||
const Standard_Real Tolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real ZEPS) :
|
||||
TheLocation(1, F.NbVariables()),
|
||||
TheDirections(1, F.NbVariables(),
|
||||
1, F.NbVariables()) {
|
||||
|
||||
XTol = Tolerance;
|
||||
EPSZ = ZEPS;
|
||||
Itermax = NbIterations;
|
||||
Perform(F, StartingPoint, StartingDirections);
|
||||
}
|
||||
|
||||
math_Powell::math_Powell(math_MultipleVarFunction& F,
|
||||
const Standard_Real Tolerance,
|
||||
const Standard_Integer NbIterations,
|
||||
const Standard_Real ZEPS) :
|
||||
TheLocation(1, F.NbVariables()),
|
||||
TheDirections(1, F.NbVariables(),
|
||||
1, F.NbVariables()) {
|
||||
|
||||
XTol = Tolerance;
|
||||
EPSZ = ZEPS;
|
||||
Itermax = NbIterations;
|
||||
}
|
||||
|
||||
void math_Powell::Dump(Standard_OStream& o) const {
|
||||
|
||||
//=======================================================================
|
||||
//function : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void math_Powell::Dump(Standard_OStream& o) const
|
||||
{
|
||||
o << "math_Powell resolution:";
|
||||
if(Done) {
|
||||
o << " Status = Done \n";
|
||||
|
@@ -15,7 +15,20 @@
|
||||
#include <StdFail_NotDone.hxx>
|
||||
#include <math_Vector.hxx>
|
||||
|
||||
inline Standard_Boolean math_Powell::IsDone() const { return Done; }
|
||||
inline void math_Powell::Delete() const
|
||||
{
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_Powell::IsSolutionReached(math_MultipleVarFunction&)
|
||||
{
|
||||
return 2.0 * fabs(PreviousMinimum - TheMinimum) <=
|
||||
XTol * (fabs(PreviousMinimum) + fabs(TheMinimum) + EPSZ);
|
||||
}
|
||||
|
||||
inline Standard_Boolean math_Powell::IsDone() const
|
||||
{
|
||||
return Done;
|
||||
}
|
||||
|
||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||
const math_Powell& P)
|
||||
|
Reference in New Issue
Block a user