ROL
ROL_BarzilaiBorwein.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Rapid Optimization Library (ROL) Package
4//
5// Copyright 2014 NTESS and the ROL contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef ROL_SECANTFACTORY_H
11#include "ROL_SecantFactory.hpp"
12#else
13
14#ifndef ROL_BARZILAIBORWEIN_H
15#define ROL_BARZILAIBORWEIN_H
16
21#include "ROL_Secant.hpp"
22
23namespace ROL {
24
25template<class Real>
26class BarzilaiBorwein : public Secant<Real> {
27private:
28
29 int type_;
30
31public:
32 BarzilaiBorwein(int type = 1) : Secant<Real>(1), type_(type) {}
33
34 // Apply lBFGS Approximate Inverse Hessian
35 void applyH( Vector<Real> &Hv, const Vector<Real> &v ) const {
36 // Get Generic Secant State
37 const ROL::Ptr<SecantState<Real> >& state = Secant<Real>::get_state();
38
39 Hv.set(v.dual());
40 if ( state->iter != 0 && state->current != -1 ) {
41 if ( type_ == 1 ) {
42 Real yy = state->gradDiff[state->current]->dot(*(state->gradDiff[state->current]));
43 Hv.scale(state->product[state->current]/yy);
44 }
45 else if ( type_ == 2 ) {
46 Real ss = state->iterDiff[state->current]->dot(*(state->iterDiff[state->current]));
47 Hv.scale(ss/state->product[state->current]);
48 }
49 }
50 }
51
52 // Apply lBFGS Approximate Hessian
53 void applyB( Vector<Real> &Bv, const Vector<Real> &v ) const {
54 // Get Generic Secant State
55 const ROL::Ptr<SecantState<Real> >& state = Secant<Real>::get_state();
56
57 Bv.set(v.dual());
58 if ( state->iter != 0 && state->current != -1 ) {
59 if ( type_ == 1 ) {
60 Real yy = state->gradDiff[state->current]->dot(*(state->gradDiff[state->current]));
61 Bv.scale(yy/state->product[state->current]);
62 }
63 else if ( type_ == 2 ) {
64 Real ss = state->iterDiff[state->current]->dot(*(state->iterDiff[state->current]));
65 Bv.scale(state->product[state->current]/ss);
66 }
67 }
68 }
69};
70
71}
72
73#endif
74#endif