Interior-point-optimisation  1.0-1
Interior-pointoptimisationlibrary
LineSearch.hpp
Go to the documentation of this file.
1 /*
2  * $Id: LineSearch.hpp 135 2013-06-29 15:09:42Z jdl3 $
3  * Copyright (C) 2011, 2013 John D Lamb
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 
20 #ifndef IPO_DETAIL_LINESEARCH_HPP
21 #define IPO_DETAIL_LINESEARCH_HPP
22 
23 #include<cmath>
24 #include<limits>
25 #include<iomanip>
26 #include<ccgsl/blas.hpp>
27 #include"../../ipo_function/detail/ForwardDifferenceGradientEstimate.hpp"
28 
29 namespace ipo {
30  namespace detail {
31 
36  class LineSearch {
37  public:
42  class Parameters {
43  public:
53  Parameters( double const alpha = 1e-3,
54  double const beta = 0.8,
55  double const epsilon = std::sqrt( std::numeric_limits<double>::epsilon() ),
56  size_t const maxNoImproveSteps = 10 );
61  void setAlpha( double alpha );
66  void setBeta( double beta );
71  void setEpsilon( double epsilon );
81  double getAlpha() const;
86  double getBeta() const;
91  double getEpsilon() const;
96  size_t getMaxNoImproveSteps() const;
103  void setVectorDigits( size_t const vectorDigits ){
104  this->vectorDigits = vectorDigits; }
110  size_t getVectorDigits() const { return vectorDigits; }
115  void setOutputStream( std::ostream* outputStream ){
116  this->outputStream = outputStream; }
121  std::ostream* getOutputStream() const { return outputStream; }
122  private:
132  double alpha;
140  double beta;
148  double epsilon;
158  size_t vectorDigits;
169  std::ostream* outputStream;
170  };
171  private:
173  public:
184  LineSearch( ipo_function::Function& function, double const alpha = 1e-3,
185  double const beta = 0.8,
186  double const epsilon = std::sqrt( std::numeric_limits<double>::epsilon() ),
187  size_t const maxNoImproveSteps = 10 );
200  double operator()( gsl::vector& vector,
201  gsl::vector const direction,
202  double const functionValue = -std::numeric_limits<double>::infinity(),
203  gsl::vector const gradientValue = gsl::vector( nullptr ) );
209  void setFunctionScale( double const functionScale ){
210  this->functionScale = functionScale; }
215  Parameters& getParameters();
216  protected:
224  double functionScale { 1.0 };
225  };
226  }
227 }
228 
229 #endif
double beta
A value in (0,1): usually quite big (0.1–0.8).
Definition: LineSearch.hpp:140
void setMaxNoImproveSteps(size_t maxNoImproveSteps)
Set the value of maxNoImproveSteps.
Definition: LineSearch.cc:213
double functionScale
Scaling factor for output of function values.
Definition: LineSearch.hpp:224
size_t getVectorDigits() const
Get the value of vectorDigits.
Definition: LineSearch.hpp:110
double getAlpha() const
Get the value of alpha.
Definition: LineSearch.cc:67
LineSearch(ipo_function::Function &function, double const alpha=1e-3, double const beta=0.8, double const epsilon=std::sqrt(std::numeric_limits< double >::epsilon()), size_t const maxNoImproveSteps=10)
Set up the line search function object with a function and some default parameters.
Definition: LineSearch.cc:41
double alpha
A value in (0,0.5): usually quite small 0.0001–0.3 (default 1e-3 though 1e-4 is suggested in Dennis ...
Definition: LineSearch.hpp:132
std::ostream * outputStream
A stream (default is nullptr) for sending output to.
Definition: LineSearch.hpp:169
Backtracking line search.
Definition: LineSearch.hpp:36
Parameters & getParameters()
Get parameters by reference.
Definition: LineSearch.cc:39
void setFunctionScale(double const functionScale)
Set the scaling factor for output of function values.
Definition: LineSearch.hpp:209
double operator()(gsl::vector &vector, gsl::vector const direction, double const functionValue=-std::numeric_limits< double >::infinity(), gsl::vector const gradientValue=gsl::vector(nullptr))
Carry out the line search.
Definition: LineSearch.cc:82
void setVectorDigits(size_t const vectorDigits)
Set the number of significant digits of entries of vector to show in each step.
Definition: LineSearch.hpp:103
void setOutputStream(std::ostream *outputStream)
Set outputStream.
Definition: LineSearch.hpp:115
size_t vectorDigits
If this value is set to zero and outputStream is not null then vector arguments are not shown (more u...
Definition: LineSearch.hpp:158
This class computes a function at a vector.
Definition: Function.hpp:38
void setBeta(double beta)
Set the value of beta.
Definition: LineSearch.cc:54
double epsilon
A value for forward difference gradient estimates.
Definition: LineSearch.hpp:148
Parameters(double const alpha=1e-3, double const beta=0.8, double const epsilon=std::sqrt(std::numeric_limits< double >::epsilon()), size_t const maxNoImproveSteps=10)
Set up some default parameters.
Definition: LineSearch.cc:28
Line search parameters.
Definition: LineSearch.hpp:42
void setEpsilon(double epsilon)
Set the value of epsilon.
Definition: LineSearch.cc:61
void setAlpha(double alpha)
Set the value of alpha.
Definition: LineSearch.cc:47
double getBeta() const
Get the value of beta.
Definition: LineSearch.cc:72
size_t maxNoImproveSteps
Maximum number of nonimproving steps (default is 10).
Definition: LineSearch.hpp:152
std::ostream * getOutputStream() const
Get the current value of outputStream.
Definition: LineSearch.hpp:121
double getEpsilon() const
Get the value of epsilon.
Definition: LineSearch.cc:77
size_t getMaxNoImproveSteps() const
Get the value of maxNoImproveSteps.
Definition: LineSearch.cc:218
This namespace holds all the interior-point optimisation classes.
Definition: Array.hpp:28
std::string const infinity
Infinity sign, ∞.
Definition: Format.hpp:54