Debian Codegraph @

src/dr/math/distributions/MultivariateKDEDistribution.java

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