ROL
ROL_DistributionFactory.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_DISTRIBUTIONFACTORY_HPP
11 #define ROL_DISTRIBUTIONFACTORY_HPP
12 
13 #include "ROL_ParameterList.hpp"
14 
15 #include "ROL_Dirac.hpp"
16 #include "ROL_Gaussian.hpp"
18 #include "ROL_Uniform.hpp"
19 #include "ROL_Logistic.hpp"
20 #include "ROL_Triangle.hpp"
21 #include "ROL_Parabolic.hpp"
22 #include "ROL_RaisedCosine.hpp"
23 #include "ROL_Laplace.hpp"
24 #include "ROL_Cauchy.hpp"
25 #include "ROL_Smale.hpp"
26 #include "ROL_Arcsine.hpp"
27 #include "ROL_Kumaraswamy.hpp"
28 #include "ROL_Exponential.hpp"
30 #include "ROL_Gamma.hpp"
31 #include "ROL_Beta.hpp"
32 
33 namespace ROL {
34 
54  };
55 
56  inline std::string EDistributionToString(EDistribution ed) {
57  std::string retString;
58  switch(ed) {
59  case DISTRIBUTION_ARCSINE: retString = "Arcsine"; break;
60  case DISTRIBUTION_BETA: retString = "Beta"; break;
61  case DISTRIBUTION_CAUCHY: retString = "Cauchy"; break;
62  case DISTRIBUTION_DIRAC: retString = "Dirac"; break;
63  case DISTRIBUTION_EXPONENTIAL: retString = "Exponential"; break;
64  case DISTRIBUTION_GAMMA: retString = "Gamma"; break;
65  case DISTRIBUTION_GAUSSIAN: retString = "Gaussian"; break;
66  case DISTRIBUTION_KUMARASWAMY: retString = "Kumaraswamy"; break;
67  case DISTRIBUTION_LAPLACE: retString = "Laplace"; break;
68  case DISTRIBUTION_LOGISTIC: retString = "Logistic"; break;
69  case DISTRIBUTION_PARABOLIC: retString = "Parabolic"; break;
70  case DISTRIBUTION_RAISEDCOSINE: retString = "Raised Cosine"; break;
71  case DISTRIBUTION_SMALE: retString = "Smale"; break;
72  case DISTRIBUTION_TRIANGLE: retString = "Triangle"; break;
73  case DISTRIBUTION_TRUNCATEDEXPONENTIAL: retString = "Truncated Exponential"; break;
74  case DISTRIBUTION_TRUNCATEDGAUSSIAN: retString = "Truncated Gaussian"; break;
75  case DISTRIBUTION_UNIFORM: retString = "Uniform"; break;
76  case DISTRIBUTION_LAST: retString = "Last Type (Dummy)"; break;
77  default: retString = "INVALID EDistribution"; break;
78  }
79  return retString;
80  }
81 
83  return( (ed == DISTRIBUTION_DIRAC) ||
84  (ed == DISTRIBUTION_BETA) ||
85  (ed == DISTRIBUTION_GAMMA) ||
86  (ed == DISTRIBUTION_GAUSSIAN) ||
88  (ed == DISTRIBUTION_UNIFORM) ||
89  (ed == DISTRIBUTION_LOGISTIC) ||
90  (ed == DISTRIBUTION_TRIANGLE) ||
91  (ed == DISTRIBUTION_PARABOLIC) ||
92  (ed == DISTRIBUTION_RAISEDCOSINE) ||
93  (ed == DISTRIBUTION_LAPLACE) ||
94  (ed == DISTRIBUTION_CAUCHY) ||
95  (ed == DISTRIBUTION_SMALE) ||
96  (ed == DISTRIBUTION_ARCSINE) ||
97  (ed == DISTRIBUTION_KUMARASWAMY) ||
98  (ed == DISTRIBUTION_EXPONENTIAL) ||
100  }
101 
103  return type = static_cast<EDistribution>(type+1);
104  }
105 
107  EDistribution oldval = type;
108  ++type;
109  return oldval;
110  }
111 
113  return type = static_cast<EDistribution>(type-1);
114  }
115 
117  EDistribution oldval = type;
118  --type;
119  return oldval;
120  }
121 
122  inline EDistribution StringToEDistribution(std::string s) {
123  s = removeStringFormat(s);
124  for ( EDistribution tr = DISTRIBUTION_ARCSINE; tr < DISTRIBUTION_LAST; tr++ ) {
125  if ( !s.compare(removeStringFormat(EDistributionToString(tr))) ) {
126  return tr;
127  }
128  }
129  return DISTRIBUTION_UNIFORM;
130  }
131 
132  template<class Real>
133  inline ROL::Ptr<Distribution<Real> > DistributionFactory(ROL::ParameterList &parlist) {
134  std::string dist;
135  ROL::ParameterList sollist;
136  if ( parlist.isSublist("SOL") ) {
137  dist.assign(parlist.sublist("SOL").sublist("Distribution").get("Name","Dirac"));
138  sollist = parlist;
139  }
140  else {
141  dist.assign(parlist.sublist("Distribution").get("Name","Dirac"));
142  sollist.sublist("SOL") = parlist;
143  }
145  switch(ed) {
146  case DISTRIBUTION_ARCSINE: return ROL::makePtr<Arcsine<Real>>(sollist);
147  case DISTRIBUTION_BETA: return ROL::makePtr<Beta<Real>>(sollist);
148  case DISTRIBUTION_CAUCHY: return ROL::makePtr<Cauchy<Real>>(sollist);
149  case DISTRIBUTION_DIRAC: return ROL::makePtr<Dirac<Real>>(sollist);
150  case DISTRIBUTION_EXPONENTIAL: return ROL::makePtr<Exponential<Real>>(sollist);
151  case DISTRIBUTION_GAMMA: return ROL::makePtr<Gamma<Real>>(sollist);
152  case DISTRIBUTION_GAUSSIAN: return ROL::makePtr<Gaussian<Real>>(sollist);
153  case DISTRIBUTION_KUMARASWAMY: return ROL::makePtr<Kumaraswamy<Real>>(sollist);
154  case DISTRIBUTION_LAPLACE: return ROL::makePtr<Laplace<Real>>(sollist);
155  case DISTRIBUTION_LOGISTIC: return ROL::makePtr<Logistic<Real>>(sollist);
156  case DISTRIBUTION_PARABOLIC: return ROL::makePtr<Parabolic<Real>>(sollist);
157  case DISTRIBUTION_RAISEDCOSINE: return ROL::makePtr<RaisedCosine<Real>>(sollist);
158  case DISTRIBUTION_SMALE: return ROL::makePtr<Smale<Real>>(sollist);
159  case DISTRIBUTION_TRIANGLE: return ROL::makePtr<Triangle<Real>>(sollist);
160  case DISTRIBUTION_TRUNCATEDEXPONENTIAL: return ROL::makePtr<TruncatedExponential<Real>>(sollist);
161  case DISTRIBUTION_TRUNCATEDGAUSSIAN: return ROL::makePtr<TruncatedGaussian<Real>>(sollist);
162  case DISTRIBUTION_UNIFORM: return ROL::makePtr<Uniform<Real>>(sollist);
163  default: return ROL::nullPtr;
164  }
165  }
166 }
167 #endif
EDistribution StringToEDistribution(std::string s)
EPolyProjAlgo & operator++(EPolyProjAlgo &type)
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:215
int isValidDistribution(EDistribution ed)
EPolyProjAlgo & operator--(EPolyProjAlgo &type)
std::string EDistributionToString(EDistribution ed)
ROL::Ptr< Distribution< Real > > DistributionFactory(ROL::ParameterList &parlist)