ROL
ROL_Logistic.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_LOGISTIC_HPP
11 #define ROL_LOGISTIC_HPP
12 
13 #include "ROL_Distribution.hpp"
14 #include "ROL_ParameterList.hpp"
15 
16 namespace ROL {
17 
18 template<class Real>
19 class Logistic : public Distribution<Real> {
20 private:
21  Real mean_;
22  Real var_;
23 
24 public:
25  Logistic(const Real mean = 0., const Real var = 1.)
26  : mean_(mean), var_((var>0.) ? var : 1.) {}
27 
28  Logistic(ROL::ParameterList &parlist) {
29  mean_ = parlist.sublist("SOL").sublist("Distribution").sublist("Logistic").get("Mean",0.);
30  var_ = parlist.sublist("SOL").sublist("Distribution").sublist("Logistic").get("Scale",1.);
31  var_ = (var_ > 0.) ? var_ : 1.;
32  }
33 
34  Real evaluatePDF(const Real input) const {
35  Real val = std::exp(-(input-mean_)/var_);
36  return val/(var_*std::pow(1.0+val,2.0));
37  }
38 
39  Real evaluateCDF(const Real input) const {
40  Real val = std::exp(-(input-mean_)/var_);
41  return 1.0/(1.0+val);
42  }
43 
44  Real integrateCDF(const Real input) const {
45  Real val = std::exp(-(input-mean_)/var_);
46  return (input-mean_) + var_*std::log(1.0+val);
47  }
48 
49  Real invertCDF(const Real input) const {
50  return mean_ + var_*std::log(input/(1.0-input));
51  }
52 
53  Real moment(const size_t m) const {
54  Real val = 0.;
55  switch(m) {
56  case 1: val = mean_; break;
57  case 2: val = std::pow(var_*ROL::ScalarTraits<Real>::pi(),2)/3. + std::pow(mean_,2); break;
58  default:
59  ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
60  ">>> ERROR (ROL::Logistic): Logistic moment not implemented for m > 2!");
61  }
62  return val;
63  }
64 
65  Real lowerBound(void) const {
66  return ROL_NINF<Real>();
67  }
68 
69  Real upperBound(void) const {
70  return ROL_INF<Real>();
71  }
72 
73  void test(std::ostream &outStream = std::cout ) const {
74  size_t size = 1;
75  std::vector<Real> X(size,4.*(Real)rand()/(Real)RAND_MAX - 2.);
76  std::vector<int> T(size,0);
77  Distribution<Real>::test(X,T,outStream);
78  }
79 };
80 
81 }
82 
83 #endif
Logistic(ROL::ParameterList &parlist)
Real invertCDF(const Real input) const
Logistic(const Real mean=0., const Real var=1.)
Real lowerBound(void) const
void test(std::ostream &outStream=std::cout) const
Real evaluateCDF(const Real input) const
Real evaluatePDF(const Real input) const
virtual void test(std::ostream &outStream=std::cout) const
Real moment(const size_t m) const
Real upperBound(void) const
Real integrateCDF(const Real input) const