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.*; // import uk.ac.leeds.ccg.geotools.classification.*; /** 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 Grimson extends SimpleMethod implements Method, Runnable { // Members GrimsonTimeParameters parameters; GrimsonTimeParametersViewer parametersViewer; Database database; Results results; Viewer viewer; // Geotools viewer GeoRectangle geoRectangle = null; // Geotools geoRectangle Shader shader; // Geotools shader EqualInterval2 equalinterval2; // Methods public static void main(String args[]){ Grimson grimson = new Grimson(); grimson.run(); } public Grimson(){ parameters = new GrimsonTimeParameters(); parametersViewer = new GrimsonTimeParametersViewer(parameters); } public String toString() {return "Grimson";} 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(){ int n = 0, K = 0; double EA; int A = 0, x; double Vary, VarA, RC, VC, prob, pois, y, Z; double bL, bU, to, from; results = new Results(); double highrisk = parameters.getHR(); int numbin = parameters.getNumBin(); double bin[] = new double[numbin]; double mintime = parameters.getStartTime(); double maxtime = parameters.getEndTime(); double thresh = parameters.getSignificanceThreshold(); double norm[] = {0.0, 1.645, 1.75, 1.88, 2.05, 2.32, 2.37, 2.41, 2.46, 2.51, 2.57, 2.65, 2.75, 2.88, 3.09, 3.29}; double thre[] = {0.5, 0.05, 0.04, 0.03, 0.02, 0.01, 0.009, 0.008, 0.007, 0.006, 0.005, 0.004, 0.003, 0.002, 0.001, 0.0005}; // MyPoint p; double stat = (double) 0.0; // System.out.println("Grimson "+significanceTest); // if (significanceTest == null) { // System.out.println("Grimson started with a null sig test using Poisson"); // significanceTest = new PoissonTest(); // significanceTest.setParameters(parameters); // } System.out.println(""+this+" "+significanceTest); GeoData gcases = database.getCaseVals(); Vector tcases = database.getCases(); Vector points = database.getPoints(); equalinterval2 = new EqualInterval2(gcases, numbin, mintime, maxtime); for (int j=0; j= bU || to < bL) continue; if (from < mintime) from=mintime; if (to > maxtime) to = maxtime; if (to == from){ bin[j]++; continue; } double length = to - from; if (from <= bL){ if (to < bU) bin[j] += (to - bL)/length; else bin[j] += (bU - bL)/length; } else{ if (to < bU) bin[j] += 1.; else bin[j] += (bU - from)/length; } } // System.out.println(bin[j]); } // for (int i=1; i<=gcases.getSize(); i++){ // if (gcases.getValue(i) < mintime || gcases.getValue(i) > maxtime) continue; // bin[ equalinterval2.classify((double) gcases.getValue(i)) ]++; // } x = numbin; for (int i=0; i= highrisk) n +=1; // System.out.println(n +" "+ x); for (int i=1; i= highrisk && bin[i-1] >= highrisk) A += 1; } System.out.println("Value for Grimson's method "+ A); // Calculate the expectation, variance & probability y = (double) (2. * x - 2.) / x; EA = (double) y * n * (n-1) / (2. * (x - 1.)); System.out.println("E[A] = " + EA); if (A <= EA || A==0) System.out.println("No evidence of a single cluster"); else{ Vary = (double) 2. * (x - 2.) / (x * (x - 1.)); RC = (double) 2. * (y-1.) *(n-2) / (x-2.); RC += (x*y-4.*y+2.)*(n-2.)*(n-3.)/(2.*(x-2.)*(x-3)); RC += 1. - EA; RC *= EA; VC = (double) n*(n-1.)*(n-2.)/((x-1.)*(x-2.)); VC -= n*(n-1.)*(n-2.)*(n-3.)/((x-1.)*(x-2.)*(x-3.)); VC *= Vary; VarA = RC + VC; // System.out.println(Vary +" "+ RC +" "+ VC +" "+ VarA); if (VC/VarA < 0.2 && EA/VarA < 2 && EA/VarA > 0.5){ // use Poisson prob = Math.exp(-EA); pois = prob; for (int i=1; i zthre) System.out.println("Significant at the "+ 100.*thresh +"% level - cluster!"); else System.out.println("This is not significant at the "+ 100.*thresh +"% level - no cluster!"); } } // System.out.println("prob " + prob); // If significant pass details to the results object // if(significanceTest.isSignificant(points)) // { // stat = significanceTest.getStatistic(); // results.addResult(cc,stat); // } notifyProgressEventListener(0.0); } }