/* -------------------------------------------------------------------------- */ /* */ /* F U Z Z Y A P R I O R I T */ /* */ /* Frans Coenen */ /* */ /* Tuesday 4 Match 2008 */ /* (Revised 22 August 2008) */ /* */ /* Department of Computer Science */ /* The University of Liverpool */ /* */ /* -------------------------------------------------------------------------- */ /** Class that contains methods to support Fuzzy Association Rule Mining (FARM) based in the Apriori-T algorithm. */ /* Structure: AssocRuleMining | +-- TotalSupportTree | +-- FuzzyAprioriT */ //package lucsKDD_ARM; // Java packages import java.io.*; import java.util.*; // Java GUI packages import javax.swing.*; public class FuzzyAprioriT extends TotalSupportTree { /*------------------------------------------------------------------------*/ /* */ /* FIELDS */ /* */ /*------------------------------------------------------------------------*/ /** 2-D aray to hold input data from data file.

First index is row (record or TID) number starting from 0, and second is attribute (column) number starting from zero. */ protected FuzzyDataItem[][] dataArray = null; /** Array used to renumber columns for input data in terms of frequency of single attributes (reordering will enhance performance for some ARM algorithms). */ protected FuzzyDataItem[] conversionArray = null; /** The reference to start of t-tree. */ protected FuzzyTtreeNode[] startTtreeRef; /*---------------------------------------------------------------------*/ /* */ /* CONSTRUCTORS */ /* */ /*---------------------------------------------------------------------*/ /** With argument from existing instance of class AssocRuleMining. @param newInstance the given instance of the AssocRuleMining class. */ public FuzzyAprioriT(FuzzyAprioriT newInstance) { super(newInstance); dataArray = newInstance.dataArray; } /** Default constructor. */ public FuzzyAprioriT() { } /*-------------------------------------------------------------------*/ /* */ /* T-TREE BUILDING METHODS */ /* */ /*-------------------------------------------------------------------*/ /** Commences start process of generating a total support tree (T-tree): GUI version. Min support is used in non-weighted Apriori-T and is the support in terms of number of records, this has no meaning with respect to fuzzy support as defined here. Min support therefore has the same value as the support field. @param textArea the given instance of the JTextArea class. */ public void createTotalSupportTree(JTextArea textArea) { // Calculate support in terms of number of records double tempSup = numRows*support; textArea.append("Apriori-T with X-Cchecking\nMinimum support " + "threshold = " + twoDecPlaces(support) + " (" + twoDecPlaces(tempSup) + " records)\n"); // If no data (possibly as a result of an order and pruning operation) // return if (numOneItemSets==0) return; // Initilise T-tree data structure and diagnostic counters. Set number // of t-tree nodes to zero (this is a static field so will not be reset // in repeat calls to the T-tree constructor). startTtreeRef = null; numFrequentSets = 0; numUpdates = 0l; TtreeNode.setNumberOfNodesFieldToZero(); // Continue contCreateTtree(textArea); // Potential output if (outputTtreeStatsFlag) outputTtreeStats(textArea); if (outputTtreeFlag) outputTtree(textArea); //if (outputTtreeGraphFlag) drawTtreeGraph(); } /* CREATE T-TREE TOP LEVEL */ /** Generates level 1 (top) of the T-tree. */ protected void createTtreeTopLevel() { // Dimension and initialise top level of T-tree startTtreeRef = new FuzzyTtreeNode[numOneItemSets+1]; for (int index=1;index<=numOneItemSets;index++) startTtreeRef[index] = new FuzzyTtreeNode(); // Add support for each 1 itemset createTtreeTopLevel2(); // Prune top level, setting any unsupported 1-itemsets to null pruneLevelN(startTtreeRef,1); } /** Adds supports to level 1 (top) of the T-tree. */ protected void createTtreeTopLevel2() { numLevelsInTtree = 1; // Loop through data set record by record and add support for each // 1 itemset for (int index1=0;index1JTextArea class. */ protected void createTtreeLevelN(JTextArea textArea) { int nextLevel=2; // Loop while a further level exists while (nextLevelExists) { // Add support addSupportToTtreeLevelN(nextLevel); // Prune unsupported candidate sets pruneLevelN(startTtreeRef,nextLevel); // Attempt to generate next level nextLevelExists=false; generateLevelN(startTtreeRef,nextLevel,null); //if (nextLevel==3) //outputTtree(textArea); nextLevel++; } //End numLevelsInTtree = nextLevel-1; textArea.append("Levels in T-tree = " + numLevelsInTtree + "\n"); } /* ---------------------------- */ /* ADD SUPPORT VALUES TO T-TREE */ /* ---------------------------- */ /* ADD SUPPORT VALUES TO T-TREE LEVEL N */ /** Commences process of adding support to a given level in the T-tree (other than the top level). @param level the current level number (top level = 1). */ protected void addSupportToTtreeLevelN(int level) { // Loop through data set record by record for (int index=0;index Operates in a recursive manner to first find the appropriate level in the T-tree before processing the required level (when found). @param linkRef the reference to the current sub-branch of T-tree (start at top of tree) @param level the level marker, set to the required level at the start and then decremented by 1 on each recursion. @param endIndex the index into the item set array at which processing should be stopped. This should be the index of the attribute in the item set that is the parent T-tree node of the current level. On start this will usually be the length of the input item set. @param itemSet the current itemset (record from data array) under consideration. @param supportSoFar the support value. */ protected void addSupportToTtree(FuzzyTtreeNode[] linkRef, int level, int endIndex, FuzzyDataItem[] itemSet, double supportSoFar) { //System.out.print("addSupportToTtree: level = " + level + ", endIndex = " + //endIndex + ", itemSet = "); //outputItemSet(itemSet); //System.out.println(", supSoFar = " + supportSoFar); // At right level; if (level == 1) { // Step through itemSet for (int index1=0;index1 Operates in a recursive manner to first find the appropriate level in the T-tree before processing the required level (when found). Pruning carried out according to value of minSupport field. @param linkRef The reference to the current sub-branch of T-tree (start at top of tree) @param level the level marker, set to the required level at the start and then decremented by 1 on each recursion. @return true if all nodes at a given level in the given branch of the T-tree have been pruned (in which case the t-tree generation processing can be stopped), false otherwise. */ protected boolean pruneLevelN(FuzzyTtreeNode [] linkRef, int level) { int size = linkRef.length; // At right level; if (level == 1) { boolean allUnsupported = true; // Step through level and set to null where below min support for (int index1=1;index1 The general generateLevelN method assumes we have to first find the right level in the T-tree, that is not necessary in this case of level 2. */ protected void generateLevel2() { // Set next level flag nextLevelExists=false; // loop through top level (start at index 2 because cannot generate a // level from index 1 as there will be no proceeding attributes, // remember index 0 is unused. for (int index=2;index Proceeds in a recursive manner level by level until the required level is reached. Example, if we have a T-tree of the form:

    (A) ----- (B) ----- (C)
               |         |
	       |         |
	      (A)       (A) ----- (B)
    

Where all nodes are supported and we wish to add the third level we would walk the tree and attempt to add new nodes to every level 2 node found. Having found the correct level we step through starting from B (we cannot add a node to A), so in this case there is only one node from which a level 3 node may be attached. @param linkRef the reference to the current sub-branch of T-tree (start at top of tree). @param level the level marker, set to the required level at the start and then decremented by 1 on each recursion. @param itemSet the current itemset (T-tree node) under consideration. */ protected void generateLevelN(FuzzyTtreeNode[] linkRef, int level, short[] itemSet) { int localSize = linkRef.length; // Correct level if (level == 1) { // Step through T-tree array in current branch at current level for (int index=2;index Example 1, given the following:

    (A) ----- (B) ----- (C)
               |         |
	       |         |
	      (A)       (A) ----- (B)
    

where we wish to add a level 3 node to node (B), i.e. the node {A}, we would proceed as follows:

  1. Generate a new level in the T-tree attached to node (B) of length one less than the numeric equivalent of B i.e. 2-1=1.
  2. Loop through parent level from (A) to node immediately before (B).
  3. For each supported parent node create an itemset label by combing the index of the parent node (e.g. A) with the complete itemset label for B --- {C,B} (note reverse order), thus for parent node (B) we would get a new level in the T-tree with one node in it --- {C,B,A} represented as A.
  4. For this node to be a candidate large item set its size-1 subsets must be supported, there are three of these in this example {C,A}, {C,B} and {B,A}. We know that the first two are supported because they are in the current branch, but {B,A} is in another branch. So we must generate this set and test it. More generally we must test all cardinality-1 subsets which do not include the first element. This is done using the method testCombinations.

Example 2, given:

    (A) ----- (D)
               |
	       |
	      (A) ----- (B) ----- (C)
	                           |
				   |
				  (A) ----- (B)
    

where we wish to add a level 4 node (A) to (B) this would represent the complete label {D,C,B,A}, the N-1 subsets will then be {{D,C,B},{D,C,A}, {D,B,A} and {C,B,A}}. We know the first two are supported because they are contained in the current sub-branch of the T-tree, {D,B,A} and {C,B,A} are not. @param parentRef the reference to the level in the sub-branch of the T-tree under consideration. @param endIndex the index of the current node under consideration. @param itemSet the complete label represented by the current node (required to generate further itemsets to be X-checked). */ protected void generateNextLevel(FuzzyTtreeNode[] parentRef, int endIndex, short[] itemSet) { parentRef[endIndex].childRef = new FuzzyTtreeNode[endIndex]; // New level short[] newItemSet; // Generate a level in Ttree FuzzyTtreeNode currentNode = parentRef[endIndex]; // Loop through parent sub-level of siblings upto current node for (int index=1;index Used when generating Association Rules (ARs). Note that itemsets are stored in reverse order in the T-tree therefore the given itemset must be processed in reverse. @param itemSet the given itemset. @return returns the support value (0 if not found). */ private double getFuzzySupportForItemSetInTtree(short[] itemSet) { int endInd = itemSet.length-1; // Test if endItem exists in top level. if (itemSet[endInd]>=startTtreeRef.length) return(0); // Last element of itemset in Ttree (Note: Ttree itemsets stored in // reverse) if (startTtreeRef[itemSet[endInd]] != null) { // If "current index" is 0, then this is the last element (i.e the // input is a 1 itemset) and therefore item set found if (endInd == 0) return(startTtreeRef[itemSet[0]].support); // Otherwise continue down branch else { FuzzyTtreeNode[] tempRef = startTtreeRef[itemSet[endInd]].childRef; if (tempRef != null) return(getSupForIsetInTtree2(itemSet, endInd-1,tempRef)); // No further branch therefore rerurn 0 else return(0); } } // Item set not in Ttree thererfore return 0 else return(0); } /** Returns the support value for the given itemset if found in the T-tree and 0 otherwise.

Operates recursively. @param itemSet the given itemset. @param index the current index in the given itemset. @param linRef the reference to the current Fuzzy T-tree level. @return returns the support value (0 if not found). */ private double getSupForIsetInTtree2(short[] itemSet, int index, FuzzyTtreeNode[] linkRef) { // Element at "index" in item set exists in Ttree if (linkRef[itemSet[index]] != null) { // If "current index" is 0, then this is the last element of the // item set and therefore item set found if (index == 0) return(linkRef[itemSet[0]].support); // Otherwise continue provided there is a child branch to follow else if (linkRef[itemSet[index]].childRef != null) return(getSupForIsetInTtree2(itemSet,index-1, linkRef[itemSet[index]].childRef)); else return(0); } // Item set not in Ttree therefore return 0 else return(0); } /* FIND ITEM SET IN T-TREE */ /** Commences process of determining if an itemset exists in a T-tree.

Used to X-check existence of Ttree nodes when generating new levels of the Tree. Note that T-tree node labels are stored in "reverse", e.g. {3,2,1}. @param itemSet the given itemset (IN REVERSE ORDER). @return returns true if itemset found and false otherwise. */ protected boolean findItemSetInTtree(short[] itemSet) { // first element of itemset in Ttree (Note: Ttree itemsets stored in // reverse) if (startTtreeRef[itemSet[0]] != null) { int lastIndex = itemSet.length-1; // If "current index" is 0, then this is the last element (i.e the // input is a 1 itemset) and therefore item set found if (lastIndex == 0) return(true); // Otherwise continue down branch else if (startTtreeRef[itemSet[0]].childRef!=null) { return(findItemSetInTtree2(itemSet,1,lastIndex, startTtreeRef[itemSet[0]].childRef)); } else return(false); } // Item set not in Ttree else return(false); } /*-------------------------------------------------------------------*/ /* */ /* INPUT FILE HANDLING METHODS */ /* */ /*-------------------------------------------------------------------*/ /* INPUT DATA SET */ /** Commences process of getting input data. @param textArea the text area in the GUI used for output. @param fName the name of the input file to be read. */ public void inputDataSet(JTextArea textArea, File fName) { // Set filePath instance field filePath = fName; // Read the file (method below overwrites metjhod in Association Rules // Class readFile(textArea); // Once input file has been read, processed and stored in data array // count number of columns. Input format flag set during readFile process. if (inputFormatOkFlag) { countNumCols(); textArea.append("Number of columns = " + numCols + "\n"); // Set have data flag to true haveDataFlag = true; } else { textArea.append("Operation failed!\n"); dataArray=null; } } /* COUNT NUMBER OF COLUMNS */ /** Counts number of columns represented by input data. */ protected void countNumCols() { short maxAttribute=0; // Loop through data array for(int index=0;indexinputFormatOkFlag set to false. @param counter the line number in the input file. @param str the current line from the input file. */ protected void checkLine(int counter, String str) { for (int index=0;index ' " + "or white space."); inputFormatOkFlag = false; haveDataFlag = false; break; } } } /* READ INPUT DATA SET */ /** Reads input data from given file. @param fName the given file name. */ protected void readInputDataSet(String fName) throws IOException { int rowIndex=0; // Open the file if (filePath==null) openFileName(fName); else openFilePath(); // Get first row. String line = fileInput.readLine(); // Process rest of file while (line != null) { // Process line if (!processInputLine(line,rowIndex)) inputFormatOkFlag = false; // Increment first (row) index in 2-D data array rowIndex++; // get next line line = fileInput.readLine(); } // Close file closeFile(); } /* PROCESS INPUT LINE */ /** Processes a line from the input file and places it in the dataArray structure. @param inputString the line to be processed from the input file @param rowIndex the index to the current location in the dataArray structure. @return true if successfull, false if empty record. */ protected boolean processInputLine(String inputString, int rowIndex) { boolean lineOK = true; //System.out.println("processInputLine: inputString = " + inputString + //", rowIndex = " + rowIndex); // Tokenize StringTokenizer dataLine = new StringTokenizer(inputString); // Get number of tokens (items) dimension row in data array int numberOfTokens = dataLine.countTokens(); dataArray[rowIndex] = new FuzzyDataItem[numberOfTokens]; // Process tokens for (int colIndex=0;colIndex!","Data Input Error.", JOptionPane.ERROR_MESSAGE); } // Else formatting not OK else JOptionPane.showMessageDialog(null,"Error: Line number " + (lineNum+1) + ", item number " + (index+1) + ", (\"" + dataString + "\"),\nno closing '>' for tuple !","Data Input Error.", JOptionPane.ERROR_MESSAGE); } // otherwise token is a binary attribute else { // Check for closing '>' even if no opening '<' int endIndex = dataString.indexOf('>'); if (endIndex>0) { JOptionPane.showMessageDialog(null,"Error: Line number " + (lineNum+1) + ", item number " + (index+1) + ", (\"" + dataString + "\"),\nno opening '<' for tuple !","Data Input Error.", JOptionPane.ERROR_MESSAGE); } else { short attNum = processTokenAttribute(dataString,index,lineNum); if (attNum>0) { dataArray[lineNum][index] = new FuzzyDataItem(attNum,1.0); formattingOK = true; } // Else formatting not OK } } // End return(formattingOK); } /** Process attribute @param attString the binary attribute in the form of an input string. @param index the current index in the attribute array. @param lineNum the current line number. @return attribute number if successful, and -1 otherwise. */ private short processTokenAttribute(String attString, int index, int lineNum) { //System.out.println("processTokenAttribute: attString = " + attString + ", lineNum = " + //lineNum + ", index = " + index); // try-catch block try { short attNum = new Short(attString).shortValue(); // Check attribute is greater than prvious attribite (provided // such an attribute exists if (index>0) { int preAttNum = dataArray[lineNum][index-1].getItemNumber(); if (attNum<=preAttNum) { JOptionPane.showMessageDialog(null,"Error: Line number " + (lineNum+1) + ", item number " + (index+1) + " (\"" + attNum + "\"), atttibute\nnumber is not greater " + "than previous number (\"" + preAttNum + "\")!", "Data Input Error.",JOptionPane.ERROR_MESSAGE); return(-1); } else return(attNum); } // Check if first attribute number that it is greater than zero else if (attNum<=0) { JOptionPane.showMessageDialog(null,"Error: Line number " + (lineNum+1) + ", item number " + (index+1) + " (\"" + attNum + "\"); atttibute\nnumber must be greater than " + "zero!","Data Input Error.",JOptionPane.ERROR_MESSAGE); return(-1); } // OK found attribute else return(attNum); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null,"Error: Line number " + (lineNum+1) + " item number " + (index+1) + " (\"" + attString + "\"); is not\n in the right format; " + "expecting an integer greater than 0!", "Data Input Error.",JOptionPane.ERROR_MESSAGE); return(-1); } } /** Process weighting @param dataString the binary attribute in the form of an input string. @param index the current index in the attribute array. @param lineNum the current line number. @return weighting if successful, and -1.0 otherwise. */ private double processTokenWeighting(String whtString, int index, int lineNum) { // try-catch block try { double weight = new Double(whtString).doubleValue(); // Check if (weight>=0.0 && weight<=1.0) return(weight); else { JOptionPane.showMessageDialog(null,"Error: Line number " + (lineNum+1) + ", item number " + (index+1) + ", weighting \"" + weight + "\";\nweighting " + "must be between 0.0 and 1.0.","Data Input Error!", JOptionPane.ERROR_MESSAGE); return(-1.0); } } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null,"Error: Line number " + (lineNum+1) + ", item number " + (index+1) + ", weighting \"" + whtString + "\"; weighting is not\n" + "in the right format; " + "expecting a double between 0.0 " + "and 1.0!","Data Input Error.",JOptionPane.ERROR_MESSAGE); return(-1); } } /* ------------------------------------------------------ */ /* */ /* OUTPUT SCHEMA METHODS (GUI VERSIONS) */ /* */ /* ------------------------------------------------------ */ /** Check if number of attributes in output schema are same as number of attributes in input file.

If either the output schema or the input file has nor been loaded then method will return false. @return true if number of attributes are the same and false otherwise. */ public boolean checkSchemaVdata() { boolean schemaAndDataAttsSame = true; // Check schema if (outputSchema==null) { JOptionPane.showMessageDialog(null,"No output schema file.", "CHECK SCHEMA v DATA ATTRIBUTES ERROR", JOptionPane.ERROR_MESSAGE); return(!schemaAndDataAttsSame); } // Check data array if (dataArray==null) { JOptionPane.showMessageDialog(null,"No input data file.", "CHECK SCHEMA v DATA ATTRIBUTES ERROR", JOptionPane.ERROR_MESSAGE); return(!schemaAndDataAttsSame); } // Check lengths. if (outputSchema.length==numCols) return(schemaAndDataAttsSame); else { JOptionPane.showMessageDialog(null,"Number of attributes in " + "schema file (" + outputSchema.length + ") not\n" + "same as number of attributes in data file (" + numCols + ")\n","CHECK SCHEMA v DATA ATTRIBUTES ERROR", JOptionPane.ERROR_MESSAGE); return(!schemaAndDataAttsSame); } } /*----------------------------------------------------------------------- */ /* */ /* ASSOCIATION RULE (AR) GENERATION */ /* */ /*----------------------------------------------------------------------- */ /** Loops through top level of T-tree as part of the AR generation process. */ protected void generateARs2() { //System.out.println("GenerateARs2: confidence = " + confidence); // Loop for (short index=1;index<=numOneItemSets;index++) { if (startTtreeRef[index]!=null) { if (startTtreeRef[index].support >= minSupport) { short[] itemSetSoFar = new short[1]; itemSetSoFar[0] = index; generateARs(itemSetSoFar,index, startTtreeRef[index].childRef); } } } } /* GENERATE ASSOCIATION RULES */ /** Continues process of generating association rules from a T-tree by recursively looping through T-tree level by level. @param itemSetSofar the label for a T-tree node as generated sofar. @param size the length/size of the current array level in the T-tree. @param linkRef the reference to the current array level in the T-tree. */ protected void generateARs(short[] itemSetSofar, int size, FuzzyTtreeNode[] linkRef) { // If no more nodes return if (linkRef == null) return; // Otherwise process for (int index=1; index < size; index++) { if (linkRef[index] != null) { if (linkRef[index].support >= minSupport) { // Temp itemset short[] tempItemSet = realloc2(itemSetSofar,(short) index); // Generate ARs for current large itemset generateARsFromItemset(tempItemSet,linkRef[index].support); // Continue generation process generateARs(tempItemSet,index,linkRef[index].childRef); } } } } /* GENERATE ASSOCIATION RULES */ /** Generates all association rules for a given large item set found in a T-tree structure.

Called from generateARs method. @param itemSet the given large itemset. @param support the associated support value for the given large itemset. */ protected void generateARsFromItemset(short[] itemSet, double support) { // Determine combinations short[][] combinations = combinations(itemSet); // Loop through combinations for(int index=0;index= minSupport) { short newAttNum = conversionArray[oldAttNum].getItemNumber(); double fuzzyValue = dataArray[rowIndex][colIndex].getFuzzyValue(); FuzzyDataItem newItem = new FuzzyDataItem(newAttNum,fuzzyValue); itemSet = reallocInsert(itemSet,newItem); } } // Return new item set to data array dataArray[rowIndex] = itemSet; } } // Set isPrunedFlag (used with GUI interface) isPrunedFlag=true; // Reset number of one item sets field numOneItemSets = getNumSupOneItemSets(); } /* GET NUM OF SUPPORTE ONE ITEM SETS */ /** Gets number of supported single item sets (note this is not necessarily the same as the number of columns/attributes in the input set). @return Number of supported 1-item sets */ protected int getNumSupOneItemSets() { int counter = 0; // Step through conversion array incrementing counter for each // supported element found for (int index=1;index < conversionArray.length;index++) { if (conversionArray[index].getFuzzyValue()>=minSupport) counter++; } // Return return(counter); } /** Reconverts given item set according to contents of reconversion array. @param itemSet the fgiven itemset. @return the reconverted itemset. */ protected FuzzyDataItem[] reconvertItemSet(FuzzyDataItem[] itemSet) { // If no conversion return orginal item set if (reconversionArray==null) return(itemSet); // If item set null return null if (itemSet==null) return(null); // Define new item set FuzzyDataItem[] newItemSet = new FuzzyDataItem[itemSet.length]; // Copy for(int index=0;index itemSet2[index1]) return(false); } // Return true return(true); } /* SUBSET CHECK */ /** Checks whether one item set is subset of a second item set. @param itemSet1 the first item set (from input data). @param itemSet2 the second item set to be compared with first (from P-tree). @return true if itemSet1 is a subset of itemSet2, and false otherwise. */ protected boolean isSubset(short[] itemSet1, FuzzyDataItem[] itemSet2) { // Check for empty itemsets if (itemSet1==null) return(true); if (itemSet2==null) return(false); // Loop through itemSet1 for(int index1=0;index1oldItemSet. @return Revised item set with leading subset removed. */ protected short[] realloc4(short[] oldItemSet, FuzzyDataItem[] array2) { int array2length = array2.length; int newItemSetLength = oldItemSet.length-array2length; // Create new array short[] newItemSet = new short[newItemSetLength]; // Loop for (int index=0;index < newItemSetLength;index++) newItemSet[index] = oldItemSet[index+array2length]; // Return new array return(newItemSet); } protected FuzzyDataItem[] realloc4(FuzzyDataItem[] oldItemSet, short[] array2) { int array2length = array2.length; int newItemSetLength = oldItemSet.length-array2length; // Create new array FuzzyDataItem[] newItemSet = new FuzzyDataItem[newItemSetLength]; // Loop for (int index=0;index < newItemSetLength;index++) newItemSet[index] = new FuzzyDataItem(oldItemSet[index+array2length]); // Return new array return(newItemSet); } protected FuzzyDataItem[] realloc4(FuzzyDataItem[] oldItemSet, FuzzyDataItem[] array2) { int array2length = array2.length; int newItemSetLength = oldItemSet.length-array2length; // Create new array FuzzyDataItem[] newItemSet = new FuzzyDataItem[newItemSetLength]; // Loop for (int index=0;index < newItemSetLength;index++) newItemSet[index] = new FuzzyDataItem(oldItemSet[index+array2length]); // Return new array return(newItemSet); } /* ----------------------------------------------------- */ /* */ /* GUI OUTPUT METHODS */ /* */ /* ----------------------------------------------------- */ /* OUTPUT DATA TABLE */ /** Outputs stored input data set; initially read from input data file, but may be reordered or pruned if desired by a particular application. @param textArea the text area. */ public void outputDataArray(JTextArea textArea) { if (isPrunedFlag) textArea.append("DATA SET (Ordered and Pruned)\n"); else { if (isOrderedFlag) textArea.append("DATA SET (Ordered)\n"); else textArea.append("DATA SET\n"); } textArea.append("\n"); textArea.append("-------------------------------\n"); // Loop for(int index=0;indexJTextArea class. */ public void outputTtree(JTextArea textArea) { int number = 1; // Start textArea.append("T-TREE:\n-------\n"); textArea.append("Format: [N] {I} = S, where N is the node " + "number, I is the item set and S the support.\n"); // Check if (startTtreeRef==null) { textArea.append("Ttree empty!\n--------------------------------"); return; } // Loop for (short index=1; index < startTtreeRef.length; index++) { if (startTtreeRef[index] !=null) { // Create itemset so far array short[] itemSetSofar = new short[1]; itemSetSofar[0] = index; // Output textArea.append("[" + number + "]"); outputItemSet(textArea,itemSetSofar); textArea.append("= " + twoDecPlaces(startTtreeRef[index].support) + "\n"); outputTtree(textArea,new Integer(number).toString(), itemSetSofar,startTtreeRef[index].childRef); number++; } } // End textArea.append("------------------------------------\n"); } /** Continue process of outputting T-tree.

Operates in a recursive manner. @param textArea the given instance of the JTextArea class. @param number the ID number of a particular node. @param itemSetSofar the label for a T-tree node as generated sofar. @param linkRef the reference to the current array level in the T-tree. */ private void outputTtree(JTextArea textArea, String number, short[] itemSetSofar, FuzzyTtreeNode[] linkRef) { // Set output local variables. int num=1; number = number + "."; // Check for empty branch/sub-branch. if (linkRef == null) return; // Loop through current level of branch/sub-branch. for (short index=1;index Operates in a recursive manner. @param number the ID number of a particular node. @param itemSetSofar the label for a T-tree node as generated sofar. @param linkRef the reference to the current array level in the T-tree. */ private void outputTtree(String number, short[] itemSetSofar, FuzzyTtreeNode[] linkRef) { // Set output local variables. int num=1; number = number + "."; // Check for empty branch/sub-branch. if (linkRef == null) return; // Loop through current level of branch/sub-branch. for (short index=1;indexJTextArea class. */ public void outputFrequentSets(JTextArea textArea) { int number = 1; // Labels textArea.append("Format: [N] {I} = S, where N is a sequential " + "number, I is the item set and S the support.\n"); // Loop for (short index=1; index <= numOneItemSets; index++) { if (startTtreeRef[index] !=null) { if (startTtreeRef[index].support >= minSupport) { short[] itemSetSofar = new short[1]; itemSetSofar[0] = index; textArea.append("[" + number + "]"); outputItemSet(textArea,itemSetSofar); textArea.append("= " + (twoDecPlaces(startTtreeRef[index].support)) + "\n"); number = outputFrequentSets(textArea,number+1,itemSetSofar, index,startTtreeRef[index].childRef); } } } } /** Outputs T-tree frequent sets (GUI version).

Operates in a recursive manner. @param textArea the given instance of the JTextArea class. @param number the number of frequent sets so far. @param itemSetSofar the label for a T-treenode as generated sofar. @param size the length/size of the current array level in the T-tree. @param linkRef the reference to the current array level in the T-tree. @return the incremented (possibly) number the number of frequent sets so far. */ private int outputFrequentSets(JTextArea textArea, int number, short[] itemSetSofar, int size, FuzzyTtreeNode[] linkRef) { // No more nodes if (linkRef == null) return(number); // Otherwise process for (short index=1; index < size; index++) { if (linkRef[index] != null) { if (linkRef[index].support >= minSupport) { short[] newItemSet = realloc2(itemSetSofar,index); textArea.append("[" + number + "]"); outputItemSet(textArea,newItemSet); textArea.append("= " + (twoDecPlaces(linkRef[index].support)) + "\n"); number = outputFrequentSets(textArea,number + 1,newItemSet, index,linkRef[index].childRef); } } } // Return return(number); } /** Commences the process of outputting the frequent sets contained in the T-tree as series of schema labels (GUI version). @param textArea the given instance of the JTextArea class. */ public void outputFrequentSetsSchema(JTextArea textArea) { // Check that we have a schema if (!hasOutputSchemaFlag) { textArea.append("No schema found!\nOperation failed\n"); return; } // Proceed int number = 1; textArea.append("Format: [N] {I} = S, where N is a sequential " + "number, I is the item set and S the support.\n"); // Loop for (short index=1; index <= numOneItemSets; index++) { if (startTtreeRef[index] !=null) { if (startTtreeRef[index].support >= minSupport) { short[] itemSetSofar = new short[1]; itemSetSofar[0] = index; textArea.append("[" + number + "]"); outputItemSetSchema(textArea,itemSetSofar); textArea.append("= " + (twoDecPlaces(startTtreeRef[index].support)) + "\n"); number = outputFrequentSetsSchema(textArea,number+1, itemSetSofar,index,startTtreeRef[index].childRef); } } } // End System.out.println("\n"); } /** Outputs T-tree frequent sets (GUI version).

Operates in a recursive manner. @param textArea the given instance of the JTextArea class. @param number the number of frequent sets so far. @param itemSetSofar the label for a T-treenode as generated sofar. @param size the length/size of the current array level in the T-tree. @param linkRef the reference to the current array level in the T-tree. @return the incremented (possibly) number the number of frequent sets so far. */ private int outputFrequentSetsSchema(JTextArea textArea, int number, short[] itemSetSofar, int size, FuzzyTtreeNode[] linkRef) { // No more nodes if (linkRef == null) return(number); // Otherwise process for (short index=1; index < size; index++) { if (linkRef[index] != null) { if (linkRef[index].support >= minSupport) { short[] newItemSet = realloc2(itemSetSofar,index); textArea.append("[" + number + "]"); outputItemSetSchema(textArea,newItemSet); textArea.append("= " + (twoDecPlaces(linkRef[index].support)) + "\n"); number = outputFrequentSetsSchema(textArea,number + 1, newItemSet,index,linkRef[index].childRef); } } } // Return return(number); } /* ------------------------ */ /* OUTPUT CONVERSION ARRAYS */ /* ------------------------ */ /** Outputs conversion array (used to renumber columns 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\nindex = old attribute number\n" + "."); for(int index=1;indexJTextArea class. */ public void outputConversionArrays(JTextArea textArea) { if (conversionArray==null) { textArea.append("No conversion arrays found.\n"); return; } // Conversion array textArea.append("CONVERSION ARRAY\nindex = old attribute number\n" + ".\n"); for(int index=1;index