Debian Codegraph @

src/dr/math/distributions/NormalGammaDistribution.java

raw symbols SCIP
1 /*
2 * NormalGammaDistribution.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 import dr.math.functionEval.GammaFunction;
30
31 /**
32 * Normal-gamma distribution
33 * @author Matthew Hall
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 }