ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
step
secant
ROL_lDFP.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_LDFP_H
11
#define ROL_LDFP_H
12
16
17
#include "
ROL_Secant.hpp
"
18
19
namespace
ROL
{
20
21
template
<
class
Real>
22
class
lDFP
:
public
Secant
<Real> {
23
private
:
24
using
Secant
<Real>
::state_
;
25
using
Secant
<Real>
::useDefaultScaling_
;
26
using
Secant
<Real>
::Bscaling_
;
27
28
public
:
29
lDFP
(
int
M,
bool
useDefaultScaling =
true
, Real Bscaling = Real(1))
30
:
Secant
<Real>(M,useDefaultScaling,Bscaling) {}
31
32
// Apply lBFGS Approximate Inverse Hessian
33
void
applyH
(
Vector<Real>
&Hv,
const
Vector<Real>
&v )
const
{
34
const
Real one(1);
35
36
// Apply initial Hessian approximation to v
37
applyH0
(Hv,v);
38
39
std::vector<Ptr<Vector<Real>>> a(
state_
->current+1);
40
std::vector<Ptr<Vector<Real>>> b(
state_
->current+1);
41
Real bv(0), av(0), bs(0), as(0);
42
for
(
int
i = 0; i <=
state_
->current; i++) {
43
b[i] = Hv.
clone
();
44
b[i]->set(*(
state_
->iterDiff[i]));
45
b[i]->scale(1.0/sqrt(
state_
->product[i]));
46
//bv = b[i]->dot(v.dual());
47
bv = b[i]->apply(v);
48
Hv.
axpy
(bv,*b[i]);
49
50
a[i] = Hv.
clone
();
51
applyH0
(*a[i],*(
state_
->gradDiff[i]));
52
53
for
(
int
j = 0; j < i; j++) {
54
//bs = b[j]->dot((state_->gradDiff[i])->dual());
55
bs = b[j]->apply(*(
state_
->gradDiff[i]));
56
a[i]->axpy(bs,*b[j]);
57
//as = a[j]->dot((state_->gradDiff[i])->dual());
58
as = a[j]->apply(*(
state_
->gradDiff[i]));
59
a[i]->axpy(-as,*a[j]);
60
}
61
//as = a[i]->dot((state_->gradDiff[i])->dual());
62
as = a[i]->apply(*(
state_
->gradDiff[i]));
63
a[i]->scale(one/sqrt(as));
64
//av = a[i]->dot(v.dual());
65
av = a[i]->apply(v);
66
Hv.
axpy
(-av,*a[i]);
67
}
68
}
69
70
// Apply Initial Secant Approximate Hessian
71
virtual
void
applyH0
(
Vector<Real>
&Hv,
const
Vector<Real>
&v )
const
{
72
Hv.
set
(v.
dual
());
73
if
(
useDefaultScaling_
) {
74
if
(
state_
->iter != 0 &&
state_
->current != -1) {
75
Real ss =
state_
->iterDiff[
state_
->current]->dot(*(
state_
->iterDiff[
state_
->current]));
76
Hv.
scale
(
state_
->product[
state_
->current]/ss);
77
}
78
}
79
else
{
80
Hv.
scale
(
static_cast<
Real
>
(1)/
Bscaling_
);
81
}
82
}
83
84
// Apply lBFGS Approximate Hessian
85
void
applyB
(
Vector<Real>
&Bv,
const
Vector<Real>
&v )
const
{
86
const
Real
zero
(0);
87
88
Bv.
set
(v.
dual
());
89
std::vector<Real> alpha(
state_
->current+1,
zero
);
90
for
(
int
i =
state_
->current; i>=0; i--) {
91
alpha[i] =
state_
->gradDiff[i]->dot(Bv);
92
alpha[i] /=
state_
->product[i];
93
Bv.
axpy
(-alpha[i],(
state_
->iterDiff[i])->dual());
94
}
95
96
// Apply initial inverse Hessian approximation to v
97
Ptr<Vector<Real>> tmp = Bv.
clone
();
98
applyB0
(*tmp,Bv.
dual
());
99
Bv.
set
(*tmp);
100
101
Real beta(0);
102
for
(
int
i = 0; i <=
state_
->current; i++) {
103
//beta = state_->iterDiff[i]->dot(Bv.dual());
104
beta =
state_
->iterDiff[i]->apply(Bv);
105
beta /=
state_
->product[i];
106
Bv.
axpy
((alpha[i]-beta),*(
state_
->gradDiff[i]));
107
}
108
}
109
110
// Apply Initial Secant Approximate Hessian
111
virtual
void
applyB0
(
Vector<Real>
&Bv,
const
Vector<Real>
&v )
const
{
112
Bv.
set
(v.
dual
());
113
if
(
useDefaultScaling_
) {
114
if
(
state_
->iter != 0 &&
state_
->current != -1) {
115
Real ss =
state_
->iterDiff[
state_
->current]->dot(*(
state_
->iterDiff[
state_
->current]));
116
Bv.
scale
(ss/
state_
->product[
state_
->current]);
117
}
118
}
119
else
{
120
Bv.
scale
(
Bscaling_
);
121
}
122
}
123
};
124
125
}
126
127
#endif
zero
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0 zero)()
Definition
ROL_Objective_SerialSimOpt.hpp:77
ROL_Secant.hpp
ROL::ROL::Secant::Bscaling_
Real Bscaling_
Definition
ROL_Constraint_SerialSimOpt.hpp:51
ROL::ROL::Secant::state_
const Ptr< SecantState< Real > > state_
Definition
ROL_Constraint_SerialSimOpt.hpp:48
ROL::ROL::Secant::useDefaultScaling_
bool useDefaultScaling_
Definition
ROL_Constraint_SerialSimOpt.hpp:50
ROL::ROL::Secant::Secant
Secant(int M=10, bool useDefaultScaling=true, Real Bscaling=Real(1), ESecantMode mode=SECANTMODE_BOTH)
Definition
ROL_Constraint_SerialSimOpt.hpp:62
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::set
virtual void set(const Vector &x)
Set where .
Definition
ROL_Vector.hpp:176
ROL::Vector::scale
virtual void scale(const Real alpha)=0
Compute where .
ROL::Vector::dual
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:193
ROL::Vector::clone
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
ROL::Vector::axpy
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition
ROL_Vector.hpp:120
ROL::lDFP::lDFP
lDFP(int M, bool useDefaultScaling=true, Real Bscaling=Real(1))
Definition
ROL_lDFP.hpp:29
ROL::lDFP::applyB0
virtual void applyB0(Vector< Real > &Bv, const Vector< Real > &v) const
Definition
ROL_lDFP.hpp:111
ROL::lDFP::applyH
void applyH(Vector< Real > &Hv, const Vector< Real > &v) const
Definition
ROL_lDFP.hpp:33
ROL::lDFP::applyB
void applyB(Vector< Real > &Bv, const Vector< Real > &v) const
Definition
ROL_lDFP.hpp:85
ROL::lDFP::applyH0
virtual void applyH0(Vector< Real > &Hv, const Vector< Real > &v) const
Definition
ROL_lDFP.hpp:71
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0