44 #ifndef ROL_KLDIVERGENCE_HPP 45 #define ROL_KLDIVERGENCE_HPP 100 TEUCHOS_TEST_FOR_EXCEPTION((
eps_ <= zero), std::invalid_argument,
101 ">>> ERROR (ROL::KLDivergence): Threshold must be positive!");
124 Teuchos::ParameterList &list
125 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"KL Divergence");
126 eps_ = list.get<Real>(
"Threshold");
153 void update(
const Real val,
const Real weight) {
159 if (
xstat_ == static_cast<Real>(0) ) {
160 return ROL_INF<Real>();
163 sampler.
sumAll(&val,&ev,1);
164 return (static_cast<Real>(1) + std::log(ev)/
eps_)/
xstat_;
170 gval_ += weight * ev * val;
175 std::vector<Real> local(2), global(2);
178 sampler.
sumAll(&local[0],&global[0],2);
179 Real ev = global[0], egval = global[1];
186 if (
xstat_ == static_cast<Real>(0) ) {
187 gstat = ROL_INF<Real>();
190 gstat = -((
static_cast<Real
>(1) + std::log(ev)/
eps_)/
xstat_ 201 gval_ += weight * ev * val;
202 gvval_ += weight * ev * val * gv;
203 hval_ += weight * ev * val * val;
211 std::vector<Real> local(5), global(5);
217 sampler.
sumAll(&local[0],&global[0],5);
218 Real ev = global[0], egv = global[1], egval = global[2];
219 Real egvval = global[3], ehval = global[4];
220 Real c0 =
static_cast<Real
>(1)/ev, c1 = c0*egval, c2 = c0*egv, c3 =
eps_*c0;
238 if (
xstat_ == static_cast<Real>(0) ) {
239 hstat = ROL_INF<Real>();
243 Real h11 = xstat2*((
static_cast<Real
>(1) + std::log(ev)/
eps_)/
xstat_ - c1)
245 hstat =
vstat_ * h11 + (c3*egvval -
eps_*c1*c2);
262 if ( arg >= std::log(ROL_INF<Real>()) ) {
263 return ROL_INF<Real>();
266 return std::exp(arg);
270 Real
power(
const Real arg,
const Real pow)
const {
271 if ( arg >= std::pow(ROL_INF<Real>(),static_cast<Real>(1)/pow) ) {
272 return ROL_INF<Real>();
275 return std::pow(arg,pow);
Real getValue(SampleGenerator< Real > &sampler)
Return risk measure value.
void update(const Real val, const Real weight)
Update internal risk measure storage for value computation.
Provides an interface for the Kullback-Leibler distributionally robust expectation.
Teuchos::RCP< Vector< Real > > dualVector1_
void sumAll(Real *input, Real *output, int dim) const
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
Real exponential(const Real arg1, const Real arg2) const
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
Defines the linear algebra or vector space interface.
KLDivergence(Teuchos::ParameterList &parlist)
Constructor.
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x, Teuchos::RCP< Vector< Real > > &v0, const Vector< Real > &v)
Reset internal risk measure storage. Called for Hessian-times-a-vector computation.
Real power(const Real arg, const Real pow) const
Teuchos::RCP< Vector< Real > > scaledGradient_
void update(const Real val, const Vector< Real > &g, const Real weight)
Update internal risk measure storage for gradient computation.
Teuchos::RCP< Vector< Real > > scaledHessVec_
Real exponential(const Real arg) const
virtual void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
void checkInputs(void) const
KLDivergence(const Real eps=1.e-2)
Constructor.
Provides the interface to implement risk measures.
Teuchos::RCP< Vector< Real > > dualVector2_
void update(const Real val, const Vector< Real > &g, const Real gv, const Vector< Real > &hv, const Real weight)
Update internal risk measure storage for Hessian-time-a-vector computation.