Package fim
Class TrActBag
java.lang.Object
fim.TrActBag
- All Implemented Interfaces:
Serializable
,Cloneable
Class for a bag/multiset of transactions.
- Since:
- 2007.06.06
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected util.IdMap
the underlying item baseprotected int
the current number of transactionsprotected int[]
the support values of the items; is computed on demandprotected TrAct[]
the bag/multiset of transactionsprotected int
the total weight of all transactionsprotected int
the maximal weight/multiplicity of a transactionprotected int
the minimal weight/multiplicity of a transactionprotected int
the maximal size of a transaction -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Add a transaction.final int
Add a transaction.final void
addTrActBag
(TrActBag tabag) Add a transaction bag (the transactions are transferred, not cloned).final void
addTrActBag
(TrActBag tabag, boolean clone) Add a transaction bag.final void
clear()
Clear this transaction bag, that is, remove all transactions.final Object
clone()
Clone this bag/multiset of transactions.clone
(boolean clonebase, boolean clonetracts) Clone this bag/multiset of transactions.final TrAct
get
(int i) Get a transaction.final int
getCount()
Get the size of the transaction bag (number of transactions).final int[]
getCoverOf
(Pattern pat) Get the cover (list of transaction identifiers) of an item pattern.final util.IdMap
Get the underlying item base.final String
getItemName
(int item) Get the name of an item.final int
getItemSupp
(int item) Get the support value of an item (given by its identifier).final int
getItemSuppById
(int item) Get the support value of an item (given by its identifier).final int
getItemSuppByName
(String item) Get the support value of an item (given by its name).final int
getItemSuppByObject
(Object item) Get the support value of an item (given by its object).final int[]
Get the item support values as an array (to be indexed by item identifiers).final int
Get the maximal size of a transaction.final int
Get the maximal weight/multiplicity of a transaction.final int
Get the minimal weight/multiplicity of a transaction.final Pattern
getPattern
(int[] items) Get the given pattern for this transaction bag.final Pattern
getPattern
(int[] items, int cnt) Get the given pattern for this transaction bag.final Pattern
getPattern
(Pattern pat) Get the given pattern for this transaction bag.final PatternSet
getPatternSet
(PatternSet patset) Get the given pattern set for this transaction bag.final ARule
Get the given association rule for this transaction bag.final ARuleSet
getRuleSet
(ARuleSet ruleset) Get the given association rule set for this transaction bag.final int
getSize()
Get the size of the transaction bag (number of transactions).final int
getSupport
(int[] items) Get the support of the given item pattern in this transaction bag.final int
getSupport
(int[] items, int cnt) Get the support of the given item pattern in this transaction bag.final int
getSupport
(Pattern pat) Get the support of the given item pattern in this transaction bag.final int[]
getSupport
(PatternSet patset) Get the support values of the given pattern set in this transaction bag.final int[]
getSupport
(PatternSet patset, int[] supps) Get the support values of the given pattern set in this transaction bag.final TrAct
getTrAct
(int i) Get a transaction.final int[][]
Get all transactions as an array of integer arrays.final int
getTrActSize
(int i) Get a transaction.final int
Get the total weight of all transactions.final int[]
Get all transaction weights as an array of integers.static void
Main function for testing some basic functionality.final void
pack()
Pack the transactions, i.e., optimize memory usage.static TrActBag
Parse a bag/multiset of transactions.static TrActBag
Parse a bag/multiset of transactions.static TrActBag
parse
(util.IdMap ibase, util.TableReader reader) Parse a bag/multiset of transactions.static TrActBag
parse
(util.IdMap ibase, util.TableReader reader, boolean wgt) Parse a bag/multiset of transactions.final void
recodeTo
(util.IdMap ibase) Recode a transaction bag to another item base, replacing the item base.final int
reduce()
Reduce the transactions, i.e., combine equal transactions.final int
reduce
(int smin) Reduce the transactions, i.e., combine equal transactions; optionally remove infrequent items prior to combination.final void
sort()
Sort the transactions lexicographically by item identifiers.final boolean
Check for unit weight/multiplicity of all transactions.final void
write
(util.TableWriter writer) Write a transaction bag/multiset.final void
write
(util.TableWriter writer, boolean wgt) Write a transaction bag/multiset.
-
Field Details
-
ibase
protected util.IdMap ibasethe underlying item base -
tracts
the bag/multiset of transactions -
size
protected int sizethe current number of transactions -
zmax
protected int zmaxthe maximal size of a transaction -
wgt
protected int wgtthe total weight of all transactions -
wmin
protected int wminthe minimal weight/multiplicity of a transaction -
wmax
protected int wmaxthe maximal weight/multiplicity of a transaction -
supps
protected int[] suppsthe support values of the items; is computed on demand
-
-
Constructor Details
-
TrActBag
public TrActBag()Create an empty bag/multiset of transactions.- Since:
- 2007.06.06 (Christian Borgelt)
-
TrActBag
public TrActBag(util.IdMap ibase) Create an empty bag/multiset of transactions.- Parameters:
ibase
- the underlying item base- Since:
- 2007.06.06 (Christian Borgelt)
-
-
Method Details
-
clone
Clone this bag/multiset of transactions.The clone is a deep clone, that is, the underlying item base and all contained transactions are cloned as well.
-
clone
Clone this bag/multiset of transactions.- Parameters:
clonebase
- whether to clone the underlying item baseclonetracts
- whether to clone the transactions- Returns:
- a clone of this bag/multiset of transactions
- Since:
- 2017.06.20 (Christian Borgelt)
-
clear
public final void clear()Clear this transaction bag, that is, remove all transactions.- Since:
- 2017.06.20 (Christian Borgelt)
-
getItemBase
public final util.IdMap getItemBase()Get the underlying item base.- Returns:
- the underlying item base
- Since:
- 2007.06.06 (Christian Borgelt)
-
getItemName
Get the name of an item.- Parameters:
item
- the item identifier for which to get the name- Returns:
- the name of the item with identifier
item
- Since:
- 2007.06.06 (Christian Borgelt)
-
getSize
public final int getSize()Get the size of the transaction bag (number of transactions).- Returns:
- the size of the transaction bag
- Since:
- 2007.06.06 (Christian Borgelt)
-
getCount
public final int getCount()Get the size of the transaction bag (number of transactions).- Returns:
- the size of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getWeight
public final int getWeight()Get the total weight of all transactions.- Returns:
- the size of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getMaxSize
public final int getMaxSize()Get the maximal size of a transaction.- Returns:
- the maximal size of a transaction
- Since:
- 2007.06.06 (Christian Borgelt)
-
getMinWeight
public final int getMinWeight()Get the minimal weight/multiplicity of a transaction.- Returns:
- the maximal size of a transaction
- Since:
- 2014.10.03 (Christian Borgelt)
-
getMaxWeight
public final int getMaxWeight()Get the maximal weight/multiplicity of a transaction.- Returns:
- the maximal size of a transaction
- Since:
- 2014.10.03 (Christian Borgelt)
-
unitWeight
public final boolean unitWeight()Check for unit weight/multiplicity of all transactions.- Returns:
- whether all transactions have unit weight/multiplicity
- Since:
- 2014.10.03 (Christian Borgelt)
-
get
Get a transaction.- Parameters:
i
- the index of the transaction- Returns:
- the transaction with index
i
- Since:
- 2017.06.22 (Christian Borgelt)
-
getTrAct
Get a transaction.- Parameters:
i
- the index of the transaction- Returns:
- the transaction with index
i
- Since:
- 2007.06.06 (Christian Borgelt)
-
getTrActSize
public final int getTrActSize(int i) Get a transaction.- Parameters:
i
- the index of the transaction- Returns:
- the transaction with index
i
- Since:
- 2007.06.06 (Christian Borgelt)
-
add
Add a transaction.- Parameters:
tract
- the transaction to add- Returns:
- the index of the transaction in the bag/multiset
- Since:
- 2017.06.22 (Christian Borgelt)
-
addTrAct
Add a transaction.- Parameters:
tract
- the transaction to add- Returns:
- the index of the transaction in the bag/multiset
- Since:
- 2007.06.06 (Christian Borgelt)
-
addTrActBag
Add a transaction bag.- Parameters:
tabag
- the transaction bag to addclone
- whether to clone the transactions of the given transaction bag- Since:
- 2017.06.20 (Christian Borgelt)
-
addTrActBag
Add a transaction bag (the transactions are transferred, not cloned).- Parameters:
tabag
- the transaction bag to add- Since:
- 2017.06.20 (Christian Borgelt)
-
sort
public final void sort()Sort the transactions lexicographically by item identifiers.- Since:
- 2017.06.20 (Christian Borgelt)
-
reduce
public final int reduce(int smin) Reduce the transactions, i.e., combine equal transactions; optionally remove infrequent items prior to combination.- Parameters:
smin
- the minimum support of items to keep- Returns:
- the reduced number of transactions
- Since:
- 2017.06.20 (Christian Borgelt)
-
reduce
public final int reduce()Reduce the transactions, i.e., combine equal transactions.- Returns:
- the reduced number of transactions
- Since:
- 2017.06.20 (Christian Borgelt)
-
getItemSupp
public final int getItemSupp(int item) Get the support value of an item (given by its identifier).- Parameters:
item
- the item for which to get the support value- Returns:
- the support value of the item with identifier
item
- Since:
- 2017.06.20 (Christian Borgelt)
-
getItemSuppById
public final int getItemSuppById(int item) Get the support value of an item (given by its identifier).- Parameters:
item
- the item for which to get the support value- Returns:
- the support value of the item with identifier
item
- Since:
- 2017.06.20 (Christian Borgelt)
-
getItemSuppByName
Get the support value of an item (given by its name).- Parameters:
item
- the name of the item for which to get the support value- Returns:
- the support value of the item with name
item
- Since:
- 2017.06.20 (Christian Borgelt)
-
getItemSuppByObject
Get the support value of an item (given by its object).- Parameters:
item
- the object of the item for which to get the support value- Returns:
- the support value of the item with object
item
- Since:
- 2017.06.20 (Christian Borgelt)
-
getItemSupps
public final int[] getItemSupps()Get the item support values as an array (to be indexed by item identifiers).- Returns:
- an array with the support values of the items
- Since:
- 2017.06.20 (Christian Borgelt)
-
getCoverOf
Get the cover (list of transaction identifiers) of an item pattern.- Parameters:
pat
- the item pattern for which to get the cover- Returns:
- an array of indices of transactions in which the item pattern is contained
- Since:
- 2017.06.20 (Christian Borgelt)
-
getSupport
Get the support of the given item pattern in this transaction bag.- Parameters:
pat
- the item pattern for which to get the support in this transaction bag- Returns:
- the support of the given item pattern in this transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getSupport
public final int getSupport(int[] items, int cnt) Get the support of the given item pattern in this transaction bag.- Parameters:
items
- the array of items to of the pattern for which to get the support in this transaction bag (may be oversized)cnt
- the number of items in the given array to consider; if negative, the length of the item arrayitems
is used- Returns:
- the support of the given item pattern in this transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getSupport
public final int getSupport(int[] items) Get the support of the given item pattern in this transaction bag.- Parameters:
items
- the array of items to of the pattern for which to get the support in this transaction bag- Returns:
- the support of the given item pattern in this transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getSupport
Get the support values of the given pattern set in this transaction bag.- Parameters:
patset
- the item pattern set which to get the support values in this transaction bagsupps
- the array into which to store the support values ifnull
, a new array is created, otherwise it must have at least sizepatset.getSize()
- Returns:
- an array of support values, with as many entries as there are patterns in the given pattern set, containing the support values of the item patterns in this transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getSupport
Get the support values of the given pattern set in this transaction bag.- Parameters:
patset
- the item pattern set which to get the support values in this transaction bag- Returns:
- an array of support values, with as many entries as there are patterns in the given pattern set, containing the support values of the item patterns in this transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getPattern
Get the given pattern for this transaction bag.- Parameters:
pat
- the item pattern which to get for this transaction bag- Returns:
- a new pattern with the same items, but with the item base and the support values of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getPattern
Get the given pattern for this transaction bag.- Parameters:
items
- the array of items to of the pattern to get (may be oversized)cnt
- the number of items in the given array to consider; if negative, the length of the item arrayitems
is used- Returns:
- a new pattern with the same items, but with the item base and the support values of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getPattern
Get the given pattern for this transaction bag.- Parameters:
items
- the array of items to of the pattern to get (may be oversized)- Returns:
- a new pattern with the same items, but with the item base and the support values of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getPatternSet
Get the given pattern set for this transaction bag.- Parameters:
patset
- the item pattern set which to get for this transaction bag- Returns:
- a new pattern set with the same patterns, but with the item base and the support values of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
GetRule
Get the given association rule for this transaction bag.- Parameters:
rule
- the association rule which to get for this transaction bag- Returns:
- a new association rule with the same items, but with the item base and the support values of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
getRuleSet
Get the given association rule set for this transaction bag.- Parameters:
ruleset
- the association rule set which to get for this transaction bag- Returns:
- a new association rule set with the same rules, but with the item base and the support values of the transaction bag
- Since:
- 2017.06.20 (Christian Borgelt)
-
recodeTo
public final void recodeTo(util.IdMap ibase) Recode a transaction bag to another item base, replacing the item base.- Parameters:
ibase
- the item base to recode the transaction bag to- Since:
- 2017.06.20 (Christian Borgelt)
-
pack
public final void pack()Pack the transactions, i.e., optimize memory usage.- Since:
- 2014.10.03 (Christian Borgelt)
-
getTrActs
public final int[][] getTrActs()Get all transactions as an array of integer arrays.- Returns:
- all transactions as an array of integer arrays.
- Since:
- 2014.10.03 (Christian Borgelt)
-
getWeights
public final int[] getWeights()Get all transaction weights as an array of integers.- Returns:
- all transaction weights as an array of integers
- Since:
- 2014.10.23 (Christian Borgelt)
-
write
Write a transaction bag/multiset.- Parameters:
writer
- the table writer to write to- Throws:
IOException
- if a write error occurs- Since:
- 2007.06.06 (Christian Borgelt)
-
write
Write a transaction bag/multiset.- Parameters:
writer
- the table writer to write towgt
- whether to write transaction weights/multiplicities- Throws:
IOException
- if a write error occurs- Since:
- 2014.10.02 (Christian Borgelt)
-
parse
public static TrActBag parse(util.IdMap ibase, util.TableReader reader, boolean wgt) throws IOException Parse a bag/multiset of transactions.- Parameters:
ibase
- the underlying item basereader
- the table reader to read fromwgt
- whether to read transaction weights/multiplicities- Returns:
- the parsed bag/multiset of transactions
- Throws:
IOException
- if a read error occurs- Since:
- 2014.10.02 (Christian Borgelt)
-
parse
Parse a bag/multiset of transactions.- Parameters:
ibase
- the underlying item basereader
- the table reader to read from- Returns:
- the parsed bag/multiset of transactions
- Throws:
IOException
- if a read error occurs- Since:
- 2007.06.06 (Christian Borgelt)
-
parse
Parse a bag/multiset of transactions.- Parameters:
ibase
- the underlying item basereader
- the reader to read fromwgt
- whether to read transaction weights/multiplicities- Returns:
- the parsed bag/multiset of transactions
- Throws:
IOException
- if a read error occurs- Since:
- 2014.10.02 (Christian Borgelt)
-
parse
Parse a bag/multiset of transactions.- Parameters:
ibase
- the underlying item basereader
- the reader to read from- Returns:
- the parsed bag/multiset of transactions
- Throws:
IOException
- if a read error occurs- Since:
- 2014.10.02 (Christian Borgelt)
-
main
Main function for testing some basic functionality.It is tried to parse the file that is given as the first command line argument as a bag/multiset of transactions.
- Parameters:
args
- the command line arguments- Since:
- 2007.06.06 (Christian Borgelt)
-