Package fim

Class TrActBag

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

public class TrActBag extends Object implements Cloneable, Serializable
Class for a bag/multiset of transactions.
Since:
2007.06.06
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected util.IdMap
    the underlying item base
    protected int
    the current number of transactions
    protected int[]
    the support values of the items; is computed on demand
    protected TrAct[]
    the bag/multiset of transactions
    protected int
    the total weight of all transactions
    protected int
    the maximal weight/multiplicity of a transaction
    protected int
    the minimal weight/multiplicity of a transaction
    protected int
    the maximal size of a transaction
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty bag/multiset of transactions.
    TrActBag(util.IdMap ibase)
    Create an empty bag/multiset of transactions.
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    add(TrAct tract)
    Add a transaction.
    final int
    addTrAct(TrAct tract)
    Add a transaction.
    final void
    Add a transaction bag (the transactions are transferred, not cloned).
    final void
    addTrActBag(TrActBag tabag, boolean clone)
    Add a transaction bag.
    final void
    Clear this transaction bag, that is, remove all transactions.
    final Object
    Clone this bag/multiset of transactions.
    clone(boolean clonebase, boolean clonetracts)
    Clone this bag/multiset of transactions.
    final TrAct
    get(int i)
    Get a transaction.
    final int
    Get the size of the transaction bag (number of transactions).
    final int[]
    Get the cover (list of transaction identifiers) of an item pattern.
    final util.IdMap
    Get the underlying item base.
    final String
    getItemName(int item)
    Get the name of an item.
    final int
    getItemSupp(int item)
    Get the support value of an item (given by its identifier).
    final int
    getItemSuppById(int item)
    Get the support value of an item (given by its identifier).
    final int
    Get the support value of an item (given by its name).
    final int
    Get the support value of an item (given by its object).
    final int[]
    Get the item support values as an array (to be indexed by item identifiers).
    final int
    Get the maximal size of a transaction.
    final int
    Get the maximal weight/multiplicity of a transaction.
    final int
    Get the minimal weight/multiplicity of a transaction.
    final Pattern
    getPattern(int[] items)
    Get the given pattern for this transaction bag.
    final Pattern
    getPattern(int[] items, int cnt)
    Get the given pattern for this transaction bag.
    final Pattern
    Get the given pattern for this transaction bag.
    Get the given pattern set for this transaction bag.
    final ARule
    GetRule(ARule rule)
    Get the given association rule for this transaction bag.
    final ARuleSet
    Get the given association rule set for this transaction bag.
    final int
    Get the size of the transaction bag (number of transactions).
    final int
    getSupport(int[] items)
    Get the support of the given item pattern in this transaction bag.
    final int
    getSupport(int[] items, int cnt)
    Get the support of the given item pattern in this transaction bag.
    final int
    Get the support of the given item pattern in this transaction bag.
    final int[]
    Get the support values of the given pattern set in this transaction bag.
    final int[]
    getSupport(PatternSet patset, int[] supps)
    Get the support values of the given pattern set in this transaction bag.
    final TrAct
    getTrAct(int i)
    Get a transaction.
    final int[][]
    Get all transactions as an array of integer arrays.
    final int
    getTrActSize(int i)
    Get a transaction.
    final int
    Get the total weight of all transactions.
    final int[]
    Get all transaction weights as an array of integers.
    static void
    main(String[] args)
    Main function for testing some basic functionality.
    final void
    Pack the transactions, i.e., optimize memory usage.
    static TrActBag
    parse(util.IdMap ibase, Reader reader)
    Parse a bag/multiset of transactions.
    static TrActBag
    parse(util.IdMap ibase, Reader reader, boolean wgt)
    Parse a bag/multiset of transactions.
    static TrActBag
    parse(util.IdMap ibase, util.TableReader reader)
    Parse a bag/multiset of transactions.
    static TrActBag
    parse(util.IdMap ibase, util.TableReader reader, boolean wgt)
    Parse a bag/multiset of transactions.
    final void
    recodeTo(util.IdMap ibase)
    Recode a transaction bag to another item base, replacing the item base.
    final int
    Reduce the transactions, i.e., combine equal transactions.
    final int
    reduce(int smin)
    Reduce the transactions, i.e., combine equal transactions; optionally remove infrequent items prior to combination.
    final void
    Sort the transactions lexicographically by item identifiers.
    final boolean
    Check for unit weight/multiplicity of all transactions.
    final void
    write(util.TableWriter writer)
    Write a transaction bag/multiset.
    final void
    write(util.TableWriter writer, boolean wgt)
    Write a transaction bag/multiset.

    Methods inherited from class java.lang.Object

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

    • ibase

      protected util.IdMap ibase
      the underlying item base
    • tracts

      protected TrAct[] tracts
      the bag/multiset of transactions
    • size

      protected int size
      the current number of transactions
    • zmax

      protected int zmax
      the maximal size of a transaction
    • wgt

      protected int wgt
      the total weight of all transactions
    • wmin

      protected int wmin
      the minimal weight/multiplicity of a transaction
    • wmax

      protected int wmax
      the maximal weight/multiplicity of a transaction
    • supps

      protected int[] supps
      the support values of the items; is computed on demand
  • Constructor Details

    • TrActBag

      public TrActBag()
      Create an empty bag/multiset of transactions.
      Since:
      2007.06.06 (Christian Borgelt)
    • TrActBag

      public TrActBag(util.IdMap ibase)
      Create an empty bag/multiset of transactions.
      Parameters:
      ibase - the underlying item base
      Since:
      2007.06.06 (Christian Borgelt)
  • Method Details

    • clone

      public final Object clone()
      Clone this bag/multiset of transactions.

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

      Overrides:
      clone in class Object
      Returns:
      a clone of this bag/multiset of transactions
      Since:
      2017.06.20 (Christian Borgelt)
    • clone

      public Object clone(boolean clonebase, boolean clonetracts)
      Clone this bag/multiset of transactions.
      Parameters:
      clonebase - whether to clone the underlying item base
      clonetracts - whether to clone the transactions
      Returns:
      a clone of this bag/multiset of transactions
      Since:
      2017.06.20 (Christian Borgelt)
    • clear

      public final void clear()
      Clear this transaction bag, that is, remove all transactions.
      Since:
      2017.06.20 (Christian Borgelt)
    • getItemBase

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

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

      public final int getSize()
      Get the size of the transaction bag (number of transactions).
      Returns:
      the size of the transaction bag
      Since:
      2007.06.06 (Christian Borgelt)
    • getCount

      public final int getCount()
      Get the size of the transaction bag (number of transactions).
      Returns:
      the size of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getWeight

      public final int getWeight()
      Get the total weight of all transactions.
      Returns:
      the size of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getMaxSize

      public final int getMaxSize()
      Get the maximal size of a transaction.
      Returns:
      the maximal size of a transaction
      Since:
      2007.06.06 (Christian Borgelt)
    • getMinWeight

      public final int getMinWeight()
      Get the minimal weight/multiplicity of a transaction.
      Returns:
      the maximal size of a transaction
      Since:
      2014.10.03 (Christian Borgelt)
    • getMaxWeight

      public final int getMaxWeight()
      Get the maximal weight/multiplicity of a transaction.
      Returns:
      the maximal size of a transaction
      Since:
      2014.10.03 (Christian Borgelt)
    • unitWeight

      public final boolean unitWeight()
      Check for unit weight/multiplicity of all transactions.
      Returns:
      whether all transactions have unit weight/multiplicity
      Since:
      2014.10.03 (Christian Borgelt)
    • get

      public final TrAct get(int i)
      Get a transaction.
      Parameters:
      i - the index of the transaction
      Returns:
      the transaction with index i
      Since:
      2017.06.22 (Christian Borgelt)
    • getTrAct

      public final TrAct getTrAct(int i)
      Get a transaction.
      Parameters:
      i - the index of the transaction
      Returns:
      the transaction with index i
      Since:
      2007.06.06 (Christian Borgelt)
    • getTrActSize

      public final int getTrActSize(int i)
      Get a transaction.
      Parameters:
      i - the index of the transaction
      Returns:
      the transaction with index i
      Since:
      2007.06.06 (Christian Borgelt)
    • add

      public final int add(TrAct tract)
      Add a transaction.
      Parameters:
      tract - the transaction to add
      Returns:
      the index of the transaction in the bag/multiset
      Since:
      2017.06.22 (Christian Borgelt)
    • addTrAct

      public final int addTrAct(TrAct tract)
      Add a transaction.
      Parameters:
      tract - the transaction to add
      Returns:
      the index of the transaction in the bag/multiset
      Since:
      2007.06.06 (Christian Borgelt)
    • addTrActBag

      public final void addTrActBag(TrActBag tabag, boolean clone)
      Add a transaction bag.
      Parameters:
      tabag - the transaction bag to add
      clone - whether to clone the transactions of the given transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • addTrActBag

      public final void addTrActBag(TrActBag tabag)
      Add a transaction bag (the transactions are transferred, not cloned).
      Parameters:
      tabag - the transaction bag to add
      Since:
      2017.06.20 (Christian Borgelt)
    • sort

      public final void sort()
      Sort the transactions lexicographically by item identifiers.
      Since:
      2017.06.20 (Christian Borgelt)
    • reduce

      public final int reduce(int smin)
      Reduce the transactions, i.e., combine equal transactions; optionally remove infrequent items prior to combination.
      Parameters:
      smin - the minimum support of items to keep
      Returns:
      the reduced number of transactions
      Since:
      2017.06.20 (Christian Borgelt)
    • reduce

      public final int reduce()
      Reduce the transactions, i.e., combine equal transactions.
      Returns:
      the reduced number of transactions
      Since:
      2017.06.20 (Christian Borgelt)
    • getItemSupp

      public final int getItemSupp(int item)
      Get the support value of an item (given by its identifier).
      Parameters:
      item - the item for which to get the support value
      Returns:
      the support value of the item with identifier item
      Since:
      2017.06.20 (Christian Borgelt)
    • getItemSuppById

      public final int getItemSuppById(int item)
      Get the support value of an item (given by its identifier).
      Parameters:
      item - the item for which to get the support value
      Returns:
      the support value of the item with identifier item
      Since:
      2017.06.20 (Christian Borgelt)
    • getItemSuppByName

      public final int getItemSuppByName(String item)
      Get the support value of an item (given by its name).
      Parameters:
      item - the name of the item for which to get the support value
      Returns:
      the support value of the item with name item
      Since:
      2017.06.20 (Christian Borgelt)
    • getItemSuppByObject

      public final int getItemSuppByObject(Object item)
      Get the support value of an item (given by its object).
      Parameters:
      item - the object of the item for which to get the support value
      Returns:
      the support value of the item with object item
      Since:
      2017.06.20 (Christian Borgelt)
    • getItemSupps

      public final int[] getItemSupps()
      Get the item support values as an array (to be indexed by item identifiers).
      Returns:
      an array with the support values of the items
      Since:
      2017.06.20 (Christian Borgelt)
    • getCoverOf

      public final int[] getCoverOf(Pattern pat)
      Get the cover (list of transaction identifiers) of an item pattern.
      Parameters:
      pat - the item pattern for which to get the cover
      Returns:
      an array of indices of transactions in which the item pattern is contained
      Since:
      2017.06.20 (Christian Borgelt)
    • getSupport

      public final int getSupport(Pattern pat)
      Get the support of the given item pattern in this transaction bag.
      Parameters:
      pat - the item pattern for which to get the support in this transaction bag
      Returns:
      the support of the given item pattern in this transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getSupport

      public final int getSupport(int[] items, int cnt)
      Get the support of the given item pattern in this transaction bag.
      Parameters:
      items - the array of items to of the pattern for which to get the support in this transaction bag (may be oversized)
      cnt - the number of items in the given array to consider; if negative, the length of the item array itemsis used
      Returns:
      the support of the given item pattern in this transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getSupport

      public final int getSupport(int[] items)
      Get the support of the given item pattern in this transaction bag.
      Parameters:
      items - the array of items to of the pattern for which to get the support in this transaction bag
      Returns:
      the support of the given item pattern in this transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getSupport

      public final int[] getSupport(PatternSet patset, int[] supps)
      Get the support values of the given pattern set in this transaction bag.
      Parameters:
      patset - the item pattern set which to get the support values in this transaction bag
      supps - the array into which to store the support values if null, a new array is created, otherwise it must have at least size patset.getSize()
      Returns:
      an array of support values, with as many entries as there are patterns in the given pattern set, containing the support values of the item patterns in this transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getSupport

      public final int[] getSupport(PatternSet patset)
      Get the support values of the given pattern set in this transaction bag.
      Parameters:
      patset - the item pattern set which to get the support values in this transaction bag
      Returns:
      an array of support values, with as many entries as there are patterns in the given pattern set, containing the support values of the item patterns in this transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getPattern

      public final Pattern getPattern(Pattern pat)
      Get the given pattern for this transaction bag.
      Parameters:
      pat - the item pattern which to get for this transaction bag
      Returns:
      a new pattern with the same items, but with the item base and the support values of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getPattern

      public final Pattern getPattern(int[] items, int cnt)
      Get the given pattern for this transaction bag.
      Parameters:
      items - the array of items to of the pattern to get (may be oversized)
      cnt - the number of items in the given array to consider; if negative, the length of the item array itemsis used
      Returns:
      a new pattern with the same items, but with the item base and the support values of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getPattern

      public final Pattern getPattern(int[] items)
      Get the given pattern for this transaction bag.
      Parameters:
      items - the array of items to of the pattern to get (may be oversized)
      Returns:
      a new pattern with the same items, but with the item base and the support values of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getPatternSet

      public final PatternSet getPatternSet(PatternSet patset)
      Get the given pattern set for this transaction bag.
      Parameters:
      patset - the item pattern set which to get for this transaction bag
      Returns:
      a new pattern set with the same patterns, but with the item base and the support values of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • GetRule

      public final ARule GetRule(ARule rule)
      Get the given association rule for this transaction bag.
      Parameters:
      rule - the association rule which to get for this transaction bag
      Returns:
      a new association rule with the same items, but with the item base and the support values of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • getRuleSet

      public final ARuleSet getRuleSet(ARuleSet ruleset)
      Get the given association rule set for this transaction bag.
      Parameters:
      ruleset - the association rule set which to get for this transaction bag
      Returns:
      a new association rule set with the same rules, but with the item base and the support values of the transaction bag
      Since:
      2017.06.20 (Christian Borgelt)
    • recodeTo

      public final void recodeTo(util.IdMap ibase)
      Recode a transaction bag to another item base, replacing the item base.
      Parameters:
      ibase - the item base to recode the transaction bag to
      Since:
      2017.06.20 (Christian Borgelt)
    • pack

      public final void pack()
      Pack the transactions, i.e., optimize memory usage.
      Since:
      2014.10.03 (Christian Borgelt)
    • getTrActs

      public final int[][] getTrActs()
      Get all transactions as an array of integer arrays.
      Returns:
      all transactions as an array of integer arrays.
      Since:
      2014.10.03 (Christian Borgelt)
    • getWeights

      public final int[] getWeights()
      Get all transaction weights as an array of integers.
      Returns:
      all transaction weights as an array of integers
      Since:
      2014.10.23 (Christian Borgelt)
    • write

      public final void write(util.TableWriter writer) throws IOException
      Write a transaction bag/multiset.
      Parameters:
      writer - the table writer to write to
      Throws:
      IOException - if a write error occurs
      Since:
      2007.06.06 (Christian Borgelt)
    • write

      public final void write(util.TableWriter writer, boolean wgt) throws IOException
      Write a transaction bag/multiset.
      Parameters:
      writer - the table writer to write to
      wgt - whether to write transaction weights/multiplicities
      Throws:
      IOException - if a write error occurs
      Since:
      2014.10.02 (Christian Borgelt)
    • parse

      public static TrActBag parse(util.IdMap ibase, util.TableReader reader, boolean wgt) throws IOException
      Parse a bag/multiset of transactions.
      Parameters:
      ibase - the underlying item base
      reader - the table reader to read from
      wgt - whether to read transaction weights/multiplicities
      Returns:
      the parsed bag/multiset of transactions
      Throws:
      IOException - if a read error occurs
      Since:
      2014.10.02 (Christian Borgelt)
    • parse

      public static TrActBag parse(util.IdMap ibase, util.TableReader reader) throws IOException
      Parse a bag/multiset of transactions.
      Parameters:
      ibase - the underlying item base
      reader - the table reader to read from
      Returns:
      the parsed bag/multiset of transactions
      Throws:
      IOException - if a read error occurs
      Since:
      2007.06.06 (Christian Borgelt)
    • parse

      public static TrActBag parse(util.IdMap ibase, Reader reader, boolean wgt) throws IOException
      Parse a bag/multiset of transactions.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      wgt - whether to read transaction weights/multiplicities
      Returns:
      the parsed bag/multiset of transactions
      Throws:
      IOException - if a read error occurs
      Since:
      2014.10.02 (Christian Borgelt)
    • parse

      public static TrActBag parse(util.IdMap ibase, Reader reader) throws IOException
      Parse a bag/multiset of transactions.
      Parameters:
      ibase - the underlying item base
      reader - the reader to read from
      Returns:
      the parsed bag/multiset of transactions
      Throws:
      IOException - if a read error occurs
      Since:
      2014.10.02 (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 bag/multiset of transactions.

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