NLoptSolver.hxx
1 // Copyright (C) 2011 INRIA
2 // Author(s): Marc Fragu
3 //
4 // This file is part of the linear-algebra library Seldon,
5 // http://seldon.sourceforge.net/.
6 //
7 // Seldon is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your option)
10 // any later version.
11 //
12 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with Seldon. If not, see http://www.gnu.org/licenses/.
19 
20 
21 #ifndef SELDON_COMPUTATION_OPTIMIZATION_NLOPTSOLVER_HXX
22 #define SELDON_COMPUTATION_OPTIMIZATION_NLOPTSOLVER_HXX
23 
24 
25 #include "NLopt.hxx"
26 
27 
28 namespace Seldon
29 {
30 
31 
33  // NLOPTSOLVER //
35 
36 
39  {
40 
41  protected:
42 
43  typedef double (*cost_ptr)(const Vector<double>&,
44  Vector<double>&, void*);
45 
49  nlopt::algorithm algorithm_;
66  double cost_;
67 
68  public:
69  // Constructor and destructor.
70  NLoptSolver();
71  ~NLoptSolver();
72 
73  void Initialize(int Nparameter, string algorithm,
74  double parameter_tolerance = 1.e-6,
75  double cost_function_tolerance = 1.e-6,
76  int Niteration_max = -1);
77  void SetLowerBound(const Vector<double>&);
78  void SetUpperBound(const Vector<double>&);
79  void SetParameterTolerance(double);
80  void SetCostFunctionTolerance(double);
81  void SetNiterationMax(int);
82  void GetParameterTolerance(double&) const;
83  void GetCostFunctionTolerance(double&) const;
84  void GetNiterationMax(int&) const;
85  void SetParameter(const Vector<double>& parameter);
86  void GetParameter(Vector<double>& parameter) const;
87  void Optimize(cost_ptr cost, void* argument);
88  double GetCost() const;
89 
90  };
91 
92 
93 } // namespace Seldon.
94 
95 
96 #endif
Seldon::NLoptSolver::GetParameter
void GetParameter(Vector< double > &parameter) const
Gets the parameters.
Definition: NLoptSolver.cxx:272
Seldon::NLoptSolver::GetParameterTolerance
void GetParameterTolerance(double &) const
Gets the relative tolerance on the parameters.
Definition: NLoptSolver.cxx:228
Seldon::NLoptSolver::cost_function_tolerance_
double cost_function_tolerance_
Relative tolerance on the cost function.
Definition: NLoptSolver.hxx:53
Seldon::Vector< double >
Seldon::NLoptSolver
NLopt optimization.
Definition: NLoptSolver.hxx:38
Seldon::NLoptSolver::GetCostFunctionTolerance
void GetCostFunctionTolerance(double &) const
Gets the relative tolerance on the cost function.
Definition: NLoptSolver.cxx:241
Seldon::NLoptSolver::SetCostFunctionTolerance
void SetCostFunctionTolerance(double)
Sets the relative tolerance on the cost function.
Definition: NLoptSolver.cxx:204
nlopt::SeldonOpt
Definition: NLopt.hxx:37
Seldon::NLoptSolver::SetLowerBound
void SetLowerBound(const Vector< double > &)
Sets lower bounds on the parameters.
Definition: NLoptSolver.cxx:162
Seldon::NLoptSolver::SetParameterTolerance
void SetParameterTolerance(double)
Sets the relative tolerance on the parameters.
Definition: NLoptSolver.cxx:189
Seldon::NLoptSolver::~NLoptSolver
~NLoptSolver()
Destructor.
Definition: NLoptSolver.cxx:39
Seldon::NLoptSolver::opt_
nlopt::SeldonOpt opt_
NLopt optimization solver.
Definition: NLoptSolver.hxx:47
Seldon::NLoptSolver::Optimize
void Optimize(cost_ptr cost, void *argument)
Optimization.
Definition: NLoptSolver.cxx:293
Seldon::NLoptSolver::gradient_
Vector< double > gradient_
The vector that stores gradient values. Before optimization, unspecified; after optimization,...
Definition: NLoptSolver.hxx:64
Seldon::NLoptSolver::GetNiterationMax
void GetNiterationMax(int &) const
Gets the maximum number of cost function evaluations.
Definition: NLoptSolver.cxx:251
Seldon::NLoptSolver::SetParameter
void SetParameter(const Vector< double > &parameter)
Sets the parameters.
Definition: NLoptSolver.cxx:261
Seldon::NLoptSolver::GetCost
double GetCost() const
Returns the value of the cost function.
Definition: NLoptSolver.cxx:317
Seldon::NLoptSolver::SetUpperBound
void SetUpperBound(const Vector< double > &)
Sets upper bounds on the parameters.
Definition: NLoptSolver.cxx:173
Seldon::NLoptSolver::NLoptSolver
NLoptSolver()
Default constructor.
Definition: NLoptSolver.cxx:33
Seldon::NLoptSolver::cost_
double cost_
The value of cost function for given parameter values.
Definition: NLoptSolver.hxx:66
Seldon::NLoptSolver::parameter_tolerance_
double parameter_tolerance_
Relative tolerance on the optimization parameters.
Definition: NLoptSolver.hxx:51
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::NLoptSolver::SetNiterationMax
void SetNiterationMax(int)
Sets the maximum number of cost function evaluations.
Definition: NLoptSolver.cxx:215
Seldon::NLoptSolver::parameter_
Vector< double > parameter_
The vector that stores parameters values. Before optimization, stores the initial parameter vector; a...
Definition: NLoptSolver.hxx:60
Seldon::NLoptSolver::algorithm_
nlopt::algorithm algorithm_
Optimization algorithm.
Definition: NLoptSolver.hxx:49
Seldon::NLoptSolver::Initialize
void Initialize(int Nparameter, string algorithm, double parameter_tolerance=1.e-6, double cost_function_tolerance=1.e-6, int Niteration_max=-1)
Initializations.
Definition: NLoptSolver.cxx:72
Seldon::NLoptSolver::Niteration_max_
int Niteration_max_
Maximum number of function evaluations. It is ignored if it is non-positive.
Definition: NLoptSolver.hxx:56