package uk.ac.leeds.ccg.cluster; // Monte Carlo test class for cluster methods import java.util.*; //import com.sun.java.util.collections.*; import uk.ac.leeds.ccg.geotools.*; public class MontecarloTest extends SignificanceTest implements Constants { public Parameters getParameters() {return parameters;} Database database; public void setData(Database d) {database=d;} double stat = (double) 0.0; public MontecarloTest(Database d) { // CHECK WHAT, IF ANYTHING, IS REQUIRED HERE, ESP. ALL THE PARAMETERS ABOVE database = d; cons = new double[MAXCAN]; canMax = MAXCAN; System.out.println(" *Test used with MAXIMUM case count of " + MAXCAN); for (int i=1; i< MAXCAN; i++) { cons[i] = ((double) 1.0)/i; } } public final boolean isSignificant(Vector points) { MyPoint p2; double cases = (double) 0.0; double samp_cases = (double) 0.0; double pop = (double) 0.0; double Z, prob; int psize, k, r, count; Vector tcases = database.getCases(); int hH = (int) parameters.getMonteCarloRejectionCount(); int maxMC = parameters.getMonteCarloSampleSize(); // double thr = parameters.getSignificanceThreshold(); for (int j=0; j cases) r += 1; count += 1; if (r > hH) break; // stop early if its not going to be significant } Z = (double) (r + 1) / (count + 1); // calculate probability // System.out.println("Z:" +" "+ Z +" "+ r +" "+ count); prob = Z; // if (Z < 0.05) if (Z < parameters.getSignificanceThreshold()) { switch (parameters.getStatType()) { case 1: stat = cases - pop; break; case 2: stat = cases/pop; break; case 3: stat = (double) 1.0 - prob; break; } return true; } else return false; } public double getStatistic(){ return (double) stat; } public String tostring() {return "Montecarlo";} private int canMax; private double cons[]; }