public class FeatureVector extends Object implements Cloneable, Serializable
| Modifier and Type | Field and Description |
|---|---|
protected FVector |
features
Stores non-label features.
|
protected FVector |
labels
Stores labels.
|
protected FeatureVector |
realCache
Caches the result of the
makeReal() method. |
protected double |
weight
With this variable, the user can weight the entire vector.
|
| Constructor and Description |
|---|
FeatureVector()
Simply instantiates the member variables.
|
FeatureVector(Feature f)
Creates the vector and adds the given feature to it.
|
FeatureVector(Feature[] features)
Creates the vector and adds the given features to it.
|
FeatureVector(Object[] ex,
Lexicon lex,
Lexicon llex)
Instantiates a feature vector from example arrays and lexicons.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFeature(Feature f)
Adds a feature to the vector.
|
void |
addFeatures(FeatureVector v)
Adds all the features in another vector to this vector.
|
void |
addLabel(Feature l)
Adds a label to the vector.
|
void |
addLabels(FeatureVector v)
Adds all the features in another vector (but not the labels in that vector) to the labels of
this vector.
|
void |
clear()
|
void |
clearLabels()
Removes all elements from just the
labels list. |
Object |
clone()
Returns a shallow clone of this vector; the vectors are cloned, but their elements aren't.
|
String[] |
discreteValueArray()
Returns all the values of the features in this vector (not labels) arranged in a
String array. |
double |
dot(FeatureVector vector)
Take the dot product of two feature vectors.
|
static double |
dot(int[] firstFeatures,
double[] firstValues,
int[] secondFeatures,
double[] secondValues)
Computes the dot product of the 2 argument vectors.
|
boolean |
equals(Object o)
Two
FeatureVectors are equivalent if they contain the same features and labels,
as defined by Feature equivalence. |
int |
featuresSize()
Returns the size of just the
features list. |
Feature |
firstFeature()
Returns the first feature in
features. |
Feature |
firstLabel()
Returns the first feature in
labels. |
Feature |
getFeature(int index)
Returns the feature at the specified index.
|
Feature |
getLabel(int index)
Returns the label at the specified index.
|
static SortedMap |
getSortedMap(int[] features,
double[] values)
Returns a sorted map where the key is the feature index and the value is the feature value.
|
double |
getWeight()
Returns the value of
weight. |
int |
hashCode()
The hash code for a
FeatureVector is simply the sum of the hash codes of the
features and the labels. |
boolean |
isLabeled()
Determines whether this vector has any labels.
|
double |
L2NormSquared()
Returns the square of the magnitude of the feature vector.
|
static double |
L2NormSquared(double[] exampleValues)
Returns the square of the magnitude of the given vector.
|
int |
labelsSize()
Returns the size of just the
labels list. |
FeatureVector |
makeReal()
Converts all of the features in the
features list to RealFeatures with
appropriate strengths. |
void |
read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the binary representation of a feature vector from the specified stream, overwriting
the contents of this vector.
|
double[] |
realValueArray()
Returns all the values of the features in this vector (not labels) arranged in a
double array. |
int |
size()
|
void |
sort()
Sorts both of the feature lists.
|
String |
toString()
Returns the string representation of this
FeatureVector as created by
write(StringBuffer). |
String |
toStringNoPackage()
Returns the string representation of this
FeatureVector like toString()
except without package names. |
boolean |
valueEquals(FeatureVector vector)
Two
FeatureVectors have equal value if they contain the same number of
Features and if the values of those Features are pair-wise equivalent
according to the Feature.valueEquals(String) method. |
void |
write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
Writes a binary representation of the feature vector.
|
void |
write(StringBuffer buffer)
Creates a string representation of this
FeatureVector. |
void |
write(StringBuffer buffer,
boolean packages)
Creates a string representation of this
FeatureVector. |
protected FVector features
protected FVector labels
protected double weight
protected FeatureVector realCache
makeReal() method.public FeatureVector()
public FeatureVector(Feature f)
f - A feature to start this vector off with.public FeatureVector(Feature[] features)
features - A feature array to start this vector off with.public int size()
public int featuresSize()
features list.public int labelsSize()
labels list.public Feature getFeature(int index)
index - The index of the requested feature.public Feature getLabel(int index)
index - The index of the requested label.public double getWeight()
weight.public void clear()
public void clearLabels()
labels list.public void sort()
public void addFeature(Feature f)
f - The features to be added.public void addFeatures(FeatureVector v)
v - The vector whose features are to be added.public void addLabel(Feature l)
l - The label to be added.public void addLabels(FeatureVector v)
v - The vector whose features will become this vector's labels.public boolean isLabeled()
true iff this vector has at least one label.public FeatureVector makeReal()
features list to RealFeatures with
appropriate strengths. Otherwise, the returned feature vector is the same as this one. In
particular, the labels list of the returned vector is a shallow clone of this
vector's labels list.RealFeatures.public String[] discreteValueArray()
String array.Strings with all the feature values from this vector, or
null if there are any RealFeatures in this vector.public double[] realValueArray()
double array.doubles with all the feature values from this vector, or
null if there are any DiscreteFeatures in this vector.public Feature firstFeature()
features.null if there aren't any.public Feature firstLabel()
labels.null if there aren't any.public double L2NormSquared()
public static double L2NormSquared(double[] exampleValues)
exampleValues - A vector.public int hashCode()
FeatureVector is simply the sum of the hash codes of the
features and the labels.public boolean equals(Object o)
FeatureVectors are equivalent if they contain the same features and labels,
as defined by Feature equivalence.public static SortedMap getSortedMap(int[] features, double[] values)
features - The feature indices.values - The feature values.public static double dot(int[] firstFeatures,
double[] firstValues,
int[] secondFeatures,
double[] secondValues)
firstFeatures - The first feature vector's indices.firstValues - The first feature vector's values.secondFeatures - The second feature vector's indices.secondValues - The second feature vector's values.public double dot(FeatureVector vector)
vector - The feature vector to take the dot product with.vector.public boolean valueEquals(FeatureVector vector)
FeatureVectors have equal value if they contain the same number of
Features and if the values of those Features are pair-wise equivalent
according to the Feature.valueEquals(String) method.vector - The vector with which to test equivalence.true iff the two vectors are "value equivalent" as defined above.public void write(StringBuffer buffer)
FeatureVector. A comma separated list of
labels appears first, surrounded by square brackets. Then follows a comma separated list of
features.buffer - The buffer in which to create the representation.public void write(StringBuffer buffer, boolean packages)
FeatureVector. A comma separated list of
labels appears first, surrounded by square brackets. Then follows a comma separated list of
features.buffer - The buffer in which to create the representation.packages - Whether or not to print package names.public String toString()
FeatureVector as created by
write(StringBuffer).public String toStringNoPackage()
FeatureVector like toString()
except without package names.public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
out - The output stream.public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
in - The input stream.Copyright © 2016. All rights reserved.