📄 assocrulemining.java
字号:
/* ITEM SET COMBINATIONS */ /* */ /* -------------------------------------------------- */ /* COMBINATIONS */ /** Invokes <TT>combinations</TT> method to calculate all possible combinations of a given item set. <P> For example given the item set [1,2,3] this will result in the combinations[[1],[2],[3],[1,2],[1,3],[2,3],[1,2,3]]. @param inputSet the given item set. @return array of arrays representing all possible combinations (may be null if bo combinations). */ protected short[][] combinations(short[] inputSet) { if (inputSet == null) return(null); else { short[][] outputSet = new short[getCombinations(inputSet)][]; combinations(inputSet,0,null,outputSet,0); return(outputSet); } } /** Recursively calculates all possible combinations of a given item set. @param inputSet the given item set. @param inputIndex the index within the input set marking current element under consideration (0 at start). @param sofar the part of a combination determined sofar during the recursion (null at start). @param outputSet the combinations collected so far, will hold all combinations when recusion ends. @param outputIndex the current location in the output set. @return revised output index. */ private int combinations(short[] inputSet, int inputIndex, short[] sofar, short[][] outputSet, int outputIndex) { short[] tempSet; int index=inputIndex; // Loop through input array while(index < inputSet.length) { tempSet = realloc1(sofar,inputSet[index]); outputSet[outputIndex] = tempSet; outputIndex = combinations(inputSet,index+1, copyItemSet(tempSet),outputSet,outputIndex+1); index++; } // Return return(outputIndex); } /* GET COMBINATTIONS */ /** Gets the number of possible combinations of a given item set. @param set the given item set. @return number of possible combinations. */ private int getCombinations(short[] set) { int counter=0, numComb; numComb = (int) Math.pow(2.0,set.length)-1; // Return return(numComb); } /* ---------------------------------------------------------------- */ /* */ /* MISCELANEOUS */ /* */ /* ---------------------------------------------------------------- */ /* COPY ITEM SET */ /** Makes a copy of a given itemSet. @param itemSet the given item set. @return copy of given item set. */ protected short[] copyItemSet(short[] itemSet) { // Check whether there is a itemSet to copy if (itemSet == null) return(null); // Do copy and return short[] newItemSet = new short[itemSet.length]; for(int index=0;index<itemSet.length;index++) { newItemSet[index] = itemSet[index]; } // Return return(newItemSet); } /** Makes a copy of a given set of itemSets. @param itemSets the given set of item sets. @return copy of given set of item sets. */ protected short[][] copyItemSet(short[][] itemSets) { // Check whether there is a itemSet to copy if (itemSets == null) return(null); // Do copy and return short[][] newItemSets = new short[itemSets.length][]; for(int index1=0;index1<itemSets.length;index1++) { if (itemSets[index1]==null) newItemSets[index1]=null; else { newItemSets[index1] = new short[itemSets[index1].length]; for(int index2=0;index2<itemSets[index1].length;index2++) { newItemSets[index1][index2] = itemSets[index1][index2]; } } } // Return return(newItemSets); } /* ------------------------------------------------- */ /* */ /* GET METHODS */ /* */ /* ------------------------------------------------- */ /* GET SUPPORT */ /** Gets the current support setting. @return the support value. */ /*public double getSupport() { return(support); } */ /* GET CONFIDENCE */ /** Gets the current confidence setting. @return the confidence value. */ public double getConfidence() { return(confidence); } /* ------------------------------------------------- */ /* */ /* OUTPUT METHODS */ /* */ /* ------------------------------------------------- */ /* ----------------- */ /* OUTPUT DATA TABLE */ /* ----------------- */ /** Outputs stored input data set; initially read from input data file, but may be reirdered or pruned if desired by a particular application. */ public void outputDataArray() { if (isPrunedFlag) System.out.println("DATA SET (Ordered and Pruned)\n" + "-----------------------------"); else { if (isOrderedFlag) System.out.println("DATA SET (Ordered)\n" + "------------------"); else System.out.println("DATA SET\n" + "--------"); } // Loop through data array for(int index=0;index<dataArray.length;index++) { outputItemSet(dataArray[index]); System.out.println(); } } /** Outputs the given array of array of short integers. <P> Used for diagnostic purposes. @param dataSet the five array of arrays. */ protected void outputDataArray(short[][] dataSet) { if (dataSet==null) { System.out.println("null"); return; } // Loop through data array for(int index=0;index<dataSet.length;index++) { outputItemSet(dataSet[index]); System.out.println(); } } /* -------------- */ /* OUTPUT ITEMSET */ /* -------------- */ /** Outputs a given item set. @param itemSet the given item set. */ protected void outputItemSet(short[] itemSet) { // Loop through item set elements if (itemSet == null) System.out.print(" null "); else { int counter = 0; for (int index=0;index<itemSet.length;index++) { if (counter == 0) { counter++; System.out.print(" {"); } else System.out.print(" "); System.out.print(itemSet[index]); } System.out.print("} "); } } /* ---------------------------------*/ /* OUTPUT ITEMSET WITH RECONVERSION */ /* ---------------------------------*/ /** Outputs a given item set reconverting it to its orginal column number labels (used where input dataset has been reordered and possible pruned). @param itemSet the given item set. */ protected void outputItemSetWithReconversion(short[] itemSet) { // Loop through item set elements if (itemSet == null) System.out.print(" null "); else { int counter = 0; for (int index=0;index<itemSet.length;index++) { if (counter == 0) { counter++; System.out.print(" ["); } else System.out.print(" "); //System.out.print(itemSet[index]); System.out.print(reconversionArray[itemSet[index]]); } System.out.print("] "); } } /* ---------------------- */ /* OUTPUT DATA ARRAY SIZE */ /* ---------------------- */ /** Ouputs size (number of records and number of elements) of stored input data set read from input data file. */ public void outputDataArraySize() { int numRecords = 0; int numElements = 0; // Loop through data array for (int index=0;index<dataArray.length;index++) { if (dataArray[index] != null) { numRecords++; numElements = numElements+dataArray[index].length; } } // Output System.out.println("Number of records = " + numRecords); System.out.println("Number of elements = " + numElements); } /* ------------------------ */ /* OUTPUT CONVERSION ARRAYS */ /* ------------------------ */ /** Outputs conversion array (used to renumber coulmns for input data in terms of frequency of single attributes --- reordering will enhance performance for some ARM algorithms). */ public void outputConversionArrays() { // Conversion array System.out.println("Conversion Array = "); for(int index=1;index<conversionArray.length;index++) { System.out.println("(" + index + ") " + conversionArray[index][0] + " = " + conversionArray[index][1]); } // Reconversion array System.out.println("Reonversion Array = "); for(int index=1;index<reconversionArray.length;index++) { System.out.println("(" + index + ") " + reconversionArray[index]); } } /* ----------- */ /* OUTPUT MENU */ /* ----------- */ /** Outputs menu for command line arguments. */ protected void outputMenu() { System.out.println(); System.out.println("-C = Confidence (default 80%)"); System.out.println("-F = File name"); System.out.println("-N = Number of classes (Optional)"); System.out.println("-S = Support (default 20%)"); System.out.println(); // Exit System.exit(1); } /* --------------- */ /* OUTPUT SETTINGS */ /* --------------- */ /** Outputs command line values provided by user. */ protected void outputSettings() { System.out.println("SETTINGS\n--------"); System.out.println("File name = " + fileName); System.out.println("Support (default 20%) = " + support); System.out.println("Confidence (default 80%) = " + confidence); System.out.println("Num. classes (Optional) = " + numClasses); System.out.println(); } /* OUTPUT SETTINGS */ /** Outputs instance field values. */ protected void outputSettings2() { System.out.println("SETTINGS\n--------"); System.out.println("Number of records = " + numRows); System.out.println("Number of columns = " + numCols); System.out.println("Support (default 20%) = " + support); System.out.println("Confidence (default 80%) = " + confidence); System.out.println("Min support = " + minSupport + " (records)"); System.out.println("Num one itemsets = " + numOneItemSets); System.out.println("Num. classes (Optional) = " + numClasses); } /* -------------------------------------- */ /* OUTPUT SUPPORT AND CONFIDENCE SETTINGS */ /* -------------------------------------- */ /** Outputs current support and confidence settings. */ public void outputSuppAndConf() { System.out.println("Support = " + twoDecPlaces(support) + ", Confidence = " + twoDecPlaces(confidence)); } /* --------------------------------- */ /* */ /* DIAGNOSTIC OUTPUT */ /* */ /* --------------------------------- */ /* OUTPUT DURATION */ /** Outputs difference between two given times. @param time1 the first time. @param time2 the second time. @return duration. */ public double outputDuration(double time1, double time2) { double duration = (time2-time1)/1000; System.out.println("Generation time = " + duration + " seconds (" + (duration/60) + " mins)"); // Return return(duration); } /* GET DURATION */ /** Returns the difference between two given times as a string. @param time1 the first time. @param time2 the second time. @return the difference between the given times as a string. */ protected String getDuration(double time1, double time2) { double duration = (time2-time1)/1000; return("Generation time = " + duration + " seconds (" + (duration/60) + " mins)"); } /* -------------------------------- */ /* */ /* SIMILARITY UTILITIES */ /* */ /* -------------------------------- */ /* SIMILAR 2 DFECIMAL PLACES */ /* Compares two real numbers and returns true if the two numbers are the same within two decimal places. @param the first given real number. @param the second given number. @return true if similar within two decimal places ad false otherwise. */ protected boolean similar2dec(double number1, double number2) { // Convert to integers int numInt1 = (int) ((number1+0.005)*100.0); int numInt2 = (int) ((number2+0.005)*100.0); // Compare and return if (numInt1 == numInt2) return(true); else return(false); } /* -------------------------------- */ /* */ /* OUTPUT UTILITIES */ /* */ /* -------------------------------- */ /* TWO DECIMAL PLACES */ /** Converts given real number to real number rounded up to two decimal places. @param number the given number. @return the number to two decimal places. */ protected double twoDecPlaces(double number) { int numInt = (int) ((number+0.005)*100.0); number = ((double) numInt)/100.0; return(number); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -