10 #ifndef ROL_KLDIVERGENCE_HPP
11 #define ROL_KLDIVERGENCE_HPP
75 ROL_TEST_FOR_EXCEPTION((
eps_ <= zero), std::invalid_argument,
76 ">>> ERROR (ROL::KLDivergence): Threshold must be positive!");
99 ROL::ParameterList &list
100 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"KL Divergence");
101 eps_ = list.get<Real>(
"Threshold");
119 const std::vector<Real> &xstat,
127 const std::vector<Real> &xstat,
129 if ( xstat[0] == static_cast<Real>(0) ) {
130 return ROL_INF<Real>();
134 return (static_cast<Real>(1) + std::log(ev)/
eps_)/xstat[0];
139 const std::vector<Real> &xstat,
150 std::vector<Real> &gstat,
152 const std::vector<Real> &xstat,
154 std::vector<Real> local(2), global(2);
157 sampler.
sumAll(&local[0],&global[0],2);
158 Real ev = global[0], egval = global[1];
161 g.
scale(static_cast<Real>(1)/ev);
163 if ( xstat[0] == static_cast<Real>(0) ) {
164 gstat[0] = ROL_INF<Real>();
167 gstat[0] = -((
static_cast<Real
>(1) + std::log(ev)/
eps_)/xstat[0]
168 - egval/ev)/xstat[0];
174 const std::vector<Real> &vstat,
176 const std::vector<Real> &xstat,
194 std::vector<Real> &hvstat,
196 const std::vector<Real> &vstat,
198 const std::vector<Real> &xstat,
200 std::vector<Real> local(5), global(5);
206 sampler.
sumAll(&local[0],&global[0],5);
207 Real ev = global[0], egv = global[1], egval = global[2];
208 Real egvval = global[3], ehval = global[4];
209 Real c0 =
static_cast<Real
>(1)/ev, c1 = c0*egval, c2 = c0*egv, c3 =
eps_*c0;
225 if ( xstat[0] == static_cast<Real>(0) ) {
226 hvstat[0] = ROL_INF<Real>();
229 Real xstat2 =
static_cast<Real
>(2)/(xstat[0]*xstat[0]);
230 Real h11 = xstat2*((
static_cast<Real
>(1) + std::log(ev)/
eps_)/xstat[0] - c1)
231 + (c3*ehval - eps_*c1*c1)/xstat[0];
232 hvstat[0] = vstat[0] * h11 + (c3*egvval - eps_*c1*c2);
247 if ( arg >= std::log(ROL_INF<Real>()) ) {
248 return ROL_INF<Real>();
251 return std::exp(arg);
255 Real
power(
const Real arg,
const Real pow)
const {
256 if ( arg >= std::pow(ROL_INF<Real>(),static_cast<Real>(1)/pow) ) {
257 return ROL_INF<Real>();
260 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.