ROL
ROL_Chi2Divergence.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_CHI2DIVERGENCE_HPP
11 #define ROL_CHI2DIVERGENCE_HPP
12 
13 #include "ROL_FDivergence.hpp"
14 
36 namespace ROL {
37 
38 template<class Real>
39 class Chi2Divergence : public FDivergence<Real> {
40 
41 public:
46  Chi2Divergence(const Real thresh) : FDivergence<Real>(thresh) {}
47 
56  Chi2Divergence(ROL::ParameterList &parlist) : FDivergence<Real>(parlist) {}
57 
58  Real Fprimal(Real x, int deriv = 0) const {
59  Real zero(0), one(1), half(0.5), val(0);
60  if (deriv==0) {
61  val = (x < zero) ? ROL_INF<Real>() : half*(x-one)*(x-one);
62  }
63  else if (deriv==1) {
64  val = (x < zero) ? ROL_INF<Real>() : x-one;
65  }
66  else if (deriv==2) {
67  val = (x < zero) ? ROL_INF<Real>() : one;
68  }
69  else {
70  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
71  ">>> (ROL::Chi2Divergence): Derivative order must be 0, 1, or 2!");
72  }
73  return val;
74  }
75 
76  Real Fdual(Real x, int deriv = 0) const {
77  Real zero(0), one(1), half(0.5), val(0);
78  if (deriv==0) {
79  val = (x < -one) ? -half : (half*x + one)*x;
80  }
81  else if (deriv==1) {
82  val = (x < -one) ? zero : x + one;
83  }
84  else if (deriv==2) {
85  val = (x < -one) ? zero : one;
86  }
87  else {
88  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
89  ">>> (ROL::Chi2Divergence): Derivative order must be 0, 1, or 2!");
90  }
91  return val;
92  }
93 };
94 
95 }
96 
97 #endif
Provides an interface for the chi-squared-divergence distributionally robust expectation.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Real Fdual(Real x, int deriv=0) const
Implementation of the scalar dual F function.
Chi2Divergence(const Real thresh)
Constructor.
Provides a general interface for the F-divergence distributionally robust expectation.
Chi2Divergence(ROL::ParameterList &parlist)
Constructor.
Real Fprimal(Real x, int deriv=0) const
Implementation of the scalar primal F function.