ROL
ROL_Cauchy.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_CAUCHY_HPP
11 #define ROL_CAUCHY_HPP
12 
13 #include "ROL_Distribution.hpp"
14 #include "ROL_ParameterList.hpp"
15 
16 namespace ROL {
17 
18 template<class Real>
19 class Cauchy : public Distribution<Real> {
20 private:
21  Real loc_;
22  Real scale_;
23 
24 public:
25  Cauchy(const Real loc = 0., const Real scale = 1.)
26  : loc_(loc), scale_((scale>0.) ? scale : 1.) {}
27 
28  Cauchy(ROL::ParameterList &parlist) {
29  loc_ = parlist.sublist("SOL").sublist("Distribution").sublist("Cauchy").get("Location",0.);
30  scale_ = parlist.sublist("SOL").sublist("Distribution").sublist("Cauchy").get("Scale",1.);
31  scale_ = (scale_>0.) ? scale_ : 1.;
32  }
33 
34  Real evaluatePDF(const Real input) const {
35  return 1./(ROL::ScalarTraits<Real>::pi()*scale_*(1.+std::pow((input-loc_)/scale_,2.)));
36  }
37 
38  Real evaluateCDF(const Real input) const {
39  return 0.5+atan((input-loc_)/scale_)/ROL::ScalarTraits<Real>::pi();
40  }
41 
42  Real integrateCDF(const Real input) const {
43  Real v = input-loc_;
44  return 0.5*input + (v*atan(v/scale_) - 0.5*scale_*std::log(v*v+scale_*scale_))/ROL::ScalarTraits<Real>::pi();
45  }
46 
47  Real invertCDF(const Real input) const {
48  return loc_+scale_*tan(ROL::ScalarTraits<Real>::pi()*(input-0.5));
49  }
50 
51  Real moment(const size_t m) const {
52  ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
53  ">>> ERROR (ROL::Cauchy): Cauchy moments are undefined!");
54  }
55 
56  Real lowerBound(void) const {
57  return ROL_NINF<Real>();
58  }
59 
60  Real upperBound(void) const {
61  return ROL_INF<Real>();
62  }
63 
64  void test(std::ostream &outStream = std::cout ) const {
65  size_t size = 1;
66  std::vector<Real> X(size,4.*(Real)rand()/(Real)RAND_MAX - 2.);
67  std::vector<int> T(size,0);
68  Distribution<Real>::test(X,T,outStream);
69  }
70 };
71 
72 }
73 
74 #endif
Cauchy(const Real loc=0., const Real scale=1.)
Definition: ROL_Cauchy.hpp:25
Real evaluatePDF(const Real input) const
Definition: ROL_Cauchy.hpp:34
Real lowerBound(void) const
Definition: ROL_Cauchy.hpp:56
Cauchy(ROL::ParameterList &parlist)
Definition: ROL_Cauchy.hpp:28
Real integrateCDF(const Real input) const
Definition: ROL_Cauchy.hpp:42
static constexpr Real pi() noexcept
Real upperBound(void) const
Definition: ROL_Cauchy.hpp:60
Real invertCDF(const Real input) const
Definition: ROL_Cauchy.hpp:47
virtual void test(std::ostream &outStream=std::cout) const
Real evaluateCDF(const Real input) const
Definition: ROL_Cauchy.hpp:38
void test(std::ostream &outStream=std::cout) const
Definition: ROL_Cauchy.hpp:64
Real moment(const size_t m) const
Definition: ROL_Cauchy.hpp:51