armijo.hpp 1.42 KB
Newer Older
1
// Software License for MTL
2
3
//
// Copyright (c) 2007 The Trustees of Indiana University.
4
//               2008 Dresden University of Technology and the Trustees of Indiana University.
5
//               2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
6
7
// All rights reserved.
// Authors: Peter Gottschling, Cornelius Steinhardt and Andrew Lumsdaine
8
//
9
// This file is part of the Matrix Template Library
10
//
11
12
13
14
15
16
17
18
// See also license.mtl.txt in the distribution.

#ifndef ITL_ARMIJO_INCLUDE
#define ITL_ARMIJO_INCLUDE

namespace itl {

/// Step size control by Armijo
19
/**
20
21
22
23
24
25
26
27
28
29
30
 **/
template <typename Value= double>
class armijo
{
  public:
    typedef Value   value_type;

    // Defaults from Prof. Fischer's lecture
    armijo(Value delta= 0.5, Value gamma= 0.5, Value beta1= 0.25, Value beta2= 0.5)
      : delta(delta), gamma(gamma), beta1(beta1), beta((beta1 + beta2) / 2.0) {}

31
    ///
32
    template <typename Vector, typename F, typename Grad>
33
    typename mtl::Collection<Vector>::value_type
34
35
36
37
38
39
    operator() (const Vector& x, const Vector& d, F f, Grad grad_f) const
    {
	// Star's step size
	typename mtl::Collection<Vector>::value_type alpha= -gamma * dot(grad_f(x), d) / dot(d, d);
	Vector     x_k(x + alpha * d);

40
	while (f(x_k) > f(x) + (beta1 * alpha) * dot(grad_f(x), d)) {
41
42
43
44
45
46
47
48
49
50
51
52
53
	    alpha*= beta;
	    x_k= x+ alpha * d;
	}
	return alpha;
    }
  private:
    Value delta, gamma, beta1, beta;
};


} // namespace itl

#endif // ITL_ARMIJO_INCLUDE