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,
121 Real val = computeValue(obj,x,tol);
123 val_ += weight_ * ev;
127 const std::vector<Real> &xstat,
129 if ( xstat[0] ==
static_cast<Real
>(0) ) {
133 sampler.
sumAll(&val_,&ev,1);
134 return (
static_cast<Real
>(1) + std::log(ev)/
eps_)/xstat[0];
139 const std::vector<Real> &xstat,
141 Real val = computeValue(obj,x,tol);
143 val_ += weight_ * ev;
144 gval_ += weight_ * ev * val;
145 computeGradient(*dualVector_,obj,x,tol);
146 g_->axpy(weight_*ev,*dualVector_);
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) ) {
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,
178 Real val = computeValue(obj,x,tol);
180 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
181 val_ += weight_ * ev;
182 gv_ += weight_ * ev * gv;
183 gval_ += weight_ * ev * val;
184 gvval_ += weight_ * ev * val * gv;
185 hval_ += weight_ * ev * val * val;
186 g_->axpy(weight_*ev,*dualVector_);
189 computeHessVec(*dualVector_,obj,v,x,tol);
190 hv_->axpy(weight_*ev,*dualVector_);
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;
214 hv.
axpy(xstat[0]*
eps_,*dualVector_);
218 sampler.
sumAll(*g_,*dualVector_);
219 hv.
axpy(-c3*(vstat[0]*c1 + xstat[0]*c2),*dualVector_);
223 hv.
axpy(vstat[0]*c3,*dualVector_);
225 if ( xstat[0] ==
static_cast<Real
>(0) ) {
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);
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) ) {
260 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 .