Debian Codegraph @

src/dr/math/distributions/MultivariateGammaDistribution.java

raw symbols SCIP
1 /*
2 * MultivariateGammaDistribution.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.math.distributions;
27
28 /**
29 * @author Marc Suchard
30 * @author Guy Baele
31 */
32 public class MultivariateGammaDistribution implements MultivariateDistribution {
33
34 //TODO: Currently this implements a product of independent Gammas, need to re-code as true multivariate distribution
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 //for each flag that is true, add the logPdf of that gamma distribution to the overall logPdf
103 private boolean[] flags;
104
105 }