package uk.ac.leeds.ccg.cluster; import java.awt.*; import java.awt.event.*; import java.util.*; //import com.sun.java.util.collections.*; //change for 1.2! import uk.ac.leeds.ccg.geotools.*; /** A class that implements Besag and Newell Cluster Hunt * The main class BandN creates the main frame and proivides 3 buttons * modified to use the new results object - 31/01/01 */ public class Spatscan extends SimpleMethod implements Method, Runnable { // Members SpatscanParameters parameters; SpatscanParametersViewer parametersViewer; Database database; Results results; Viewer viewer; // Geotools viewer GeoRectangle geoRectangle = null; // Geotools geoRectangle Shader shader; // Geotools shader // Methods public static void main(String args[]){ Spatscan spatscan = new Spatscan(); spatscan.run(); } public Spatscan(){ parameters = new SpatscanParameters(); parametersViewer = new SpatscanParametersViewer(parameters); } public String toString() {return "Spatscan";} public Parameters getParameters() {return parameters;} public ParametersViewer getParametersViewer() {return parametersViewer;} public void setShader(Shader s) {shader=s;} public void setViewer(Viewer v) {viewer=v;} public void setData(Database d) {database=d;} public SignificanceTest getSignificanceTest(){return significanceTest;} public void setSearch(GeoRectangle r) {geoRectangle=r;} public Results getResults(){return results;} public void run(){ results = new Results(); double radMin = parameters.getRadMin(); double radMax = parameters.getRadMax(); double radInc = parameters.getRadInc(); int numRuns = parameters.getNumRuns(); double thresh = parameters.getSignificanceThreshold(); MyPoint p, p2; double n_g = (double) 0.0; double mu_g = (double) 0.0; double maxLam = (double) 0.0; double maxLam2 = (double) 0.0; int nge = 0; double stat = (double) 0.0; System.out.println("Spatscan "+significanceTest); if (significanceTest == null) { System.out.println("Spatscan started with a null sig test using Poisson"); significanceTest = new PoissonTest(); significanceTest.setParameters(parameters); } System.out.println(""+this+" "+significanceTest); if(geoRectangle==null) geoRectangle=database.getBounds(); Vector tcases = database.getCases(); Vector cases= new Vector(); for(int i=0;i maxLam){ maxLam = lambda; p2 = p; System.out.println("num1 "+num1+" num2 "+num2+" lambda "+lambda); } // what's all this lot?? // this method just finds one cluster (at present) so I have commented out // the stuff that marks it(them) on a map - might have to check what sort // of value is returned as 'stat' if/when I allow more than one cluster! // try{ // if(significanceTest.isSignificant(points)) // { // stat = significanceTest.getStatistic(); // // results.addResult(cc,stat); // results.addResult(gc,stat); // } // }catch(SignificanceException e){ // System.out.println(""+e); // } } } System.out.println(p2 +"\n"); // Here starts the Monte Carlo significance part Vector orig = database.getPoints(); // System.out.println(orig.size()); int no_points = orig.size(); // numRuns = 1; //just for the time being! for (int k=0; k maxLam2){ maxLam2 = lamb2; // System.out.println("num1 "+num1+" num2 "+num2+" lamb2 "+lamb2); } } } if (maxLam2 >= maxLam) nge++; if ( (double) (nge+1)/(numRuns+1) > thresh){ System.out.println("Will not be significant, nge = " + nge +","+ k +" out of NRuns"); break; } } if ( (double) (nge+1)/(numRuns+1) > thresh) System.out.println("Prob. of such a result is greater than " + (double) (nge+1)/(numRuns+1)); else System.out.println("Prob. of such a result is less than, or equal to " + (double) (nge+1)/(numRuns+1)); notifyProgressEventListener(0.0); } }