ROL
ROL_Logistic.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44#ifndef ROL_LOGISTIC_HPP
45#define ROL_LOGISTIC_HPP
46
47#include "ROL_Distribution.hpp"
48#include "ROL_ParameterList.hpp"
49
50namespace ROL {
51
52template<class Real>
53class Logistic : public Distribution<Real> {
54private:
55 Real mean_;
56 Real var_;
57
58public:
59 Logistic(const Real mean = 0., const Real var = 1.)
60 : mean_(mean), var_((var>0.) ? var : 1.) {}
61
62 Logistic(ROL::ParameterList &parlist) {
63 mean_ = parlist.sublist("SOL").sublist("Distribution").sublist("Logistic").get("Mean",0.);
64 var_ = parlist.sublist("SOL").sublist("Distribution").sublist("Logistic").get("Scale",1.);
65 var_ = (var_ > 0.) ? var_ : 1.;
66 }
67
68 Real evaluatePDF(const Real input) const {
69 Real val = std::exp(-(input-mean_)/var_);
70 return val/(var_*std::pow(1.0+val,2.0));
71 }
72
73 Real evaluateCDF(const Real input) const {
74 Real val = std::exp(-(input-mean_)/var_);
75 return 1.0/(1.0+val);
76 }
77
78 Real integrateCDF(const Real input) const {
79 Real val = std::exp(-(input-mean_)/var_);
80 return (input-mean_) + var_*std::log(1.0+val);
81 }
82
83 Real invertCDF(const Real input) const {
84 return mean_ + var_*std::log(input/(1.0-input));
85 }
86
87 Real moment(const size_t m) const {
88 Real val = 0.;
89 switch(m) {
90 case 1: val = mean_; break;
91 case 2: val = std::pow(var_*ROL::ScalarTraits<Real>::pi(),2)/3. + std::pow(mean_,2); break;
92 default:
93 ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
94 ">>> ERROR (ROL::Logistic): Logistic moment not implemented for m > 2!");
95 }
96 return val;
97 }
98
99 Real lowerBound(void) const {
100 return ROL_NINF<Real>();
101 }
102
103 Real upperBound(void) const {
104 return ROL_INF<Real>();
105 }
106
107 void test(std::ostream &outStream = std::cout ) const {
108 size_t size = 1;
109 std::vector<Real> X(size,4.*(Real)rand()/(Real)RAND_MAX - 2.);
110 std::vector<int> T(size,0);
111 Distribution<Real>::test(X,T,outStream);
112 }
113};
114
115}
116
117#endif
virtual void test(std::ostream &outStream=std::cout) const
Real integrateCDF(const Real input) const
Real evaluatePDF(const Real input) const
Logistic(ROL::ParameterList &parlist)
Real lowerBound(void) const
Real invertCDF(const Real input) const
Real upperBound(void) const
Logistic(const Real mean=0., const Real var=1.)
void test(std::ostream &outStream=std::cout) const
Real moment(const size_t m) const
Real evaluateCDF(const Real input) const