4 namespace Distributions {
11 seed(static_cast<unsigned int>(std::time(0)));
24 using Polymorph<Derived>::derived;
29 double minimum(
void)
const {
33 double maximum(
void)
const {
37 double mean(
void)
const {
38 return boost::math::mean(derived().boost_dist());
41 double median(
void)
const {
42 return boost::math::median(derived().boost_dist());
45 double mode(
void)
const {
46 return boost::math::mode(derived().boost_dist());
49 double sd(
void)
const {
50 return boost::math::standard_deviation(derived().boost_dist());
53 double variance(
void)
const {
54 return boost::math::variance(derived().boost_dist());
57 double skewness(
void)
const {
58 return boost::math::skewness(derived().boost_dist());
61 double kurtosis(
void)
const {
62 return boost::math::kurtosis(derived().boost_dist());
65 double kurtosis_excess(
void)
const {
66 return boost::math::kurtosis_excess(derived().boost_dist());
69 bool valid(
void)
const {
73 double loglike(
const double& x)
const {
74 return std::log(derived().pdf(x));
77 double pdf(
const double& x)
const {
78 if(derived().valid())
return boost::math::pdf(derived().boost_dist(),x);
82 double cdf(
const double& x)
const {
83 if(derived().valid())
return boost::math::cdf(derived().boost_dist(),x);
87 double quantile(
const double& p)
const {
88 if(derived().valid())
return boost::math::quantile(derived().boost_dist(),p);
92 double integral(
const double& from,
const double& to)
const {
93 return cdf(to)-cdf(from);
96 double random(
void)
const {
97 auto boost_rand = derived().boost_rand();
98 boost::variate_generator<boost::mt19937&,decltype(boost_rand)> random(
Generator,boost_rand);
109 bool valid(
void)
const {
110 return std::isfinite(value);
113 double minimum(
void)
const {
117 double maximum(
void)
const {
121 double mean(
void)
const {
125 double sd(
void)
const {
129 double random(
void)
const {
133 double likelihood(
const double& x)
const {
134 return (x==value)?0:-INFINITY;
137 double pdf(
const double& x)
const {
138 return (x==value)?1:0;
141 double quantile(
const double& p)
const {
145 template<
class Mirror>
146 void reflect(Mirror& mirror) {
159 Beta(
const double& alpha = NAN,
const double& beta = NAN):
164 Beta& mean_sd(
const double& mean,
const double& sd){
166 alpha = boost::math::beta_distribution<>::find_alpha(mean,var);
167 beta = boost::math::beta_distribution<>::find_beta(mean,var);
171 boost::math::beta_distribution<> boost_dist(
void)
const {
172 return boost::math::beta_distribution<>(alpha,beta);
175 boost::random::beta_distribution<> boost_rand(
void)
const {
176 return boost::random::beta_distribution<>(alpha,beta);
179 template<
class Mirror>
180 void reflect(Mirror& mirror) {
194 Normal(
double mean = NAN,
double sd = NAN): mean(mean),sd(sd){}
196 bool valid(
void)
const {
197 return std::isfinite(mean) and sd>0;
200 boost::math::normal boost_dist(
void)
const {
201 return boost::math::normal(mean,sd);
204 boost::normal_distribution<> boost_rand(
void)
const {
205 return boost::random::normal_distribution<>(mean,sd);
208 template<
class Mirror>
209 void reflect(Mirror& mirror) {
225 TruncatedNormal(
double mean = NAN,
double sd = NAN,
double min_ = -INFINITY,
double max_ = INFINITY):
226 mean(mean),sd(sd),min(min_),max(max_){}
228 double minimum(
void)
const {
232 double maximum(
void)
const {
236 double random(
void)
const {
237 boost::random::normal_distribution<> dist(mean,sd);
238 boost::variate_generator<boost::mt19937&,decltype(dist)> random(
Generator,dist);
239 auto trial = random();
240 if(trial<min or trial>max) trial = random();
244 double pdf(
const double& x)
const {
245 boost::math::normal norm(mean,sd);
246 if(x<min or x>max)
return std::numeric_limits<double>::epsilon();
247 else return boost::math::pdf(norm,x);
250 template<
class Mirror>
251 void reflect(Mirror& mirror) {
265 double location = NAN;
266 double dispersion = NAN;
268 Lognormal(
double location = NAN,
double dispersion = NAN): location(location),dispersion(dispersion){}
270 double minimum(
void)
const {
271 return std::numeric_limits<double>::epsilon();
274 bool valid(
void)
const {
275 return location>0 and dispersion>0;
278 boost::math::lognormal boost_dist(
void)
const {
279 return boost::math::lognormal(location,dispersion);
282 boost::lognormal_distribution<> boost_rand(
void)
const {
287 return boost::lognormal_distribution<>(location,dispersion);
290 template<
class Mirror>
291 void reflect(Mirror& mirror) {
293 .data(location,
"location")
294 .data(dispersion,
"dispersion")
306 Uniform(
double lower = NAN,
double upper = NAN):
311 bool valid(
void)
const {
312 return std::isfinite(lower) and std::isfinite(upper) and lower<upper;
315 double minimum(
void)
const {
319 double maximum(
void)
const {
323 boost::math::uniform boost_dist(
void)
const {
324 return boost::math::uniform(lower,upper);
327 double random(
void)
const {
330 if(lower==upper)
return lower;
332 boost::uniform_real<> distr(lower,upper);
333 boost::variate_generator<boost::mt19937&,decltype(distr)> randomVariate(
Generator,distr);
334 return randomVariate();
338 template<
class Mirror>
339 void reflect(Mirror& mirror) {
353 static double max_size;
356 proportion(proportion),
360 bool valid(
void)
const {
361 return std::isfinite(proportion) and size>0;
364 double minimum(
void)
const {
368 double maximum(
void)
const {
372 double mean(
void)
const {
376 double sd(
void)
const {
377 return proportion * (1-proportion);
380 double loglike(
const double& x)
const {
381 double n_apos = std::min(size,max_size);
382 double e_apos = (1-x)*x+0.1/40.0;
383 return 0.5*e_apos+std::log(std::exp(-std::pow(proportion-x,2)/(2*e_apos/n_apos))+0.01);
386 template<
class Mirror>
387 void reflect(Mirror& mirror) {
389 .data(proportion,
"proportion")
394 double FournierRobustifiedMultivariateNormal::max_size = 1000;
Definition: distributions.hpp:21
Definition: distributions.hpp:188
Definition: distributions.hpp:153
Definition: distributions.hpp:9
Definition: distributions.hpp:3
Definition: distributions.hpp:217
Definition: distributions.hpp:104
Definition: distributions.hpp:262
Definition: distributions.hpp:348