Package fim

Class ARuleSet

java.lang.Object
fim.ARuleSet
All Implemented Interfaces:
PatternReceiver, Serializable, Cloneable

public class ARuleSet extends Object implements Cloneable, PatternReceiver, Serializable
Class for a set of association rules.
Since:
2004.07.06
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    the maximal number of items in a rule body
    static final int
    sort mode: size / number of items in antecedent/body
    static final int
    sort mode: antecedent/body support
    static final int
    sort mode: confidence
    protected int
    the current rule index for the rule set reduction
    static final int
    sort mode: evaluation
    static final int
    selection mode: find exact match of given rule
    protected int
    the maximal number of items in a rule head
    static final int
    sort mode: consequent/head item of the rule
    static final int
    filter mode: keep only rules in which the head item is not contained in the body
    static final int
    filter mode: keep only rules in which the head item is not also the last item in the body
    static final int
    sort mode: consequent/head support
    protected util.IdMap
    the underlying item base
    static final int
    sort mode: items (in the order in which they appear)
    static final int
    reduction mode: compare only the head items (not support etc.)
    static final int
    sort mode: lift value
    static final int
    reduction mode: maximize the size of the antecedent/rule body
    static final int
    reduction mode: minimize the size of the antecedent/rule body
    static final int
    sort mode: names of the consequent items
    static final int
    reduction mode: do not use a CloMaxFilter, but rather work directly on the item pattern array
    static final int
    reduction mode: do nothing
    protected ARule[]
    the set of association rules
    protected int
    the current number of rules
    static final int
    sort mode: size / number of items
    static final int
    filter mode: do nothing (keep all association rules, sort only)
    static final int
    selection mode: find subrule of given rule (or exact match)
    static final int
    selection mode: find superrule of given rule (or exact match)
    static final int
    sort mode: item pattern support (body and head)
    protected int[]
    the support values of individual items
    static final int
    reduction mode: remove duplicates/ensure unique rules
    protected int
    the maximal number of items in a rule (body and head)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty set of association rules.
    ARuleSet(util.IdMap ibase)
    Create an empty set of association rules.
    ARuleSet(util.IdMap ibase, int s_base, Object[] rules)
    Create a set of association rules from FIM output.
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    add(ARule rule)
    Add an association rule.
    final int
    addRule(ARule rule)
    Add an association rule.
    final void
    Add an association rule set (the rules are not cloned/copied, but merely transferred).
    final void
    addRuleSet(ARuleSet ruleset, boolean clonerules)
    Add an association rule set.
    final void
    Clear this association rule set, that is, remove all rules.
    final Object
    Clone this set of association rules.
    clone(boolean clonebase, boolean clonerules)
    Clone this set of association rules.
    boolean
    equals(ARuleSet ruleset)
    Check whether two association rule sets are equal.
    int
    filter(int mode)
    Filter a set of association rules.
    int
    filter(int zmin, int zmax)
    Filter an association rule set by antecedent/body size.
    final ARule
    get(int i)
    Get an association rule
    final ARule[]
    Get all association rules as an array (array length fits only after packing with pack(); should be considered read only).
    final int[]
    Get the support values of all individual items.
    final util.IdMap
    Get the underlying item base.
    final String
    getItemName(int item)
    Get the name of an item.
    final int[]
    Get a list of all items that occur in at least one association rule (in body or head).
    final int
    Get the maximal size of a rule body/antecedent.
    final int
    Get the maximal size of a rule head/consequent.
    final int
    Get the maximal size of a rule.
    final ARule
    getRule(int i)
    Get an association rule
    final int
    Get the number of association rules (size of rule set).
    final int
    getRuleSize(int i)
    Get the size of an association rule.
    final int
    Get the number of association rules (size of rule set).
    final int
    getSupp(int item)
    Get the support of an individual item.
    final int
    getSuppById(int item)
    Get the support of an individual item.
    final int
    Get the support of an individual item.
    final int
    Get the support of an individual item.
    static void
    main(String[] args)
    Main function for testing some basic functionality.
    final void
    Pack the association rules, i.e., optimize memory usage.
    static ARuleSet
    parse(util.IdMap ibase, InputStream inp)
    Parse a set of association rules.
    static ARuleSet
    parse(util.IdMap ibase, Reader reader)
    Parse a set of association rules.
    static ARuleSet
    parse(util.IdMap ibase, String desc)
    Parse a set of association rules.
    static ARuleSet
    parse(util.IdMap ibase, util.Scanner scan)
    Parse a set of association rules.
    void
    receive(int[] items, int size, int s_pat, int s_base)
    Receive an item pattern (implements PatternReceiver).
    final void
    recode(util.IdMap ibase)
    Recode an association rule set to another item base, replacing the item base.
    int
    reduce(int mode)
    Reduce a set of association rules.
    final void
    Reverse the order of the association rules in a rule set.
    final ARuleSet
    select(int[] body, int size, int head, int mode)
    Select rules that are subrules, superrules (w.r.t.
    final ARuleSet
    select(ARule rule, int mode)
    Select rules that are subrules, superrules (w.r.t.
    final void
    setAllSupps(int[] supps)
    Set the support values of all individual items.
    protected final void
    setSort(int valid, int dir)
    Set the sort parameters for all item patterns.
    final void
    setSupp(int item, int supp)
    Set the support of an individual item.
    final void
    setSuppById(int item, int supp)
    Set the support of an individual item.
    final void
    setSuppByName(String item, int supp)
    Set the support of an individual item.
    final void
    setSuppByObject(String item, int supp)
    Set the support of an individual item.
    final void
    Sort the set of association rules (by their size).
    final void
    sort(int valid)
    Sort the set of association rules.
    final void
    sort(int valid, int dir)
    Sort the set of association rules.
    final void
    Sort the items in each association rule's body.
    final void
    Sort the items in each association rule's body.
    void
    Write a set of association rules.
    void
    write(Writer writer)
    Write a set of association rules.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ITEMS

      public static final int ITEMS
      sort mode: items (in the order in which they appear)
      See Also:
    • SIZE

      public static final int SIZE
      sort mode: size / number of items
      See Also:
    • BODYSIZE

      public static final int BODYSIZE
      sort mode: size / number of items in antecedent/body
      See Also:
    • CONF

      public static final int CONF
      sort mode: confidence
      See Also:
    • SUPP

      public static final int SUPP
      sort mode: item pattern support (body and head)
      See Also:
    • BODYSUPP

      public static final int BODYSUPP
      sort mode: antecedent/body support
      See Also:
    • HEADSUPP

      public static final int HEADSUPP
      sort mode: consequent/head support
      See Also:
    • LIFT

      public static final int LIFT
      sort mode: lift value
      See Also:
    • EVAL

      public static final int EVAL
      sort mode: evaluation
      See Also:
    • NAMES

      public static final int NAMES
      sort mode: names of the consequent items
      See Also:
    • NONE

      public static final int NONE
      reduction mode: do nothing
      See Also:
    • UNIQUE

      public static final int UNIQUE
      reduction mode: remove duplicates/ensure unique rules
      See Also:
    • MINSIZE

      public static final int MINSIZE
      reduction mode: minimize the size of the antecedent/rule body
      See Also:
    • MAXSIZE

      public static final int MAXSIZE
      reduction mode: maximize the size of the antecedent/rule body
      See Also:
    • ITEMSONLY

      public static final int ITEMSONLY
      reduction mode: compare only the head items (not support etc.)
      See Also:
    • NOFILTER

      public static final int NOFILTER
      reduction mode: do not use a CloMaxFilter, but rather work directly on the item pattern array
      See Also:
    • SORTONLY

      public static final int SORTONLY
      filter mode: do nothing (keep all association rules, sort only)
      See Also:
    • HEADNOTLAST

      public static final int HEADNOTLAST
      filter mode: keep only rules in which the head item is not also the last item in the body
      See Also:
    • HEADNOTBODY

      public static final int HEADNOTBODY
      filter mode: keep only rules in which the head item is not contained in the body
      See Also:
    • EXACT

      public static final int EXACT
      selection mode: find exact match of given rule
      See Also:
    • SUB

      public static final int SUB
      selection mode: find subrule of given rule (or exact match)
      See Also:
    • SUPER

      public static final int SUPER
      selection mode: find superrule of given rule (or exact match)
      See Also:
    • ibase

      protected util.IdMap ibase
      the underlying item base
    • rules

      protected ARule[] rules
      the set of association rules
    • size

      protected int size
      the current number of rules
    • body

      protected int body
      the maximal number of items in a rule body
    • zmax

      protected int zmax
      the maximal number of items in a rule (body and head)
    • supps

      protected int[] supps
      the support values of individual items
    • curr

      protected int curr
      the current rule index for the rule set reduction
  • Constructor Details

    • ARuleSet

      public ARuleSet()
      Create an empty set of association rules.
      Since:
      2005.07.06 (Christian Borgelt)
    • ARuleSet

      public ARuleSet(util.IdMap ibase)
      Create an empty set of association rules.
      Parameters:
      ibase - the underlying item base
      Since:
      2005.07.06 (Christian Borgelt)
    • ARuleSet

      public ARuleSet(util.IdMap ibase, int s_base, Object[] rules)
      Create a set of association rules from FIM output.
      Parameters:
      ibase - the underlying item base
      s_base - the number of transactions from which the (frequent) item sets where derived
      rules - the output of a native function JNIFIM.xxx(), called with report = "bsh" or report = "bsh[e|E]"
      Since:
      2014.10.23 (Christian Borgelt)
  • Method Details

    • clone

      public final Object clone()
      Clone this set of association rules.

      The clone is a deep clone, that is, the underlying item base and all contained association rules are cloned as well.

      Overrides:
      clone in class Object
      Returns:
      a clone of this set of association rules
      Since:
      2017.06.29 (Christian Borgelt)
    • clone

      public Object clone(boolean clonebase, boolean clonerules)
      Clone this set of association rules.
      Parameters:
      clonebase - whether to clone the underlying item base
      clonerules - whether to clone the association rules
      Returns:
      a clone of this set of association rules
      Since:
      2017.06.29 (Christian Borgelt)
    • clear

      public final void clear()
      Clear this association rule set, that is, remove all rules.
      Since:
      2017.06.29 (Christian Borgelt)
    • getItemBase

      public final util.IdMap getItemBase()
      Get the underlying item base.
      Returns:
      the underlying item base
      Since:
      2005.07.06 (Christian Borgelt)
    • getSize

      public final int getSize()
      Get the number of association rules (size of rule set).
      Returns:
      the number of association rules
      Since:
      2016.04.08 (Christian Borgelt)
    • getRuleCount

      public final int getRuleCount()
      Get the number of association rules (size of rule set).
      Returns:
      the number of association rules
      Since:
      2005.07.06 (Christian Borgelt)
    • getMaxSize

      public final int getMaxSize()
      Get the maximal size of a rule.
      Returns:
      the maximal size of a rule
      Since:
      2007.03.12 (Christian Borgelt)
    • getMaxBodySize

      public final int getMaxBodySize()
      Get the maximal size of a rule body/antecedent.
      Returns:
      the maximal size of a rule body/antecedent
      Since:
      2005.07.06 (Christian Borgelt)
    • getMaxHeadSize

      public final int getMaxHeadSize()
      Get the maximal size of a rule head/consequent.
      Returns:
      the maximal size of a rule body/consequent
      Since:
      2005.07.06 (Christian Borgelt)
    • getItemName

      public final String getItemName(int item)
      Get the name of an item.
      Parameters:
      item - the identifier of the item for which to get the name
      Returns:
      the name of the item with identifier item
      Since:
      2017.06.29 (Christian Borgelt)
    • get

      public final ARule get(int i)
      Get an association rule
      Parameters:
      i - the index of the association rule
      Returns:
      the association rule with index i
      Since:
      2017.06.22 (Christian Borgelt)
    • getRule

      public final ARule getRule(int i)
      Get an association rule
      Parameters:
      i - the index of the association rule
      Returns:
      the association rule with index i
      Since:
      2005.07.06 (Christian Borgelt)
    • getAllRules

      public final ARule[] getAllRules()
      Get all association rules as an array (array length fits only after packing with pack(); should be considered read only).
      Returns:
      the array of association rules
      Since:
      2017.06.29 (Christian Borgelt)
    • getRuleSize

      public final int getRuleSize(int i)
      Get the size of an association rule.
      Parameters:
      i - the index of the association rule
      Returns:
      the size of the association rule with index i /*------------------------------------------------------------------
    • add

      public final int add(ARule rule)
      Add an association rule.
      Parameters:
      rule - the association rule to add
      Returns:
      the index of the association rule in the set
      Since:
      2017.06.22 (Christian Borgelt)
    • addRule

      public final int addRule(ARule rule)
      Add an association rule.
      Parameters:
      rule - the association rule to add
      Returns:
      the index of the association rule in the set
      Since:
      2005.07.06 (Christian Borgelt)
    • addRuleSet

      public final void addRuleSet(ARuleSet ruleset)
      Add an association rule set (the rules are not cloned/copied, but merely transferred).
      Parameters:
      ruleset - the association rule set to add
      Since:
      2017.06.29 (Christian Borgelt)
    • addRuleSet

      public final void addRuleSet(ARuleSet ruleset, boolean clonerules)
      Add an association rule set.
      Parameters:
      ruleset - the association rule set to add
      clonerules - whether to clone the rules of the given set
      Since:
      2017.06.29 (Christian Borgelt)
    • getSupp

      public final int getSupp(int item)
      Get the support of an individual item.
      Parameters:
      item - the item identifier for which to get the support value
      Returns:
      the support value of the item with identifier item
      Since:
      2017.06.29 (Christian Borgelt)
    • getSuppById

      public final int getSuppById(int item)
      Get the support of an individual item.
      Parameters:
      item - the item identifier for which to get the support value
      Returns:
      the support value of the item with identifier item
      Since:
      2017.06.29 (Christian Borgelt)
    • getSuppByName

      public final int getSuppByName(String item)
      Get the support of an individual item.
      Parameters:
      item - the item name for which to get the support value
      Returns:
      the support value of the item with name item
      Since:
      2017.06.29 (Christian Borgelt)
    • getSuppByObject

      public final int getSuppByObject(Object item)
      Get the support of an individual item.
      Parameters:
      item - the item object for which to get the support value
      Returns:
      the support value of the item with object item
      Since:
      2017.06.29 (Christian Borgelt)
    • setSupp

      public final void setSupp(int item, int supp)
      Set the support of an individual item.
      Parameters:
      item - the item identifier for which to set the support value
      supp - the support value to set for the item
      Since:
      2017.06.29 (Christian Borgelt)
    • setSuppById

      public final void setSuppById(int item, int supp)
      Set the support of an individual item.
      Parameters:
      item - the item identifier for which to set the support value
      supp - the support value to set for the item
      Since:
      2017.06.29 (Christian Borgelt)
    • setSuppByName

      public final void setSuppByName(String item, int supp)
      Set the support of an individual item.
      Parameters:
      item - the item name for which to set the support value
      supp - the support value to set for the item
      Since:
      2017.06.29 (Christian Borgelt)
    • setSuppByObject

      public final void setSuppByObject(String item, int supp)
      Set the support of an individual item.
      Parameters:
      item - the item name for which to set the support value
      supp - the support value to set for the item
      Since:
      2017.06.29 (Christian Borgelt)
    • getAllSupps

      public final int[] getAllSupps()
      Get the support values of all individual items.
      Returns:
      an array of support values for each item
      Since:
      2017.06.29 (Christian Borgelt)
    • setAllSupps

      public final void setAllSupps(int[] supps)
      Set the support values of all individual items.
      Parameters:
      supps - an array of support values for each item
      Since:
      2017.06.29 (Christian Borgelt)
    • sortItems

      public final void sortItems()
      Sort the items in each association rule's body.
      Since:
      2017.06.29 (Christian Borgelt)
    • sortBodyItems

      public final void sortBodyItems()
      Sort the items in each association rule's body.
      Since:
      2017.06.29 (Christian Borgelt)
    • setSort

      protected final void setSort(int valid, int dir)
      Set the sort parameters for all item patterns.
      Parameters:
      valid - the identifier of the value to sort on
      dir - the sort direction (positive: ascending, negative: descending)
      Since:
      2017.06.17 (Christian Borgelt)
    • sort

      public final void sort()
      Sort the set of association rules (by their size).
      Since:
      2017.06.29 (Christian Borgelt)
    • sort

      public final void sort(int valid)
      Sort the set of association rules.
      Parameters:
      valid - the identifier of the value to compare first
      Since:
      2005.07.06/2016.04.10 (Christian Borgelt)
    • sort

      public final void sort(int valid, int dir)
      Sort the set of association rules.
      Parameters:
      valid - the identifier of the value to compare first
      dir - the sort direction (positive: ascending, negative: descending)
      Since:
      2016.04.10 (Christian Borgelt)
    • reverse

      public final void reverse()
      Reverse the order of the association rules in a rule set.
      Since:
      2016.06.27 (Christian Borgelt)
    • equals

      public boolean equals(ARuleSet ruleset)
      Check whether two association rule sets are equal.

      It is assumed that both association rule sets have been sorted with a call to the function sort() with parameter ITEMS. If the rule bodies represents item sets instead of permutations or sequences, it is also assumed that the items have been sorted by a call to the function sortItems().

      Parameters:
      ruleset - the rule set to compare to
      Returns:
      true if the two rule sets contain the same rule (in the same order) and false otherwise
      Since:
      2016.06.29 (Christian Borgelt)
    • filter

      public int filter(int mode)
      Filter a set of association rules.
      Parameters:
      mode - the filter mode (e.g. HEADNOTLAST)
      Returns:
      the new number of association rules
      Since:
      2016.06.29 (Christian Borgelt)
    • filter

      public int filter(int zmin, int zmax)
      Filter an association rule set by antecedent/body size.
      Parameters:
      zmin - the minimum body size of the rules to keep
      zmax - the maximum body size of the rules to keep
      Returns:
      the new number of association rules
      Since:
      2016.06.29 (Christian Borgelt)
    • receive

      public void receive(int[] items, int size, int s_pat, int s_base)
      Receive an item pattern (implements PatternReceiver).

      This function is needed internally to implement the function reduce(). It performs no operation if called from the outside of this class. On the other hand, it cannot be declared private, because it implements an interface.

      Specified by:
      receive in interface PatternReceiver
      Parameters:
      items - the items in the item pattern (may be an oversized buffer)
      size - the number of items in the pattern
      s_pat - the (absolute) support of the item pattern
      s_base - the (absolute) base support (support of the empty item pattern, database size)
      Since:
      2016.06.29 (Christian Borgelt)
    • reduce

      public int reduce(int mode)
      Reduce a set of association rules.
      Parameters:
      mode - the reduction mode (e.g. MINSIZE)
      Returns:
      the new number of association rules
      Since:
      2016.06.29 (Christian Borgelt)
    • select

      public final ARuleSet select(ARule rule, int mode)
      Select rules that are subrules, superrules (w.r.t. the rule body) or an exact match of the given rule (in terms of the contained items, including the head).
      Parameters:
      rule - the rule with which to select rules
      mode - the mode with which to select rules; either EXACT, SUB, or SUPER.
      Returns:
      an association rule set with the qualifying rules (uncloned)
      Since:
      2016.06.29 (Christian Borgelt)
    • select

      public final ARuleSet select(int[] body, int size, int head, int mode)
      Select rules that are subrules, superrules (w.r.t. the rule body) or an exact match of the given rule (in terms of the contained items, including the head).
      Parameters:
      body - the items of the rule body to compare to
      size - the number of items in the body
      head - the head item of the rule
      mode - the mode with which to select rules EXACT, SUB, or SUPER.
      Returns:
      an association rule set with the qualifying rules (uncloned)
      Since:
      2016.06.29 (Christian Borgelt)
    • getItems

      public final int[] getItems()
      Get a list of all items that occur in at least one association rule (in body or head).
      Returns:
      an array with the identifiers of items that occur in at least one association rule, sorted by item identifier
      Since:
      2016.06.29 (Christian Borgelt)
    • recode

      public final void recode(util.IdMap ibase)
      Recode an association rule set to another item base, replacing the item base.
      Parameters:
      ibase - the item base to recode the association rule set to
      Since:
      2016.06.29 (Christian Borgelt)
    • pack

      public final void pack()
      Pack the association rules, i.e., optimize memory usage.
      Since:
      2017.06.29 (Christian Borgelt)
    • write

      public void write(Writer writer) throws IOException
      Write a set of association rules.
      Parameters:
      writer - the writer to write to
      Throws:
      IOException - if a write error occurs
      Since:
      2007.06.06 (Christian Borgelt)
    • write

      public void write(OutputStream out) throws IOException
      Write a set of association rules.
      Parameters:
      out - the output stream to write to
      Throws:
      IOException - if a write error occurs
      Since:
      2016.04.08 (Christian Borgelt)
    • parse

      public static ARuleSet parse(util.IdMap ibase, util.Scanner scan) throws IOException
      Parse a set of association rules.
      Parameters:
      ibase - the underlying item base
      scan - the scanner to read from
      Returns:
      the parsed set of association rules
      Throws:
      IOException - if a read error occurs
      Since:
      2005.07.06 (Christian Borgelt)
    • parse

      public static ARuleSet parse(util.IdMap ibase, Reader reader) throws IOException
      Parse a set of association rules.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      Returns:
      the parsed set of association rules
      Throws:
      IOException - if a read error occurs
      Since:
      2005.07.06 (Christian Borgelt)
    • parse

      public static ARuleSet parse(util.IdMap ibase, String desc) throws IOException
      Parse a set of association rules.
      Parameters:
      ibase - the underlying item base
      desc - the string description to parse
      Returns:
      the parsed set of association rules
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • parse

      public static ARuleSet parse(util.IdMap ibase, InputStream inp) throws IOException
      Parse a set of association rules.
      Parameters:
      ibase - the underlying item base
      inp - the input stream to read from
      Returns:
      the parsed set of association rules
      Throws:
      IOException - if a read error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • main

      public static void main(String[] args)
      Main function for testing some basic functionality.

      It is tried to parse the file that is given as the first command line argument as a set of association rules.

      Parameters:
      args - the command line arguments
      Since:
      2005.07.06 (Christian Borgelt)