package uk.ac.leeds.ccg.cluster; /** Besag and Newell Kth nearest neighbour parameters class */ import java.io.*; import java.awt.*; import java.awt.event.*; public class KnnParameters extends Parameters { // Version id private static final String version = "$id$"; // Members /**@param k number of nearest neighbours */ private int k; // Number of nearest neighbours // Constructors public KnnParameters(){ setDefaultParameters(); } public KnnParameters(File file) throws IOException,FileNotFoundException{ // Read into a stream tokenised buffered input stream StreamTokenizer st = new StreamTokenizer ( new BufferedReader ( new InputStreamReader ( new FileInputStream (file)))); System.out.println ("Setting Knn parameters from "+file); st.nextToken(); if (st.sval.equalsIgnoreCase("true")) {setAnimate(true);} else {setAnimate(false);} st.nextToken(); setK((int)st.nval); st.nextToken(); st.nextToken(); setSignificanceThreshold(st.nval); st.nextToken(); setMinPopSize(st.nval); st.nextToken(); setMinIncidenceCount(st.nval); st.nextToken(); setMonteCarloRejectionCount(st.nval); st.nextToken(); setStatType((int)st.nval); st.nextToken(); setMinPointCount((int)st.nval); st.nextToken(); setBootstrapSampleSize((int)st.nval); st.nextToken(); setMonteCarloSampleSize((int)st.nval); st.nextToken(); setMultipleTestReruns((int)st.nval); } public KnnParameters(boolean animate, int k, double thresh, double popMin, double canMin, double hH, int meas, int minPnt, int maxSam, int maxMC, int maxRep){ setAnimate(animate); setK(k); setSignificanceThreshold(thresh); setMinPopSize(popMin); setMinIncidenceCount(canMin); setMonteCarloRejectionCount(hH); setStatType(meas); setMinPointCount(minPnt); setBootstrapSampleSize(maxSam); setMonteCarloSampleSize(maxMC); setMultipleTestReruns(maxRep); } // Methods public String toString(){ return "[animate "+getAnimate()+"]\n"+ "[Number of nearest neighbours "+getK()+"]\n"+ "[significance threshold "+getSignificanceThreshold()+"]\n"+ "[minimum population size "+getMinPopSize()+"]\n"+ "[minimum incidence count "+getMinIncidenceCount()+"]\n"+ "[rejection count for Monte Carlo test "+getMonteCarloRejectionCount()+"]\n"+ "[type of statistic "+ getStatType()+"]\n"+ "[minimum point count "+getMinPointCount()+"]\n"+ "[sample size for bootstrap "+getBootstrapSampleSize()+"]\n"+ "[integer Monte Carlo sample size "+getMonteCarloSampleSize()+"]\n"+ "[number of multiple testing re-runs "+getMultipleTestReruns()+"]\n"; } public Parameters getParameters() {return this;} public void setParameters(boolean animate, int k, double thresh, double popMin, double canMin, double hH, int meas, int minPnt, int maxSam, int maxMC, int maxRep){ setAnimate(animate); setK(k); setSignificanceThreshold(thresh); setMinPopSize(popMin); setMinIncidenceCount(canMin); setMonteCarloRejectionCount(hH); setStatType(meas); setMinPointCount(minPnt); setBootstrapSampleSize(maxSam); setMonteCarloSampleSize(maxMC); setMultipleTestReruns(maxRep); } public void setDefaultParameters(){ setK(5); super.setDefaultParameters(); } public int getK() {return k;} public void setK(int i) {k=i;} public void writeParameters(File file) throws IOException,FileNotFoundException{ PrintWriter pw = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream (file)))); pw.println(getAnimate()); pw.println(getK()); pw.println(getSignificanceThreshold()); pw.println(getMinPopSize()); pw.println(getMinIncidenceCount()); pw.println(getMonteCarloRejectionCount()); pw.println(getStatType()); pw.println(getMinPointCount()); pw.println(getBootstrapSampleSize()); pw.println(getMonteCarloSampleSize()); pw.println(getMultipleTestReruns()); System.out.println ("Parameters saved to "+file); pw.flush(); pw.close(); } }