-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProfileZAGA.cpp
81 lines (59 loc) · 1.91 KB
/
ProfileZAGA.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Profile.h"
#include "ProfileUniform.h"
#include "ProfileZAGA.h"
ProfileZAGA::ProfileZAGA(boost::math::gamma_distribution<double> profile, double q) : Profile(), profile(profile.shape(), profile.scale()) {
assert(0 <= q && q <= 1);
this->profile = profile;
this->q = q;
}
double ProfileZAGA::getMean() {
return q * boost::math::mean(profile);
}
double ProfileZAGA::getVariance() {
return q * boost::math::mean(profile) * boost::math::mean(profile) * (1 - q + 1 / profile.shape());
}
double ProfileZAGA::getPDF(double x) {
assert(x >= 0);
if (x == 0) {
return 1 - q;
} else {
return q * boost::math::pdf(profile, x);
}
}
double ProfileZAGA::getCDF(double x) {
assert(x >= 0);
if (x == 0) {
return 1 - q;
} else {
return (1 - q) + q * boost::math::cdf(profile, x);
}
}
double ProfileZAGA::getQuantile(double p) {
assert(0 <= p && p <= 1);
if (p <= 1 - q && q == 0) {
return 0;
} else {
return boost::math::quantile(profile, (p - (1 - q)) / q);
}
}
double ProfileZAGA::getMGF(double t) {
assert(t < 1 / profile.scale());
return (1 - q) + q * pow(1 - t * profile.scale(), -profile.shape());
}
double ProfileZAGA::getSample() {
ProfileUniform profile_uniform = ProfileUniform(boost::math::uniform(0, 1.0));
double random_probability = profile_uniform.getSample();
if (random_probability < 1 - q) {
return 0;
} else {
// 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 ZAGA probability distribution
boost::gamma_distribution<double> dist(profile.shape(), profile.scale());
// bind random number generator to distribution, forming a function
boost::variate_generator<boost::mt19937&, boost::gamma_distribution<double> > sampler(rng, dist);
// sample from the distribution
return sampler();
}
}