bpp-core3  3.0.0
SimpleNewtonMultiDimensions.cpp
Go to the documentation of this file.
1 //
2 // File: SimpleNewtonMultiDimensions.cpp
3 // Authors:
4 // Julien Dutheil
5 // Created: 2007-04-26 15:29:00
6 //
7 
8 /*
9  Copyright or © or Copr. CNRS, (November 19, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for numerical calculus.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 
42 
43 /******************************************************************************/
44 
46 
47 using namespace bpp;
48 using namespace std;
49 
50 /******************************************************************************/
51 
53  AbstractOptimizer(function), nbParams_(0), optimizer_(function)
54 {
58 }
59 
60 /******************************************************************************/
61 
63 {
65  optimizer_.setFunction(function);
66 }
67 
68 /******************************************************************************/
69 
71 {
72  nbParams_ = params.size();
73  if (nbParams_ == 0)
74  return;
75 
76  // Initialize optimizers:
77  unsigned int nbEvalMax = nbEvalMax_ / static_cast<unsigned int>(nbParams_);
83  optimizer_.setVerbose(getVerbose() > 0 ? getVerbose() - 1 : 0);
86 }
87 
88 /******************************************************************************/
89 
91 {
92  double f = getFunction()->getValue();
93  for (unsigned int i = 0; i < nbParams_; i++)
94  {
95  if (getVerbose() > 0)
96  {
97  cout << getParameters()[i].getName() << ":";
98  cout.flush();
99  }
100  // Re-init optimizer according to new values:
101  optimizer_.init(getParameters().createSubList(i));
102 
103  // Optimize through this dimension:
104  f = optimizer_.optimize();
105  if (getVerbose() > 0)
106  cout << endl;
109  }
110  tolIsReached_ = nbParams_ <= 1;
111  return f;
112 }
113 
114 /******************************************************************************/
Partial implementation of the Optimizer interface.
void setOptimizationProgressCharacter(const std::string &c)
Set the character to be displayed during optimization.
void setFunction(Function *function)
Set the function to optimize.
void setProfiler(OutputStream *profiler)
Set the profiler for this optimizer.
void setConstraintPolicy(const std::string &constraintPolicy)
Set the constraint policy for this optimizer.
OutputStream * getMessageHandler() const
OutputStream * getProfiler() const
void setMessageHandler(OutputStream *mh)
Set the message handler for this optimizer.
double optimize()
Basic implementation.
OptimizationStopCondition * getDefaultStopCondition()
Get the default stop condition of the optimization algorithm.
unsigned int nbEvalMax_
The maximum number of function evaluations allowed.
unsigned int nbEval_
The current number of function evaluations achieved.
const ParameterList & getParameters() const
void setStopCondition(const OptimizationStopCondition &stopCondition)
Set the stop condition of the optimization algorithm.
void init(const ParameterList &params)
Basic implementation.
void setVerbose(unsigned int v)
Set the verbose level.
unsigned int getNumberOfEvaluations() const
Get the number of function evaluations performed since the call of the init function.
ParameterList & getParameters_()
OptimizationStopCondition * getStopCondition()
Get the stop condition of the optimization algorithm.
const Function * getFunction() const
Get the current function being optimized.
void setMaximumNumberOfEvaluations(unsigned int max)
Set the maximum number of function evaluation to perform during optimization.
std::string getConstraintPolicy() const
Get the constraint policy for this optimizer.
bool tolIsReached_
Tell if the tolerance level has been reached.
unsigned int getVerbose() const
Get the verbose level.
void setDefaultStopCondition_(OptimizationStopCondition *osc)
This is the abstract class for second order derivable functions.
Definition: Functions.h:188
Stop condition on function value.
This is the function abstract class.
Definition: Functions.h:89
virtual double getValue() const =0
Get the value of the function at the current point.
virtual void setParameters(const ParameterList &parameters)=0
Set the point where the function must be computed.
void setMaximumNumberOfCorrections(unsigned int mx)
virtual void setTolerance(double tolerance)=0
Set the tolerance parameter.
virtual double getTolerance() const =0
Get the tolerance parameter.
The parameter list object.
Definition: ParameterList.h:65
size_t size() const
Definition: ParameterList.h:92
virtual bool matchParametersValues(const ParameterList &params, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
SimpleNewtonMultiDimensions(DerivableSecondOrder *function)
void doInit(const ParameterList &params)
This function is called by the init() method and contains all calculations.
void setFunction(Function *function)
Set the function to optimize.
double doStep()
This function is called by the step() method and contains all calculations.