public class PairSet<T,I> extends AbstractExtendedSet<Pair<T,I>> implements Serializable
This class can be used to represent a set of transactions, where each transaction is a set of items. Rows are transactions, columns are the items involved with each transaction.
Pair,
IntSet,
Serialized FormAbstractExtendedSet.ExtendedSubSet, AbstractExtendedSet.FilteredSet, AbstractExtendedSet.UnmodifiableExtendedSetExtendedSet.ExtendedIterator<X>| Constructor and Description |
|---|
PairSet(BinaryMatrix matrix,
Collection<? extends Pair<T,I>> pairs)
Converts a generic collection of transaction-item pairs to a
PairSet instance. |
PairSet(BinaryMatrix matrix,
Collection<T> transactions,
Collection<I> items)
Initializes the set by specifying all possible transactions and items.
|
PairSet(BinaryMatrix matrix,
Object[][] pairs)
Initializes the set by specifying all possible transactions and items.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Pair<T,I> e) |
boolean |
add(T transaction,
I item)
Adds a single transaction-item pair
|
boolean |
addAll(Collection<? extends Pair<T,I>> c) |
boolean |
addAll(Collection<T> trans,
Collection<I> items)
Add the pairs obtained from the Cartesian product of transactions
and items
|
boolean |
addAll(Collection<T> trans,
I item)
Add the pairs obtained from the Cartesian product of transactions
and items
|
boolean |
addAll(T trans,
Collection<I> items)
Add the pairs obtained from the Cartesian product of transactions
and items
|
IndexedSet<I> |
allItems()
Gets the set of all possible items that can be contained within each
transaction
|
IndexedSet<T> |
allTransactions()
Gets the set of all possible transactions that can be contained within
the set
|
double |
bitmapCompressionRatio()
|
void |
clear() |
void |
clear(Pair<T,I> from,
Pair<T,I> to)
Removes from the set all the elements between
first and
last, both included. |
PairSet<T,I> |
clone()
See the
clone() of Object |
double |
collectionCompressionRatio()
|
PairSet<T,I> |
compacted()
Creates a new
PairSet instance with only non-empty transactions
and items. |
Comparator<? super Pair<T,I>> |
comparator() |
int |
compareTo(ExtendedSet<Pair<T,I>> o)
Compares this object with the specified object for order.
|
void |
complement()
Complements the current set.
|
PairSet<T,I> |
complemented()
Generates the complement set.
|
int |
complementSize()
Computes the complement set size.
|
boolean |
contains(Object o) |
boolean |
contains(T transaction,
I item)
Checks if the given transaction-item pair is contained within the set
|
boolean |
containsAll(Collection<?> c) |
boolean |
containsAll(Collection<T> trans,
Collection<I> items)
Checks if the pairs obtained from the Cartesian product of
transactions and items are contained
|
boolean |
containsAll(Collection<T> trans,
I item)
Checks if the pairs obtained from the Cartesian product of
transactions and items are contained
|
boolean |
containsAll(T trans,
Collection<I> items)
Checks if the pairs obtained from the Cartesian product of
transactions and items are contained
|
boolean |
containsAny(Collection<? extends Pair<T,I>> other)
Returns
true if the specified Collection instance
contains any elements that are also contained within this
ExtendedSet instance |
boolean |
containsAtLeast(Collection<? extends Pair<T,I>> other,
int minElements)
Returns
true if the specified Collection instance
contains at least minElements elements that are also
contained within this ExtendedSet instance |
PairSet<T,I> |
convert(Collection<?> c)
Converts a given
Collection instance into an instance of the
current class. |
PairSet<T,I> |
convert(Object... e)
Converts a given integer array into an instance of the current class
|
static PairSet<Integer,Integer> |
createFromBinaryMatrix(BinaryMatrix b)
Wraps a
BinaryMatrix instance with a PairSet instance. |
String |
debugInfo()
Prints debug info about the given
ExtendedSet implementation |
ExtendedSet.ExtendedIterator<Pair<T,I>> |
descendingIterator()
Gets the descending order iterator over the elements of type
T |
PairSet<T,I> |
difference(Collection<? extends Pair<T,I>> other)
Generates the difference set
|
int |
differenceSize(Collection<? extends Pair<T,I>> other)
Computes the difference set size.
|
PairSet<T,I> |
empty()
Generates an empty set
|
boolean |
equals(Object obj) |
void |
fill(Pair<T,I> from,
Pair<T,I> to)
Adds to the set all the elements between
first and
last, both included. |
Pair<T,I> |
first() |
void |
flip(Pair<T,I> e)
Adds the element if it not existing, or removes it if existing
|
Pair<T,I> |
get(int index)
Gets the
ith element of the set |
int |
hashCode() |
PairSet<T,I> |
headSet(Pair<T,I> toElement) |
int |
indexOf(Pair<T,I> element)
Provides position of element within the set.
|
PairSet<T,I> |
intersection(Collection<? extends Pair<T,I>> c)
Generates the intersection set
|
IndexedSet<I> |
involvedItems()
Gets the set of items in
allItems() that are contained in at
least one transaction |
IndexedSet<T> |
involvedTransactions()
Gets the set of transactions in
allTransactions() that contains
at least one item |
boolean |
isEmpty() |
IndexedSet<I> |
itemsOf(T transaction)
Lists all items contained within a given transaction
|
ExtendedSet.ExtendedIterator<Pair<T,I>> |
iterator() |
Pair<T,I> |
last() |
BinaryMatrix |
matrix()
Returns the set of indices.
|
PairSet<T,I> |
merged(PairSet<T,I> other)
Creates a new
PairSet instance with the union of all possible
transactions and items as result for allTransactions() and
allItems(), respectively, and the union of pairs. |
List<? extends PairSet<T,I>> |
powerSet()
Computes the power-set of the current set.
|
List<? extends PairSet<T,I>> |
powerSet(int min,
int max)
Computes a subset of the power-set of the current set, composed by those
subsets that have cardinality between
min and
max. |
boolean |
remove(Object o) |
boolean |
remove(T transaction,
I item)
Removes a single transaction-item pair
|
boolean |
removeAll(Collection<?> c) |
boolean |
removeAll(Collection<T> trans,
Collection<I> items)
Removes the pairs obtained from the Cartesian product of transactions and
items
|
boolean |
removeAll(Collection<T> trans,
I item)
Removes the pairs obtained from the Cartesian product of transactions and
items
|
boolean |
removeAll(T trans,
Collection<I> items)
Removes the pairs obtained from the Cartesian product of transactions and
items
|
boolean |
retainAll(Collection<?> c) |
boolean |
retainAll(Collection<T> trans,
Collection<I> items)
Retains the pairs obtained from the Cartesian product of transactions and
items
|
boolean |
retainAll(Collection<T> trans,
I item)
Retains the pairs obtained from the Cartesian product of transactions and
items
|
boolean |
retainAll(T trans,
Collection<I> items)
Retains the pairs obtained from the Cartesian product of transactions and
items
|
int |
size() |
PairSet<T,I> |
subSet(Pair<T,I> fromElement,
Pair<T,I> toElement) |
PairSet<T,I> |
symmetricDifference(Collection<? extends Pair<T,I>> other)
Generates the symmetric difference set
|
int |
symmetricDifferenceSize(Collection<? extends Pair<T,I>> other)
Computes the symmetric difference set size.
|
PairSet<T,I> |
tailSet(Pair<T,I> fromElement) |
IndexedSet<T> |
transactionsOf(I item)
Lists all transactions involved with a specified item
|
PairSet<I,T> |
transposed() |
PairSet<T,I> |
union(Collection<? extends Pair<T,I>> other)
Generates the union set
|
int |
unionSize(Collection<? extends Pair<T,I>> other)
Computes the union set size.
|
descending, intersectionSize, jaccardDistance, jaccardSimilarity, powerSetSize, powerSetSize, unmodifiable, weightedJaccardDistance, weightedJaccardSimilaritytoArray, toArray, toStringpublic PairSet(BinaryMatrix matrix, Collection<T> transactions, Collection<I> items)
matrix - BinaryMatrix instance used to internally represent the matrixtransactions - collection of all possible transactions. The specified
order will be preserved within when iterating over the
PairSet instance.items - collection of all possible items. The specified order
will be preserved within each transaction PairSet.public PairSet(BinaryMatrix matrix, Object[][] pairs)
matrix - BinaryMatrix instance used to internally represent the
matrixpairs - arrays n x 2 of pairs of transactions (first) and items (second).public PairSet(BinaryMatrix matrix, Collection<? extends Pair<T,I>> pairs)
PairSet instance.public static PairSet<Integer,Integer> createFromBinaryMatrix(BinaryMatrix b)
BinaryMatrix instance with a PairSet instance.
NOTE: the maximum item and transaction IDs are those existing in the binary matrix when the wrapping take place
b - a BinaryMatrix instance to wrapPairSet instance, indexed by the given matrixpublic PairSet<T,I> clone()
clone() of Object
NOTE: When overriding this method, please note that
Object.clone() is much slower then performing
new and "manually" copying data!
clone in interface ExtendedSet<Pair<T,I>>clone in class AbstractExtendedSet<Pair<T,I>>public boolean add(T transaction, I item)
transaction - the transaction of the pairitem - the item of the pairtrue if the set has been changedpublic boolean addAll(Collection<? extends Pair<T,I>> c)
public boolean addAll(Collection<T> trans, Collection<I> items)
trans - collection of transactionsitems - collection of itemstrue if the set set has been changedpublic boolean addAll(T trans, Collection<I> items)
trans - the given transactionitems - collection of itemstrue if the set set has been changedpublic boolean addAll(Collection<T> trans, I item)
trans - collection of transactionsitem - the given itemtrue if the set set has been changedpublic void clear()
public boolean contains(Object o)
public boolean contains(T transaction, I item)
transaction - the transaction of the pairitem - the item of the pairtrue if the given transaction-item pair is contained
within the setpublic boolean containsAll(Collection<?> c)
containsAll in interface Collection<Pair<T,I>>containsAll in interface Set<Pair<T,I>>containsAll in class AbstractCollection<Pair<T,I>>public boolean containsAll(Collection<T> trans, Collection<I> items)
trans - collection of transactionsitems - collection of itemstrue if the pairs set set has been changedpublic boolean containsAll(T trans, Collection<I> items)
trans - the transactionitems - collection of itemstrue if the pairs set set has been changedpublic boolean containsAll(Collection<T> trans, I item)
trans - collection of transactionsitem - the itemtrue if the pairs set set has been changedpublic boolean isEmpty()
public ExtendedSet.ExtendedIterator<Pair<T,I>> iterator()
public ExtendedSet.ExtendedIterator<Pair<T,I>> descendingIterator()
TdescendingIterator in interface ExtendedSet<Pair<T,I>>descendingIterator in class AbstractExtendedSet<Pair<T,I>>public boolean remove(Object o)
public boolean remove(T transaction, I item)
transaction - the transaction of the pairitem - the item of the pairtrue if the pair set has been changedpublic boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public boolean removeAll(Collection<T> trans, Collection<I> items)
trans - collection of transactionsitems - collection of itemstrue if the set set has been changedpublic boolean removeAll(T trans, Collection<I> items)
trans - a transactionitems - collection of itemstrue if the set set has been changedpublic boolean removeAll(Collection<T> trans, I item)
trans - collection of transactionsitem - collection of itemstrue if the set set has been changedpublic boolean retainAll(Collection<T> trans, Collection<I> items)
trans - collection of transactionsitems - collection of itemstrue if the set set has been changedpublic boolean retainAll(T trans, Collection<I> items)
trans - the transactionitems - collection of itemstrue if the set set has been changedpublic boolean retainAll(Collection<T> trans, I item)
trans - collection of transactionsitem - the itemtrue if the set set has been changedpublic int size()
public IndexedSet<T> allTransactions()
public IndexedSet<I> allItems()
public int hashCode()
public boolean equals(Object obj)
public IndexedSet<I> itemsOf(T transaction)
transaction - the given transactionpublic IndexedSet<T> transactionsOf(I item)
item - the given itempublic IndexedSet<T> involvedTransactions()
allTransactions() that contains
at least one itemallTransactions() that
contains at least one itempublic IndexedSet<I> involvedItems()
allItems() that are contained in at
least one transactionallItems() that are contained in at
least one transactionpublic Pair<T,I> get(int index)
ith element of the setget in interface ExtendedSet<Pair<T,I>>get in class AbstractExtendedSet<Pair<T,I>>index - position of the element in the sorted setith element of the setIndexOutOfBoundsException - if i is less than zero, or greater or equal to
size()public int indexOf(Pair<T,I> element)
It returns -1 if the element does not exist within the set.
indexOf in interface ExtendedSet<Pair<T,I>>indexOf in class AbstractExtendedSet<Pair<T,I>>element - element of the setpublic String debugInfo()
ExtendedSet implementationdebugInfo in interface ExtendedSet<Pair<T,I>>debugInfo in class AbstractExtendedSet<Pair<T,I>>public double bitmapCompressionRatio()
BitSet, 2 means twice the size of BitSet, etc.)bitmapCompressionRatio in interface ExtendedSet<Pair<T,I>>bitmapCompressionRatio in class AbstractExtendedSet<Pair<T,I>>public double collectionCompressionRatio()
ArrayList, 2 means twice the size of ArrayList, etc.)collectionCompressionRatio in interface ExtendedSet<Pair<T,I>>collectionCompressionRatio in class AbstractExtendedSet<Pair<T,I>>public BinaryMatrix matrix()
PairSet instance. Trying to perform operation on
out-of-bound indices will throw an IllegalArgumentException
exception.public PairSet<T,I> empty()
empty in interface ExtendedSet<Pair<T,I>>empty in class AbstractExtendedSet<Pair<T,I>>public void complement()
SortedSet.last() that do not exist in the
current set.complement in interface ExtendedSet<Pair<T,I>>ExtendedSet.complemented()public Comparator<? super Pair<T,I>> comparator()
comparator in interface SortedSet<Pair<T,I>>public PairSet<T,I> convert(Collection<?> c)
Collection instance into an instance of the
current class. NOTE: when the collection is already an instance of
the current class, the method returns the collection itself.convert in interface ExtendedSet<Pair<T,I>>convert in class AbstractExtendedSet<Pair<T,I>>c - collection to use to generate the new instanceExtendedSet.convert(Object...)public PairSet<T,I> convert(Object... e)
convert in interface ExtendedSet<Pair<T,I>>convert in class AbstractExtendedSet<Pair<T,I>>e - objects to use to generate the new instanceExtendedSet.convert(Collection)public void clear(Pair<T,I> from, Pair<T,I> to)
first and
last, both included. It supposes that there is an ordering
of the elements of type T and that the universe of all
possible elements is known.clear in interface ExtendedSet<Pair<T,I>>clear in class AbstractExtendedSet<Pair<T,I>>from - first elementto - last elementpublic int complementSize()
This is faster than calling ExtendedSet.complemented() and then
Set.size()
complementSize in interface ExtendedSet<Pair<T,I>>complementSize in class AbstractExtendedSet<Pair<T,I>>public PairSet<T,I> complemented()
SortedSet.last() that do not exist in the
current set.complemented in interface ExtendedSet<Pair<T,I>>complemented in class AbstractExtendedSet<Pair<T,I>>ExtendedSet.complement()public PairSet<T,I> difference(Collection<? extends Pair<T,I>> other)
difference in interface ExtendedSet<Pair<T,I>>difference in class AbstractExtendedSet<Pair<T,I>>other - ExtendedSet instance that represents the right
operandSet.removeAll(java.util.Collection)public boolean containsAny(Collection<? extends Pair<T,I>> other)
true if the specified Collection instance
contains any elements that are also contained within this
ExtendedSet instancecontainsAny in interface ExtendedSet<Pair<T,I>>containsAny in class AbstractExtendedSet<Pair<T,I>>other - ExtendedSet to intersect withExtendedSet intersects
the specified ExtendedSet.public boolean containsAtLeast(Collection<? extends Pair<T,I>> other, int minElements)
true if the specified Collection instance
contains at least minElements elements that are also
contained within this ExtendedSet instancecontainsAtLeast in interface ExtendedSet<Pair<T,I>>containsAtLeast in class AbstractExtendedSet<Pair<T,I>>other - Collection instance to intersect withminElements - minimum number of elements to be contained within this
ExtendedSet instanceExtendedSet intersects
the specified Collection.public int differenceSize(Collection<? extends Pair<T,I>> other)
This is faster than calling ExtendedSet.difference(Collection) and
then Set.size()
differenceSize in interface ExtendedSet<Pair<T,I>>differenceSize in class AbstractExtendedSet<Pair<T,I>>other - Collection instance that represents the right
operandpublic void fill(Pair<T,I> from, Pair<T,I> to)
first and
last, both included. It supposes that there is an ordering
of the elements of type T and that the universe of all
possible elements is known.fill in interface ExtendedSet<Pair<T,I>>fill in class AbstractExtendedSet<Pair<T,I>>from - first elementto - last elementpublic void flip(Pair<T,I> e)
flip in interface ExtendedSet<Pair<T,I>>flip in class AbstractExtendedSet<Pair<T,I>>e - element to flipExtendedSet.symmetricDifference(Collection)public PairSet<T,I> intersection(Collection<? extends Pair<T,I>> c)
intersection in interface ExtendedSet<Pair<T,I>>intersection in class AbstractExtendedSet<Pair<T,I>>c - ExtendedSet instance that represents the right
operandSet.retainAll(java.util.Collection)public List<? extends PairSet<T,I>> powerSet()
It is a particular implementation of the algorithm Apriori (see: Rakesh Agrawal, Ramakrishnan Srikant, Fast Algorithms for Mining Association Rules in Large Databases, in Proceedings of the 20th International Conference on Very Large Data Bases, p.487-499, 1994). The returned power-set does not contain the empty set.
The subsets composing the powerset are returned in a list that is sorted according to the lexicographical order provided by the sorted set.
powerSet in interface ExtendedSet<Pair<T,I>>powerSet in class AbstractExtendedSet<Pair<T,I>>ExtendedSet.powerSet(int, int),
ExtendedSet.powerSetSize()public List<? extends PairSet<T,I>> powerSet(int min, int max)
min and
max.
It is a particular implementation of the algorithm Apriori (see: Rakesh Agrawal, Ramakrishnan Srikant, Fast Algorithms for Mining Association Rules in Large Databases, in Proceedings of the 20th International Conference on Very Large Data Bases, p.487-499, 1994). The power-set does not contains the empty set.
The subsets composing the powerset are returned in a list that is sorted according to the lexicographical order provided by the sorted set.
powerSet in interface ExtendedSet<Pair<T,I>>powerSet in class AbstractExtendedSet<Pair<T,I>>min - minimum subset size (greater than zero)max - maximum subset sizeExtendedSet.powerSet(),
ExtendedSet.powerSetSize(int, int)public PairSet<T,I> symmetricDifference(Collection<? extends Pair<T,I>> other)
symmetricDifference in interface ExtendedSet<Pair<T,I>>symmetricDifference in class AbstractExtendedSet<Pair<T,I>>other - ExtendedSet instance that represents the right
operandExtendedSet.flip(Object)public int symmetricDifferenceSize(Collection<? extends Pair<T,I>> other)
This is faster than calling
ExtendedSet.symmetricDifference(Collection) and then Set.size()
symmetricDifferenceSize in interface ExtendedSet<Pair<T,I>>symmetricDifferenceSize in class AbstractExtendedSet<Pair<T,I>>other - Collection instance that represents the right
operandpublic PairSet<T,I> union(Collection<? extends Pair<T,I>> other)
union in interface ExtendedSet<Pair<T,I>>union in class AbstractExtendedSet<Pair<T,I>>other - ExtendedSet instance that represents the right
operandSet.addAll(java.util.Collection)public int unionSize(Collection<? extends Pair<T,I>> other)
This is faster than calling ExtendedSet.union(Collection) and then
Set.size()
unionSize in interface ExtendedSet<Pair<T,I>>unionSize in class AbstractExtendedSet<Pair<T,I>>other - Collection instance that represents the right
operandpublic int compareTo(ExtendedSet<Pair<T,I>> o)
IntSet
instance A is less than another IntSet instance
B if B-A (that is, the elements in
B that are not contained in A) contains at
least one element that is greater than all the elements in
A-B.
The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)
The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.
Finally, the implementor must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.
It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."
In the foregoing description, the notation sgn(expression ) designates the mathematical signum function, which is defined to return one of -1, 0, or 1 according to whether the value of expression is negative, zero or positive.
compareTo in interface ExtendedSet<Pair<T,I>>compareTo in interface Comparable<ExtendedSet<Pair<T,I>>>compareTo in class AbstractExtendedSet<Pair<T,I>>o - the object to be compared.public PairSet<T,I> merged(PairSet<T,I> other)
PairSet instance with the union of all possible
transactions and items as result for allTransactions() and
allItems(), respectively, and the union of pairs.Copyright © 2016. All rights reserved.