Debian Codegraph @

src/dr/geo/contouring/ContourWithSynder.java

raw symbols SCIP
1 /*
2 * ContourWithSynder.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.geo.contouring;
27
28 import dr.geo.KernelDensityEstimator2D;
29
30 import java.util.*;
31 import java.awt.geom.Point2D;
32
33
34 /**
35 * @author Marc A. Suchard
36 */
37 public class ContourWithSynder extends KernelDensityEstimator2D {
38
39 public ContourWithSynder(final double[] x, final double[] y, final double[] h, final int n, final double[] lims) {
40 super(x, y, h, n, lims);
41 }
42
43 public ContourWithSynder(final double[] x, final double[] y, boolean bandwidthLimit) {
44 super(x, y, bandwidthLimit);
45 }
46
47 public ContourWithSynder(final double[] x, final double[] y) {
48 super(x, y);
49 }
50
51 public ContourWithSynder(final double[] x, final double[] y, int n) {
52 super(x, y, n);
53 }
54
55 public ContourPath[] getContourPaths(double hpdValue) {
56
57 if (contourPaths == null) {
58
59 double thresholdDensity = findLevelCorrespondingToMass(hpdValue);
60
61 SnyderContour contourPlot = new SnyderContour(getXGrid().length,getYGrid().length);
62 contourPlot.setDeltas(getXGrid()[1]-getXGrid()[0],getYGrid()[1]-getYGrid()[0] );
63 contourPlot.setOffsets(getXGrid()[0],getYGrid()[0]);
64
65 List<LinkedList<Point2D>> allPaths = new ArrayList<LinkedList<Point2D>>();
66 contourPlot.ContourKernel(getKDE(),allPaths,thresholdDensity);
67
68 contourPaths = new ContourPath[allPaths.size()];
69 for(int i=0; i<allPaths.size(); i++) {
70 LinkedList<Point2D> path = allPaths.get(i);
71 int len = path.size();
72 double[] x = new double[len];
73 double[] y = new double[len];
74 for(int j=0; j<len; j++) {
75 Point2D pt = path.get(j);
76 x[j] = pt.getX();
77 y[j] = pt.getY();
78 }
79 contourPaths[i] = new ContourPath(new ContourAttrib(thresholdDensity),1,x,y);
80 }
81 }
82
83 return contourPaths;
84 }
85
86 private ContourPath[] contourPaths = null;
87
88 }