public class SparseVector extends Object implements Vector
| Modifier and Type | Field and Description |
|---|---|
static float |
threshold |
| Constructor and Description |
|---|
SparseVector() |
| Modifier and Type | Method and Description |
|---|---|
void |
add(float coeff,
float vectorCoeff,
Vector vector)
Add a
vector multiplied by vectorCoeff to this
vector multiplied by |
void |
add(float coeff,
Vector vector)
Add a
vector multiplied by coeff to this vector |
void |
add(Vector vector)
Add a
vector to this vector |
SparseVector |
copyVector()
Returns a copy of this vector.
|
float |
euclideanDistance(Vector vector)
Returns the euclidean distance between this vector and
vector |
Map<Object,Number> |
getActiveFeatures()
Returns a map containing all the non-zero features
|
float |
getFeatureValue(Object featureIdentifier)
Returns the value of the feature identified with
featureIdentifier |
float |
getFeatureValue(String featureName)
Returns the value associated to a feature
|
static gnu.trove.map.TIntObjectMap<String> |
getFromIntToWord() |
static gnu.trove.map.TObjectIntMap<String> |
getFromWordToInt() |
float |
getSquaredNorm()
Returns the squared norm of this vector
|
String |
getTextFromData()
Returns a textual representation of the data stored in this
representation
|
gnu.trove.map.TIntFloatMap |
getVector() |
static int |
getWordCounter() |
SparseVector |
getZeroVector()
Returns a vector whose values are all 0.
|
void |
incrementFeature(String featureName,
float valueIncrement)
Increments the value associated to a feature
|
float |
innerProduct(Vector vector)
Returns the dot product between this vector and
vector |
boolean |
isCompatible(Representation rep)
Evaluates whether a representation is compatible with this one, e.g.., they have
same type and pass additional checks that are type-dependent
|
void |
merge(Vector vector,
float coefficient,
String newDimensionPrefix)
Merge this vector with
vector (it is like a vector
concatenation) If V1 is the space where this vector lies and V2 is the
space where vector lies, then the resulting vector lies in
V1xV2 |
void |
normalize()
Scales the representation in order to have a unit norm in the explicit feature
space
|
void |
pointWiseProduct(Vector vector)
Compute the point-wise product of this vector with the one in
vector. |
void |
scale(float coeff)
Multiplies each element of this representation by
coeff |
void |
setDataFromText(String representationDescription)
Initializes a Representation using its textual description provided in
representationDescription |
void |
setFeatureValue(Object featureIdentifier,
float value)
Assigns
value to the feature identified by |
void |
setFeatureValue(String featureName,
float value)
Sets the value of a feature
|
void |
setVector(gnu.trove.map.TIntFloatMap vector) |
static void |
setWordCounter(int wordCounter) |
String |
toString() |
public static final float threshold
public void normalize()
Normalizablenormalize in interface Normalizablepublic void setDataFromText(String representationDescription) throws IOException
RepresentationrepresentationDescriptionsetDataFromText in interface RepresentationrepresentationDescription - the textual description of the representation to be
initializedIOExceptionpublic gnu.trove.map.TIntFloatMap getVector()
public void setVector(gnu.trove.map.TIntFloatMap vector)
vector - the vector to setpublic float innerProduct(Vector vector)
VectorvectorinnerProduct in interface Vectorpublic void scale(float coeff)
Normalizablecoeffscale in interface Normalizablecoeff - the scaling factorpublic void add(Vector vector)
Vectorvector to this vectorpublic void add(float coeff,
Vector vector)
Vectorvector multiplied by coeff to this vectorpublic void add(float coeff,
float vectorCoeff,
Vector vector)
Vectorvector multiplied by vectorCoeff to this
vector multiplied bypublic SparseVector getZeroVector()
VectorgetZeroVector in interface Vectorpublic String getTextFromData()
RepresentationgetTextFromData in interface Representationpublic float getSquaredNorm()
NormalizablegetSquaredNorm in interface Normalizablepublic Map<Object,Number> getActiveFeatures()
VectorgetActiveFeatures in interface Vectorpublic void merge(Vector vector, float coefficient, String newDimensionPrefix)
vector (it is like a vector
concatenation) If V1 is the space where this vector lies and V2 is the
space where vector lies, then the resulting vector lies in
V1xV2
NOTE: this is not a sum because even if some feature names are shared
between the two vectors, those will be considered different dimensions (a
prefix is added to all feature names of vector)
vector - the input vector to be merged with thiscoefficient - a scaling factor for vectornewDimensionPrefix - the prefix to be added to all the feature names of
vector during the merging process
(vector is not modified)public void pointWiseProduct(Vector vector)
Vectorvector.pointWiseProduct in interface Vectorvector - the vector used for the point-wise productpublic SparseVector copyVector()
VectorcopyVector in interface Vectorpublic void setFeatureValue(String featureName, float value)
featureName - the name of the featurevalue - the value of the featurepublic float getFeatureValue(String featureName)
featureName - the identifier of the featurepublic void incrementFeature(String featureName, float valueIncrement)
featureName - the identifier of the featurevalueIncrement - the incrementpublic void setFeatureValue(Object featureIdentifier, float value)
Vectorvalue to the feature identified by featureIdentifier
NOTE: this method could be not the most efficient to set a feature value. Actual implementations
of the Vector class may provide faster methods using their specific type to identify features (instead of
a generic Object)
setFeatureValue in interface VectorfeatureIdentifier - the identifier of the featurevalue - the value of the featurepublic float getFeatureValue(Object featureIdentifier)
VectorfeatureIdentifier
NOTE: this method could be not the most efficient to get a feature value. Actual implementations of the Vector class may provide faster methods using their specific type to identify features (instead of a generic Object)
getFeatureValue in interface Vectorpublic float euclideanDistance(Vector vector) throws VectorOperationException
VectorvectoreuclideanDistance in interface VectorVectorOperationExceptionpublic boolean isCompatible(Representation rep)
RepresentationisCompatible in interface Representationrep - the representation to be compared with this onepublic static void setWordCounter(int wordCounter)
public static gnu.trove.map.TIntObjectMap<String> getFromIntToWord()
public static gnu.trove.map.TObjectIntMap<String> getFromWordToInt()
public static int getWordCounter()
Copyright © 2018 Semantic Analytics Group @ Uniroma2. All rights reserved.