| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
public class MultivariateGammaDistribution implements MultivariateDistribution { |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public static final String TYPE = "multivariateGamma"; |
| 37 |
|
| 38 |
public MultivariateGammaDistribution(double[] shape, double[] scale) { |
| 39 |
|
| 40 |
if (shape.length != scale.length) |
| 41 |
throw new RuntimeException("Creation error in MultivariateGammaDistribution"); |
| 42 |
|
| 43 |
dim = shape.length; |
| 44 |
|
| 45 |
this.shape = shape; |
| 46 |
this.scale = scale; |
| 47 |
|
| 48 |
this.flags = new boolean[dim]; |
| 49 |
for (int i = 0; i < dim; i++) { |
| 50 |
flags[i] = true; |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
public MultivariateGammaDistribution(double[] shape, double[] scale, boolean[] flags) { |
| 56 |
|
| 57 |
if (shape.length != scale.length) |
| 58 |
throw new RuntimeException("Creation error in MultivariateGammaDistribution"); |
| 59 |
|
| 60 |
dim = shape.length; |
| 61 |
|
| 62 |
this.shape = shape; |
| 63 |
this.scale = scale; |
| 64 |
|
| 65 |
this.flags = flags; |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
public double logPdf(double[] x) { |
| 70 |
|
| 71 |
double logPdf = 0; |
| 72 |
|
| 73 |
if (x.length != dim) { |
| 74 |
throw new IllegalArgumentException("data array is of the wrong dimension"); |
| 75 |
} |
| 76 |
|
| 77 |
for (int i = 0; i < dim; i++) { |
| 78 |
if (flags[i]) { |
| 79 |
logPdf += GammaDistribution.logPdf(x[i], shape[i], scale[i]); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
return logPdf; |
| 84 |
} |
| 85 |
|
| 86 |
public double[][] getScaleMatrix() { |
| 87 |
throw new RuntimeException("Not yet implemented"); |
| 88 |
} |
| 89 |
|
| 90 |
public double[] getMean() { |
| 91 |
throw new RuntimeException("Not yet implemented"); |
| 92 |
} |
| 93 |
|
| 94 |
public String getType() { |
| 95 |
return TYPE; |
| 96 |
} |
| 97 |
|
| 98 |
private double[] shape; |
| 99 |
private double[] scale; |
| 100 |
private int dim; |
| 101 |
|
| 102 |
|
| 103 |
private boolean[] flags; |
| 104 |
|
| 105 |
} |