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 namespace ROL {
52 
53 template<class Real>
54 class lDFP : public Secant<Real> {
55 public:
56  lDFP(int M) : Secant<Real>(M) {}
57 
58  // Apply lBFGS Approximate Inverse Hessian
59  void applyH( Vector<Real> &Hv, const Vector<Real> &v, const Vector<Real> &x ) {
60  // Get Generic Secant State
61  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
62 
63  // Apply initial Hessian approximation to v
64  applyH0(Hv,v,x);
65 
66  std::vector<Teuchos::RCP<Vector<Real> > > a(state->current+1);
67  std::vector<Teuchos::RCP<Vector<Real> > > b(state->current+1);
68  Real bv = 0.0, av = 0.0, bs = 0.0, as = 0.0;
69  for (int i = 0; i <= state->current; i++) {
70  b[i] = Hv.clone();
71  b[i]->set(*(state->iterDiff[i]));
72  b[i]->scale(1.0/sqrt(state->product[i]));
73  bv = b[i]->dot(v.dual());
74  Hv.axpy(bv,*b[i]);
75 
76  a[i] = Hv.clone();
77  applyH0(*a[i],*(state->gradDiff[i]),x);
78 
79  for (int j = 0; j < i; j++) {
80  bs = b[j]->dot((state->gradDiff[i])->dual());
81  a[i]->axpy(bs,*b[j]);
82  as = a[j]->dot((state->gradDiff[i])->dual());
83  a[i]->axpy(-as,*a[j]);
84  }
85  as = a[i]->dot((state->gradDiff[i])->dual());
86  a[i]->scale(1.0/sqrt(as));
87  av = a[i]->dot(v.dual());
88  Hv.axpy(-av,*a[i]);
89  }
90  }
91 
92  // Apply Initial Secant Approximate Hessian
93  virtual void applyH0( Vector<Real> &Hv, const Vector<Real> &v, const Vector<Real> &x ) {
94  // Get Generic Secant State
95  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
96 
97  Hv.set(v.dual());
98  if (state->iter != 0 && state->current != -1) {
99  Real ss = state->iterDiff[state->current]->dot(*(state->iterDiff[state->current]));
100  Hv.scale(state->product[state->current]/ss);
101  }
102  }
103 
104 
105  // Apply lBFGS Approximate Hessian
106  void applyB( Vector<Real> &Bv, const Vector<Real> &v, const Vector<Real> &x ) {
107  // Get Generic Secant State
108  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
109 
110  Bv.set(v.dual());
111  std::vector<Real> alpha(state->current+1,0.0);
112  for (int i = state->current; i>=0; i--) {
113  alpha[i] = state->gradDiff[i]->dot(Bv);
114  alpha[i] /= state->product[i];
115  Bv.axpy(-alpha[i],(state->iterDiff[i])->dual());
116  }
117 
118  // Apply initial inverse Hessian approximation to v
119  Teuchos::RCP<Vector<Real> > tmp = Bv.clone();
120  applyB0(*tmp,Bv,x);
121  Bv.set(*tmp);
122 
123  Real beta = 0.0;
124  for (int i = 0; i <= state->current; i++) {
125  beta = state->iterDiff[i]->dot(Bv.dual());
126  beta /= state->product[i];
127  Bv.axpy((alpha[i]-beta),*(state->gradDiff[i]));
128  }
129  }
130 
131  // Apply Initial Secant Approximate Hessian
132  virtual void applyB0( Vector<Real> &Bv, const Vector<Real> &v, const Vector<Real> &x ) {
133  // Get Generic Secant State
134  Teuchos::RCP<SecantState<Real> >& state = Secant<Real>::get_state();
135 
136  Bv.set(v.dual());
137  if (state->iter != 0 && state->current != -1) {
138  Real ss = state->iterDiff[state->current]->dot(*(state->iterDiff[state->current]));
139  Bv.scale(ss/state->product[state->current]);
140  }
141  }
142 
143 };
144 
145 }
146 
147 #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:211
virtual void scale(const Real alpha)=0
Compute where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:141
Provides definitions for limited-memory DFP operators.
Definition: ROL_lDFP.hpp:54
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:106
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:72
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:67
lDFP(int M)
Definition: ROL_lDFP.hpp:56
Teuchos::RCP< SecantState< Real > > & get_state()
Definition: ROL_Secant.hpp:84
void applyH(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &x)
Definition: ROL_lDFP.hpp:59
virtual void applyH0(Vector< Real > &Hv, const Vector< Real > &v, const Vector< Real > &x)
Definition: ROL_lDFP.hpp:93
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:194
virtual void applyB0(Vector< Real > &Bv, const Vector< Real > &v, const Vector< Real > &x)
Definition: ROL_lDFP.hpp:132