44 #ifndef ROL_KLDIVERGENCE_HPP
45 #define ROL_KLDIVERGENCE_HPP
109 ROL_TEST_FOR_EXCEPTION((
eps_ <= zero), std::invalid_argument,
110 ">>> ERROR (ROL::KLDivergence): Threshold must be positive!");
133 ROL::ParameterList &list
134 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"KL Divergence");
135 eps_ = list.get<Real>(
"Threshold");
153 const std::vector<Real> &xstat,
161 const std::vector<Real> &xstat,
163 if ( xstat[0] == static_cast<Real>(0) ) {
164 return ROL_INF<Real>();
168 return (static_cast<Real>(1) + std::log(ev)/
eps_)/xstat[0];
173 const std::vector<Real> &xstat,
184 std::vector<Real> &gstat,
186 const std::vector<Real> &xstat,
188 std::vector<Real> local(2), global(2);
191 sampler.
sumAll(&local[0],&global[0],2);
192 Real ev = global[0], egval = global[1];
195 g.
scale(static_cast<Real>(1)/ev);
197 if ( xstat[0] == static_cast<Real>(0) ) {
198 gstat[0] = ROL_INF<Real>();
201 gstat[0] = -((
static_cast<Real
>(1) + std::log(ev)/
eps_)/xstat[0]
202 - egval/ev)/xstat[0];
208 const std::vector<Real> &vstat,
210 const std::vector<Real> &xstat,
228 std::vector<Real> &hvstat,
230 const std::vector<Real> &vstat,
232 const std::vector<Real> &xstat,
234 std::vector<Real> local(5), global(5);
240 sampler.
sumAll(&local[0],&global[0],5);
241 Real ev = global[0], egv = global[1], egval = global[2];
242 Real egvval = global[3], ehval = global[4];
243 Real c0 =
static_cast<Real
>(1)/ev, c1 = c0*egval, c2 = c0*egv, c3 =
eps_*c0;
259 if ( xstat[0] == static_cast<Real>(0) ) {
260 hvstat[0] = ROL_INF<Real>();
263 Real xstat2 =
static_cast<Real
>(2)/(xstat[0]*xstat[0]);
264 Real h11 = xstat2*((
static_cast<Real
>(1) + std::log(ev)/
eps_)/xstat[0] - c1)
265 + (c3*ehval - eps_*c1*c1)/xstat[0];
266 hvstat[0] = vstat[0] * h11 + (c3*egvval - eps_*c1*c2);
281 if ( arg >= std::log(ROL_INF<Real>()) ) {
282 return ROL_INF<Real>();
285 return std::exp(arg);
289 Real
power(
const Real arg,
const Real pow)
const {
290 if ( arg >= std::pow(ROL_INF<Real>(),static_cast<Real>(1)/pow) ) {
291 return ROL_INF<Real>();
294 return std::pow(arg,pow);
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
virtual void scale(const Real alpha)=0
Compute where .
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Ptr< Vector< Real > > hv_
Provides an interface for the Kullback-Leibler distributionally robust expectation.
void checkInputs(void) const
void updateHessVec(Objective< Real > &obj, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for Hessian-time-a-vector computation.
Ptr< Vector< Real > > dualVector_
Defines the linear algebra or vector space interface.
Real exponential(const Real arg) const
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
KLDivergence(ROL::ParameterList &parlist)
Constructor.
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
void initialize(const Vector< Real > &x)
Initialize temporary variables.
ROL::Ptr< Vector< Real > > scaledGradient_
void getGradient(Vector< Real > &g, std::vector< Real > &gstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
Real exponential(const Real arg1, const Real arg2) const
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Real power(const Real arg, const Real pow) const
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
Real computeGradVec(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
KLDivergence(const Real eps=1.e-2)
Constructor.
ROL::Ptr< Vector< Real > > scaledHessVec_
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
void getHessVec(Vector< Real > &hv, std::vector< Real > &hvstat, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.