Vous êtes sur la page 1sur 5

BINNING PROGRAM

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package agglomative; import java.util.Arrays; import java.util.Scanner; /** * * @author Admin */ public class Binning { /** * @param args the command line arguments */ int n; int bin[]; int tbin[][]; int meanbin[][]; int boundarybin[][]; int medianbin[][]; int depth, row; Scanner scanner = new Scanner(System.in); public void readData() { System.out.println("enter number of items"); n = Integer.parseInt(scanner.next()); System.out.println("enter the depth of each bin"); depth = Integer.parseInt(scanner.next()); row = n / depth; bin = new int[n]; System.out.println("enter the itemset"); for (int i = 0; i < n; i++) { bin[i] = Integer.parseInt(scanner.next()); } Arrays.sort(bin); }

public void partitionIntoEquiDepthBins() { tbin = new int[row][depth]; meanbin = new int[row][depth]; boundarybin = new int[row][depth]; medianbin = new int[row][depth]; int p = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { tbin[i][j] = bin[p]; p = p + 1; } } System.out.println("Partition into (equi-depth) bins"); for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { System.out.print(tbin[i][j] + "\t"); } System.out.println(""); } } public void binBymedian() { double temp = 0.0; int count = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { count = count + 1; } if (count % 2 == 0) { temp = (tbin[i][count / 2] + tbin[i][(count / 2) - 1]) / 2; for (int j = 0; j < count; j++) { medianbin[i][j] = (int) temp; } } else { for (int j = 0; j < count; j++) { medianbin[i][j] = tbin[i][(int) Math.floor(count / 2)]; } } count = 0; }

System.out.println("bin by median"); for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { System.out.print(medianbin[i][j] + "\t"); } System.out.println(""); } } public void binByMean() { double mean = 0.0; int count = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { mean = mean + tbin[i][j]; count = count + 1; } mean = mean / count; for (int j = 0; j < count; j++) { meanbin[i][j] = (int) Math.round(mean); } count = 0; mean = 0; } System.out.println("bin by mean"); for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { System.out.print(meanbin[i][j] + "\t"); } System.out.println(""); } } public void binByBoundary() { double temp = 0.0; for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { boundarybin[i][j] = tbin[i][j]; if (Math.abs(tbin[i][j] - tbin[i][0]) < Math.abs(tbin[i][j] - tbin[i][depth - 1])) {

boundarybin[i][j] = tbin[i][0]; } else { boundarybin[i][j] = tbin[i][depth - 1]; } }

} System.out.println("bin by boundary"); for (int i = 0; i < row; i++) { for (int j = 0; j < depth; j++) { System.out.print(boundarybin[i][j] + "\t"); } System.out.println(""); }

} public static void main(String[] args) { // TODO code application logic here Binning binning = new Binning(); binning.readData(); binning.partitionIntoEquiDepthBins(); binning.binByMean(); binning.binByBoundary(); binning.binBymedian(); } }

OUTPUT run: enter number of items 9 enter the depth of each bin 3 enter the itemset 28 25 34 4 8 15 24 21 21 Partition into (equi-depth) bins 4 8 15 21 21 24 25 28 34 bin by mean 9 9 9 22 22 22 29 29 29 bin by boundary 4 4 15 21 21 24 25 25 34 bin by median 8 8 8 21 21 21 28 28 28 BUILD SUCCESSFUL (total time: 20 seconds)

Vous aimerez peut-être aussi