Package fim

Class PatternSet

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

public class PatternSet extends Object implements Cloneable, PatternReceiver, Serializable
Class for a set of patterns/item sets.
Since:
2013.11.28
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Interface for a comparator for pattern signatures.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    reduction mode: reduce to closed item patterns; identical to MAXSIZE (since the union of the maximum size patterns for each support value are the closed patterns)
    static final int
    reduction mode: excess coincidences (zb,cb-ca)
    static final int
    reduction mode: excess coincidences (zb,cb-ca+1)
    static final int
    reduction mode: covered points/spikes za*ca : zb*cb
    static final int
    reduction mode: covered points/spikes (za-1)*ca : (zb-1)*cb
    static final int
    sort mode: evaluation
    static final int
    selection mode: find exact match of given pattern
    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: excess items/neurons (za-zb+2,ca)
    static final int
    reduction mode: compare only the items (not support)
    static final int
    reduction mode: none (keep all patterns after filtering)
    static final int
    reduction mode: combined lenient (z, break rejection tie)
    static final int
    reduction mode: combined lenient (z-1, break rejection tie)
    static final int
    reduction mode: reduce to maximal item patterns; combination of MAXSIZE and ITEMSONLY
    static final int
    reduction mode: maximize size of item patterns
    static final int
    reduction mode: minimize size of item patterns
    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 Pattern[]
    the set of patterns/item sets
    protected int
    the current number of patterns
    static final int
    sort mode: size / number of items
    static final int
    reduction mode: combined strict (z, force decision)
    static final int
    reduction mode: combined strict (z-1, force decision)
    static final int
    selection mode: find subpattern(s) of given pattern (or exact match)
    static final int
    selection mode: find superpattern(s) of given pattern (or exact match)
    static final int
    sort mode: support
    protected int[]
    the support values of individual items
    static final int
    reduction mode: remove duplicates/ensure unique patterns
    protected int
    the maximal size of a pattern
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty set of item patterns.
    PatternSet(util.IdMap ibase)
    Create an empty set of item patterns.
    PatternSet(util.IdMap ibase, int s_base, Object[] ipats)
    Create an item pattern set from FIM output.
    PatternSet(util.IdMap ibase, Object[] ipats)
    Create a pattern set from CoCoNAD output.
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    add(Pattern pat)
    Add a pattern/item set.
    final int
    Add a pattern/item set.
    final void
    Add an item pattern set.
    final void
    addPatternSet(PatternSet patset, boolean clonepats)
    Add an item pattern set.
    final void
    Clear this item pattern set, that is, remove all patterns.
    final Object
    Clone this item pattern set.
    clone(boolean clonebase, boolean clonepats)
    Clone this item pattern set.
    boolean
    Check whether two item pattern sets are equal.
    final int
    filter(int zmin, int zmax)
    Filter an item pattern set by size.
    final Pattern
    get(int i)
    Get a pattern.
    final Pattern[]
    Get all item patterns 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 int
    Get the number of patterns.
    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 leat one pattern.
    final int
    Get the maximal size of a pattern.
    final Pattern
    getPattern(int i)
    Get a pattern.
    final int
    Get the size of an item patterns.
    final int
    Get the number of patterns.
    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.
    final int
    getSupport(int i)
    Get the support of a pattern.
    static void
    main(String[] args)
    Main function for testing some basic functionality.
    final void
    Pack the patterns, i.e., optimize memory usage.
    static PatternSet
    parse(util.IdMap ibase, InputStream inp)
    Parse a set of item patterns.
    static PatternSet
    parse(util.IdMap ibase, Reader reader)
    Parse a set of item patterns.
    static PatternSet
    parse(util.IdMap ibase, String desc)
    Parse a set of item patterns.
    static PatternSet
    parse(util.IdMap ibase, util.Scanner scan)
    Parse a set of item patterns.
    void
    receive(int[] items, int cnt, int s_pat, int s_base)
    Receive an item pattern (implements PatternReceiver).
    final void
    recode(util.IdMap ibase)
    Recode a pattern set to another item base, replacing the item base.
    final int
    reduce(int mode)
    Reduce an item pattern set.
    final int
    reduce(int method, int[] border, boolean addis)
    Reduce a set of item patterns (by pattern signatures).
    final void
    Reverse the order of the patterns in a pattern set.
    select(int[] items, int cnt, int mode)
    Select patterns that are subpatterns, superpatterns or an exact match of the given pattern (in terms of the contained items).
    select(Pattern pat, int mode)
    Select patterns that are subpatterns, superpatterns or an exact match of the given pattern (in terms of the contained items).
    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 a set of item patterns.
    final void
    sort(int valid)
    Sort a set of item patterns.
    final void
    sort(int valid, int dir)
    Sort a set of item patterns.
    final void
    Sort the items in the patterns of an item pattern set.
    final void
    write(Writer writer)
    Write a set of item patterns.
    final void
    write(Writer writer, String addinfo)
    Write a set of item patterns.
    final void
    write(Writer writer, String isep, String addinfo)
    Write a set of item patterns.

    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:
    • SUPP

      public static final int SUPP
      sort mode: support
      See Also:
    • EVAL

      public static final int EVAL
      sort mode: evaluation
      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 patterns
      See Also:
    • MINSIZE

      public static final int MINSIZE
      reduction mode: minimize size of item patterns
      See Also:
    • MAXSIZE

      public static final int MAXSIZE
      reduction mode: maximize size of item patterns
      See Also:
    • ITEMSONLY

      public static final int ITEMSONLY
      reduction mode: compare only the items (not support)
      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:
    • CLOSED

      public static final int CLOSED
      reduction mode: reduce to closed item patterns; identical to MAXSIZE (since the union of the maximum size patterns for each support value are the closed patterns)
      See Also:
    • MAXIMAL

      public static final int MAXIMAL
      reduction mode: reduce to maximal item patterns; combination of MAXSIZE and ITEMSONLY
      See Also:
    • KEEP

      public static final int KEEP
      reduction mode: none (keep all patterns after filtering)
      See Also:
    • COINS0

      public static final int COINS0
      reduction mode: excess coincidences (zb,cb-ca)
      See Also:
    • COINS1

      public static final int COINS1
      reduction mode: excess coincidences (zb,cb-ca+1)
      See Also:
    • ITEMS2

      public static final int ITEMS2
      reduction mode: excess items/neurons (za-zb+2,ca)
      See Also:
    • COVER0

      public static final int COVER0
      reduction mode: covered points/spikes za*ca : zb*cb
      See Also:
    • COVER1

      public static final int COVER1
      reduction mode: covered points/spikes (za-1)*ca : (zb-1)*cb
      See Also:
    • LENIENT0

      public static final int LENIENT0
      reduction mode: combined lenient (z, break rejection tie)
      See Also:
    • LENIENT1

      public static final int LENIENT1
      reduction mode: combined lenient (z-1, break rejection tie)
      See Also:
    • STRICT0

      public static final int STRICT0
      reduction mode: combined strict (z, force decision)
      See Also:
    • STRICT1

      public static final int STRICT1
      reduction mode: combined strict (z-1, force decision)
      See Also:
    • EXACT

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

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

      public static final int SUB
      selection mode: find subpattern(s) of given pattern (or exact match)
      See Also:
    • ibase

      protected util.IdMap ibase
      the underlying item base
    • size

      protected int size
      the current number of patterns
    • zmax

      protected int zmax
      the maximal size of a pattern
    • pats

      protected Pattern[] pats
      the set of patterns/item sets
    • supps

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

    • PatternSet

      public PatternSet()
      Create an empty set of item patterns.
      Since:
      2013.11.28 (Christian Borgelt)
    • PatternSet

      public PatternSet(util.IdMap ibase)
      Create an empty set of item patterns.
      Parameters:
      ibase - the underlying item base
      Since:
      2013.11.28 (Christian Borgelt)
    • PatternSet

      public PatternSet(util.IdMap ibase, Object[] ipats)
      Create a pattern set from CoCoNAD output.
      Parameters:
      ibase - the underlying item base
      ipats - the output of the native function JNICoCo.coconad()
      Since:
      2013.11.28 (Christian Borgelt)
    • PatternSet

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

    • clone

      public final Object clone()
      Clone this item pattern set.

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

      Overrides:
      clone in class Object
      Returns:
      a clone of this item pattern set
      Since:
      2017.06.16 (Christian Borgelt)
    • clone

      public Object clone(boolean clonebase, boolean clonepats)
      Clone this item pattern set.
      Parameters:
      clonebase - whether to clone the underlying item base
      clonepats - whether to clone the item patterns
      Returns:
      a clone of this item pattern set
      Since:
      2017.06.16 (Christian Borgelt)
    • clear

      public final void clear()
      Clear this item pattern set, that is, remove all patterns.
      Since:
      2017.06.16 (Christian Borgelt)
    • getItemBase

      public final util.IdMap getItemBase()
      Get the underlying item base.
      Returns:
      the underlying item base
      Since:
      2013.11.28 (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 i
      Since:
      2013.11.28 (Christian Borgelt)
    • getSize

      public final int getSize()
      Get the number of patterns.
      Returns:
      the number of patterns
      Since:
      2017.06.17 (Christian Borgelt)
    • getCount

      public final int getCount()
      Get the number of patterns.
      Returns:
      the number of patterns
      Since:
      2013.11.28 (Christian Borgelt)
    • get

      public final Pattern get(int i)
      Get a pattern.
      Parameters:
      i - the index of the pattern
      Returns:
      the pattern with index i
      Since:
      2017.06.22 (Christian Borgelt)
    • getPattern

      public final Pattern getPattern(int i)
      Get a pattern.
      Parameters:
      i - the index of the pattern
      Returns:
      the pattern with index i
      Since:
      2013.11.28 (Christian Borgelt)
    • getAllPatterns

      public final Pattern[] getAllPatterns()
      Get all item patterns as an array (array length fits only after packing with pack(); should be considered read only).
      Returns:
      the array of item patterns
      Since:
      2017.06.29 (Christian Borgelt)
    • getPatternSize

      public final int getPatternSize(int i)
      Get the size of an item patterns.
      Parameters:
      i - the index of the pattern
      Returns:
      the size of the item pattern with index i
      Since:
      2017.06.17 (Christian Borgelt)
    • getSupport

      public final int getSupport(int i)
      Get the support of a pattern.
      Parameters:
      i - the index of the pattern
      Returns:
      the support of the pattern with index i
      Since:
      2013.11.28 (Christian Borgelt)
    • add

      public final int add(Pattern pat)
      Add a pattern/item set.
      Parameters:
      pat - the pattern to add
      Returns:
      the index of the pattern in the set
      Since:
      2017.06.22 (Christian Borgelt)
    • addPattern

      public final int addPattern(Pattern pat)
      Add a pattern/item set.
      Parameters:
      pat - the pattern to add
      Returns:
      the index of the pattern in the set
      Since:
      2013.11.28 (Christian Borgelt)
    • addPatternSet

      public final void addPatternSet(PatternSet patset)
      Add an item pattern set.
      Parameters:
      patset - the pattern set to add
      Since:
      2017.06.17 (Christian Borgelt)
    • addPatternSet

      public final void addPatternSet(PatternSet patset, boolean clonepats)
      Add an item pattern set.
      Parameters:
      patset - the pattern set to add
      clonepats - whether to clone the patterns of the given set
      Since:
      2017.06.17 (Christian Borgelt)
    • receive

      public void receive(int[] items, int cnt, int s_pat, int s_base)
      Receive an item pattern (implements PatternReceiver).
      Specified by:
      receive in interface PatternReceiver
      Parameters:
      items - the items in the item pattern (may be an oversized buffer)
      cnt - 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:
      2017.06.29 (Christian Borgelt)
    • getMaxSize

      public final int getMaxSize()
      Get the maximal size of a pattern.
      Returns:
      the maximal size of a pattern
      Since:
      2013.11.28 (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.17 (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.17 (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.17 (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.17 (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.17 (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.17 (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.17 (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.17 (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.17 (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.17 (Christian Borgelt)
    • sortItems

      public final void sortItems()
      Sort the items in the patterns of an item pattern set.
      Since:
      2015.08.12 (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 a set of item patterns.
      Since:
      2014.10.05 (Christian Borgelt)
    • sort

      public final void sort(int valid)
      Sort a set of item patterns.
      Parameters:
      valid - the identifier of the value to compare first
      Since:
      2014.10.05 (Christian Borgelt)
    • sort

      public final void sort(int valid, int dir)
      Sort a set of item patterns.
      Parameters:
      valid - the identifier of the field to compare first
      dir - the sort direction (positive: ascending, negative: descending)
      Since:
      2014.10.05 (Christian Borgelt)
    • reverse

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

      public boolean equals(PatternSet patset)
      Check whether two item pattern sets are equal. It is assumed that both item pattern sets have been sorted with a call to the function sort() with parameter ITEMS. If the item pattern set represents item sets instead of permutations or sequences, it is also assumed that the items in each pattern have been sorted by a call to the function sortItems()
      Parameters:
      patset - the pattern set to compare to
      Returns:
      true if the two item pattern sets contain the same patterns (in the same order) and false otherwise /*------------------------------------------------------------------
    • reduce

      public final int reduce(int mode)
      Reduce an item pattern set.
      Parameters:
      mode - the reduction mode (e.g. MINSIZE)
      Returns:
      the new number of item patterns
      Since:
      2016.06.27 (Christian Borgelt)
    • reduce

      public final int reduce(int method, int[] border, boolean addis)
      Reduce a set of item patterns (by pattern signatures).
      Parameters:
      method - the pattern set reduction method (one of KEEP, COINS0, COINS1, ITEMS2, COVER0, COVER1, LENIENT0, LENIENT1, STRICT0, STRICT1)
      border - the decision border for rejecting patterns
      addis - whether to add pattern intersections
      Returns:
      the new number of patterns
      Since:
      2015.08.12 (Christian Borgelt)
    • filter

      public final int filter(int zmin, int zmax)
      Filter an item pattern set by size.
      Parameters:
      zmin - the minimum size of the patterns to keep
      zmax - the maximum size of the patterns to keep
      Returns:
      the new number of item patterns
      Since:
      2017.06.17 (Christian Borgelt)
    • select

      public final PatternSet select(Pattern pat, int mode)
      Select patterns that are subpatterns, superpatterns or an exact match of the given pattern (in terms of the contained items).
      Parameters:
      pat - the pattern with which to select patterns
      mode - the mode with which to select patterns; either EXACT, SUPERPAT, or SUBPAT.
      Returns:
      a pattern set with the qualifying patterns (uncloned)
      Since:
      2017.06.17 (Christian Borgelt)
    • select

      public final PatternSet select(int[] items, int cnt, int mode)
      Select patterns that are subpatterns, superpatterns or an exact match of the given pattern (in terms of the contained items).
      Parameters:
      items - the items of the pattern to compare to
      cnt - the number of items; if negative, the length of the given item array is used
      mode - the mode with which to select patterns; either EXACT, SUPERPAT, or SUBPAT.
      Returns:
      a pattern set with the qualifying patterns (uncloned)
      Since:
      2017.06.17 (Christian Borgelt)
    • getItems

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

      public final void recode(util.IdMap ibase)
      Recode a pattern set to another item base, replacing the item base.
      Parameters:
      ibase - the item base to recode the pattern set to
      Since:
      2017.06.17 (Christian Borgelt)
    • pack

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

      public final void write(Writer writer) throws IOException
      Write a set of item patterns.
      Parameters:
      writer - the writer to write to
      Throws:
      IOException - if a write error occurs
      Since:
      2013.11.28 (Christian Borgelt)
    • write

      public final void write(Writer writer, String addinfo) throws IOException
      Write a set of item patterns.
      Parameters:
      writer - the writer to write to
      addinfo - the additional information to write
      Throws:
      IOException - if a write error occurs
      Since:
      2017.06.27 (Christian Borgelt)
    • write

      public final void write(Writer writer, String isep, String addinfo) throws IOException
      Write a set of item patterns.
      Parameters:
      writer - the writer to write to
      isep - the item separator
      addinfo - the additional information to write
      Throws:
      IOException - if a write error occurs
      Since:
      2017.06.27 (Christian Borgelt)
    • parse

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

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

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

      public static PatternSet parse(util.IdMap ibase, InputStream inp) throws IOException
      Parse a set of item patterns.
      Parameters:
      ibase - the underlying item base
      inp - the input stream to read from
      Returns:
      the parsed set of patterns
      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 patterns.

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