ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
progressivehedging
ROL_PH_ProbObjective.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 PH_PROBOBJECTIVE_H
11
#define PH_PROBOBJECTIVE_H
12
13
#include "
ROL_Objective.hpp
"
14
21
namespace
ROL
{
22
23
template
<
class
Real>
24
class
PH_ProbObjective
:
public
Objective
<Real> {
25
private
:
26
const
Ptr<Objective<Real>>
obj_
;
27
Real
threshold_
;
28
Real
eps_
;
29
30
bool
isValueComputed_
;
31
Real
val_
;
32
33
bool
isGradientInitialized_
;
34
bool
isGradientComputed_
;
35
Ptr<Vector<Real>>
g_
;
36
37
void
getValue
(
const
Vector<Real>
&x, Real &tol) {
38
if
(!
isValueComputed_
) {
39
val_
=
obj_
->value(x,tol);
40
isValueComputed_
=
true
;
41
}
42
}
43
44
void
getGradient
(
const
Vector<Real>
&x, Real &tol) {
45
if
(!
isGradientInitialized_
) {
46
g_
= x.
dual
().
clone
();
47
isGradientInitialized_
=
true
;
48
}
49
if
(!
isGradientComputed_
) {
50
obj_
->gradient(*
g_
,x,tol);
51
isGradientComputed_
=
true
;
52
}
53
}
54
55
Real
smoothHeaviside
(
const
Real x,
const
int
deriv = 0)
const
{
56
const
Real one(1), two(2);
57
Real val(0);
58
if
(deriv == 0) {
59
Real ex = std::exp(-two*x/
eps_
);
60
val = one/(one+ex);
61
}
62
else
if
(deriv == 1) {
63
Real ex = std::exp(-two*x/
eps_
);
64
val = (two/
eps_
)*ex/std::pow(one+ex,2);
65
}
66
else
if
(deriv == 2) {
67
Real ex = std::exp(two*x/
eps_
);
68
val = std::pow(two/
eps_
,2)*ex*(one-ex)/std::pow(one+ex,3);
69
}
70
return
val;
71
}
72
73
public
:
74
75
PH_ProbObjective
(
const
Ptr<
Objective<Real>
> &obj,
76
ParameterList &parlist)
77
:
obj_
(obj),
78
isValueComputed_
(false),
79
isGradientInitialized_
(false),
80
isGradientComputed_
(false) {
81
ParameterList &list = parlist.sublist(
"SOL"
).sublist(
"Probability"
).sublist(
"Smoothed POE"
);
82
threshold_
= list.get<Real>(
"Threshold"
);
83
eps_
= list.get<Real>(
"Smoothing Parameter"
);
84
}
85
86
void
update
(
const
Vector<Real>
&x,
bool
flag =
true
,
int
iter = -1 ) {
87
obj_
->update(x,flag,iter);
88
isValueComputed_
=
false
;
89
isGradientComputed_
=
false
;
90
}
91
92
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
93
getValue
(x,tol);
94
Real prob =
smoothHeaviside
(
val_
-
threshold_
,0);
95
if
(std::abs(prob) >
ROL_EPSILON<Real>
()) {
96
return
prob;
97
}
98
return
static_cast<
Real
>
(0);
99
}
100
101
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
102
getValue
(x,tol);
103
Real prob =
smoothHeaviside
(
val_
-
threshold_
,1);
104
if
(std::abs(prob) >
ROL_EPSILON<Real>
()) {
105
getGradient
(x,tol);
106
g.
set
(*
g_
); g.
scale
(prob);
107
}
108
else
{
109
g.
zero
();
110
}
111
}
112
113
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
114
getValue
(x,tol);
115
Real prob1 =
smoothHeaviside
(
val_
-
threshold_
,1);
116
Real prob2 =
smoothHeaviside
(
val_
-
threshold_
,2);
117
if
(std::abs(prob1) >
ROL_EPSILON<Real>
()) {
118
obj_
->hessVec(hv,v,x,tol);
119
hv.
scale
(prob1);
120
}
121
else
{
122
hv.
zero
();
123
}
124
if
(std::abs(prob2) >
ROL_EPSILON<Real>
()) {
125
getGradient
(x,tol);
126
//Real gv = v.dot(g_->dual());
127
Real gv = v.
apply
(*
g_
);
128
hv.
axpy
(prob2*gv,*
g_
);
129
}
130
}
131
132
void
setParameter
(
const
std::vector<Real> ¶m) {
133
obj_
->setParameter(param);
134
Objective<Real>::setParameter
(param);
135
}
136
137
};
138
139
}
140
#endif
ROL_Objective.hpp
ROL::Objective::setParameter
virtual void setParameter(const std::vector< Real > ¶m)
Definition
ROL_Objective.hpp:509
ROL::PH_ProbObjective::smoothHeaviside
Real smoothHeaviside(const Real x, const int deriv=0) const
Definition
ROL_PH_ProbObjective.hpp:55
ROL::PH_ProbObjective::isGradientComputed_
bool isGradientComputed_
Definition
ROL_PH_ProbObjective.hpp:34
ROL::PH_ProbObjective::isValueComputed_
bool isValueComputed_
Definition
ROL_PH_ProbObjective.hpp:30
ROL::PH_ProbObjective::getValue
void getValue(const Vector< Real > &x, Real &tol)
Definition
ROL_PH_ProbObjective.hpp:37
ROL::PH_ProbObjective::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_PH_ProbObjective.hpp:92
ROL::PH_ProbObjective::getGradient
void getGradient(const Vector< Real > &x, Real &tol)
Definition
ROL_PH_ProbObjective.hpp:44
ROL::PH_ProbObjective::eps_
Real eps_
Definition
ROL_PH_ProbObjective.hpp:28
ROL::PH_ProbObjective::obj_
const Ptr< Objective< Real > > obj_
Definition
ROL_PH_ProbObjective.hpp:26
ROL::PH_ProbObjective::g_
Ptr< Vector< Real > > g_
Definition
ROL_PH_ProbObjective.hpp:35
ROL::PH_ProbObjective::threshold_
Real threshold_
Definition
ROL_PH_ProbObjective.hpp:27
ROL::PH_ProbObjective::val_
Real val_
Definition
ROL_PH_ProbObjective.hpp:31
ROL::PH_ProbObjective::update
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Definition
ROL_PH_ProbObjective.hpp:86
ROL::PH_ProbObjective::setParameter
void setParameter(const std::vector< Real > ¶m)
Definition
ROL_PH_ProbObjective.hpp:132
ROL::PH_ProbObjective::isGradientInitialized_
bool isGradientInitialized_
Definition
ROL_PH_ProbObjective.hpp:33
ROL::PH_ProbObjective::hessVec
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_PH_ProbObjective.hpp:113
ROL::PH_ProbObjective::PH_ProbObjective
PH_ProbObjective(const Ptr< Objective< Real > > &obj, ParameterList &parlist)
Definition
ROL_PH_ProbObjective.hpp:75
ROL::PH_ProbObjective::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_PH_ProbObjective.hpp:101
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::Vector::apply
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
Definition
ROL_Vector.hpp:205
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::zero
virtual void zero()
Set to zero vector.
Definition
ROL_Vector.hpp:134
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
Definition
ROL_ElementwiseVector.hpp:27
ROL::ROL_EPSILON
Real ROL_EPSILON(void)
Platform-dependent machine epsilon.
Definition
ROL_Types.hpp:57
Generated by
1.17.0