laur.dm.ar
Class AssociationRule

java.lang.Object
  |
  +--laur.dm.ar.AssociationRule
All Implemented Interfaces:
CriteriaComparable, java.io.Serializable

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

An association rule has two parts: the antecedent of the rule and the consequent of the rule, both of which are itemsets. 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.

See Also:
Serialized Form

Field Summary
static int BY_ANTECEDENT_SIZE
          Specifies sorting should be performed according to antecedent size.
static int BY_CONFIDENCE
          Specifies sorting should be performed according to rule confidence.
static int BY_CONSEQUENT_SIZE
          Specifies sorting should be performed according to consequent size.
static int BY_SUPPORT
          Specifies sorting should be performed according to rule support.
 
Constructor Summary
AssociationRule(Itemset antecedent, Itemset consequent, double support, double confidence)
          Creates a new association rule.
 
Method Summary
 int antecedentSize()
          Return size of antecedent.
 int compareTo(java.lang.Object obj, int criteria)
          Compare two AssociationRule objects on one of several criteria.
 double computeConfidence()
          Compute and return the confidence of the rule.
 double computeInfluence()
          Compute and return the influence of the rule.
 double computeLift()
          Compute and return the lift of the rule.
 double computePiatetskyShapiro()
          Compute and return the Piatetsky-Shapiro measure of the rule.
 int consequentSize()
          Return size of consequent.
 boolean equals(java.lang.Object obj)
          Compare two AssociationRule objects on one of several criteria.
 Itemset getAntecedent()
          Return antecedent of association rule.
 int getAntecedentItem(int i)
          Return i-th item in antecedent.
 double getConfidence()
          Return confidence of association rule.
 Itemset getConsequent()
          Return consequent of association rule.
 int getConsequentItem(int i)
          Return i-th item in consequent.
 double getSupport()
          Return support of association rule.
 boolean isCoveredBy(AssociationRule ar)
          Find out if this rule is covered (can be inferred from) the ar rule.
static void main(java.lang.String[] args)
          sample usage and testing
 void setConfidence(double confidence)
          Set confidence of association rule.
 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

BY_ANTECEDENT_SIZE

public static final int BY_ANTECEDENT_SIZE
Specifies sorting should be performed according to antecedent size.

BY_CONSEQUENT_SIZE

public static final int BY_CONSEQUENT_SIZE
Specifies sorting should be performed according to consequent size.

BY_SUPPORT

public static final int BY_SUPPORT
Specifies sorting should be performed according to rule support.

BY_CONFIDENCE

public static final int BY_CONFIDENCE
Specifies sorting should be performed according to rule confidence.
Constructor Detail

AssociationRule

public AssociationRule(Itemset antecedent,
                       Itemset consequent,
                       double support,
                       double confidence)
Creates a new association rule.
Parameters:
antecedent - the antecedent of the association rule
consequent - the consequent of the association rule
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

antecedentSize

public int antecedentSize()
Return size of antecedent.
Returns:
size of antecedent

consequentSize

public int consequentSize()
Return size of consequent.
Returns:
size of consequent

getAntecedent

public Itemset getAntecedent()
Return antecedent of association rule.

getConsequent

public Itemset getConsequent()
Return consequent of association rule.

getSupport

public double getSupport()
Return support of association rule.

getConfidence

public double getConfidence()
Return confidence of association rule.

setConfidence

public void setConfidence(double confidence)
Set confidence of association rule.
Parameters:
confidence - the new value of the confidence

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:
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:
IndexOutOfBoundsException - i is an invalid index

compareTo

public int compareTo(java.lang.Object obj,
                     int criteria)
Compare two AssociationRule objects on one of several criteria.
Specified by:
compareTo in interface CriteriaComparable
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 - obj is not an AssociationRule or criteria is invalid

equals

public boolean equals(java.lang.Object obj)
Compare two AssociationRule objects on one of several criteria.
Overrides:
equals in class java.lang.Object
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:
true if the objects are equal in terms of antecedent and consequent items; false otherwise.

isCoveredBy

public boolean isCoveredBy(AssociationRule ar)
Find out if this rule is covered (can be inferred from) the ar rule.
Parameters:
ar - the rule that we test against
Returns:
true if our rule is covered by ar and false otherwise.

computeConfidence

public double computeConfidence()
Compute and return the confidence of the rule. The confidence of rule A -> C is defined by sup(AC)/sup(A)
Returns:
confidence of rule

computePiatetskyShapiro

public double computePiatetskyShapiro()
Compute and return the Piatetsky-Shapiro measure of the rule. The Piatetsky-Shapiro measure of rule A -> C is defined by sup(AC) - sup(A)*sup(C)
Returns:
Piatetsky-Shapiro measure of rule

computeLift

public double computeLift()
Compute and return the lift of the rule. The lift of rule A -> C is defined by sup(AC) / (sup(A)*sup(C))
Returns:
lift of rule

computeInfluence

public double computeInfluence()
Compute and return the influence of the rule. The influence of rule A -> C is defined by sup(AC)/sup(A) - sup(C)
Returns:
influence of rule

toString

public java.lang.String toString()
Return a String representation of the AssociationRule.
Overrides:
toString in class java.lang.Object
Returns:
String representation of AssociationRule

main

public static void main(java.lang.String[] args)
sample usage and testing