@Deprecated public abstract class SparseVector extends Object implements Iterable<VectorEntry>, Serializable
Read-only interface to sparse vectors.
This vector class works a lot like a map, but it also caches some commonly-used statistics. The values are stored in parallel arrays sorted by key. This allows fast lookup and sorted iteration. All iterators access the items in key order.
Vectors have a key domain, which is a set containing all valid keys in the vector. This key domain is fixed at construction; mutable vectors cannot set values for keys not in this domain. Thinking of the vector as a function from longs to doubles, the key domain would actually be the codomain, and the key set the algebraic domain, but that gets cumbersome to write in code. So think of the key domain as the domain from which valid keys are drawn.
This class provides a read-only interface to sparse vectors. It may actually be a MutableSparseVector
, so the data may be modified by code elsewhere that has access to the mutable representation. For sparse vectors that are guaranteed to be unchanging, see ImmutableSparseVector
.
Modifier and Type | Method and Description |
---|---|
Long2DoubleMap |
asMap()
Deprecated.
|
abstract SparseVector |
combineWith(SparseVector o)
Deprecated.
Combine this vector with another vector by taking the union of the key domains of two vectors.
|
boolean |
containsKey(long key)
Deprecated.
Query whether the vector contains an entry for the key in question.
|
int |
countCommonKeys(SparseVector o)
Deprecated.
Count the common keys between two vectors.
|
double |
dot(SparseVector o)
Deprecated.
Compute the dot product between two vectors.
|
static ImmutableSparseVector |
empty()
Deprecated.
Get an empty sparse vector.
|
boolean |
equals(Object o)
Deprecated.
|
Iterable<VectorEntry> |
fast()
Deprecated.
Fast iteration is going away.
|
Iterable<VectorEntry> |
fast(VectorEntry.State state)
Deprecated.
Fast iteration is going away.
|
static Iterable<org.apache.commons.lang3.tuple.Pair<VectorEntry,VectorEntry>> |
fastIntersect(SparseVector v1,
SparseVector v2)
Deprecated.
Iterate over the intersection of two vectors without the overhead of object creation.
|
Iterator<VectorEntry> |
fastIterator()
Deprecated.
Fast iteration is going away.
|
Iterator<VectorEntry> |
fastIterator(VectorEntry.State state)
Deprecated.
Fast iteration is going away.
|
double |
get(long key)
Deprecated.
Get the value for key.
|
double |
get(long key,
double dft)
Deprecated.
Get the value for key.
|
double |
get(VectorEntry entry)
Deprecated.
Get the value for the entry’s key.
|
abstract <K> Long2ObjectMap<K> |
getChannel(TypedSymbol<K> channelSymbol)
Deprecated.
Fetch the channel stored under a particular typed symbol.
|
abstract Set<TypedSymbol<?>> |
getChannelSymbols()
Deprecated.
Retrieve all symbols that map to typed side channels for this vector.
|
abstract SparseVector |
getChannelVector(Symbol channelSymbol)
Deprecated.
Get the vector associated with a particular unboxed channel.
|
abstract Set<Symbol> |
getChannelVectorSymbols()
Deprecated.
Retrieve all symbols that map to side channels for this vector.
|
abstract boolean |
hasChannel(TypedSymbol<?> channelSymbol)
Deprecated.
Return whether this sparse vector has a channel stored under a particular typed symbol.
|
abstract boolean |
hasChannelVector(Symbol channelSymbol)
Deprecated.
Return whether this sparse vector has a channel vector stored under a particular symbol.
|
int |
hashCode()
Deprecated.
|
abstract ImmutableSparseVector |
immutable()
Deprecated.
Return an immutable snapshot of this sparse vector.
|
boolean |
isEmpty()
Deprecated.
Query whether this vector is empty.
|
boolean |
isSet(VectorEntry entry)
Deprecated.
Check whether an entry is set.
|
Iterator<VectorEntry> |
iterator()
Deprecated.
|
Iterator<VectorEntry> |
iterator(VectorEntry.State state)
Deprecated.
|
LongSortedSet |
keyDomain()
Deprecated.
Get the key domain for this vector.
|
LongArrayList |
keysByValue()
Deprecated.
Return the keys of this vector sorted by value.
|
LongArrayList |
keysByValue(boolean decreasing)
Deprecated.
Get the keys of this vector sorted by the value of the items stored for each key.
|
LongSortedSet |
keySet()
Deprecated.
Get the set of keys of this vector.
|
double |
mean()
Deprecated.
Compute and return the mean of the vector’s values.
|
abstract MutableSparseVector |
mutableCopy()
Deprecated.
Return a mutable copy of this sparse vector.
|
double |
norm()
Deprecated.
Compute and return the L2 norm (Euclidian length) of the vector.
|
int |
size()
Deprecated.
Get the size of this vector (the number of keys).
|
double |
sum()
Deprecated.
Compute and return the L1 norm (sum) of the vector.
|
double |
sumAbs()
Deprecated.
Compute and return the sum of the absolute values of the vector.
|
String |
toString()
Deprecated.
|
LongSortedSet |
unsetKeySet()
Deprecated.
Get the set of unset keys.
|
DoubleCollection |
values()
Deprecated.
Get the collection of values of this vector.
|
Collection<VectorEntry> |
view(VectorEntry.State state)
Deprecated.
Get a collection view of a vector entry.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static Iterable<org.apache.commons.lang3.tuple.Pair<VectorEntry,VectorEntry>> fastIntersect(SparseVector v1, SparseVector v2)
Iterate over the intersection of two vectors without the overhead of object creation.
v1
- The first vector.v2
- The second vector.public Long2DoubleMap asMap()
public boolean containsKey(long key)
Query whether the vector contains an entry for the key in question.
key
- The key to search for.true
if the key exists.public double get(long key)
Get the value for key.
key
- the key to look up; the key must be in the key set.IllegalArgumentException
- if key is not in the key set.public double get(long key, double dft)
Get the value for key.
key
- the key to look updft
- The value to return if the key is not in the vectorpublic double get(VectorEntry entry)
Get the value for the entry’s key.
entry
- A VectorEntry
with the key to look upIllegalArgumentException
- if the entry is unset, or if it is not from this vector or another vector sharing the same key domain. Only vectors and their side channels share key domains for the purposes of this check.public boolean isSet(VectorEntry entry)
Check whether an entry is set.
entry
- The entry.true
if the entry is set in this vector.IllegalArgumentException
- if the entry is not from this vector or another vector sharing the same key domain. Only vectors and their side channels share key domains for the purposes of this check.@Deprecated public Iterator<VectorEntry> fastIterator()
Fast iterator over all set entries (it can reuse entry objects).
fastIterator(VectorEntry.State)
,
Long2DoubleMap.FastEntrySet.fastIterator()
@Deprecated public Iterator<VectorEntry> fastIterator(VectorEntry.State state)
Fast iterator over entries (it can reuse entry objects).
state
- The state of entries to iterate.Long2DoubleMap.FastEntrySet.fastIterator()
@Deprecated public Iterable<VectorEntry> fast()
Return an iterable view of this vector using a fast iterator. This method delegates to fast(VectorEntry.State)
with state VectorEntry.State.SET
.
fastIterator()
@Deprecated public Iterable<VectorEntry> fast(VectorEntry.State state)
Return an iterable view of this vector using a fast iterator.
state
- The entries the resulting iterable should return.fastIterator(VectorEntry.State)
public Iterator<VectorEntry> iterator()
iterator
in interface Iterable<VectorEntry>
public Iterator<VectorEntry> iterator(VectorEntry.State state)
public Collection<VectorEntry> view(VectorEntry.State state)
Get a collection view of a vector entry.
state
- The state of entries to view.public LongSortedSet keyDomain()
Get the key domain for this vector. All keys used are in this set. The keys will be in sorted order.
public LongSortedSet keySet()
Get the set of keys of this vector. It is a subset of the key domain. The keys will be in sorted order.
public LongSortedSet unsetKeySet()
Get the set of unset keys. This is (D \ S), where (D) is the key domain and (S) the key set.
public LongArrayList keysByValue()
Return the keys of this vector sorted by value.
keysByValue(boolean)
public DoubleCollection values()
Get the collection of values of this vector.
public LongArrayList keysByValue(boolean decreasing)
Get the keys of this vector sorted by the value of the items stored for each key.
decreasing
- If true
, sort in decreasing order.public int size()
Get the size of this vector (the number of keys).
public boolean isEmpty()
Query whether this vector is empty.
true
if the vector is empty.public double norm()
Compute and return the L2 norm (Euclidian length) of the vector.
public double sum()
Compute and return the L1 norm (sum) of the vector.
public double sumAbs()
Compute and return the sum of the absolute values of the vector.
public double mean()
Compute and return the mean of the vector’s values.
public double dot(SparseVector o)
Compute the dot product between two vectors.
o
- The other vector.public int countCommonKeys(SparseVector o)
Count the common keys between two vectors.
o
- The other vector.public abstract SparseVector combineWith(SparseVector o)
Combine this vector with another vector by taking the union of the key domains of two vectors. If both vectors have values the same key, the values in o
override those from the current vector.
o
- The other vectorpublic abstract ImmutableSparseVector immutable()
Return an immutable snapshot of this sparse vector. The new vector’s key domain may be shrunk to remove storage of unused keys; no keys in the key set will be removed.
public abstract MutableSparseVector mutableCopy()
Return a mutable copy of this sparse vector. The key domain of the mutable vector will be the same as this vector’s key domain.
public abstract boolean hasChannelVector(Symbol channelSymbol)
Return whether this sparse vector has a channel vector stored under a particular symbol.
channelSymbol
- the symbol under which the channel was stored in the vector.public abstract boolean hasChannel(TypedSymbol<?> channelSymbol)
Return whether this sparse vector has a channel stored under a particular typed symbol.
channelSymbol
- the typed symbol under which the channel was stored in the vector.public abstract SparseVector getChannelVector(Symbol channelSymbol)
Get the vector associated with a particular unboxed channel.
channelSymbol
- the symbol under which the channel was/is stored in the vector.null
if there is no such channel.public abstract <K> Long2ObjectMap<K> getChannel(TypedSymbol<K> channelSymbol)
Fetch the channel stored under a particular typed symbol.
channelSymbol
- the typed symbol under which the channel was/is stored in the vector.null
if there is no such channel.public abstract Set<Symbol> getChannelVectorSymbols()
Retrieve all symbols that map to side channels for this vector.
public abstract Set<TypedSymbol<?>> getChannelSymbols()
Retrieve all symbols that map to typed side channels for this vector.
public static ImmutableSparseVector empty()
Get an empty sparse vector.