ROL
ROL_DistributionFactory.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_DISTRIBUTIONFACTORY_HPP
45 #define ROL_DISTRIBUTIONFACTORY_HPP
46 
47 #include "ROL_ParameterList.hpp"
48 
49 #include "ROL_Dirac.hpp"
50 #include "ROL_Gaussian.hpp"
52 #include "ROL_Uniform.hpp"
53 #include "ROL_Logistic.hpp"
54 #include "ROL_Triangle.hpp"
55 #include "ROL_Parabolic.hpp"
56 #include "ROL_RaisedCosine.hpp"
57 #include "ROL_Laplace.hpp"
58 #include "ROL_Cauchy.hpp"
59 #include "ROL_Smale.hpp"
60 #include "ROL_Arcsine.hpp"
61 #include "ROL_Kumaraswamy.hpp"
62 #include "ROL_Exponential.hpp"
64 #include "ROL_Gamma.hpp"
65 #include "ROL_Beta.hpp"
66 
67 namespace ROL {
68 
88  };
89 
90  inline std::string EDistributionToString(EDistribution ed) {
91  std::string retString;
92  switch(ed) {
93  case DISTRIBUTION_ARCSINE: retString = "Arcsine"; break;
94  case DISTRIBUTION_BETA: retString = "Beta"; break;
95  case DISTRIBUTION_CAUCHY: retString = "Cauchy"; break;
96  case DISTRIBUTION_DIRAC: retString = "Dirac"; break;
97  case DISTRIBUTION_EXPONENTIAL: retString = "Exponential"; break;
98  case DISTRIBUTION_GAMMA: retString = "Gamma"; break;
99  case DISTRIBUTION_GAUSSIAN: retString = "Gaussian"; break;
100  case DISTRIBUTION_KUMARASWAMY: retString = "Kumaraswamy"; break;
101  case DISTRIBUTION_LAPLACE: retString = "Laplace"; break;
102  case DISTRIBUTION_LOGISTIC: retString = "Logistic"; break;
103  case DISTRIBUTION_PARABOLIC: retString = "Parabolic"; break;
104  case DISTRIBUTION_RAISEDCOSINE: retString = "Raised Cosine"; break;
105  case DISTRIBUTION_SMALE: retString = "Smale"; break;
106  case DISTRIBUTION_TRIANGLE: retString = "Triangle"; break;
107  case DISTRIBUTION_TRUNCATEDEXPONENTIAL: retString = "Truncated Exponential"; break;
108  case DISTRIBUTION_TRUNCATEDGAUSSIAN: retString = "Truncated Gaussian"; break;
109  case DISTRIBUTION_UNIFORM: retString = "Uniform"; break;
110  case DISTRIBUTION_LAST: retString = "Last Type (Dummy)"; break;
111  default: retString = "INVALID EDistribution"; break;
112  }
113  return retString;
114  }
115 
117  return( (ed == DISTRIBUTION_DIRAC) ||
118  (ed == DISTRIBUTION_BETA) ||
119  (ed == DISTRIBUTION_GAMMA) ||
120  (ed == DISTRIBUTION_GAUSSIAN) ||
122  (ed == DISTRIBUTION_UNIFORM) ||
123  (ed == DISTRIBUTION_LOGISTIC) ||
124  (ed == DISTRIBUTION_TRIANGLE) ||
125  (ed == DISTRIBUTION_PARABOLIC) ||
126  (ed == DISTRIBUTION_RAISEDCOSINE) ||
127  (ed == DISTRIBUTION_LAPLACE) ||
128  (ed == DISTRIBUTION_CAUCHY) ||
129  (ed == DISTRIBUTION_SMALE) ||
130  (ed == DISTRIBUTION_ARCSINE) ||
131  (ed == DISTRIBUTION_KUMARASWAMY) ||
132  (ed == DISTRIBUTION_EXPONENTIAL) ||
134  }
135 
137  return type = static_cast<EDistribution>(type+1);
138  }
139 
141  EDistribution oldval = type;
142  ++type;
143  return oldval;
144  }
145 
147  return type = static_cast<EDistribution>(type-1);
148  }
149 
151  EDistribution oldval = type;
152  --type;
153  return oldval;
154  }
155 
156  inline EDistribution StringToEDistribution(std::string s) {
157  s = removeStringFormat(s);
158  for ( EDistribution tr = DISTRIBUTION_ARCSINE; tr < DISTRIBUTION_LAST; tr++ ) {
159  if ( !s.compare(removeStringFormat(EDistributionToString(tr))) ) {
160  return tr;
161  }
162  }
163  return DISTRIBUTION_UNIFORM;
164  }
165 
166  template<class Real>
167  inline ROL::Ptr<Distribution<Real> > DistributionFactory(ROL::ParameterList &parlist) {
168  std::string dist;
169  ROL::ParameterList sollist;
170  if ( parlist.isSublist("SOL") ) {
171  dist.assign(parlist.sublist("SOL").sublist("Distribution").get("Name","Dirac"));
172  sollist = parlist;
173  }
174  else {
175  dist.assign(parlist.sublist("Distribution").get("Name","Dirac"));
176  sollist.sublist("SOL") = parlist;
177  }
179  switch(ed) {
180  case DISTRIBUTION_ARCSINE: return ROL::makePtr<Arcsine<Real>>(sollist);
181  case DISTRIBUTION_BETA: return ROL::makePtr<Beta<Real>>(sollist);
182  case DISTRIBUTION_CAUCHY: return ROL::makePtr<Cauchy<Real>>(sollist);
183  case DISTRIBUTION_DIRAC: return ROL::makePtr<Dirac<Real>>(sollist);
184  case DISTRIBUTION_EXPONENTIAL: return ROL::makePtr<Exponential<Real>>(sollist);
185  case DISTRIBUTION_GAMMA: return ROL::makePtr<Gamma<Real>>(sollist);
186  case DISTRIBUTION_GAUSSIAN: return ROL::makePtr<Gaussian<Real>>(sollist);
187  case DISTRIBUTION_KUMARASWAMY: return ROL::makePtr<Kumaraswamy<Real>>(sollist);
188  case DISTRIBUTION_LAPLACE: return ROL::makePtr<Laplace<Real>>(sollist);
189  case DISTRIBUTION_LOGISTIC: return ROL::makePtr<Logistic<Real>>(sollist);
190  case DISTRIBUTION_PARABOLIC: return ROL::makePtr<Parabolic<Real>>(sollist);
191  case DISTRIBUTION_RAISEDCOSINE: return ROL::makePtr<RaisedCosine<Real>>(sollist);
192  case DISTRIBUTION_SMALE: return ROL::makePtr<Smale<Real>>(sollist);
193  case DISTRIBUTION_TRIANGLE: return ROL::makePtr<Triangle<Real>>(sollist);
194  case DISTRIBUTION_TRUNCATEDEXPONENTIAL: return ROL::makePtr<TruncatedExponential<Real>>(sollist);
195  case DISTRIBUTION_TRUNCATEDGAUSSIAN: return ROL::makePtr<TruncatedGaussian<Real>>(sollist);
196  case DISTRIBUTION_UNIFORM: return ROL::makePtr<Uniform<Real>>(sollist);
197  default: return ROL::nullPtr;
198  }
199  }
200 }
201 #endif
EDistribution StringToEDistribution(std::string s)
EKrylov & operator++(EKrylov &type)
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:247
int isValidDistribution(EDistribution ed)
std::string EDistributionToString(EDistribution ed)
EKrylov & operator--(EKrylov &type)
ROL::Ptr< Distribution< Real > > DistributionFactory(ROL::ParameterList &parlist)