primatologist-gpl  5.1.2
newton_decl.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-2013 CEA
2  *
3  * This software and supporting documentation were developed by
4  * bioPICSEL
5  * CEA/DSV/I²BM/MIRCen/LMN, Batiment 61,
6  * 18, route du Panorama
7  * 92265 Fontenay-aux-Roses
8  * France
9  */
10 
11 #ifndef PRIMATOLOGIST_OPTIMIZATION_NEWTON_DECL_H
12 #define PRIMATOLOGIST_OPTIMIZATION_NEWTON_DECL_H
13 
14 #include <primatologist/math/matrix.h> // aims::math::Matrix
15 #include <primatologist/optimization/nolinesearch.h> // aims::NoLineSearch
16 #include <cartobase/config/verbose.h> // carto::verbose
17 
18 namespace aims {
19 
20  //==========================================================================
21  // NEWTON's METHOD
22  //==========================================================================
30  template <typename O, template <typename> class L = NoLineSearch >
31  class Newton
32  {
33  public:
34  //------------------------------------------------------------------------
35  // TYPEDEFS
36  //------------------------------------------------------------------------
37  typedef O Objective;
38  typedef L<O> LineSearch;
41 
42  //------------------------------------------------------------------------
43  // CONSTRUCTOR / DESTRUCTOR / COPY
44  //------------------------------------------------------------------------
47  Newton( const Objective & f = Objective(),
48  const Vector & x = Vector() );
49  Newton( const Newton<O,L> & other );
50  ~Newton();
51  Newton<O,L> & operator=( const Newton<O,L> & other );
52 
53  //------------------------------------------------------------------------
54  // SET PARAMETERS
55  //------------------------------------------------------------------------
56  // Intrinsic parameters
57  void setGamma( float gamma = 0.1 );
61  void setStopCriterion( const std::string & crit = "absdiff" );
62  void setStopValue( float epsilon = 1E-5 );
65  void setLineSearch( const LineSearch & l = LineSearch() );
66  void setMaximize( bool maximize = false );
67  void setMaxIterations( int n = - 1 );
68  void setVerbose( int v = carto::verbose );
69  // Search parameters
72  void setObjectiveFunction( const Objective & f );
73  void setPosition( const Vector & x = Vector() );
74 
75  //------------------------------------------------------------------------
76  // GET PARAMETERS
77  //------------------------------------------------------------------------
78  // Intrinsic parameters
79  float gamma() const;
80  const std::string & stopCriterion() const;
81  float stopValue() const;
83  bool maximize() const;
84  int maxIterations() const;
85  int verbose() const;
86  // Search parameters
87  const Vector & position() const;
88  const Objective & objectiveFunction() const;
89 
90  //------------------------------------------------------------------------
91  // EXECUTE
92  //------------------------------------------------------------------------
93  Vector execute();
94 
95  protected:
96  //------------------------------------------------------------------------
97  // PARAMETERS
98  //------------------------------------------------------------------------
99  float _gamma;
103  int _verbose;
104  bool _maximize;
105  int _max_it;
106  std::string _crit;
107  float _epsilon;
108  };
109 
110 } // namespace aims
111 
112 #endif // PRIMATOLOGIST_OPTIMIZATION_NEWTON_DECL_H
Newton's Method for optimization.
Definition: newton_decl.h:32
float gamma() const
Definition: newton_d.h:136
void setStopCriterion(const std::string &crit="absdiff")
Can take values:
Definition: newton_d.h:78
float stopValue() const
Definition: newton_d.h:148
math::Vector Vector
Definition: newton_decl.h:40
math::Matrix Matrix
Definition: newton_decl.h:39
Objective _f
objectiveFunction
Definition: newton_decl.h:101
int _max_it
maximum number of iterations
Definition: newton_decl.h:105
int _verbose
verbosity level
Definition: newton_decl.h:103
int maxIterations() const
Definition: newton_d.h:167
L< O > LineSearch
Definition: newton_decl.h:38
void setMaximize(bool maximize=false)
Definition: newton_d.h:99
float _epsilon
stop value
Definition: newton_decl.h:107
int verbose() const
Definition: newton_d.h:173
Newton(const Objective &f=Objective(), const Vector &x=Vector())
Definition: newton_d.h:23
Vector execute()
Definition: newton_d.h:197
bool _maximize
maximize or minimize
Definition: newton_decl.h:104
const Objective & objectiveFunction() const
Definition: newton_d.h:187
void setLineSearch(const LineSearch &l=LineSearch())
Definition: newton_d.h:90
const Vector & position() const
Definition: newton_d.h:180
LineSearch & lineSearch()
Definition: newton_d.h:155
void setVerbose(int v=carto::verbose)
Definition: newton_d.h:112
float _gamma
Fixed Gamma or initial gamma for line search.
Definition: newton_decl.h:99
void setObjectiveFunction(const Objective &f)
Definition: newton_d.h:119
void setGamma(float gamma=0.1)
Definition: newton_d.h:72
std::string _crit
stop criterion
Definition: newton_decl.h:106
Newton< O, L > & operator=(const Newton< O, L > &other)
Definition: newton_d.h:52
void setStopValue(float epsilon=1E-5)
Definition: newton_d.h:84
const std::string & stopCriterion() const
Definition: newton_d.h:142
Vector _x
position
Definition: newton_decl.h:100
void setMaxIterations(int n=- 1)
Definition: newton_d.h:106
bool maximize() const
Definition: newton_d.h:161
LineSearch _ls
lineSearch
Definition: newton_decl.h:102
void setPosition(const Vector &x=Vector())
Definition: newton_d.h:126
Matrix class implementing matrix operations.
Definition: matrix.h:50