Package fim
Class PatternSet
java.lang.Object
fim.PatternSet
- All Implemented Interfaces:
PatternReceiver
,Serializable
,Cloneable
Class for a set of patterns/item sets.
- Since:
- 2013.11.28
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface for a comparator for pattern signatures. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
reduction mode: reduce to closed item patterns; identical toMAXSIZE
(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*cbstatic final int
reduction mode: covered points/spikes (za-1)*ca : (zb-1)*cbstatic final int
sort mode: evaluationstatic final int
selection mode: find exact match of given patternprotected util.IdMap
the underlying item basestatic 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 ofMAXSIZE
andITEMSONLY
static final int
reduction mode: maximize size of item patternsstatic final int
reduction mode: minimize size of item patternsstatic final int
reduction mode: do not use aCloMaxFilter
, but rather work directly on the item pattern arraystatic final int
reduction mode: do nothingprotected Pattern[]
the set of patterns/item setsprotected int
the current number of patternsstatic final int
sort mode: size / number of itemsstatic 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: supportprotected int[]
the support values of individual itemsstatic final int
reduction mode: remove duplicates/ensure unique patternsprotected int
the maximal size of a pattern -
Constructor Summary
ConstructorsConstructorDescriptionCreate 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 TypeMethodDescriptionfinal int
Add a pattern/item set.final int
addPattern
(Pattern pat) Add a pattern/item set.final void
addPatternSet
(PatternSet patset) Add an item pattern set.final void
addPatternSet
(PatternSet patset, boolean clonepats) Add an item pattern set.final void
clear()
Clear this item pattern set, that is, remove all patterns.final Object
clone()
Clone this item pattern set.clone
(boolean clonebase, boolean clonepats) Clone this item pattern set.boolean
equals
(PatternSet patset) 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 withpack()
; should be considered read only).final int[]
Get the support values of all individual items.final int
getCount()
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[]
getItems()
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
getPatternSize
(int i) Get the size of an item patterns.final int
getSize()
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
getSuppByName
(String item) Get the support of an individual item.final int
getSuppByObject
(Object item) Get the support of an individual item.final int
getSupport
(int i) Get the support of a pattern.static void
Main function for testing some basic functionality.final void
pack()
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 a set of item patterns.static PatternSet
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 (implementsPatternReceiver
).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()
Reverse the order of the patterns in a pattern set.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).final PatternSet
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()
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 a set of item patterns.final void
Write a set of item patterns.final void
Write a set of item patterns.
-
Field Details
-
ITEMS
public static final int ITEMSsort mode: items (in the order in which they appear)- See Also:
-
SIZE
public static final int SIZEsort mode: size / number of items- See Also:
-
SUPP
public static final int SUPPsort mode: support- See Also:
-
EVAL
public static final int EVALsort mode: evaluation- See Also:
-
NONE
public static final int NONEreduction mode: do nothing- See Also:
-
UNIQUE
public static final int UNIQUEreduction mode: remove duplicates/ensure unique patterns- See Also:
-
MINSIZE
public static final int MINSIZEreduction mode: minimize size of item patterns- See Also:
-
MAXSIZE
public static final int MAXSIZEreduction mode: maximize size of item patterns- See Also:
-
ITEMSONLY
public static final int ITEMSONLYreduction mode: compare only the items (not support)- See Also:
-
NOFILTER
public static final int NOFILTERreduction mode: do not use aCloMaxFilter
, but rather work directly on the item pattern array- See Also:
-
CLOSED
public static final int CLOSEDreduction mode: reduce to closed item patterns; identical toMAXSIZE
(since the union of the maximum size patterns for each support value are the closed patterns)- See Also:
-
MAXIMAL
public static final int MAXIMALreduction mode: reduce to maximal item patterns; combination ofMAXSIZE
andITEMSONLY
- See Also:
-
KEEP
public static final int KEEPreduction mode: none (keep all patterns after filtering)- See Also:
-
COINS0
public static final int COINS0reduction mode: excess coincidences (zb,cb-ca)- See Also:
-
COINS1
public static final int COINS1reduction mode: excess coincidences (zb,cb-ca+1)- See Also:
-
ITEMS2
public static final int ITEMS2reduction mode: excess items/neurons (za-zb+2,ca)- See Also:
-
COVER0
public static final int COVER0reduction mode: covered points/spikes za*ca : zb*cb- See Also:
-
COVER1
public static final int COVER1reduction mode: covered points/spikes (za-1)*ca : (zb-1)*cb- See Also:
-
LENIENT0
public static final int LENIENT0reduction mode: combined lenient (z, break rejection tie)- See Also:
-
LENIENT1
public static final int LENIENT1reduction mode: combined lenient (z-1, break rejection tie)- See Also:
-
STRICT0
public static final int STRICT0reduction mode: combined strict (z, force decision)- See Also:
-
STRICT1
public static final int STRICT1reduction mode: combined strict (z-1, force decision)- See Also:
-
EXACT
public static final int EXACTselection mode: find exact match of given pattern- See Also:
-
SUPER
public static final int SUPERselection mode: find superpattern(s) of given pattern (or exact match)- See Also:
-
SUB
public static final int SUBselection mode: find subpattern(s) of given pattern (or exact match)- See Also:
-
ibase
protected util.IdMap ibasethe underlying item base -
size
protected int sizethe current number of patterns -
zmax
protected int zmaxthe maximal size of a pattern -
pats
the set of patterns/item sets -
supps
protected int[] suppsthe 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
Create a pattern set from CoCoNAD output.- Parameters:
ibase
- the underlying item baseipats
- the output of the native functionJNICoCo.coconad()
- Since:
- 2013.11.28 (Christian Borgelt)
-
PatternSet
Create an item pattern set from FIM output.- Parameters:
ibase
- the underlying item bases_base
- the number of transactions from which the (frequent) item patterns where derivedipats
- the output of a native functionJNIFIM.xxx()
, called withreport="[a|s]"
orreport="[a|s][e|E]"
- Since:
- 2014.10.03 (Christian Borgelt)
-
-
Method Details
-
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.
-
clone
Clone this item pattern set.- Parameters:
clonebase
- whether to clone the underlying item baseclonepats
- 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
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
Get a pattern.- Parameters:
i
- the index of the pattern- Returns:
- the pattern with index
i
- Since:
- 2017.06.22 (Christian Borgelt)
-
getPattern
Get a pattern.- Parameters:
i
- the index of the pattern- Returns:
- the pattern with index
i
- Since:
- 2013.11.28 (Christian Borgelt)
-
getAllPatterns
Get all item patterns as an array (array length fits only after packing withpack()
; 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
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
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
Add an item pattern set.- Parameters:
patset
- the pattern set to add- Since:
- 2017.06.17 (Christian Borgelt)
-
addPatternSet
Add an item pattern set.- Parameters:
patset
- the pattern set to addclonepats
- 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 (implementsPatternReceiver
).- Specified by:
receive
in interfacePatternReceiver
- Parameters:
items
- the items in the item pattern (may be an oversized buffer)cnt
- the number of items in the patterns_pat
- the (absolute) support of the item patterns_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
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
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 valuesupp
- 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 valuesupp
- the support value to set for the item- Since:
- 2017.06.17 (Christian Borgelt)
-
setSuppByName
Set the support of an individual item.- Parameters:
item
- the item name for which to set the support valuesupp
- the support value to set for the item- Since:
- 2017.06.17 (Christian Borgelt)
-
setSuppByObject
Set the support of an individual item.- Parameters:
item
- the item name for which to set the support valuesupp
- 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 ondir
- 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 firstdir
- 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
Check whether two item pattern sets are equal. It is assumed that both item pattern sets have been sorted with a call to the functionsort()
with parameterITEMS
. 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 functionsortItems()
- Parameters:
patset
- the pattern set to compare to- Returns:
true
if the two item pattern sets contain the same patterns (in the same order) andfalse
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 ofKEEP
,COINS0
,COINS1
,ITEMS2
,COVER0
,COVER1
,LENIENT0
,LENIENT1
,STRICT0
,STRICT1
)border
- the decision border for rejecting patternsaddis
- 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 keepzmax
- the maximum size of the patterns to keep- Returns:
- the new number of item patterns
- Since:
- 2017.06.17 (Christian Borgelt)
-
select
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 patternsmode
- the mode with which to select patterns; eitherEXACT
,SUPERPAT
, orSUBPAT
.- Returns:
- a pattern set with the qualifying patterns (uncloned)
- Since:
- 2017.06.17 (Christian Borgelt)
-
select
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 tocnt
- the number of items; if negative, the length of the given item array is usedmode
- the mode with which to select patterns; eitherEXACT
,SUPERPAT
, orSUBPAT
.- 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
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
Write a set of item patterns.- Parameters:
writer
- the writer to write toaddinfo
- the additional information to write- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.27 (Christian Borgelt)
-
write
Write a set of item patterns.- Parameters:
writer
- the writer to write toisep
- the item separatoraddinfo
- the additional information to write- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.27 (Christian Borgelt)
-
parse
Parse a set of item patterns.- Parameters:
ibase
- the underlying item basescan
- 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
Parse a set of item patterns.- Parameters:
ibase
- the underlying item basereader
- 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
Parse a set of item patterns.- Parameters:
ibase
- the underlying item basedesc
- 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
Parse a set of item patterns.- Parameters:
ibase
- the underlying item baseinp
- 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
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)
-