ROL
ROL_lDFP.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_LDFP_H
45 #define ROL_LDFP_H
46 
51 #include "ROL_Secant.hpp"
52 
53 namespace ROL {
54 
55 template<class Real>
56 class lDFP : public Secant<Real> {
57 public:
58  lDFP(int M) : Secant<Real>(M) {}
59 
60  // Apply lBFGS Approximate Inverse Hessian
61  void applyH( Vector<Real> &Hv, const Vector<Real> &v, const Vector<Real> &x ) {
62  // Get Generic Secant State
63  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
64 
65  // Apply initial Hessian approximation to v
66  applyH0(Hv,v,x);
67 
68  std::vector<Teuchos::RCP<Vector<Real> > > a(state->current+1);
69  std::vector<Teuchos::RCP<Vector<Real> > > b(state->current+1);
70  Real bv = 0.0, av = 0.0, bs = 0.0, as = 0.0;
71  for (int i = 0; i <= state->current; i++) {
72  b[i] = Hv.clone();
73  b[i]->set(*(state->iterDiff[i]));
74  b[i]->scale(1.0/sqrt(state->product[i]));
75  bv = b[i]->dot(v.dual());
76  Hv.axpy(bv,*b[i]);
77 
78  a[i] = Hv.clone();
79  applyH0(*a[i],*(state->gradDiff[i]),x);
80 
81  for (int j = 0; j < i; j++) {
82  bs = b[j]->dot((state->gradDiff[i])->dual());
83  a[i]->axpy(bs,*b[j]);
84  as = a[j]->dot((state->gradDiff[i])->dual());
85  a[i]->axpy(-as,*a[j]);
86  }
87  as = a[i]->dot((state->gradDiff[i])->dual());
88  a[i]->scale(1.0/sqrt(as));
89  av = a[i]->dot(v.dual());
90  Hv.axpy(-av,*a[i]);
91  }
92  }
93 
94  // Apply Initial Secant Approximate Hessian
95  virtual void applyH0( Vector<Real> &Hv, const Vector<Real> &v, const Vector<Real> &x ) {
96  // Get Generic Secant State
97  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
98 
99  Hv.set(v.dual());
100  if (state->iter != 0 && state->current != -1) {
101  Real ss = state->iterDiff[state->current]->dot(*(state->iterDiff[state->current]));
102  Hv.scale(state->product[state->current]/ss);
103  }
104  }
105 
106 
107  // Apply lBFGS Approximate Hessian
108  void applyB( Vector<Real> &Bv, const Vector<Real> &v, const Vector<Real> &x ) {
109  // Get Generic Secant State
110  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
111 
112  Bv.set(v.dual());
113  std::vector<Real> alpha(state->current+1,0.0);
114  for (int i = state->current; i>=0; i--) {
115  alpha[i] = state->gradDiff[i]->dot(Bv);
116  alpha[i] /= state->product[i];
117  Bv.axpy(-alpha[i],(state->iterDiff[i])->dual());
118  }
119 
120  // Apply initial inverse Hessian approximation to v
121  Teuchos::RCP<Vector<Real> > tmp = Bv.clone();
122  applyB0(*tmp,Bv,x);
123  Bv.set(*tmp);
124 
125  Real beta = 0.0;
126  for (int i = 0; i <= state->current; i++) {
127  beta = state->iterDiff[i]->dot(Bv.dual());
128  beta /= state->product[i];
129  Bv.axpy((alpha[i]-beta),*(state->gradDiff[i]));
130  }
131  }
132 
133  // Apply Initial Secant Approximate Hessian
134  virtual void applyB0( Vector<Real> &Bv, const Vector<Real> &v, const Vector<Real> &x ) {
135  // Get Generic Secant State
136  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
137 
138  Bv.set(v.dual());
139  if (state->iter != 0 && state->current != -1) {
140  Real ss = state->iterDiff[state->current]->dot(*(state->iterDiff[state->current]));
141  Bv.scale(ss/state->product[state->current]);
142  }
143  }
144 
145 };
146 
147 }
148 
149 #endif
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:213
virtual void scale(const Real alpha)=0
Compute where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:143
Provides definitions for limited-memory DFP operators.
Definition: ROL_lDFP.hpp:56
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void applyB(Vector< Real > &Bv, const Vector< Real > &v, const Vector< Real > &x)
Definition: ROL_lDFP.hpp:108
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:68
lDFP(int M)
Definition: ROL_lDFP.hpp:58
Teuchos::RCP< SecantState< Real > > & get_state()
Definition: ROL_Secant.hpp:85
void applyH(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &x)
Definition: ROL_lDFP.hpp:61
virtual void applyH0(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &x)
Definition: ROL_lDFP.hpp:95
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
virtual void applyB0(Vector< Real > &Bv, const Vector< Real > &v, const Vector< Real > &x)
Definition: ROL_lDFP.hpp:134