Changeset 2808 in Sophya for trunk/SophyaLib/NTools/simplex.cc


Ignore:
Timestamp:
Jun 14, 2005, 1:25:05 PM (20 years ago)
Author:
ansari
Message:

MAJ documentation - Reza 14/6/2005

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/NTools/simplex.cc

    r2650 r2808  
    1010//---------------------------------------------------------------
    1111// Interface de classe de function multivariable pour le SimplexMinmizer
     12/*!
     13  \class SOPHYA::MinZFunction
     14  \ingroup NTools
     15  Interface definition for a function object f(x[]) for which MinZSimplex can
     16  search the minimum.
     17  The pure virtual method Value() should be implemented by the derived classes.
     18*/
    1219
    1320MinZFunction::MinZFunction(unsigned int nvar)
     
    2330//-------------------  Classe   MinZFuncXi2  --------------------
    2431//---------------------------------------------------------------
     32/*!
     33  \class SOPHYA::MinZXi2
     34  \ingroup NTools
     35  Implements the MinZFunction interface using a xi2 calculator
     36  \sa GeneralXi2 GeneralFitData
     37*/
    2538MinZFuncXi2::MinZFuncXi2(GeneralXi2* gxi2, GeneralFitData* gd)
    2639  : mGXi2(gxi2) , mGData(gd), MinZFunction(gxi2->NPar())
     
    174187}
    175188
     189/*!
     190  \class SOPHYA::MinZSimplex
     191  \ingroup NTools
     192  This class implements non linear minimization (optimization)
     193  in a multidimensional space following the \b Simplex method.
     194  A \b Simplex is a geometrical figure made of N+1 points in a
     195  N-dimensional space. (triangle in a plane, tetrahedron in 3-d space).
     196  The minimization method implemented in this class is based on the
     197  algorithm described in "Numerical Recipes, Chapter X".
     198
     199  The algorithm has been slightly enhanced :
     200  - More complex convergence / stop test
     201  - A new transformation of the simplex has been included (ExpandHigh)
     202
     203  For each step, on of the following geometrical transform is performed
     204  on the Simplex figure:
     205  - Reflection : reflection away from the high point (expansion by factor Alpha)
     206  - ReflecExpand : reflection way from the high point and expansion by factor Beta2
     207  - ContractHigh : Contraction along the high point (factor Beta)
     208  - ContractLow : Contraction toward the low point (factor Beta2)
     209  - ExpandHigh : Expansion along the high point
     210
     211  \sa GeneralFit
     212
     213  The following sample code shows a usage example:
     214  \code
     215  include "simplex.h"
     216  ...
     217  // Define our function to be minimized:
     218  class MySFunc : public MinZFunction {
     219  public:
     220    MySFunc() : MinZFunction(2) {}
     221    virtual double Value(double const xp[])
     222    { return (xp[0]*xp[0]+2*xp[1]*xp[1]); }
     223  };
     224
     225  ...
     226
     227  MySFunc mysf;
     228  MinZSimplex simplex(&mysf);
     229  // Guess the center and step for constructing the initial simplex
     230  Vector x0(2); x0 = 1.;
     231  Vector step(2); step = 2.;
     232  simplex.SetInitialPoint(x0);
     233  simplex.SetInitialStep(step);
     234  Vector oparm(2);
     235  int rc = simplex.Minimize(oparm);
     236  if (rc != 0) {
     237    string srt;
     238    int sr = simplex.StopReason(srt);
     239    cout << " Convergence Pb, StopReason= " << sr << " : " << srt << endl;
     240    }
     241  else {
     242    cout << " Converged: NStep= " << simplex.NbIter()
     243         << " OParm= " << oparm << endl;
     244    }
     245  \endcode
     246*/
     247
     248/*!
     249  \brief Auto test function
     250  \param tsel : select autotest (0,1,2,3,4)  , tsel<0 -> all
     251  \param prtlev : printlevel
     252*/
    176253int MinZSimplex::AutoTest(int tsel, int prtlev)
    177254{
     
    214291}
    215292
     293//! Constructor from pointer to MinZFunction object
    216294MinZSimplex::MinZSimplex(MinZFunction *mzf)
    217295  : mZF(mzf) , mPoint0(mZF->NVar()) , mStep0(mZF->NVar())
     
    234312}
    235313
     314//! Perform the minimization
     315/*!
     316  Return 0 if success
     317  \param fpoint : vector containing the optimal point
     318 
     319  Convergence test :
     320  \verbatim
     321  On minimise f(x) f=mZF->Value() ,
     322              f_max = max(f) sur simplex , f_min = min(f) sur simplex
     323              fm = (abs(f_max)+abs(f_min))
     324              [Delta f] = abs(f_max-f_min)
     325              [Delta f/f]simplex = 2.*Delta f / fm
     326              fm2 = (abs(f_max)+abs(f_max(iter-1)))
     327              [Delta f_max/f_max]iter = [f_max(iter-1)-f_max]/fm2
     328  Test d'arret : 
     329   fm < mTol0                                                       OU
     330   [Delta f/f]simplex              < mTol1   mRep1 fois de suite    OU
     331   [Delta f_max/f_max]iter         < mTol2   mRep2 fois de suite 
     332*/
    236333int MinZSimplex::Minimize(Vector& fpoint)
    237334{
     
    411508}
    412509
     510//! Return the stop reason and fills the corresponding string description
    413511int MinZSimplex::StopReason(string& s)
    414512{
Note: See TracChangeset for help on using the changeset viewer.