| 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 |
package dr.math.distributions; |
| 27 |
|
| 28 |
|
| 29 |
import dr.math.functionEval.GammaFunction; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class NormalGammaDistribution implements MultivariateDistribution { |
| 36 |
|
| 37 |
public final String TYPE = "normalGammaDistribution"; |
| 38 |
|
| 39 |
private double mu; |
| 40 |
private double lambda; |
| 41 |
private double alpha; |
| 42 |
private double beta; |
| 43 |
|
| 44 |
public NormalGammaDistribution(double mu, double lambda, double alpha, double beta){ |
| 45 |
this.mu=mu; |
| 46 |
this.lambda=lambda; |
| 47 |
this.alpha=alpha; |
| 48 |
this.beta=beta; |
| 49 |
} |
| 50 |
|
| 51 |
public double pdf(double[] x){ |
| 52 |
return Math.pow(beta, alpha)*Math.sqrt(lambda)*Math.pow(x[1],alpha-0.5)*Math.exp(-beta*x[1]) |
| 53 |
*Math.exp(-lambda*x[1]*Math.pow(x[0]-mu,2)/2)/(GammaFunction.gamma(alpha)*Math.sqrt(2*Math.PI)); |
| 54 |
} |
| 55 |
|
| 56 |
public double logPdf(double[] x) { |
| 57 |
return alpha*Math.log(beta) + 0.5*Math.log(lambda) + (alpha-0.5)*Math.log(x[1])-beta*x[1] |
| 58 |
-lambda*x[1]*Math.pow(x[0]-mu,2)/2 - GammaFunction.logGamma(alpha) - 0.5*Math.log(2*Math.PI); |
| 59 |
} |
| 60 |
|
| 61 |
public double[][] getScaleMatrix() { |
| 62 |
throw new RuntimeException("Not implemented"); |
| 63 |
} |
| 64 |
|
| 65 |
public double[] getMean() { |
| 66 |
return new double[]{mu, alpha/beta}; |
| 67 |
} |
| 68 |
|
| 69 |
public String getType() { |
| 70 |
return TYPE; |
| 71 |
} |
| 72 |
|
| 73 |
public double[] getParameters() { |
| 74 |
return new double[]{mu, lambda, alpha, beta}; |
| 75 |
} |
| 76 |
} |