|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cc.mallet.types.SparseVector
public class SparseVector
A vector that allocates memory only for non-zero values. When you create a SparseVector, you pass in a list of indices. These are the only elements of the vector you will be allowed to change. The rest are fixed at 0. The interface to Sparse vector uses the concept of a location, which is an integer in the range 0..numLocations which can be mapped to the index (and value) of a non zero element of the vector. A SparseVector can be sparse or dense depending on whether or not an array if indices is specified at construction time. If the SparseVector is dense, the mapping from location to index is the identity mapping. The type of the value an element in a SparseVector (or FeatureVector) can be double or binary (0.0 or 1.0), depending on whether an array of doubles is specified at contruction time.
Field Summary | |
---|---|
protected boolean |
hasInfinite
|
protected int[] |
indices
If the vector is sparse, then both indices and values are sparse. |
protected double[] |
values
|
Constructor Summary | |
---|---|
SparseVector()
An empty vector, with all zero values |
|
SparseVector(Alphabet dict,
PropertyList pl,
boolean binary)
|
|
SparseVector(Alphabet dict,
PropertyList pl,
boolean binary,
boolean growAlphabet)
|
|
SparseVector(double[] values)
|
|
SparseVector(double[] values,
boolean copy)
|
|
SparseVector(int[] indices)
|
|
SparseVector(int[] indices,
boolean copy)
|
|
SparseVector(int[] indices,
boolean copy,
boolean checkIndicesSorted)
|
|
SparseVector(int[] indices,
boolean copy,
boolean checkIndicesSorted,
boolean removeDuplicates,
boolean binary)
|
|
SparseVector(int[] indices,
double[] values)
|
|
SparseVector(int[] indices,
double[] values,
boolean copy)
|
|
SparseVector(int[] indices,
double[] values,
boolean copy,
boolean checkIndicesSorted)
|
|
SparseVector(int[] indices,
double[] values,
boolean copy,
boolean checkIndicesSorted,
boolean removeDuplicates)
|
|
SparseVector(int[] indices,
double[] values,
int capacity,
int size,
boolean copy,
boolean checkIndicesSorted,
boolean removeDuplicates)
If "indices" is null, the vector will be dense. |
|
SparseVector(int[] indices,
int capacity,
int size,
boolean copy,
boolean checkIndicesSorted,
boolean removeDuplicates)
|
|
SparseVector(int size,
double fillValue)
|
Method Summary | |
---|---|
double |
absNorm()
|
void |
addTo(double[] accumulator)
|
void |
addTo(double[] accumulator,
double scale)
|
void |
arrayCopyFrom(double[] a)
Copy values from an array into this vector. |
int |
arrayCopyFrom(double[] a,
int startingArrayLocation)
Copy values from an array starting at a particular location into this vector. |
int |
arrayCopyInto(double[] array,
int startingArrayLocation)
Copy the contents of this vector into an array starting at a particular location. |
ConstantMatrix |
cloneMatrix()
CLONING |
ConstantMatrix |
cloneMatrixZeroed()
|
double |
dotProduct(ConstantMatrix m)
|
double |
dotProduct(DenseVector v)
|
double |
dotProduct(double[] v)
VECTOR OPERATIONS |
double |
dotProduct(SparseVector v)
|
double |
extendedDotProduct(DenseVector v)
|
double |
extendedDotProduct(SparseVector v)
|
int |
getDimensions(int[] sizes)
|
int[] |
getIndices()
|
int |
getNumDimensions()
ACCESSORS |
double[] |
getValues()
|
void |
incrementValue(int index,
double value)
Increments this[index] by value. |
int |
indexAtLocation(int location)
|
double |
infinityNorm()
|
boolean |
isBinary()
|
boolean |
isInfinite()
|
boolean |
isNaN()
|
boolean |
isNaNOrInfinite()
|
int |
location(int index)
|
void |
makeBinary()
|
void |
makeNonBinary()
|
void |
map(java.lang.reflect.Method f)
Applies the method argument to each value in a non-binary vector. |
int |
numLocations()
|
double |
oneNorm()
|
void |
plusEqualsSparse(SparseVector v)
For each index i that is present in this vector, set this[i] += v[i]. |
void |
plusEqualsSparse(SparseVector v,
double factor)
For each index i that is present in this vector, set this[i] += factor * v[i]. |
void |
print()
|
protected void |
removeDuplicates(int numDuplicates)
|
void |
setAll(double v)
Sets every present index in the vector to v. |
void |
setValue(int index,
double value)
Sets the value at the given index. |
void |
setValueAtLocation(int location,
double value)
Sets the value at the given location. |
int |
singleIndex(int[] indices)
|
int |
singleSize()
|
void |
singleToIndices(int i,
int[] indices)
|
double |
singleValue(int i)
|
protected void |
sortIndices()
|
void |
timesEquals(double factor)
Scale all elements by the same factor. |
void |
timesEqualsSparse(SparseVector v)
For each index i that is present in this vector, set this[i] *= v[i]. |
void |
timesEqualsSparse(SparseVector v,
double factor)
For each index i that is present in this vector, set this[i] *= factor * v[i]. |
void |
timesEqualsSparseZero(SparseVector v,
double factor)
For each index i that is present in this vector, set this[i] *= factor * v[i]. |
java.lang.String |
toString()
|
java.lang.String |
toString(boolean onOneLine)
|
double |
twoNorm()
|
double |
value(int index)
|
double |
value(int[] indices)
|
double |
valueAtLocation(int location)
|
SparseVector |
vectorAdd(SparseVector v,
double scale)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected int[] indices
protected double[] values
protected boolean hasInfinite
Constructor Detail |
---|
public SparseVector(int[] indices, double[] values, int capacity, int size, boolean copy, boolean checkIndicesSorted, boolean removeDuplicates)
public SparseVector(double[] values, boolean copy)
public SparseVector(double[] values)
public SparseVector(int size, double fillValue)
public SparseVector(int[] indices, double[] values, boolean copy, boolean checkIndicesSorted, boolean removeDuplicates)
public SparseVector(int[] indices, double[] values)
public SparseVector(int[] indices, double[] values, boolean copy)
public SparseVector(int[] indices, double[] values, boolean copy, boolean checkIndicesSorted)
public SparseVector(int[] indices, boolean copy, boolean checkIndicesSorted, boolean removeDuplicates, boolean binary)
public SparseVector(int[] indices, int capacity, int size, boolean copy, boolean checkIndicesSorted, boolean removeDuplicates)
public SparseVector(int[] indices, boolean copy, boolean checkIndicesSorted)
public SparseVector(int[] indices, boolean copy)
public SparseVector(int[] indices)
public SparseVector()
public SparseVector(Alphabet dict, PropertyList pl, boolean binary, boolean growAlphabet)
public SparseVector(Alphabet dict, PropertyList pl, boolean binary)
Method Detail |
---|
public boolean isBinary()
public void makeBinary()
public void makeNonBinary()
public int getNumDimensions()
getNumDimensions
in interface ConstantMatrix
public int getDimensions(int[] sizes)
getDimensions
in interface ConstantMatrix
public int[] getIndices()
public double[] getValues()
public int numLocations()
numLocations
in interface ConstantMatrix
public int location(int index)
location
in interface ConstantMatrix
public double valueAtLocation(int location)
valueAtLocation
in interface ConstantMatrix
public int indexAtLocation(int location)
indexAtLocation
in interface ConstantMatrix
public double value(int[] indices)
value
in interface ConstantMatrix
public double value(int index)
value
in interface Vector
public void addTo(double[] accumulator, double scale)
public void addTo(double[] accumulator)
public int singleIndex(int[] indices)
singleIndex
in interface ConstantMatrix
public void singleToIndices(int i, int[] indices)
singleToIndices
in interface ConstantMatrix
public double singleValue(int i)
singleValue
in interface ConstantMatrix
public int singleSize()
singleSize
in interface ConstantMatrix
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean onOneLine)
public ConstantMatrix cloneMatrix()
cloneMatrix
in interface ConstantMatrix
public ConstantMatrix cloneMatrixZeroed()
public void plusEqualsSparse(SparseVector v)
public void plusEqualsSparse(SparseVector v, double factor)
public void timesEqualsSparse(SparseVector v)
public void timesEqualsSparse(SparseVector v, double factor)
public void timesEqualsSparseZero(SparseVector v, double factor)
public void timesEquals(double factor)
public void incrementValue(int index, double value) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- If index is not present.public void setAll(double v)
public void setValue(int index, double value) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- If index is not present.public void setValueAtLocation(int location, double value)
public final void arrayCopyFrom(double[] a)
public final int arrayCopyFrom(double[] a, int startingArrayLocation)
public final void map(java.lang.reflect.Method f) throws java.lang.IllegalAccessException, java.lang.Throwable
java.lang.IllegalArgumentException
- If the method argument has an
inappropriate signature.
java.lang.UnsupportedOperationException
- If vector is binary
java.lang.IllegalAccessException
- If the method is inaccessible
java.lang.Throwable
- If the method throws an exception it is relayedpublic final int arrayCopyInto(double[] array, int startingArrayLocation)
public double dotProduct(double[] v)
public double dotProduct(ConstantMatrix m)
dotProduct
in interface ConstantMatrix
public double dotProduct(DenseVector v)
public double extendedDotProduct(DenseVector v)
public double dotProduct(SparseVector v)
public double extendedDotProduct(SparseVector v)
public SparseVector vectorAdd(SparseVector v, double scale)
public double oneNorm()
oneNorm
in interface ConstantMatrix
public double absNorm()
absNorm
in interface ConstantMatrix
public double twoNorm()
twoNorm
in interface ConstantMatrix
public double infinityNorm()
infinityNorm
in interface ConstantMatrix
public void print()
print
in interface ConstantMatrix
public boolean isNaN()
isNaN
in interface ConstantMatrix
public boolean isInfinite()
public boolean isNaNOrInfinite()
protected void sortIndices()
protected void removeDuplicates(int numDuplicates)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |