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
53namespace ROL {
54
55template<class Real>
56class lDFP : public Secant<Real> {
57private:
58 using Secant<Real>::state_;
60 using Secant<Real>::Bscaling_;
61
62public:
63 lDFP(int M, bool useDefaultScaling = true, Real Bscaling = Real(1))
64 : Secant<Real>(M,useDefaultScaling,Bscaling) {}
65
66 // Apply lBFGS Approximate Inverse Hessian
67 void applyH( Vector<Real> &Hv, const Vector<Real> &v ) const {
68 const Real one(1);
69
70 // Apply initial Hessian approximation to v
71 applyH0(Hv,v);
72
73 std::vector<Ptr<Vector<Real>>> a(state_->current+1);
74 std::vector<Ptr<Vector<Real>>> b(state_->current+1);
75 Real bv(0), av(0), bs(0), as(0);
76 for (int i = 0; i <= state_->current; i++) {
77 b[i] = Hv.clone();
78 b[i]->set(*(state_->iterDiff[i]));
79 b[i]->scale(1.0/sqrt(state_->product[i]));
80 //bv = b[i]->dot(v.dual());
81 bv = b[i]->apply(v);
82 Hv.axpy(bv,*b[i]);
83
84 a[i] = Hv.clone();
85 applyH0(*a[i],*(state_->gradDiff[i]));
86
87 for (int j = 0; j < i; j++) {
88 //bs = b[j]->dot((state_->gradDiff[i])->dual());
89 bs = b[j]->apply(*(state_->gradDiff[i]));
90 a[i]->axpy(bs,*b[j]);
91 //as = a[j]->dot((state_->gradDiff[i])->dual());
92 as = a[j]->apply(*(state_->gradDiff[i]));
93 a[i]->axpy(-as,*a[j]);
94 }
95 //as = a[i]->dot((state_->gradDiff[i])->dual());
96 as = a[i]->apply(*(state_->gradDiff[i]));
97 a[i]->scale(one/sqrt(as));
98 //av = a[i]->dot(v.dual());
99 av = a[i]->apply(v);
100 Hv.axpy(-av,*a[i]);
101 }
102 }
103
104 // Apply Initial Secant Approximate Hessian
105 virtual void applyH0( Vector<Real> &Hv, const Vector<Real> &v ) const {
106 Hv.set(v.dual());
107 if (useDefaultScaling_) {
108 if (state_->iter != 0 && state_->current != -1) {
109 Real ss = state_->iterDiff[state_->current]->dot(*(state_->iterDiff[state_->current]));
110 Hv.scale(state_->product[state_->current]/ss);
111 }
112 }
113 else {
114 Hv.scale(static_cast<Real>(1)/Bscaling_);
115 }
116 }
117
118 // Apply lBFGS Approximate Hessian
119 void applyB( Vector<Real> &Bv, const Vector<Real> &v ) const {
120 const Real zero(0);
121
122 Bv.set(v.dual());
123 std::vector<Real> alpha(state_->current+1,zero);
124 for (int i = state_->current; i>=0; i--) {
125 alpha[i] = state_->gradDiff[i]->dot(Bv);
126 alpha[i] /= state_->product[i];
127 Bv.axpy(-alpha[i],(state_->iterDiff[i])->dual());
128 }
129
130 // Apply initial inverse Hessian approximation to v
131 Ptr<Vector<Real>> tmp = Bv.clone();
132 applyB0(*tmp,Bv.dual());
133 Bv.set(*tmp);
134
135 Real beta(0);
136 for (int i = 0; i <= state_->current; i++) {
137 //beta = state_->iterDiff[i]->dot(Bv.dual());
138 beta = state_->iterDiff[i]->apply(Bv);
139 beta /= state_->product[i];
140 Bv.axpy((alpha[i]-beta),*(state_->gradDiff[i]));
141 }
142 }
143
144 // Apply Initial Secant Approximate Hessian
145 virtual void applyB0( Vector<Real> &Bv, const Vector<Real> &v ) const {
146 Bv.set(v.dual());
147 if (useDefaultScaling_) {
148 if (state_->iter != 0 && state_->current != -1) {
149 Real ss = state_->iterDiff[state_->current]->dot(*(state_->iterDiff[state_->current]));
150 Bv.scale(ss/state_->product[state_->current]);
151 }
152 }
153 else {
154 Bv.scale(Bscaling_);
155 }
156 }
157};
158
159}
160
161#endif
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:79
bool useDefaultScaling_
Definition: ROL_Secant.hpp:84
Real Bscaling_
Definition: ROL_Secant.hpp:85
const Ptr< SecantState< Real > > state_
Definition: ROL_Secant.hpp:82
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209
virtual void scale(const Real alpha)=0
Compute where .
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:226
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153
Provides definitions for limited-memory DFP operators.
Definition: ROL_lDFP.hpp:56
lDFP(int M, bool useDefaultScaling=true, Real Bscaling=Real(1))
Definition: ROL_lDFP.hpp:63
virtual void applyB0(Vector< Real > &Bv, const Vector< Real > &v) const
Definition: ROL_lDFP.hpp:145
void applyH(Vector< Real > &Hv, const Vector< Real > &v) const
Definition: ROL_lDFP.hpp:67
void applyB(Vector< Real > &Bv, const Vector< Real > &v) const
Definition: ROL_lDFP.hpp:119
virtual void applyH0(Vector< Real > &Hv, const Vector< Real > &v) const
Definition: ROL_lDFP.hpp:105