/* -------------------------------------------------------------------------- */
/* */
/* F U Z Z Y W E I G H T E D A S S O C I A T I O N R U L E */
/* M I N I N G (F W A R M) A P R I O R I T */
/* */
/* Frans Coenen */
/* */
/* Friday 22 August 2008 */
/* (Revised .......) */
/* */
/* Department of Computer Science */
/* The University of Liverpool */
/* */
/* -------------------------------------------------------------------------- */
/** Class that contains methods to support Fuzzy Weighted Association Rule Mining
(FWARM) based on the Apriori-T algorithm. */
/* Structure:
AssocRuleMining
|
+-- TotalSupportTree
|
+-- FuzzyAprioriT
|
+-- FWARMaprioriT */
//package lucsKDD_ARM;
// Java packages
import java.io.*;
import java.util.*;
// Java GUI packages
import javax.swing.*;
public class FWARMaprioriT extends FuzzyAprioriT {
/*------------------------------------------------------------------------*/
/* */
/* FIELDS */
/* */
/*------------------------------------------------------------------------*/
/** Weightings array. */
public double[] weightings = null;
/** Number of weighting values, */
public int numWeightings = 0;
/*---------------------------------------------------------------------*/
/* */
/* CONSTRUCTORS */
/* */
/*---------------------------------------------------------------------*/
/** With argument from existing instance of class AssocRuleMining; sets fuzzy
support to 0.2.
@param aemInstance the given instance of the AssocRuleMining
class. */
public FWARMaprioriT(FWARMaprioriT newInstance) {
super(newInstance);
weightings = newInstance.weightings;
numWeightings = newInstance.numWeightings;
dataArray = newInstance.dataArray;
}
/** Default constructor; sets fuzzy support to 0.2. */
public FWARMaprioriT() {
}
/*-------------------------------------------------------------------*/
/* */
/* 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("Fuzzy Weighted Apriori-T with X-Checking\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);
}
/** 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;index1 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
Proceeds as follows:
- Gets number of lines in file, checking format of each line (space
separated integers), if incorrectly formatted line found
inputFormatOkFlag set to false.
- Diminsions input array.
- Reads data
@param textArea the text area in the gui used for output. */
public void readWeightingsFile(JTextArea textArea) {
try {
// Dimension data structure
inputFormatOkFlag = true;
numWeightings = getNumberOfLines(fileName);
// Plus one because first index is ignored (it is not an item number).
weightings = new double[numWeightings+1];
// Read file
textArea.append("Reading weightings input file:\n" + filePath + "\n");
readInputWeightings(fileName);
}
catch(IOException ioException) {
JOptionPane.showMessageDialog(this,"Error Reading Weightings File",
"Error: ",JOptionPane.ERROR_MESSAGE);
textArea.append("Error reading File\n");
closeFile();
// Set have data flag to false
haveDataFlag = false;
}
}
/* GET NUMBER OF LINES */
/** Gets number of lines/records in input file and checks format of each
line.
@param nameOfFile the filename of the file to be opened.
@return the number of rows in the given file. */
protected int getNumberOfLines(String nameOfFile) throws IOException {
int counter = 0;
// Open the file
if (filePath==null) openFileName(nameOfFile);
else openFilePath();
// Loop through file incrementing counter
// get first row.
String line = fileInput.readLine();
while (line != null) {
StringTokenizer dataLine = new StringTokenizer(line);
int numberOfTokens = dataLine.countTokens();
if (numberOfTokens == 0) break;
counter++;
line = fileInput.readLine();
}
// Close file and return
closeFile();
return(counter);
}
/* READ INPUT WEIGHTINGS */
/** Reads input data from given file.
@param fName the given file name. */
protected void readInputWeightings(String fName) throws IOException {
int rowIndex=1;
// Open the file
if (filePath==null) openFileName(fName);
else openFilePath();
// Get first row.
String line = fileInput.readLine();
// Process rest of file
while (line != null) {
// Tokenise line
StringTokenizer dataLine = new StringTokenizer(line);
weightings[rowIndex] = Double.parseDouble(dataLine.nextToken());
// Increment first (row) index in 2-D data array
rowIndex++;
// get next line
line = fileInput.readLine();
}
// Close file
closeFile();
}
/** Check number of weightings is same is number of columns in input data. */
public void checkDataVweightings() {
if (numWeightings!=numCols) {
JOptionPane.showMessageDialog(null,"WARNING READING INPUT DATA FILE:\n " +
"Number of columns (" + numCols + ") in the data file is\n" +
"not equal to the number of wightings (" + numWeightings +
")\nin the weightings input file\n");
}
}
/** Check number of colunbs is same is number of weightings in weighting input. */
public void checkWeightingsVdata() {
if (numWeightings!=numCols) {
JOptionPane.showMessageDialog(null,"WARNING READING WEIGHTING FILE:\n " +
"Number of wightings (" + numWeightings + ") is not equal\n" +
"to the number of columns (" + numCols + ") in the data file\n");
}
}
/** Sorts weightings according to reconversion array. */
public void sortWeightings() {
double [] newWeights = new double[weightings.length];
// Loop
for (int index=1;indexJTextArea class. */
public void outputWeightings(JTextArea textArea) {
textArea.append("DATA WEIGHTINGS\n-----------------\n");
// Loop
for (int index=1;index\n");
textArea.append("------------------------------------------\n");
// Loop
for(int index=0;index