ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
progressivehedging
ROL_PH_RiskObjective.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_RISKOBJECTIVE_H
11
#define PH_RISKOBJECTIVE_H
12
13
#include "
ROL_Objective.hpp
"
14
#include "
ROL_RiskMeasureFactory.hpp
"
15
22
namespace
ROL
{
23
24
template
<
class
Real>
25
class
PH_RiskObjective
:
public
Objective
<Real> {
26
private
:
27
const
Ptr<Objective<Real>>
obj_
;
28
Ptr<ExpectationQuad<Real>>
quad_
;
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
Ptr<const Vector<Real>>
getConstVector
(
const
Vector<Real>
&x)
const
{
56
const
RiskVector<Real>
&xrv =
dynamic_cast<
const
RiskVector<Real>
&
>
(x);
57
return
xrv.
getVector
();
58
}
59
60
Ptr<Vector<Real>>
getVector
(
Vector<Real>
&x)
const
{
61
RiskVector<Real>
&xrv =
dynamic_cast<
RiskVector<Real>
&
>
(x);
62
return
xrv.
getVector
();
63
}
64
65
Ptr<const std::vector<Real>>
getConstStat
(
const
Vector<Real>
&x)
const
{
66
const
RiskVector<Real>
&xrv =
dynamic_cast<
const
RiskVector<Real>
&
>
(x);
67
Ptr<const std::vector<Real>> xstat = xrv.
getStatistic
();
68
if
(xstat == nullPtr) {
69
xstat = makePtr<const std::vector<Real>>(0);
70
}
71
return
xstat;
72
}
73
74
Ptr<std::vector<Real>>
getStat
(
Vector<Real>
&x)
const
{
75
RiskVector<Real>
&xrv =
dynamic_cast<
RiskVector<Real>
&
>
(x);
76
Ptr<std::vector<Real>> xstat = xrv.
getStatistic
();
77
if
(xstat == nullPtr) {
78
xstat = makePtr<std::vector<Real>>(0);
79
}
80
return
xstat;
81
}
82
83
public
:
84
85
PH_RiskObjective
(
const
Ptr<
Objective<Real>
> &obj,
86
ParameterList &parlist)
87
:
obj_
(obj),
88
isValueComputed_
(false),
89
isGradientInitialized_
(false),
90
isGradientComputed_
(false) {
91
std::string risk = parlist.sublist(
"SOL"
).sublist(
"Risk Measure"
).get(
"Name"
,
"CVaR"
);
92
ERiskMeasure
ed =
StringToERiskMeasure
(risk);
93
switch
(ed) {
94
case
RISKMEASURE_CVAR
:
95
quad_
= makePtr<QuantileQuadrangle<Real>>(parlist);
break
;
96
case
RISKMEASURE_MOREAUYOSIDACVAR
:
97
quad_
= makePtr<MoreauYosidaCVaR<Real>>(parlist);
break
;
98
case
RISKMEASURE_GENMOREAUYOSIDACVAR
:
99
quad_
= makePtr<GenMoreauYosidaCVaR<Real>>(parlist);
break
;
100
case
RISKMEASURE_LOGEXPONENTIAL
:
101
quad_
= makePtr<LogExponentialQuadrangle<Real>>(parlist);
break
;
102
case
RISKMEASURE_SAFETYMARGIN
:
103
quad_
= makePtr<MeanVarianceQuadrangle<Real>>(parlist);
break
;
104
case
RISKMEASURE_TRUNCATEDMEAN
:
105
quad_
= makePtr<TruncatedMeanQuadrangle<Real>>(parlist);
break
;
106
case
RISKMEASURE_LOGQUANTILE
:
107
quad_
= makePtr<LogQuantileQuadrangle<Real>>(parlist);
break
;
108
case
RISKMEASURE_SMOOTHEDWORSTCASE
:
109
quad_
= makePtr<SmoothedWorstCaseQuadrangle<Real>>(parlist);
break
;
110
// case RISKMEASURE_CHI2DIVERGENCE:
111
// return makePtr<Chi2Divergence<Real>>(parlist);
112
// case RISKMEASURE_KLDIVERGENCE:
113
// return makePtr<KLDivergence<Real>>(parlist);
114
default
:
115
ROL_TEST_FOR_EXCEPTION(
true
,std::invalid_argument,
116
"Invalid risk measure type "
<< risk <<
"!"
);
117
}
118
}
119
120
void
update
(
const
Vector<Real>
&x,
bool
flag =
true
,
int
iter = -1 ) {
121
Ptr<const Vector<Real>> xvec =
getConstVector
(x);
122
obj_
->update(*xvec,flag,iter);
123
isValueComputed_
=
false
;
124
isGradientComputed_
=
false
;
125
}
126
127
Real
value
(
const
Vector<Real>
&x, Real &tol ) {
128
Ptr<const Vector<Real>> xvec =
getConstVector
(x);
129
Ptr<const std::vector<Real>> xstat =
getConstStat
(x);
130
getValue
(*xvec,tol);
131
Real reg =
quad_
->regret(
val_
-(*xstat)[0],0);
132
return
(*xstat)[0] + reg;
133
}
134
135
void
gradient
(
Vector<Real>
&g,
const
Vector<Real>
&x, Real &tol ) {
136
Ptr<Vector<Real>> gvec =
getVector
(g);
137
Ptr<std::vector<Real>> gstat =
getStat
(g);
138
Ptr<const Vector<Real>> xvec =
getConstVector
(x);
139
Ptr<const std::vector<Real>> xstat =
getConstStat
(x);
140
getValue
(*xvec,tol);
141
Real reg =
quad_
->regret(
val_
-(*xstat)[0],1);
142
getGradient
(*xvec,tol);
143
gvec->set(*
g_
); gvec->scale(reg);
144
(*gstat)[0] =
static_cast<
Real
>
(1)-reg;
145
}
146
147
void
hessVec
(
Vector<Real>
&hv,
const
Vector<Real>
&v,
const
Vector<Real>
&x, Real &tol ) {
148
Ptr<Vector<Real>> hvec =
getVector
(hv);
149
Ptr<std::vector<Real>> hstat =
getStat
(hv);
150
Ptr<const Vector<Real>> vvec =
getConstVector
(v);
151
Ptr<const std::vector<Real>> vstat =
getConstStat
(v);
152
Ptr<const Vector<Real>> xvec =
getConstVector
(x);
153
Ptr<const std::vector<Real>> xstat =
getConstStat
(x);
154
getValue
(*xvec,tol);
155
Real reg1 =
quad_
->regret(
val_
-(*xstat)[0],1);
156
Real reg2 =
quad_
->regret(
val_
-(*xstat)[0],2);
157
getGradient
(*xvec,tol);
158
//Real gv = vvec->dot(g_->dual());
159
Real gv = vvec->apply(*
g_
);
160
obj_
->hessVec(*hvec,*vvec,*xvec,tol);
161
hvec->scale(reg1); hvec->axpy(reg2*(gv-(*vstat)[0]),*
g_
);
162
(*hstat)[0] = reg2*((*vstat)[0]-gv);
163
}
164
165
void
setParameter
(
const
std::vector<Real> ¶m) {
166
obj_
->setParameter(param);
167
Objective<Real>::setParameter
(param);
168
}
169
170
};
171
172
}
173
#endif
ROL_Objective.hpp
ROL_RiskMeasureFactory.hpp
ROL::Objective::setParameter
virtual void setParameter(const std::vector< Real > ¶m)
Definition
ROL_Objective.hpp:509
ROL::PH_RiskObjective::quad_
Ptr< ExpectationQuad< Real > > quad_
Definition
ROL_PH_RiskObjective.hpp:28
ROL::PH_RiskObjective::update
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Definition
ROL_PH_RiskObjective.hpp:120
ROL::PH_RiskObjective::isValueComputed_
bool isValueComputed_
Definition
ROL_PH_RiskObjective.hpp:30
ROL::PH_RiskObjective::obj_
const Ptr< Objective< Real > > obj_
Definition
ROL_PH_RiskObjective.hpp:27
ROL::PH_RiskObjective::isGradientComputed_
bool isGradientComputed_
Definition
ROL_PH_RiskObjective.hpp:34
ROL::PH_RiskObjective::getConstStat
Ptr< const std::vector< Real > > getConstStat(const Vector< Real > &x) const
Definition
ROL_PH_RiskObjective.hpp:65
ROL::PH_RiskObjective::getConstVector
Ptr< const Vector< Real > > getConstVector(const Vector< Real > &x) const
Definition
ROL_PH_RiskObjective.hpp:55
ROL::PH_RiskObjective::setParameter
void setParameter(const std::vector< Real > ¶m)
Definition
ROL_PH_RiskObjective.hpp:165
ROL::PH_RiskObjective::val_
Real val_
Definition
ROL_PH_RiskObjective.hpp:31
ROL::PH_RiskObjective::gradient
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Definition
ROL_PH_RiskObjective.hpp:135
ROL::PH_RiskObjective::value
Real value(const Vector< Real > &x, Real &tol)
Definition
ROL_PH_RiskObjective.hpp:127
ROL::PH_RiskObjective::PH_RiskObjective
PH_RiskObjective(const Ptr< Objective< Real > > &obj, ParameterList &parlist)
Definition
ROL_PH_RiskObjective.hpp:85
ROL::PH_RiskObjective::g_
Ptr< Vector< Real > > g_
Definition
ROL_PH_RiskObjective.hpp:35
ROL::PH_RiskObjective::getGradient
void getGradient(const Vector< Real > &x, Real &tol)
Definition
ROL_PH_RiskObjective.hpp:44
ROL::PH_RiskObjective::getValue
void getValue(const Vector< Real > &x, Real &tol)
Definition
ROL_PH_RiskObjective.hpp:37
ROL::PH_RiskObjective::isGradientInitialized_
bool isGradientInitialized_
Definition
ROL_PH_RiskObjective.hpp:33
ROL::PH_RiskObjective::getStat
Ptr< std::vector< Real > > getStat(Vector< Real > &x) const
Definition
ROL_PH_RiskObjective.hpp:74
ROL::PH_RiskObjective::hessVec
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition
ROL_PH_RiskObjective.hpp:147
ROL::PH_RiskObjective::getVector
Ptr< Vector< Real > > getVector(Vector< Real > &x) const
Definition
ROL_PH_RiskObjective.hpp:60
ROL::ROL::Objective::Objective
Objective()
Definition
ROL_Constraint_SerialSimOpt.hpp:53
ROL::RiskVector
Definition
ROL_RiskVector.hpp:20
ROL::RiskVector::getStatistic
Ptr< std::vector< Real > > getStatistic(const int comp=0, const int index=0)
Definition
ROL_RiskVector.hpp:475
ROL::RiskVector::getVector
Ptr< const Vector< Real > > getVector(void) const
Definition
ROL_RiskVector.hpp:463
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
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
Definition
ROL_ElementwiseVector.hpp:27
ROL::StringToERiskMeasure
ERiskMeasure StringToERiskMeasure(std::string s)
Definition
ROL_RiskMeasureFactory.hpp:184
ROL::ERiskMeasure
ERiskMeasure
Definition
ROL_RiskMeasureFactory.hpp:50
ROL::RISKMEASURE_TRUNCATEDMEAN
@ RISKMEASURE_TRUNCATEDMEAN
Definition
ROL_RiskMeasureFactory.hpp:68
ROL::RISKMEASURE_MOREAUYOSIDACVAR
@ RISKMEASURE_MOREAUYOSIDACVAR
Definition
ROL_RiskMeasureFactory.hpp:52
ROL::RISKMEASURE_LOGEXPONENTIAL
@ RISKMEASURE_LOGEXPONENTIAL
Definition
ROL_RiskMeasureFactory.hpp:71
ROL::RISKMEASURE_CVAR
@ RISKMEASURE_CVAR
Definition
ROL_RiskMeasureFactory.hpp:51
ROL::RISKMEASURE_GENMOREAUYOSIDACVAR
@ RISKMEASURE_GENMOREAUYOSIDACVAR
Definition
ROL_RiskMeasureFactory.hpp:53
ROL::RISKMEASURE_LOGQUANTILE
@ RISKMEASURE_LOGQUANTILE
Definition
ROL_RiskMeasureFactory.hpp:69
ROL::RISKMEASURE_SMOOTHEDWORSTCASE
@ RISKMEASURE_SMOOTHEDWORSTCASE
Definition
ROL_RiskMeasureFactory.hpp:70
ROL::RISKMEASURE_SAFETYMARGIN
@ RISKMEASURE_SAFETYMARGIN
Definition
ROL_RiskMeasureFactory.hpp:72
Generated by
1.17.0