44 #ifndef ROL_FDIVERGENCE_HPP
45 #define ROL_FDIVERGENCE_HPP
112 ROL_TEST_FOR_EXCEPTION((
thresh_ <= zero), std::invalid_argument,
113 ">>> ERROR (ROL::FDivergence): Threshold must be positive!");
136 ROL::ParameterList &list
137 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"F-Divergence");
138 thresh_ = list.get<Real>(
"Threshold");
149 virtual Real
Fprimal(Real x,
int deriv = 0) = 0;
163 virtual Real
Fdual(Real x,
int deriv = 0) = 0;
165 bool check(std::ostream &outStream = std::cout)
const {
166 const Real tol(std::sqrt(ROL_EPSILON<Real>()));
169 Real x =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
170 Real t =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
173 outStream <<
"Check Fenchel-Young Inequality: F(x) + F*(t) >= xt" << std::endl;
174 outStream <<
"x = " << x << std::endl;
175 outStream <<
"t = " << t << std::endl;
176 outStream <<
"F(x) = " << fp << std::endl;
177 outStream <<
"F*(t) = " << fd << std::endl;
178 outStream <<
"Is Valid? " << (fp+fd >= x*t) << std::endl;
179 flag = (fp+fd >= x*t) ? flag :
false;
181 x =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
185 outStream <<
"Check Fenchel-Young Equality: F(x) + F(t) = xt for t = d/dx F(x)" << std::endl;
186 outStream <<
"x = " << x << std::endl;
187 outStream <<
"t = " << t << std::endl;
188 outStream <<
"F(x) = " << fp << std::endl;
189 outStream <<
"F*(t) = " << fd << std::endl;
190 outStream <<
"Is Valid? " << (std::abs(fp+fd - x*t)<=tol) << std::endl;
191 flag = (std::abs(fp+fd - x*t)<=tol) ? flag :
false;
193 t =
static_cast<Real
>(rand())/static_cast<Real>(RAND_MAX);
197 outStream <<
"Check Fenchel-Young Equality: F(x) + F(t) = xt for x = d/dt F*(t)" << std::endl;
198 outStream <<
"x = " << x << std::endl;
199 outStream <<
"t = " << t << std::endl;
200 outStream <<
"F(x) = " << fp << std::endl;
201 outStream <<
"F*(t) = " << fd << std::endl;
202 outStream <<
"Is Valid? " << (std::abs(fp+fd - x*t)<=tol) << std::endl;
203 flag = (std::abs(fp+fd - x*t)<=tol) ? flag :
false;
216 const std::vector<Real> &xstat,
219 Real xlam = xstat[0];
221 Real r =
Fdual((val-xmu)/xlam,0);
226 const std::vector<Real> &xstat,
230 Real xlam = xstat[0];
232 return xlam*(
thresh_ + val) + xmu;
238 const std::vector<Real> &xstat,
241 Real xlam = xstat[0];
243 Real inp = (val-xmu)/xlam;
246 if (std::abs(r0) >= ROL_EPSILON<Real>()) {
249 if (std::abs(r1) >= ROL_EPSILON<Real>()) {
258 std::vector<Real> &gstat,
260 const std::vector<Real> &xstat,
262 std::vector<Real> mygval(3), gval(3);
266 sampler.
sumAll(&mygval[0],&gval[0],3);
268 gstat[0] =
thresh_ + gval[0] + gval[1];
269 gstat[1] =
static_cast<Real
>(1) + gval[2];
276 const std::vector<Real> &vstat,
278 const std::vector<Real> &xstat,
281 Real xlam = xstat[0];
283 Real vlam = vstat[0];
285 Real inp = (val-xmu)/xlam;
287 if (std::abs(r2) >= ROL_EPSILON<Real>()) {
296 if (std::abs(r1) >= ROL_EPSILON<Real>()) {
303 std::vector<Real> &hvstat,
305 const std::vector<Real> &vstat,
307 const std::vector<Real> &xstat,
309 std::vector<Real> myhval(5), hval(5);
315 sampler.
sumAll(&myhval[0],&hval[0],5);
317 std::vector<Real> stat(2);
318 Real xlam = xstat[0];
320 Real vlam = vstat[0];
322 hvstat[0] = (vlam * hval[1] + vmu * hval[0] + hval[2])/xlam;
323 hvstat[1] = (vlam * hval[0] + vmu * hval[3] + hval[4])/xlam;
Provides the interface to evaluate objective functions.
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
Contains definitions of custom data types in ROL.
void initialize(const Vector< Real > &x)
Initialize temporary variables.
Ptr< Vector< Real > > dualVector_
Defines the linear algebra or vector space interface.
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
bool check(std::ostream &outStream=std::cout) const
void checkInputs(void) const
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
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.
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.
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.
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
virtual Real Fdual(Real x, int deriv=0)=0
Implementation of the scalar dual F function.
FDivergence(const Real thresh)
Constructor.
virtual Real Fprimal(Real x, int deriv=0)=0
Implementation of the scalar primal F function.
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
FDivergence(ROL::ParameterList &parlist)
Constructor.
Provides a general interface for the F-divergence distributionally robust expectation.
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...
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.