ROL
ROL_Dirac.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_DIRAC_HPP
11 #define ROL_DIRAC_HPP
12 
13 #include "ROL_Distribution.hpp"
14 #include "ROL_ParameterList.hpp"
15 
16 namespace ROL {
17 
18 template<class Real>
19 class Dirac : public Distribution<Real> {
20 private:
21  Real data_;
22 
23 public:
24  Dirac(const Real data = 0.) : data_(data) {}
25 
26  Dirac(ROL::ParameterList &parlist) {
27  data_ = parlist.sublist("SOL").sublist("Distribution").sublist("Dirac").get("Location",0.);
28  }
29 
30  Real evaluatePDF(const Real input) const {
31  return ((input==data_) ? 1.0 : 0.0);
32  }
33 
34  Real evaluateCDF(const Real input) const {
35  return ((input >= data_) ? 1.0 : 0.0);
36  }
37 
38  Real integrateCDF(const Real input) const {
39  return ((input < data_) ? 0.0 : input);
40  }
41 
42  Real invertCDF(const Real input) const {
43  return data_;
44  }
45 
46  Real moment(const size_t m) const {
47  if (m==1) {
48  return data_;
49  }
50  return std::pow(data_,(Real)m);
51  }
52 
53  Real lowerBound(void) const {
54  return data_;
55  }
56 
57  Real upperBound(void) const {
58  return data_;
59  }
60 
61  void test(std::ostream &outStream = std::cout ) const {
62  size_t size = 0;
63  std::vector<Real> X(size,4.*(Real)rand()/(Real)RAND_MAX - 2.);
64  std::vector<int> T(size,0);
65  Distribution<Real>::test(X,T,outStream);
66  }
67 };
68 
69 }
70 
71 #endif
Real moment(const size_t m) const
Definition: ROL_Dirac.hpp:46
Real lowerBound(void) const
Definition: ROL_Dirac.hpp:53
Real evaluateCDF(const Real input) const
Definition: ROL_Dirac.hpp:34
virtual void test(std::ostream &outStream=std::cout) const
Dirac(ROL::ParameterList &parlist)
Definition: ROL_Dirac.hpp:26
Dirac(const Real data=0.)
Definition: ROL_Dirac.hpp:24
void test(std::ostream &outStream=std::cout) const
Definition: ROL_Dirac.hpp:61
Real data_
Definition: ROL_Dirac.hpp:21
Real integrateCDF(const Real input) const
Definition: ROL_Dirac.hpp:38
Real evaluatePDF(const Real input) const
Definition: ROL_Dirac.hpp:30
Real invertCDF(const Real input) const
Definition: ROL_Dirac.hpp:42
Real upperBound(void) const
Definition: ROL_Dirac.hpp:57