org.grouplens.lenskit.vectors

## Class ImmutableSparseVector

• ### Method Summary

All Methods
Modifier and Type Method and Description
ImmutableSparseVector combineWith(SparseVector o)
Combine this vector with another vector by taking the union of the key domains of two vectors.
static ImmutableSparseVector create(Map<Long,Double> data)
Construct a new immutable sparse vector from a map.
<K> Long2ObjectMap<K> getChannel(TypedSymbol<K> channelSymbol)
Fetch the channel stored under a particular typed symbol.
Set<TypedSymbol<?>> getChannelSymbols()
Retrieve all symbols that map to typed side channels for this vector.
ImmutableSparseVector getChannelVector(Symbol channelSymbol)
Get the vector associated with a particular unboxed channel.
Set<Symbol> getChannelVectorSymbols()
Retrieve all symbols that map to side channels for this vector.
boolean hasChannel(TypedSymbol<?> channelSymbol)
Return whether this sparse vector has a channel stored under a particular typed symbol.
boolean hasChannelVector(Symbol channelSymbol)
Return whether this sparse vector has a channel vector stored under a particular symbol.
ImmutableSparseVector immutable()
Return an immutable snapshot of this sparse vector.
double mean()
Compute and return the mean of the vector's values.
MutableSparseVector mutableCopy()
Return a mutable copy of this sparse vector.
double norm()
Compute and return the L2 norm (Euclidian length) of the vector.
double sum()
Compute and return the L1 norm (sum) of the vector.
• ### Methods inherited from class org.grouplens.lenskit.vectors.SparseVector

containsKey, countCommonKeys, dot, empty, equals, fast, fast, fastIterator, fastIterator, get, get, get, hashCode, isEmpty, isSet, iterator, iterator, keyDomain, keysByValue, keysByValue, keySet, size, sumAbs, toString, unsetKeySet, values, view
• ### Methods inherited from class java.lang.Object

clone, finalize, getClass, notify, notifyAll, wait, wait, wait
• ### Methods inherited from interface java.lang.Iterable

forEach, spliterator
• ### Method Detail

• #### create

public static ImmutableSparseVector create(Map<Long,Double> data)
Construct a new immutable sparse vector from a map.
Parameters:
data - The data. It may not contain any null values.
Returns:
An immutable sparse vector containing the specified data.
• #### immutable

public ImmutableSparseVector immutable()
Description copied from class: SparseVector
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.
Specified by:
immutable in class SparseVector
Returns:
An immutable sparse vector whose contents are the same as this vector. If the vector is already immutable, the returned object may be identical.
• #### mutableCopy

public MutableSparseVector mutableCopy()
Description copied from class: SparseVector
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.
Specified by:
mutableCopy in class SparseVector
Returns:
A mutable sparse vector which can be modified without modifying this vector.
• #### hasChannelVector

public boolean hasChannelVector(Symbol channelSymbol)
Description copied from class: SparseVector
Return whether this sparse vector has a channel vector stored under a particular symbol.
Specified by:
hasChannelVector in class SparseVector
Parameters:
channelSymbol - the symbol under which the channel was stored in the vector.
Returns:
whether this vector has such a channel right now.
• #### hasChannel

public boolean hasChannel(TypedSymbol<?> channelSymbol)
Description copied from class: SparseVector
Return whether this sparse vector has a channel stored under a particular typed symbol.
Specified by:
hasChannel in class SparseVector
Parameters:
channelSymbol - the typed symbol under which the channel was stored in the vector.
Returns:
whether this vector has such a channel right now.
• #### getChannelVector

public ImmutableSparseVector getChannelVector(Symbol channelSymbol)
Description copied from class: SparseVector
Get the vector associated with a particular unboxed channel.
Specified by:
getChannelVector in class SparseVector
Parameters:
channelSymbol - the symbol under which the channel was/is stored in the vector.
Returns:
The vector corresponding to the specified unboxed channel, or null if there is no such channel.
• #### getChannel

public <K> Long2ObjectMap<K> getChannel(TypedSymbol<K> channelSymbol)
Description copied from class: SparseVector
Fetch the channel stored under a particular typed symbol.
Specified by:
getChannel in class SparseVector
Parameters:
channelSymbol - the typed symbol under which the channel was/is stored in the vector.
Returns:
the channel, which is itself a map from the key domain to objects of the channel's type, or null if there is no such channel.
• #### getChannelVectorSymbols

public Set<Symbol> getChannelVectorSymbols()
Description copied from class: SparseVector
Retrieve all symbols that map to side channels for this vector.
Specified by:
getChannelVectorSymbols in class SparseVector
Returns:
A set of symbols, each of which identifies a side channel of the vector.
• #### getChannelSymbols

public Set<TypedSymbol<?>> getChannelSymbols()
Description copied from class: SparseVector
Retrieve all symbols that map to typed side channels for this vector.
Specified by:
getChannelSymbols in class SparseVector
Returns:
A set of symbols, each of which identifies a side channel of the vector.
• #### combineWith

public ImmutableSparseVector combineWith(SparseVector o)
Description copied from class: SparseVector
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.
Specified by:
combineWith in class SparseVector
Parameters:
o - The other vector
Returns:
A vector whose key domain is the union of the key domains of this vector and the other.
• #### norm

public double norm()
Description copied from class: SparseVector
Compute and return the L2 norm (Euclidian length) of the vector.
Overrides:
norm in class SparseVector
Returns:
The L2 norm of the vector
• #### sum

public double sum()
Description copied from class: SparseVector
Compute and return the L1 norm (sum) of the vector.
Overrides:
sum in class SparseVector
Returns:
the sum of the vector's values
• #### mean

public double mean()
Description copied from class: SparseVector
Compute and return the mean of the vector's values.
Overrides:
mean in class SparseVector
Returns:
the mean of the vector