/* * Equalinterval2.java * * Created on March 29, 2001, 12:05 PM */ // package uk.ac.leeds.ccg.geotools.classification; package uk.ac.leeds.ccg.cluster; import uk.ac.leeds.ccg.geotools.classification.*; import uk.ac.leeds.ccg.geotools.*; // import com.sun.java.util.collections.ArrayList; import java.util.*; /** * This classification splits the range of data into equal sized bins. * Some bins may contain no values. * @author jamesm * @version */ public class EqualInterval2 extends uk.ac.leeds.ccg.geotools.classification.SimpleClassifier { /** Creates new Equalinterval2 */ public EqualInterval2(GeoData source, int binCount, double minTime, double maxTime) { buildBins(source,binCount, minTime, maxTime); } private void buildBins(GeoData data,int binCount, double minTime, double maxTime){ bins.clear(); Bin bin; ArrayList list = GeoDataUtils.sort(data); System.out.println("Using Equal Interval"); System.out.println("Number of categories desired "+binCount); // (NB. list.size()=data.getSize()) System.out.println("Number of records to assign "+data.getSize()); double thisDataValue=data.getMissingValueCode(); double nextDataValue=data.getMissingValueCode(); int numberOfDifferentValues=0; for (int j=1;j<=list.size();j++){ thisDataValue=((Double)list.get(j-1)).doubleValue(); if(thisDataValue!=data.getMissingValueCode()){ if(thisDataValue!=nextDataValue){ numberOfDifferentValues=numberOfDifferentValues+1; nextDataValue=thisDataValue; } } } System.out.println("Number of different data values to assign "+numberOfDifferentValues); System.out.println("Missing value code "+data.getMissingValueCode()); System.out.println("Number of missing values "+data.getMissingCount()); System.out.println("Minimum value from data "+data.getMin()); System.out.println("Minimum value set at "+minTime); System.out.println("Maximum value from data "+data.getMax()); System.out.println("Maximum value set at "+maxTime); if (minTime > data.getMin()){ System.out.println("\n Note that there is data prior to your chosen start time \n"); // System.out.println("\n Bad choice of start time - has been reset \n"); // minTime = data.getMin(); } if (maxTime < data.getMax()){ System.out.println("\n Note that there is data after your chosen end time \n"); // System.out.println("\n Bad choice of end time - has been reset \n"); // maxTime = data.getMax(); } // Classify missing values if(data.getMissingCount()>0)bins.add(new Bin(data.getMissingValueCode(),data.getMissingValueCode())); // Handle case where number of categories desired cat is >= to the number of different data values to assign if (binCount>=numberOfDifferentValues){ // System.out.println("The number of different data values to assign is greater than the number of categories desired. Why not try specifying fewer categories or use a different classification?"); System.out.println("The number of different data values to assign is less than the number of categories (bins) desired. Why not try specifying fewer categories or use a different classification?"); } // double length = (data.getMax()-data.getMin())/(double)binCount; double length = (maxTime - minTime + 1.)/(double)binCount; //NOTE the +1 !! // System.out.println("Length of interval" +" "+ length); // thisDataValue=data.getMin(); // thisDataValue= minTime; // minTime -= length/2.; minTime -= 0.5; thisDataValue = minTime; for(int i=1;i<=binCount;i++){ // if(i==binCount){ //temp fix to top class // bin = new Bin(thisDataValue,data.getMax()+1.0); // bin = new Bin(thisDataValue,maxTime+1.0); // }//bit of a fix this // else{ // bin = new Bin(thisDataValue,data.getMin()+(i*length)); bin = new Bin(thisDataValue,minTime+(i*length)); // } bins.add(bin); // thisDataValue = data.getMin()+(i*length); thisDataValue = minTime+(i*length); } } }