| 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.geo.contouring; |
| 27 |
|
| 28 |
import dr.geo.KernelDensityEstimator2D; |
| 29 |
|
| 30 |
import java.util.*; |
| 31 |
import java.awt.geom.Point2D; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 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 |
} |