public class SparseVector extends Object implements ConstantMatrix, Vector, Serializable
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
hasInfinite |
protected int[] |
indices
If the vector is sparse, then both indices and values are
sparse.
|
protected double[] |
values |
| Constructor and Description |
|---|
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) |
| Modifier and Type | Method and Description |
|---|---|
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 |
isNaN() |
int |
location(int index) |
void |
makeBinary() |
void |
makeNonBinary() |
void |
map(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].
|
String |
toString() |
String |
toString(boolean onOneLine) |
double |
twoNorm() |
double |
value(int index) |
double |
value(int[] indices) |
double |
valueAtLocation(int location) |
SparseVector |
vectorAdd(SparseVector v,
double scale) |
protected int[] indices
protected double[] values
protected boolean hasInfinite
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)
public boolean isBinary()
public void makeBinary()
public void makeNonBinary()
public int getNumDimensions()
getNumDimensions in interface ConstantMatrixpublic int getDimensions(int[] sizes)
getDimensions in interface ConstantMatrixpublic int[] getIndices()
public double[] getValues()
public int numLocations()
numLocations in interface ConstantMatrixpublic int location(int index)
location in interface ConstantMatrixpublic double valueAtLocation(int location)
valueAtLocation in interface ConstantMatrixpublic int indexAtLocation(int location)
indexAtLocation in interface ConstantMatrixpublic double value(int[] indices)
value in interface ConstantMatrixpublic void addTo(double[] accumulator,
double scale)
public void addTo(double[] accumulator)
public int singleIndex(int[] indices)
singleIndex in interface ConstantMatrixpublic void singleToIndices(int i,
int[] indices)
singleToIndices in interface ConstantMatrixpublic double singleValue(int i)
singleValue in interface ConstantMatrixpublic int singleSize()
singleSize in interface ConstantMatrixpublic String toString(boolean onOneLine)
public ConstantMatrix cloneMatrix()
cloneMatrix in interface ConstantMatrixpublic 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 timesEquals(double factor)
public void incrementValue(int index,
double value)
throws IllegalArgumentException
IllegalArgumentException - If index is not present.public void setAll(double v)
public void setValue(int index,
double value)
throws IllegalArgumentException
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(Method f) throws IllegalAccessException, Throwable
IllegalArgumentException - If the method argument has an
inappropriate signature.UnsupportedOperationException - If vector is binaryIllegalAccessException - If the method is inaccessibleThrowable - 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 ConstantMatrixpublic 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 ConstantMatrixpublic double absNorm()
absNorm in interface ConstantMatrixpublic double twoNorm()
twoNorm in interface ConstantMatrixpublic double infinityNorm()
infinityNorm in interface ConstantMatrixpublic void print()
print in interface ConstantMatrixpublic boolean isNaN()
isNaN in interface ConstantMatrixprotected void sortIndices()
protected void removeDuplicates(int numDuplicates)
Copyright © 2019 JULIE Lab, Germany. All rights reserved.