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,
155 Real val = computeValue(obj,x,tol);
157 val_ += weight_ * ev;
161 const std::vector<Real> &xstat,
163 if ( xstat[0] ==
static_cast<Real
>(0) ) {
167 sampler.
sumAll(&val_,&ev,1);
168 return (
static_cast<Real
>(1) + std::log(ev)/
eps_)/xstat[0];
173 const std::vector<Real> &xstat,
175 Real val = computeValue(obj,x,tol);
177 val_ += weight_ * ev;
178 gval_ += weight_ * ev * val;
179 computeGradient(*dualVector_,obj,x,tol);
180 g_->axpy(weight_*ev,*dualVector_);
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) ) {
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,
212 Real val = computeValue(obj,x,tol);
214 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
215 val_ += weight_ * ev;
216 gv_ += weight_ * ev * gv;
217 gval_ += weight_ * ev * val;
218 gvval_ += weight_ * ev * val * gv;
219 hval_ += weight_ * ev * val * val;
220 g_->axpy(weight_*ev,*dualVector_);
223 computeHessVec(*dualVector_,obj,v,x,tol);
224 hv_->axpy(weight_*ev,*dualVector_);
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;
248 hv.
axpy(xstat[0]*
eps_,*dualVector_);
252 sampler.
sumAll(*g_,*dualVector_);
253 hv.
axpy(-c3*(vstat[0]*c1 + xstat[0]*c2),*dualVector_);
257 hv.
axpy(vstat[0]*c3,*dualVector_);
259 if ( xstat[0] ==
static_cast<Real
>(0) ) {
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);
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) ) {
294 return std::pow(arg,pow);
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0 zero)()
void checkInputs(void) const
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
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)
KLDivergence(ROL::ParameterList &parlist)
Constructor.
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)
void getGradient(Vector< Real > &g, std::vector< Real > &gstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
KLDivergence(const Real eps=1.e-2)
Constructor.
Real power(const Real arg, const Real pow) const
void initialize(const Vector< Real > &x)
Real exponential(const Real arg) const
Real exponential(const Real arg1, const Real arg2) const
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
ROL::Ptr< Vector< Real > > scaledGradient_
ROL::Ptr< Vector< Real > > scaledHessVec_
Provides the interface to evaluate objective functions.
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
void sumAll(Real *input, Real *output, int dim) const
Defines the linear algebra or vector space interface.
virtual void scale(const Real alpha)=0
Compute where .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .