/usr/include/freefem++/Optima.hpp is in libfreefem++-dev 3.47+dfsg1-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #ifndef OPTIMA_HH
#define OPTIMA_HH
#include "NRJ.hpp"
#include <limits.h>
#include "defs.hpp"
#define MAX_IT_OPT 1000
//==================
//define the base class for optimization classes
// H. Lydia Deng, 03/14/94
//======================
/*
This is the base class for general optimization classes.
Classes derived from this class inherit features of
Optima. This class cannot be instantiated directly.
*/
// Attention :
// pas de copie
// pas d'opérateur =
template <class LS>
class Optima {
typedef typename LS::Real Real;
typedef typename LS::Param Param;
typedef typename LS::Vect Vect;
typedef typename LS::VMat VMat;
typedef LS LineSearch;
typedef list<Real> mlist;
protected:
// maximum number of iterations
int iterMax;
int iterNum;
// tolerance error
// c'est une tolérance sur la norme euclidienne du gradient
Real tol;
// mlist of residue
mlist * residue;
// pointer to LS
LS * ls;
// verbose or quiet
int isVerbose;
// the flag indicating if the search was a success
int isSuccess;
// append the new residue to the mlist
void appendResidue(Real res);
public:
Optima(int verb=0);
virtual ~Optima();
virtual Param optimizer(Param&) = 0;
//Output residues
int ifSuccess();
// residue of the last iteration
Real finalResidue();
// residue of the first iteration
Real firstResidue();
// residues of all iterations
mlist allResidue();
// normalized residues of all iterations
mlist normResidue();
};
template <class LS>
Optima<LS>::Optima(int verbose){
residue = new mlist;
isVerbose = verbose;
isSuccess = 0;
ls = NULL;
tol = 0.;
iterMax = MAX_IT_OPT;
}
template <class LS>
Optima<LS>::~Optima() {
if (residue!=NULL) delete residue;
}
//Output residues
template <class LS>
int Optima<LS>::ifSuccess()
{return isSuccess;}
template <class LS>
typename Optima<LS>::Real Optima<LS>::finalResidue()
{return residue->back();}
template <class LS>
typename Optima<LS>::Real Optima<LS>::firstResidue()
{return residue->front();}
template <class LS>
typename Optima<LS>::mlist Optima<LS>::allResidue()
{return *residue;}
template <class LS>
typename Optima<LS>::mlist Optima<LS>::normResidue()
{return normalize(*residue);} //cf. defs.hpp
template <class LS>
void Optima<LS>::appendResidue(Real res)
{
(residue[0]).push_back(res);
}
#endif
|