wpi.associations.arminerSequence
Class AssociationRule

java.lang.Object
  extended bywpi.associations.arminerSequence.AssociationRule
All Implemented Interfaces:
java.io.Serializable

public class AssociationRule
extends java.lang.Object
implements java.io.Serializable

AssociationRule.java

An association rule has two parts: the antecedent of the rule and the consequent of the rule, both of which are sets of items. Associated with these are a support and a confidence. The support tells how many rows of a database support this rule, the confidence tells what percentage of the rows that contain the antecedent also contain the consequent.

Author:
Dana Cristofor, Laurentiu Cristofor, Keith A. Pray (kap@wpi.edu)
See Also:
Serialized Form

Field Summary
private  int[] antecedent
          The antecedent.
static int ANTECEDENT_SIZE
           
private  float antecedentEventWeight
          The event weight of the antecedent of association rule.
private  float antecedentSupport
          The support of the antecedent of association rule.
private  float confidence
          The confidence of the association rule.
static int CONFIDENCE
           
private  int[] consequent
          The consequent.
static int CONSEQUENT_SIZE
           
private  float consequentEventWeight
          The event weight of the consequent of association rule.
private  float consequentSupport
          The support of the consequent of association rule.
private static int debug
          Specifies debug info level 0: no debug info 1: input to methods 2: and output from methods 3: and all sorts of stuff
private  int numInstances
          Number of instances in the data set.
 ARMinerItemset originalItemset
          the original item set the rule's antecedent and consequent were derived from
private  float ruleEventWeight
          The event weight of the association rule.
private  float support
          The support of the association rule.
static int SUPPORT
           
 
Constructor Summary
AssociationRule(ARMinerItemset antecedent, ARMinerItemset consequent, ARMinerItemset original, float support, float confidence)
          Creates a new association rule.
 
Method Summary
 boolean antecedentHasEvents()
          Checks if there is at least one event in the antecedent.
 int antecedentSize()
          Return size of antecedent.
 int compareTo(AssociationRule ar, int criteria)
          Compare two AssociationRule objects on one of several criteria.
 boolean consequentHasEvents()
          Checks if there is at least one event in the consequent.
 int consequentSize()
          Return size of consequent.
 int[] countEventWeights(ARMinerItemset itemset)
          Counts the number of occurrences of the antecedent and the number of occurrences of the consequent in context of the antecedents found in the specified item set.
 boolean equals(java.lang.Object obj)
          Compare two AssociationRule objects on one of several criteria.
 float eventWeightConfidence()
          Calculates and records confidence of association rule based on antecedent event weight and overall association rule event weight in context of the antecedent.
 float getAntecedentEventWeight()
          Return event weight of antecedent of association rule.
 int getAntecedentItem(int i)
          Return i-th item in antecedent.
 float getAntecedentSupport()
          Return support of antecedent of association rule.
 float getChiSquare()
          Calculates and returns the Chi-square measure of the rule.
 float getConfidence()
          Return confidence of association rule.
 float getConsequentEventWeight()
          Return event weight of consequent of association rule.
 int getConsequentItem(int i)
          Return i-th item in consequent.
 float getConsequentSupport()
          Return support of antecedent of association rule.
 float getLift()
          Return lift of association rule.
 int getNumInstances()
          Returns the number of instances contained in the data set from which the frequent item set were mined.
 float getRuleEventWeight()
          Return event weight of association rule.
 float getSupport()
          Return support of association rule.
static void main(java.lang.String[] args)
          Main method for testing purposes only.
 void resetEventWeights()
          Resets the event weight count to zero.
 void setNumInstances(int n)
          Sets the number of instances contained in the data set from which the frequent item set were mined.
 java.lang.String toString()
          Return a String representation of the AssociationRule.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANTECEDENT_SIZE

public static final int ANTECEDENT_SIZE
See Also:
Constant Field Values

CONSEQUENT_SIZE

public static final int CONSEQUENT_SIZE
See Also:
Constant Field Values

SUPPORT

public static final int SUPPORT
See Also:
Constant Field Values

CONFIDENCE

public static final int CONFIDENCE
See Also:
Constant Field Values

antecedent

private int[] antecedent
The antecedent. @serial


consequent

private int[] consequent
The consequent. @serial


support

private float support
The support of the association rule. @serial


antecedentSupport

private float antecedentSupport
The support of the antecedent of association rule. @serial


consequentSupport

private float consequentSupport
The support of the consequent of association rule. @serial


antecedentEventWeight

private float antecedentEventWeight
The event weight of the antecedent of association rule. @serial


consequentEventWeight

private float consequentEventWeight
The event weight of the consequent of association rule. @serial


ruleEventWeight

private float ruleEventWeight
The event weight of the association rule. This is the number of times the consequent is found to match a previously found antecedent. @serial


confidence

private float confidence
The confidence of the association rule. @serial


numInstances

private int numInstances
Number of instances in the data set. Used for computing statistical measures


originalItemset

public ARMinerItemset originalItemset
the original item set the rule's antecedent and consequent were derived from


debug

private static final int debug
Specifies debug info level 0: no debug info 1: input to methods 2: and output from methods 3: and all sorts of stuff

See Also:
Constant Field Values
Constructor Detail

AssociationRule

public AssociationRule(ARMinerItemset antecedent,
                       ARMinerItemset consequent,
                       ARMinerItemset original,
                       float support,
                       float confidence)
Creates a new association rule.

Parameters:
antecedent - the antecedent of the association rule
consequent - the consequent of the association rule
original - the original item set the antecedent and consequent were derived from
support - the support of the association rule
confidence - the confidence of the association rule
Throws:
java.lang.IllegalArgumentException - antecedent or consequent are null or support or confidence are not between 0 and 1
Method Detail

setNumInstances

public void setNumInstances(int n)
Sets the number of instances contained in the data set from which the frequent item set were mined.

Parameters:
n - the number of instances or rows

getNumInstances

public int getNumInstances()
Returns the number of instances contained in the data set from which the frequent item set were mined.

Returns:
the number of instances or rows

antecedentSize

public int antecedentSize()
Return size of antecedent.

Returns:
size of antecedent

consequentSize

public int consequentSize()
Return size of consequent.

Returns:
size of consequent

getSupport

public float getSupport()
Return support of association rule.


getAntecedentSupport

public float getAntecedentSupport()
Return support of antecedent of association rule.


getConsequentSupport

public float getConsequentSupport()
Return support of antecedent of association rule.


getAntecedentEventWeight

public float getAntecedentEventWeight()
Return event weight of antecedent of association rule.


getConsequentEventWeight

public float getConsequentEventWeight()
Return event weight of consequent of association rule.


getRuleEventWeight

public float getRuleEventWeight()
Return event weight of association rule.


getConfidence

public float getConfidence()
Return confidence of association rule.


eventWeightConfidence

public float eventWeightConfidence()
Calculates and records confidence of association rule based on antecedent event weight and overall association rule event weight in context of the antecedent.

Returns:
the confidence value

getLift

public float getLift()
Return lift of association rule.


getChiSquare

public float getChiSquare()
Calculates and returns the Chi-square measure of the rule.
Sergio A. Alvarez. "Chi--Squared Computation for Association Rules: Preliminary Results''. Technical Report BC-CS-2003-01, Computer Science Department, Boston College, July 2003. http://cs.bc.edu/research/reports/Alvarez:Chi2TR.html

Returns:
Chi-square measure of rule

consequentHasEvents

public boolean consequentHasEvents()
Checks if there is at least one event in the consequent.

Returns:
true if there is at least one event, false otherwise

antecedentHasEvents

public boolean antecedentHasEvents()
Checks if there is at least one event in the antecedent.

Returns:
true if there is at least one event, false otherwise

getAntecedentItem

public int getAntecedentItem(int i)
Return i-th item in antecedent.

Parameters:
i - the index of the item to get
Returns:
the i-th item in antecedent
Throws:
java.lang.IndexOutOfBoundsException - i is an invalid index

getConsequentItem

public int getConsequentItem(int i)
Return i-th item in consequent.

Parameters:
i - the index of the item to get
Returns:
the i-th item in consequent
Throws:
java.lang.IndexOutOfBoundsException - i is an invalid index

compareTo

public int compareTo(AssociationRule ar,
                     int criteria)
Compare two AssociationRule objects on one of several criteria.

Parameters:
ar - the AssociationRule object with which we want to compare this object
criteria - the criteria on which we want to compare, can be one of ANTECEDENT_SIZE, CONSEQUENT_SIZE, SUPPORT or CONFIDENCE.
Returns:
a negative value if this object is smaller than ar, 0 if they are equal, and a positive value if this object is greater.
Throws:
java.lang.IllegalArgumentException - ar is null or criteria is invalid

equals

public boolean equals(java.lang.Object obj)
Compare two AssociationRule objects on one of several criteria.

Parameters:
obj - the object to compare for equality
Returns:
true if the object is equal

countEventWeights

public int[] countEventWeights(ARMinerItemset itemset)
Counts the number of occurrences of the antecedent and the number of occurrences of the consequent in context of the antecedents found in the specified item set. These counts are stored in this association rule. To reset the count use resetEventWeights(). The counts are accumulative for each call of this method.

Parameters:
itemset - the item set to find occurrences of the antecedent and consequent in
Returns:
an array of size 2, the first index holding the count of antecedents, the second holding the count of antecedents which had matching consequents.

resetEventWeights

public void resetEventWeights()
Resets the event weight count to zero. Use this when beginning to count the event weights of this association rule. This might be necessary to accurately calculate the confidence and lift of this rule.


toString

public java.lang.String toString()
Return a String representation of the AssociationRule.

Returns:
String representation of AssociationRule

main

public static void main(java.lang.String[] args)
Main method for testing purposes only.