public abstract class VectorSimilarity extends Object implements Similarity
Modifier and Type | Field and Description |
---|---|
protected FastPreferenceData<?,?> |
data
User-item preferences.
|
protected boolean |
dense
If true, dense vectors are used to calculate similarities.
|
protected double[] |
norm2Array
Cached normalization for when dense is true.
|
protected it.unimi.dsi.fastutil.ints.Int2DoubleMap |
norm2Map
Cached normalization for when dense is false.
|
Constructor and Description |
---|
VectorSimilarity(FastPreferenceData<?,?> data,
boolean dense)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract double |
sim(double product,
double norm2A,
double norm2B)
Calculates the similarity value.
|
Stream<Tuple2id> |
similarElems(int idx1)
Returns all the users/items having a similarity greater than 0,
together with the value of the similarity.
|
IntToDoubleFunction |
similarity(int idx1)
Returns a function that returns the similarity with the user/item.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
similarity
protected final FastPreferenceData<?,?> data
protected final boolean dense
protected final it.unimi.dsi.fastutil.ints.Int2DoubleMap norm2Map
protected final double[] norm2Array
public VectorSimilarity(FastPreferenceData<?,?> data, boolean dense)
data
- preference datadense
- true for array-based calculations, false to map-basedpublic IntToDoubleFunction similarity(int idx1)
Similarity
similarity
in interface Similarity
idx1
- index of the user/itempublic Stream<Tuple2id> similarElems(int idx1)
Similarity
similarElems
in interface Similarity
idx1
- index of user/itemprotected abstract double sim(double product, double norm2A, double norm2B)
product
- value of the inner product of vectorsnorm2A
- square of the norm of the first vectornorm2B
- square of the norm of the second vectorCopyright © 2016. All rights reserved.