-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfileUniform.cpp
54 lines (34 loc) · 1.26 KB
/
ProfileUniform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Profile.h"
#include "ProfileUniform.h"
ProfileUniform::ProfileUniform(boost::math::uniform profile) : Profile() {
this->profile = profile;
}
double ProfileUniform::getMean() {
return boost::math::mean(profile);
}
double ProfileUniform::getVariance() {
return boost::math::variance(profile);
}
double ProfileUniform::getPDF(double x) {
return boost::math::pdf(profile, x);
}
double ProfileUniform::getCDF(double x) {
return boost::math::cdf(profile, x);
}
double ProfileUniform::getQuantile(double p) {
return boost::math::quantile(profile, p);
}
double ProfileUniform::getMGF(double t) {
return (exp(t * profile.upper()) - exp(t * profile.lower())) / (t * (profile.upper() - profile.lower()));
}
double ProfileUniform::getSample() {
// Create a Mersenne twister random number generator
// that is seeded once with #seconds since 1970
static boost::mt19937 rng(static_cast<unsigned> (std::time(0)));
// select Uniform probability distribution
boost::uniform_real<double> dist(profile.lower(), profile.upper());
// bind random number generator to distribution, forming a function
boost::variate_generator<boost::mt19937&, boost::uniform_real<double> > sampler(rng, dist);
// sample from the distribution
return sampler();
}