Class Pattern
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<Pattern>
- Since:
- 2013.11.28
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
the comparison direction for sorting item patternsprotected double
the evaluation of the (frequent) item patternprotected util.IdMap
the underlying item baseprotected int[]
the items of the item patternprotected int
the (absolute) base support (number of transactions)protected int
the (absolute) support of the (frequent) item patternprotected int
the current number of itemsprotected double
the value for sorting item patternsprotected double
the weight of the (frequent) item pattern (e.g. -
Constructor Summary
ConstructorsConstructorDescriptionPattern()
Create an empty item pattern.Pattern
(util.IdMap ibase) Create an empty item pattern.Pattern
(util.IdMap ibase, int[] items, int supp) Create a item pattern from an item array (the item array is stored, not copied).Pattern
(util.IdMap ibase, int[] items, int s_pat, int s_base) Create a item pattern from an item array (the item array is stored, not copied).Pattern
(util.IdMap ibase, int[] items, int s_pat, int s_base, double eval) Create an item pattern from an item array (the item array is stored, not copied).Pattern
(util.IdMap ibase, int[] items, int s_pat, int s_base, double eval, double wgt) Create an item pattern from an item array (the item array is stored, not copied).Pattern
(util.IdMap ibase, int[] items, int cnt, int s_pat, int s_base) Create a item pattern from an item array (the item array is copied).Pattern
(util.IdMap ibase, int[] items, int cnt, int s_pat, int s_base, double eval) Create an item pattern from an item array (the item array is copied).Pattern
(util.IdMap ibase, int[] items, int cnt, int s_pat, int s_base, double eval, double wgt) Create an item pattern from an item array (the item array is copied). -
Method Summary
Modifier and TypeMethodDescriptionfinal int
addItem
(int item) Add an item to the item pattern.final int
Add an item to the pattern.final int
addItemById
(int item) Add an item (given by its identifier) to the item pattern.final int
addItemByName
(String item) Add an item (given by its name) to the pattern.final int
addItemByObject
(Object item) Add an item (given by its object) to the pattern.final int
Compare this pattern to another (given as argument) by comparing its items lexicographically and its support.final Object
clone()
Clone this item pattern (the item base is kept, the item array is copied).final Object
clone
(boolean iclone) Clone this item pattern (the item base is replaced).final Object
clone
(boolean iclone, util.IdMap ibase) Clone this item pattern (the item base is replaced).final Object
clone
(util.IdMap ibase) Clone this item pattern (the item base is kept, the item array is copied).clone
(util.IdMap ibase, boolean iclone) Clone this item pattern (the item base is kept, the item array is copied).final int
Compare this item pattern to another (given as argument).final boolean
Whether this item pattern contains another item pattern.final boolean
Whether this item pattern contains a given transaction.final boolean
equals
(int[] items, int cnt) Compare the pattern's items to a given item pattern.final boolean
Check whether this pattern is equal to another (given as argument).boolean
Check whether this pattern is equal to another (given as argument).final int
Get the (absolute) support of the item pattern.final int[]
Get the item array (length/size fits only after packing withpack()
; should be considered read only).final int
Get the (absolute) support of the empty pattern (i.e.final int
getCount()
Get the size of the item pattern (number of items).final int[]
Get the cover (list of transaction identifiers) of an item pattern w.r.t.final double
getEval()
Get the value of the additional evaluation measure.final int
getItem
(int i) Get an item (i.e., its identifier).final int
getItemId
(int i) Get an item identifier (as assigned by the underlying item base).final String
getItemName
(int i) Get the name of an item.final Object
getItemObject
(int i) Get the object of an item.final double
Get the (relative) support of the item pattern.final int
getSize()
Get the size of the item pattern (number of items).final int
getSupp()
Get the support of the item pattern.final double
Get the weight of the pattern (e.g.final boolean
isContainedIn
(Pattern pat) Whether this item pattern is contained in another item pattern.final boolean
isContainedIn
(TrAct tract) Whether this item pattern is a contained in a transaction.protected final int
Create the intersection of two item patterns.final boolean
isSubOf
(int[] items, int cnt) Check whether this item pattern is a subpattern of another item pattern, given as an array of items.final boolean
Check whether this item pattern is a subpattern of another item pattern.final boolean
isSuperOf
(int[] items, int cnt) Whether this item pattern is a superpattern of a given item pattern.final boolean
Whether this item pattern is a superpattern of another item pattern.final int
itemsCmpTo
(Pattern pat) Compare this pattern to another (given as argument) by comparing its items lexicographically.final void
pack()
Pack an item pattern, i.e., optimize memory usage.static Pattern
parse
(util.IdMap ibase, InputStream inp) Parse an item pattern.static Pattern
Parse an item pattern.static Pattern
Parse an item pattern.static Pattern
parse
(util.IdMap ibase, util.Scanner scan) Parse an item pattern.final void
recode
(util.IdMap ibase, int[] map) Recode a pattern to another item base, replacing the item base.final void
setSort
(double value, int dir) Set sort value and sort direction.final void
setSort
(int value, int dir) Set sort value and sort direction.final void
sort()
Sort the items of an item pattern.static boolean
subpattern
(int[] itemsA, int cntA, int[] itemsB, int cntB) Check whether a given array of items, representing an item pattern, is a subpattern of another item pattern, given as a second given array of items.final int
Compare this item pattern to another (given as argument) w.r.t.final String
toString()
Create a string description.final String
Create a string description.Create a string description.final void
Write an item pattern.final void
Write an item pattern.final void
Write an item pattern.
-
Field Details
-
ibase
protected util.IdMap ibasethe underlying item base -
items
protected int[] itemsthe items of the item pattern -
size
protected int sizethe current number of items -
s_pat
protected int s_patthe (absolute) support of the (frequent) item pattern -
s_base
protected int s_basethe (absolute) base support (number of transactions) -
eval
protected double evalthe evaluation of the (frequent) item pattern -
wgt
protected double wgtthe weight of the (frequent) item pattern (e.g. cover similarity) -
sort
protected double sortthe value for sorting item patterns -
dir
protected int dirthe comparison direction for sorting item patterns
-
-
Constructor Details
-
Pattern
public Pattern()Create an empty item pattern.- Since:
- 2013.11.28 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase) Create an empty item pattern.- Parameters:
ibase
- the underlying item base- Since:
- 2013.11.28 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase, int[] items, int supp) Create a item pattern from an item array (the item array is stored, not copied).- Parameters:
ibase
- the underlying item baseitems
- the items in the item patternsupp
- the absolute support of the item pattern- Since:
- 2016.11.04 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase, int[] items, int s_pat, int s_base) Create a item pattern from an item array (the item array is stored, not copied).- Parameters:
ibase
- the underlying item baseitems
- the items in the item patterns_pat
- the absolute support of the item patterns_base
- the absolute support of the empty pattern- Since:
- 2014.10.03 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase, int[] items, int s_pat, int s_base, double eval) Create an item pattern from an item array (the item array is stored, not copied).- Parameters:
ibase
- the underlying item baseitems
- the items in the item patterns_pat
- the absolute support of the item patterns_base
- the absolute support of the empty patterneval
- the evaluation of the item pattern- Since:
- 2014.10.04 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase, int[] items, int s_pat, int s_base, double eval, double wgt) Create an item pattern from an item array (the item array is stored, not copied).- Parameters:
ibase
- the underlying item baseitems
- the items in the item patterns_pat
- the absolute support of the item patterns_base
- the absolute support of the empty patterneval
- the evaluation of the item patternwgt
- the weight of the item pattern (e.g. cover similarity)- Since:
- 2018.03.21 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase, int[] items, int cnt, int s_pat, int s_base) Create a item pattern from an item array (the item array is copied).- Parameters:
ibase
- the underlying item baseitems
- the items in the item patterncnt
- the number of items in the item patterns_pat
- the absolute support of the item patterns_base
- the absolute support of the empty pattern- Since:
- 2017.06.14 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase, int[] items, int cnt, int s_pat, int s_base, double eval) Create an item pattern from an item array (the item array is copied).- Parameters:
ibase
- the underlying item baseitems
- the items in the item patterncnt
- the number of items in the item patterns_pat
- the absolute support of the item patterns_base
- the absolute support of the empty patterneval
- the evaluation of the item pattern- Since:
- 2017.06.14 (Christian Borgelt)
-
Pattern
public Pattern(util.IdMap ibase, int[] items, int cnt, int s_pat, int s_base, double eval, double wgt) Create an item pattern from an item array (the item array is copied).- Parameters:
ibase
- the underlying item baseitems
- the items in the item patterncnt
- the number of items in the item patterns_pat
- the absolute support of the item patterns_base
- the absolute support of the empty patterneval
- the evaluation of the item patternwgt
- the weight of the item pattern (e.g. cover similarity)- Since:
- 2018.03.21 (Christian Borgelt)
-
-
Method Details
-
clone
Clone this item pattern (the item base is kept, the item array is copied). -
clone
Clone this item pattern (the item base is kept, the item array is copied).- Parameters:
ibase
- the item base to use for the clone- Returns:
- a clone of this item pattern
- Since:
- 2017.06.14 (Christian Borgelt)
-
clone
Clone this item pattern (the item base is replaced).- Parameters:
iclone
- whether to clone the item array- Returns:
- a clone of this item pattern /*------------------------------------------------------------------
-
clone
Clone this item pattern (the item base is replaced).- Parameters:
iclone
- whether to clone the item arrayibase
- a possible clone of the item base to use for the clone; ifnull
, the item base of the pattern to clone is used- Returns:
- a clone of this item pattern /*------------------------------------------------------------------
-
clone
Clone this item pattern (the item base is kept, the item array is copied).- Parameters:
ibase
- the item base to use for the cloneiclone
- whether to clone the item array- Returns:
- a clone of this item pattern
- Since:
- 2017.06.14 (Christian Borgelt)
-
addItemById
public final int addItemById(int item) Add an item (given by its identifier) to the item pattern.- Parameters:
item
- the identifier of the item to add- Returns:
- the index of the new item
- Since:
- 2017.06.14 (Christian Borgelt)
-
addItemByName
Add an item (given by its name) to the pattern.- Parameters:
item
- the name of the item to add- Returns:
- the index of the new item
- Since:
- 2017.06.14 (Christian Borgelt)
-
addItemByObject
Add an item (given by its object) to the pattern.- Parameters:
item
- the object of the item to add- Returns:
- the index of the new item
- Since:
- 2017.06.14 (Christian Borgelt)
-
addItem
public final int addItem(int item) Add an item to the item pattern.- Parameters:
item
- the item identifier- Returns:
- the index of the new item
- Since:
- 2013.11.28 (Christian Borgelt)
-
addItem
Add an item to the pattern.- Parameters:
item
- the item name- Returns:
- the index of the new item
- Since:
- 2013.11.28 (Christian Borgelt)
-
getItem
public final int getItem(int i) Get an item (i.e., its identifier).- Parameters:
i
- the index of the item- Returns:
- the identifier of the item at index
i
- Since:
- 2013.11.28 (Christian Borgelt)
-
getItemId
public final int getItemId(int i) Get an item identifier (as assigned by the underlying item base).- Parameters:
i
- the index of the item- Returns:
- the identifier of the item at index
i
- Since:
- 2017.06.14 (Christian Borgelt)
-
getItemName
Get the name of an item.- Parameters:
i
- the index of the item- Returns:
- the name of the item at index
i
- Since:
- 2013.11.28 (Christian Borgelt)
-
getItemObject
Get the object of an item.- Parameters:
i
- the index of the item- Returns:
- the object of the item at index
i
- Since:
- 2017.06.14 (Christian Borgelt)
-
getAllItems
public final int[] getAllItems()Get the item array (length/size fits only after packing withpack()
; should be considered read only).- Returns:
- the item array
- Since:
- 2014.10.03 (Christian Borgelt)
-
getSize
public final int getSize()Get the size of the item pattern (number of items).- Returns:
- the size of the item pattern
- Since:
- 2013.11.28 (Christian Borgelt)
-
getCount
public final int getCount()Get the size of the item pattern (number of items).- Returns:
- the size of the item pattern
- Since:
- 2017.06.20 (Christian Borgelt)
-
getSupp
public final int getSupp()Get the support of the item pattern.- Returns:
- the support of the item pattern
- Since:
- 2013.11.28 (Christian Borgelt)
-
getAbsSupp
public final int getAbsSupp()Get the (absolute) support of the item pattern.- Returns:
- the (absolute) support of the item pattern
- Since:
- 2014.10.02 (Christian Borgelt)
-
getRelSupp
public final double getRelSupp()Get the (relative) support of the item pattern.- Returns:
- the (relative) support of the item pattern
- Since:
- 2014.10.02 (Christian Borgelt)
-
getBaseSupp
public final int getBaseSupp()Get the (absolute) support of the empty pattern (i.e. the size of the transaction database).- Returns:
- the (absolute) support of the empty pattern
- Since:
- 2016.04.08 (Christian Borgelt)
-
getEval
public final double getEval()Get the value of the additional evaluation measure.- Returns:
- the value of the additional evaluation measure
- Since:
- 2014.10.02 (Christian Borgelt)
-
getWeight
public final double getWeight()Get the weight of the pattern (e.g. cover similarity).- Returns:
- the weight of the pattern (e.g. cover similarity)
- Since:
- 2018.03.21 (Christian Borgelt)
-
sort
public final void sort()Sort the items of an item pattern.- Since:
- 2015.08.12 (Christian Borgelt)
-
setSort
public final void setSort(int value, int dir) Set sort value and sort direction.- Parameters:
value
- the value to sort item patterns ondir
- the direction to sort item patterns into- Since:
- 2016.04.13 (Christian Borgelt)
-
setSort
public final void setSort(double value, int dir) Set sort value and sort direction.- Parameters:
value
- the value to sort item patterns ondir
- the direction to sort item patterns into- Since:
- 2016.04.13 (Christian Borgelt)
-
compareTo
Compare this item pattern to another (given as argument).- Specified by:
compareTo
in interfaceComparable<Pattern>
- Parameters:
pat
- the item pattern to compare to- Returns:
-1
,0
, or+1
as the sort value of this pattern is less than, equal to, or greater than the sort value of the given pattern- Since:
- 2016.04.13 (Christian Borgelt)
-
allCmpTo
Compare this pattern to another (given as argument) by comparing its items lexicographically and its support.- Parameters:
pat
- the pattern to compare to- Returns:
-1
,0
, or+1
as this pattern is less than, equal to, or greater than the pattern given as an argument- Since:
- 2017.06.14 (Christian Borgelt)
-
itemsCmpTo
Compare this pattern to another (given as argument) by comparing its items lexicographically.- Parameters:
pat
- the pattern to compare to- Returns:
-1
,0
, or+1
as this pattern is less than, equal to, or greater than the pattern given as an argument- Since:
- 2017.06.14 (Christian Borgelt)
-
suppCmpTo
Compare this item pattern to another (given as argument) w.r.t. the support value.- Parameters:
pat
- the item pattern to compare to- Returns:
-1
,0
, or+1
as the support of this item pattern is less than, equal to, or greater than the support of the item pattern given as an argument- Since:
- 2017.06.14 (Christian Borgelt)
-
equals
public final boolean equals(int[] items, int cnt) Compare the pattern's items to a given item pattern.- Parameters:
items
- the items of the pattern to compare tocnt
- the number of items (if negative, the length of the given item array is used)- Returns:
- whether the pattern equals the given item pattern
- Since:
- 2017.06.14 (Christian Borgelt)
-
equals
Check whether this pattern is equal to another (given as argument).- Parameters:
pat
- the pattern to compare tochksupp
- whether to compare the support values- Returns:
true
if the two patterns have the same items (in the same order) andfalse
otherwise- Since:
- 2017.06.14 (Christian Borgelt)
-
equals
Check whether this pattern is equal to another (given as argument).- Parameters:
pat
- the pattern to compare to- Returns:
true
if the two patterns have the same items (in the same order) andfalse
otherwise- Since:
- 2017.06.29 (Christian Borgelt)
-
subpattern
public static boolean subpattern(int[] itemsA, int cntA, int[] itemsB, int cntB) Check whether a given array of items, representing an item pattern, is a subpattern of another item pattern, given as a second given array of items.For item permutations and item sequences the function works directly, but for item sets the items in both passed arrays
itemsA
anditemsB
need to be sorted (by item identifier) for this function to work correctly.- Parameters:
itemsA
- the first array of itemscntA
- the number of items to consider in the first arrayitemsB
- the second array of itemscntB
- the number of items to consider in the second array- Returns:
true
is the first item pattern is a subpattern of the second item pattern andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
isSubOf
public final boolean isSubOf(int[] items, int cnt) Check whether this item pattern is a subpattern of another item pattern, given as an array of items.For item permutations and item sequences the function works directly, but for item sets the item set needs to be sorted with
sort()
and the items in the passed arrayitems
also need to be sorted (by identifier) for this function to work correctly.- Parameters:
items
- the array of items to checkcnt
- the number of items to consider in the given array; if negative, the length of the item array is used- Returns:
true
if this item pattern is a subpattern of the given item arrayitems
andfalse
- Since:
- 2017.06.17 (Christian Borgelt)
-
isSubOf
Check whether this item pattern is a subpattern of another item pattern.For item permutations and sequences the function works directly, but for item patterns, both item sets must have been sorted with
Sort()
for this function to work correctly.- Parameters:
pat
- the item pattern to compare to- Returns:
true
if this item pattern is a subpattern of the given item patternpat
andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
isContainedIn
Whether this item pattern is contained in another item pattern.For item permutations and sequences the function works directly, but for item sets, both item sets must have been sorted with
sort()
for this function to work correctly.- Parameters:
pat
- the item pattern to compare to- Returns:
true
if this item pattern is a subpattern of the given item patternargPattern
andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
isContainedIn
Whether this item pattern is a contained in a transaction.For item permutations and sequences the function works directly, but for sets, both the item set and the transaction must have been sorted with
sort()
for this function to work correctly.- Parameters:
tract
- the transaction to compare to- Returns:
true
if this item pattern is a subpattern of the given transactiontract
andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
isSuperOf
public final boolean isSuperOf(int[] items, int cnt) Whether this item pattern is a superpattern of a given item pattern.For item permutations and sequences the function works directly, but for item sets the item set must have been sorted with
sort()
first and also the items in the passed arrayitems
need to be sorted (by identifier) for this function to work correctly.- Parameters:
items
- the array of items to checkcnt
- the number of items to consider in the given array; if negative, the length of the item array is used- Returns:
true
if this item pattern is a superpattern of the given item arrayitems
andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
isSuperOf
Whether this item pattern is a superpattern of another item pattern.For item permutations and sequences the function works directly, but for item sets, both item sets must have been sorted with
sort()
for this function to work correctly.- Parameters:
pat
- the item pattern to compare to- Returns:
true
is this item pattern is a superpattern of the given item patternpat
andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
contains
Whether this item pattern contains another item pattern.For item permutations and sequences the function works directly, but for item sets, both item sets must have been sorted with
sort()
for this function to work correctly.- Parameters:
pat
- the item pattern to compare to- Returns:
true
is this item pattern contains the given item patternpat
andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
contains
Whether this item pattern contains a given transaction.For item permutations and sequences the function works directly, but for item sets, both the item set and the transaction must have been sorted with
sort()
for this function to work correctly.- Parameters:
tract
- the transaction to compare to- Returns:
true
is this item pattern contains the given transactiontract
andfalse
otherwise- Since:
- 2017.06.17 (Christian Borgelt)
-
getCover
Get the cover (list of transaction identifiers) of an item pattern w.r.t. a transaction bag.- Parameters:
tabag
- the transaction bag w.r.t. which to get the cover- Returns:
- an array of indices of transactions in which the item pattern is contained
- Since:
- 2017.06.17 (Christian Borgelt)
-
isect
Create the intersection of two item patterns.The intersection is created in the pattern for which this function is called, which acts as a buffer to avoid memory allocation. However, if the item array of this pattern is too small to hold the intersection, it is enlarged.
- Parameters:
A
- the first pattern to intersectB
- the second pattern to intersect- Returns:
- the size of the intersection of the patterns
- Since:
- 2015.08.12 (Christian Borgelt)
-
recode
public final void recode(util.IdMap ibase, int[] map) Recode a pattern to another item base, replacing the item base.- Parameters:
ibase
- the item base to recode the pattern tomap
- the old identifier to new identifier map; ifnull
, the map is created by a call toIdMap.getMapTo()
- Since:
- 2017.06.14 (Christian Borgelt)
-
pack
public final void pack()Pack an item pattern, i.e., optimize memory usage.- Since:
- 2013.11.28 (Christian Borgelt)
-
write
Write an item pattern.- Parameters:
writer
- the writer to write to- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.17 (Christian Borgelt)
-
write
Write an item pattern.- Parameters:
writer
- the writer to write toinfo
- the additional information to write- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.17 (Christian Borgelt)
-
write
Write an item pattern.- Parameters:
writer
- the writer to write toisep
- the item separatorinfo
- the additional information to write- Throws:
IOException
- if a write error occurs- Since:
- 2017.06.27 (Christian Borgelt)
-
parse
Parse an item pattern.- Parameters:
ibase
- the underlying item basescan
- the scanner to read from- Returns:
- the parsed item pattern
- Throws:
IOException
- if a read error occurs- Since:
- 2005.07.06 (Christian Borgelt)
-
parse
Parse an item pattern.- Parameters:
ibase
- the underlying item basereader
- the reader to read from- Returns:
- the parsed item pattern
- Throws:
IOException
- if a read error occurs- Since:
- 2005.07.06 (Christian Borgelt)
-
parse
Parse an item pattern.- Parameters:
ibase
- the underlying item basedesc
- the string description to parse- Returns:
- the parsed item pattern
- Throws:
IOException
- if a read error occurs- Since:
- 2005.07.06 (Christian Borgelt)
-
parse
Parse an item pattern.- Parameters:
ibase
- the underlying item baseinp
- the input stream to read from- Returns:
- the parsed item pattern
- Throws:
IOException
- if a read error occurs- Since:
- 2005.07.06 (Christian Borgelt)
-
toString
Create a string description.- Parameters:
isep
- the separator for the itemsinfo
- characters specifying additional information to report- Returns:
- the created string description
- Since:
- 2005.07.06 (Christian Borgelt)
-
toString
Create a string description.- Parameters:
info
- characters specifying additional information to report- Returns:
- the created string description
- Since:
- 2005.07.06 (Christian Borgelt)
-
toString
Create a string description.
-