Class FeatureVector
- java.lang.Object
-
- cc.mallet.types.SparseVector
-
- cc.mallet.types.FeatureVector
-
- All Implemented Interfaces:
AlphabetCarrying
,ConstantMatrix
,Vector
,java.io.Serializable
- Direct Known Subclasses:
AugmentableFeatureVector
,Multinomial
,RankedFeatureVector
public class FeatureVector extends SparseVector implements java.io.Serializable, AlphabetCarrying
A subset of anAlphabet
in which each element of the subset has an associated value. The subset is represented as aSparseVector
A SparseVector represents only the non-zero locations of a vector. In the case of a FeatureVector, a location represents the index of an entry in the Alphabet that is contained in the FeatureVector.
To loop over the elements of a feature vector, one loops over the consecutive integers between 0 and the number of locations in the feature vector. From these locations one can cheaply obtain the index of the entry in the underlying Alphabet, the entry itself, and the value in this feature vector associated the entry.
A SparseVector (or FeatureVector) can be sparse or dense depending on whether or not an array if indices is specified at construction time. If the FeatureVector is dense, the mapping from location to index is the identity mapping.
The associated value of an element in a SparseVector (or FeatureVector) can be a double or binary (0.0 or 1.0), depending on whether an array of doubles is specified at contruction time.
- Author:
- Andrew McCallum mccallum@cs.umass.edu
- See Also:
SparseVector
,Alphabet
, Serialized Form
-
-
Field Summary
-
Fields inherited from class cc.mallet.types.SparseVector
hasInfinite, indices, values
-
-
Constructor Summary
Constructors Modifier Constructor Description FeatureVector(Alphabet dict, double[] values)
Create a dense vectorFeatureVector(Alphabet dict, int[] featureIndices)
Create binary vectorFeatureVector(Alphabet dict, int[] featureIndices, double[] values)
Create non-binary vector, possibly dense if "featureIndices" or possibly sparse, if notprotected
FeatureVector(Alphabet dict, int[] indices, double[] values, int capacity, int size, boolean copy, boolean checkIndicesSorted, boolean removeDuplicates)
FeatureVector(Alphabet dict, PropertyList pl, boolean binary)
FeatureVector(Alphabet dict, PropertyList pl, boolean binary, boolean growAlphabet)
FeatureVector(Alphabet dict, java.lang.Object[] keys, double[] values)
FeatureVector(FeatureSequence fs)
FeatureVector(FeatureSequence fs, boolean binary)
FeatureVector(FeatureVector fv, Alphabet newVocab, int[] conjunctions)
New feature vector containing all the features of "fv", plus new features created by making conjunctions between the features in "conjunctions" and all the other features.FeatureVector(FeatureVector fv, Alphabet newVocab, FeatureSelection fsNarrow, FeatureSelection fsWide)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
alphabetsMatch(AlphabetCarrying object)
ConstantMatrix
cloneMatrix()
CLONINGConstantMatrix
cloneMatrixZeroed()
boolean
contains(java.lang.Object entry)
Alphabet
getAlphabet()
Alphabet[]
getAlphabets()
static int[]
getObjectIndices(java.lang.Object[] entries, Alphabet dict, boolean addIfNotPresent)
int
location(java.lang.Object entry)
static FeatureVector
newFeatureVector(FeatureVector fv, Alphabet newVocab, FeatureSelection fs)
Construct a new FeatureVector, selecting only those features in fs, and having new (presumably more compact, dense) Alphabet.boolean
toSimpFile(java.lang.String FileName, int curdocNo, boolean printcounts)
java.lang.String
toString()
java.lang.String
toString(boolean onOneLine)
double
value(java.lang.Object o)
-
Methods inherited from class cc.mallet.types.SparseVector
absNorm, addTo, addTo, arrayCopyFrom, arrayCopyFrom, arrayCopyInto, dotProduct, dotProduct, dotProduct, dotProduct, extendedDotProduct, extendedDotProduct, getDimensions, getIndices, getNumDimensions, getValues, incrementValue, indexAtLocation, infinityNorm, isBinary, isInfinite, isNaN, isNaNOrInfinite, location, makeBinary, makeNonBinary, map, numLocations, oneNorm, plusEqualsSparse, plusEqualsSparse, print, removeDuplicates, setAll, setValue, setValueAtLocation, singleIndex, singleSize, singleToIndices, singleValue, sortIndices, timesEquals, timesEqualsSparse, timesEqualsSparse, timesEqualsSparseZero, twoNorm, value, value, valueAtLocation, vectorAdd
-
-
-
-
Constructor Detail
-
FeatureVector
protected FeatureVector(Alphabet dict, int[] indices, double[] values, int capacity, int size, boolean copy, boolean checkIndicesSorted, boolean removeDuplicates)
-
FeatureVector
public FeatureVector(Alphabet dict, double[] values)
Create a dense vector
-
FeatureVector
public FeatureVector(Alphabet dict, int[] featureIndices, double[] values)
Create non-binary vector, possibly dense if "featureIndices" or possibly sparse, if not
-
FeatureVector
public FeatureVector(Alphabet dict, int[] featureIndices)
Create binary vector
-
FeatureVector
public FeatureVector(Alphabet dict, java.lang.Object[] keys, double[] values)
-
FeatureVector
public FeatureVector(FeatureSequence fs, boolean binary)
-
FeatureVector
public FeatureVector(FeatureSequence fs)
-
FeatureVector
public FeatureVector(Alphabet dict, PropertyList pl, boolean binary, boolean growAlphabet)
-
FeatureVector
public FeatureVector(Alphabet dict, PropertyList pl, boolean binary)
-
FeatureVector
public FeatureVector(FeatureVector fv, Alphabet newVocab, int[] conjunctions)
New feature vector containing all the features of "fv", plus new features created by making conjunctions between the features in "conjunctions" and all the other features.
-
FeatureVector
public FeatureVector(FeatureVector fv, Alphabet newVocab, FeatureSelection fsNarrow, FeatureSelection fsWide)
-
-
Method Detail
-
getObjectIndices
public static int[] getObjectIndices(java.lang.Object[] entries, Alphabet dict, boolean addIfNotPresent)
-
newFeatureVector
public static FeatureVector newFeatureVector(FeatureVector fv, Alphabet newVocab, FeatureSelection fs)
Construct a new FeatureVector, selecting only those features in fs, and having new (presumably more compact, dense) Alphabet.
-
cloneMatrix
public ConstantMatrix cloneMatrix()
Description copied from class:SparseVector
CLONING- Specified by:
cloneMatrix
in interfaceConstantMatrix
- Overrides:
cloneMatrix
in classSparseVector
-
cloneMatrixZeroed
public ConstantMatrix cloneMatrixZeroed()
- Overrides:
cloneMatrixZeroed
in classSparseVector
-
toString
public java.lang.String toString()
- Overrides:
toString
in classSparseVector
-
toSimpFile
public boolean toSimpFile(java.lang.String FileName, int curdocNo, boolean printcounts)
-
toString
public java.lang.String toString(boolean onOneLine)
- Overrides:
toString
in classSparseVector
-
getAlphabet
public Alphabet getAlphabet()
- Specified by:
getAlphabet
in interfaceAlphabetCarrying
-
getAlphabets
public Alphabet[] getAlphabets()
- Specified by:
getAlphabets
in interfaceAlphabetCarrying
-
alphabetsMatch
public boolean alphabetsMatch(AlphabetCarrying object)
-
location
public int location(java.lang.Object entry)
-
contains
public boolean contains(java.lang.Object entry)
-
value
public double value(java.lang.Object o)
-
-