Class ARuleSet
- All Implemented Interfaces:
PatternReceiver
,Serializable
,Cloneable
- Since:
- 2004.07.06
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
the maximal number of items in a rule bodystatic final int
sort mode: size / number of items in antecedent/bodystatic final int
sort mode: antecedent/body supportstatic final int
sort mode: confidenceprotected int
the current rule index for the rule set reductionstatic final int
sort mode: evaluationstatic final int
selection mode: find exact match of given ruleprotected int
the maximal number of items in a rule headstatic final int
sort mode: consequent/head item of the rulestatic final int
filter mode: keep only rules in which the head item is not contained in the bodystatic final int
filter mode: keep only rules in which the head item is not also the last item in the bodystatic final int
sort mode: consequent/head supportprotected util.IdMap
the underlying item basestatic final int
sort mode: items (in the order in which they appear)static final int
reduction mode: compare only the head items (not support etc.)static final int
sort mode: lift valuestatic final int
reduction mode: maximize the size of the antecedent/rule bodystatic final int
reduction mode: minimize the size of the antecedent/rule bodystatic final int
sort mode: names of the consequent itemsstatic final int
reduction mode: do not use aCloMaxFilter
, but rather work directly on the item pattern arraystatic final int
reduction mode: do nothingprotected ARule[]
the set of association rulesprotected int
the current number of rulesstatic final int
sort mode: size / number of itemsstatic final int
filter mode: do nothing (keep all association rules, sort only)static final int
selection mode: find subrule of given rule (or exact match)static final int
selection mode: find superrule of given rule (or exact match)static final int
sort mode: item pattern support (body and head)protected int[]
the support values of individual itemsstatic final int
reduction mode: remove duplicates/ensure unique rulesprotected int
the maximal number of items in a rule (body and head) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Add an association rule.final int
Add an association rule.final void
addRuleSet
(ARuleSet ruleset) Add an association rule set (the rules are not cloned/copied, but merely transferred).final void
addRuleSet
(ARuleSet ruleset, boolean clonerules) Add an association rule set.final void
clear()
Clear this association rule set, that is, remove all rules.final Object
clone()
Clone this set of association rules.clone
(boolean clonebase, boolean clonerules) Clone this set of association rules.boolean
Check whether two association rule sets are equal.int
filter
(int mode) Filter a set of association rules.int
filter
(int zmin, int zmax) Filter an association rule set by antecedent/body size.final ARule
get
(int i) Get an association rulefinal ARule[]
Get all association rules 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 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 least one association rule (in body or head).final int
Get the maximal size of a rule body/antecedent.final int
Get the maximal size of a rule head/consequent.final int
Get the maximal size of a rule.final ARule
getRule
(int i) Get an association rulefinal int
Get the number of association rules (size of rule set).final int
getRuleSize
(int i) Get the size of an association rule.final int
getSize()
Get the number of association rules (size of rule set).final int
getSupp
(int item) Get the support of an individual item.final int
getSuppById
(int item) Get the support of an individual item.final int
getSuppByName
(String item) Get the support of an individual item.final int
getSuppByObject
(Object item) Get the support of an individual item.static void
Main function for testing some basic functionality.final void
pack()
Pack the association rules, i.e., optimize memory usage.static ARuleSet
parse
(util.IdMap ibase, InputStream inp) Parse a set of association rules.static ARuleSet
Parse a set of association rules.static ARuleSet
Parse a set of association rules.static ARuleSet
parse
(util.IdMap ibase, util.Scanner scan) Parse a set of association rules.void
receive
(int[] items, int size, int s_pat, int s_base) Receive an item pattern (implementsPatternReceiver
).final void
recode
(util.IdMap ibase) Recode an association rule set to another item base, replacing the item base.int
reduce
(int mode) Reduce a set of association rules.final void
reverse()
Reverse the order of the association rules in a rule set.final ARuleSet
select
(int[] body, int size, int head, int mode) Select rules that are subrules, superrules (w.r.t.final ARuleSet
Select rules that are subrules, superrules (w.r.t.final void
setAllSupps
(int[] supps) Set the support values of all individual items.protected final void
setSort
(int valid, int dir) Set the sort parameters for all item patterns.final void
setSupp
(int item, int supp) Set the support of an individual item.final void
setSuppById
(int item, int supp) Set the support of an individual item.final void
setSuppByName
(String item, int supp) Set the support of an individual item.final void
setSuppByObject
(String item, int supp) Set the support of an individual item.final void
sort()
Sort the set of association rules (by their size).final void
sort
(int valid) Sort the set of association rules.final void
sort
(int valid, int dir) Sort the set of association rules.final void
Sort the items in each association rule's body.final void
Sort the items in each association rule's body.void
write
(OutputStream out) Write a set of association rules.void
Write a set of association rules.
-
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:
-
BODYSIZE
public static final int BODYSIZEsort mode: size / number of items in antecedent/body- See Also:
-
CONF
public static final int CONFsort mode: confidence- See Also:
-
SUPP
public static final int SUPPsort mode: item pattern support (body and head)- See Also:
-
BODYSUPP
public static final int BODYSUPPsort mode: antecedent/body support- See Also:
-
HEADSUPP
public static final int HEADSUPPsort mode: consequent/head support- See Also:
-
LIFT
public static final int LIFTsort mode: lift value- See Also:
-
EVAL
public static final int EVALsort mode: evaluation- See Also:
-
HEAD
public static final int HEADsort mode: consequent/head item of the rule- See Also:
-
NAMES
public static final int NAMESsort mode: names of the consequent items- See Also:
-
NONE
public static final int NONEreduction mode: do nothing- See Also:
-
UNIQUE
public static final int UNIQUEreduction mode: remove duplicates/ensure unique rules- See Also:
-
MINSIZE
public static final int MINSIZEreduction mode: minimize the size of the antecedent/rule body- See Also:
-
MAXSIZE
public static final int MAXSIZEreduction mode: maximize the size of the antecedent/rule body- See Also:
-
ITEMSONLY
public static final int ITEMSONLYreduction mode: compare only the head items (not support etc.)- See Also:
-
NOFILTER
public static final int NOFILTERreduction mode: do not use aCloMaxFilter
, but rather work directly on the item pattern array- See Also:
-
SORTONLY
public static final int SORTONLYfilter mode: do nothing (keep all association rules, sort only)- See Also:
-
HEADNOTLAST
public static final int HEADNOTLASTfilter mode: keep only rules in which the head item is not also the last item in the body- See Also:
-
HEADNOTBODY
public static final int HEADNOTBODYfilter mode: keep only rules in which the head item is not contained in the body- See Also:
-
EXACT
public static final int EXACTselection mode: find exact match of given rule- See Also:
-
SUB
public static final int SUBselection mode: find subrule of given rule (or exact match)- See Also:
-
SUPER
public static final int SUPERselection mode: find superrule of given rule (or exact match)- See Also:
-
ibase
protected util.IdMap ibasethe underlying item base -
rules
the set of association rules -
size
protected int sizethe current number of rules -
body
protected int bodythe maximal number of items in a rule body -
head
protected int headthe maximal number of items in a rule head -
zmax
protected int zmaxthe maximal number of items in a rule (body and head) -
supps
protected int[] suppsthe support values of individual items -
curr
protected int currthe current rule index for the rule set reduction
-
-
Constructor Details
-
ARuleSet
public ARuleSet()Create an empty set of association rules.- Since:
- 2005.07.06 (Christian Borgelt)
-
ARuleSet
public ARuleSet(util.IdMap ibase) Create an empty set of association rules.- Parameters:
ibase
- the underlying item base- Since:
- 2005.07.06 (Christian Borgelt)
-
ARuleSet
Create a set of association rules from FIM output.- Parameters:
ibase
- the underlying item bases_base
- the number of transactions from which the (frequent) item sets where derivedrules
- the output of a native functionJNIFIM.xxx()
, called withreport = "bsh"
orreport = "bsh[e|E]"
- Since:
- 2014.10.23 (Christian Borgelt)
-
-
Method Details
-
clone
Clone this set of association rules.The clone is a deep clone, that is, the underlying item base and all contained association rules are cloned as well.
-
clone
Clone this set of association rules.- Parameters:
clonebase
- whether to clone the underlying item baseclonerules
- whether to clone the association rules- Returns:
- a clone of this set of association rules
- Since:
- 2017.06.29 (Christian Borgelt)
-
clear
public final void clear()Clear this association rule set, that is, remove all rules.- Since:
- 2017.06.29 (Christian Borgelt)
-
getItemBase
public final util.IdMap getItemBase()Get the underlying item base.- Returns:
- the underlying item base
- Since:
- 2005.07.06 (Christian Borgelt)
-
getSize
public final int getSize()Get the number of association rules (size of rule set).- Returns:
- the number of association rules
- Since:
- 2016.04.08 (Christian Borgelt)
-
getRuleCount
public final int getRuleCount()Get the number of association rules (size of rule set).- Returns:
- the number of association rules
- Since:
- 2005.07.06 (Christian Borgelt)
-
getMaxSize
public final int getMaxSize()Get the maximal size of a rule.- Returns:
- the maximal size of a rule
- Since:
- 2007.03.12 (Christian Borgelt)
-
getMaxBodySize
public final int getMaxBodySize()Get the maximal size of a rule body/antecedent.- Returns:
- the maximal size of a rule body/antecedent
- Since:
- 2005.07.06 (Christian Borgelt)
-
getMaxHeadSize
public final int getMaxHeadSize()Get the maximal size of a rule head/consequent.- Returns:
- the maximal size of a rule body/consequent
- Since:
- 2005.07.06 (Christian Borgelt)
-
getItemName
Get the name of an item.- Parameters:
item
- the identifier of the item for which to get the name- Returns:
- the name of the item with identifier
item
- Since:
- 2017.06.29 (Christian Borgelt)
-
get
Get an association rule- Parameters:
i
- the index of the association rule- Returns:
- the association rule with index i
- Since:
- 2017.06.22 (Christian Borgelt)
-
getRule
Get an association rule- Parameters:
i
- the index of the association rule- Returns:
- the association rule with index i
- Since:
- 2005.07.06 (Christian Borgelt)
-
getAllRules
Get all association rules as an array (array length fits only after packing withpack()
; should be considered read only).- Returns:
- the array of association rules
- Since:
- 2017.06.29 (Christian Borgelt)
-
getRuleSize
public final int getRuleSize(int i) Get the size of an association rule.- Parameters:
i
- the index of the association rule- Returns:
- the size of the association rule with index
i
/*------------------------------------------------------------------
-
add
Add an association rule.- Parameters:
rule
- the association rule to add- Returns:
- the index of the association rule in the set
- Since:
- 2017.06.22 (Christian Borgelt)
-
addRule
Add an association rule.- Parameters:
rule
- the association rule to add- Returns:
- the index of the association rule in the set
- Since:
- 2005.07.06 (Christian Borgelt)
-
addRuleSet
Add an association rule set (the rules are not cloned/copied, but merely transferred).- Parameters:
ruleset
- the association rule set to add- Since:
- 2017.06.29 (Christian Borgelt)
-
addRuleSet
Add an association rule set.- Parameters:
ruleset
- the association rule set to addclonerules
- whether to clone the rules of the given set- Since:
- 2017.06.29 (Christian Borgelt)
-
getSupp
public final int getSupp(int item) Get the support of an individual item.- Parameters:
item
- the item identifier for which to get the support value- Returns:
- the support value of the item
with identifier
item
- Since:
- 2017.06.29 (Christian Borgelt)
-
getSuppById
public final int getSuppById(int item) Get the support of an individual item.- Parameters:
item
- the item identifier for which to get the support value- Returns:
- the support value of the item
with identifier
item
- Since:
- 2017.06.29 (Christian Borgelt)
-
getSuppByName
Get the support of an individual item.- Parameters:
item
- the item name for which to get the support value- Returns:
- the support value of the item with name
item
- Since:
- 2017.06.29 (Christian Borgelt)
-
getSuppByObject
Get the support of an individual item.- Parameters:
item
- the item object for which to get the support value- Returns:
- the support value of the item
with object
item
- Since:
- 2017.06.29 (Christian Borgelt)
-
setSupp
public final void setSupp(int item, int supp) Set the support of an individual item.- Parameters:
item
- the item identifier for which to set the support valuesupp
- the support value to set for the item- Since:
- 2017.06.29 (Christian Borgelt)
-
setSuppById
public final void setSuppById(int item, int supp) Set the support of an individual item.- Parameters:
item
- the item identifier for which to set the support valuesupp
- the support value to set for the item- Since:
- 2017.06.29 (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.29 (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.29 (Christian Borgelt)
-
getAllSupps
public final int[] getAllSupps()Get the support values of all individual items.- Returns:
- an array of support values for each item
- Since:
- 2017.06.29 (Christian Borgelt)
-
setAllSupps
public final void setAllSupps(int[] supps) Set the support values of all individual items.- Parameters:
supps
- an array of support values for each item- Since:
- 2017.06.29 (Christian Borgelt)
-
sortItems
public final void sortItems()Sort the items in each association rule's body.- Since:
- 2017.06.29 (Christian Borgelt)
-
sortBodyItems
public final void sortBodyItems()Sort the items in each association rule's body.- Since:
- 2017.06.29 (Christian Borgelt)
-
setSort
protected final void setSort(int valid, int dir) Set the sort parameters for all item patterns.- Parameters:
valid
- the identifier of the value to sort ondir
- the sort direction (positive: ascending, negative: descending)- Since:
- 2017.06.17 (Christian Borgelt)
-
sort
public final void sort()Sort the set of association rules (by their size).- Since:
- 2017.06.29 (Christian Borgelt)
-
sort
public final void sort(int valid) Sort the set of association rules.- Parameters:
valid
- the identifier of the value to compare first- Since:
- 2005.07.06/2016.04.10 (Christian Borgelt)
-
sort
public final void sort(int valid, int dir) Sort the set of association rules.- Parameters:
valid
- the identifier of the value to compare firstdir
- the sort direction (positive: ascending, negative: descending)- Since:
- 2016.04.10 (Christian Borgelt)
-
reverse
public final void reverse()Reverse the order of the association rules in a rule set.- Since:
- 2016.06.27 (Christian Borgelt)
-
equals
Check whether two association rule sets are equal.It is assumed that both association rule sets have been sorted with a call to the function
sort()
with parameterITEMS
. If the rule bodies represents item sets instead of permutations or sequences, it is also assumed that the items have been sorted by a call to the functionsortItems()
.- Parameters:
ruleset
- the rule set to compare to- Returns:
true
if the two rule sets contain the same rule (in the same order) andfalse
otherwise- Since:
- 2016.06.29 (Christian Borgelt)
-
filter
public int filter(int mode) Filter a set of association rules.- Parameters:
mode
- the filter mode (e.g.HEADNOTLAST
)- Returns:
- the new number of association rules
- Since:
- 2016.06.29 (Christian Borgelt)
-
filter
public int filter(int zmin, int zmax) Filter an association rule set by antecedent/body size.- Parameters:
zmin
- the minimum body size of the rules to keepzmax
- the maximum body size of the rules to keep- Returns:
- the new number of association rules
- Since:
- 2016.06.29 (Christian Borgelt)
-
receive
public void receive(int[] items, int size, int s_pat, int s_base) Receive an item pattern (implementsPatternReceiver
).This function is needed internally to implement the function
reduce()
. It performs no operation if called from the outside of this class. On the other hand, it cannot be declared private, because it implements an interface.- Specified by:
receive
in interfacePatternReceiver
- Parameters:
items
- the items in the item pattern (may be an oversized buffer)size
- 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:
- 2016.06.29 (Christian Borgelt)
-
reduce
public int reduce(int mode) Reduce a set of association rules.- Parameters:
mode
- the reduction mode (e.g.MINSIZE
)- Returns:
- the new number of association rules
- Since:
- 2016.06.29 (Christian Borgelt)
-
select
Select rules that are subrules, superrules (w.r.t. the rule body) or an exact match of the given rule (in terms of the contained items, including the head).- Parameters:
rule
- the rule with which to select rulesmode
- the mode with which to select rules; eitherEXACT
,SUB
, orSUPER
.- Returns:
- an association rule set with the qualifying rules (uncloned)
- Since:
- 2016.06.29 (Christian Borgelt)
-
select
Select rules that are subrules, superrules (w.r.t. the rule body) or an exact match of the given rule (in terms of the contained items, including the head).- Parameters:
body
- the items of the rule body to compare tosize
- the number of items in the bodyhead
- the head item of the rulemode
- the mode with which to select rulesEXACT
,SUB
, orSUPER
.- Returns:
- an association rule set with the qualifying rules (uncloned)
- Since:
- 2016.06.29 (Christian Borgelt)
-
getItems
public final int[] getItems()Get a list of all items that occur in at least one association rule (in body or head).- Returns:
- an array with the identifiers of items that occur in at least one association rule, sorted by item identifier
- Since:
- 2016.06.29 (Christian Borgelt)
-
recode
public final void recode(util.IdMap ibase) Recode an association rule set to another item base, replacing the item base.- Parameters:
ibase
- the item base to recode the association rule set to- Since:
- 2016.06.29 (Christian Borgelt)
-
pack
public final void pack()Pack the association rules, i.e., optimize memory usage.- Since:
- 2017.06.29 (Christian Borgelt)
-
write
Write a set of association rules.- Parameters:
writer
- the writer to write to- Throws:
IOException
- if a write error occurs- Since:
- 2007.06.06 (Christian Borgelt)
-
write
Write a set of association rules.- Parameters:
out
- the output stream to write to- Throws:
IOException
- if a write error occurs- Since:
- 2016.04.08 (Christian Borgelt)
-
parse
Parse a set of association rules.- Parameters:
ibase
- the underlying item basescan
- the scanner to read from- Returns:
- the parsed set of association rules
- Throws:
IOException
- if a read error occurs- Since:
- 2005.07.06 (Christian Borgelt)
-
parse
Parse a set of association rules.- Parameters:
ibase
- the underlying item basereader
- the reader to read from- Returns:
- the parsed set of association rules
- Throws:
IOException
- if a read error occurs- Since:
- 2005.07.06 (Christian Borgelt)
-
parse
Parse a set of association rules.- Parameters:
ibase
- the underlying item basedesc
- the string description to parse- Returns:
- the parsed set of association rules
- Throws:
IOException
- if a read error occurs- Since:
- 2013.11.28 (Christian Borgelt)
-
parse
Parse a set of association rules.- Parameters:
ibase
- the underlying item baseinp
- the input stream to read from- Returns:
- the parsed set of association rules
- Throws:
IOException
- if a read error occurs- Since:
- 2013.11.28 (Christian Borgelt)
-
main
Main function for testing some basic functionality.It is tried to parse the file that is given as the first command line argument as a set of association rules.
- Parameters:
args
- the command line arguments- Since:
- 2005.07.06 (Christian Borgelt)
-