use of dr.math.distributions.GeneralizedIntegerGammaDistribution in project beast-mcmc by beast-dev.
the class GeneralizedIntegerGammaTest method testGeneratingFunction.
public void testGeneratingFunction() {
for (int i = 0; i < shape1s.length; ++i) {
GeneralizedIntegerGammaDistribution gig = new GeneralizedIntegerGammaDistribution(shape1s[i], shape2s[i], rate1s[i], rate2s[i]);
double a = gig.generatingFunction(xs[i]);
double b = gig.generatingFunctionPartialFraction(xs[i]);
assertEquals(a, b, tolerance);
}
}
use of dr.math.distributions.GeneralizedIntegerGammaDistribution in project beast-mcmc by beast-dev.
the class GeneralizedIntegerGammaTest method testPdf.
public void testPdf() {
for (int i = 0; i < shape1s.length; ++i) {
final GeneralizedIntegerGammaDistribution gig = new GeneralizedIntegerGammaDistribution(shape1s[i], shape2s[i], rate1s[i], rate2s[i]);
TrapezoidIntegrator integrator = new TrapezoidIntegrator();
double m0 = 0.0;
double m1 = 0.0;
double m2 = 0.0;
try {
m0 = integrator.integrate(new UnivariateRealFunction() {
@Override
public double value(double x) throws FunctionEvaluationException {
final double pdf = gig.pdf(x);
return pdf;
}
}, 0.0, 1000.0);
m1 = integrator.integrate(new UnivariateRealFunction() {
@Override
public double value(double x) throws FunctionEvaluationException {
final double pdf = gig.pdf(x);
return x * pdf;
}
}, 0.0, 1000.0);
m2 = integrator.integrate(new UnivariateRealFunction() {
@Override
public double value(double x) throws FunctionEvaluationException {
final double pdf = gig.pdf(x);
return x * x * pdf;
}
}, 0.0, 1000.0);
} catch (MaxIterationsExceededException e) {
e.printStackTrace();
} catch (FunctionEvaluationException e) {
e.printStackTrace();
}
// Check normalization
assertEquals(1.0, m0, tolerance);
// Check mean
double mean = shape1s[i] / rate1s[i] + shape2s[i] / rate2s[i];
assertEquals(mean, m1, tolerance);
// Check variance
m2 -= m1 * m1;
double variance = shape1s[i] / rate1s[i] / rate1s[i] + shape2s[i] / rate2s[i] / rate2s[i];
// Harder to approximate
assertEquals(variance, m2, tolerance * 10);
}
}
Aggregations