public class SparseVector extends AbstractVector
Vector.IndexValueConsumer, Vector.IndexValueTransformDEFAULT_DELIMITER| Modifier | Constructor and Description |
|---|---|
protected |
SparseVector()
This should never be called by anything or anyone other than Java's
serialization code.
|
|
SparseVector(DenseVector v)
Copy constructor -- creates a deep copy of the input sparse vector.
|
|
SparseVector(int n)
Create a new sparse vector.
|
|
SparseVector(SparseVector v)
Copy constructor -- creates a deep copy of the input sparse vector.
|
| Modifier and Type | Method and Description |
|---|---|
SparseVector |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
void |
compress()
The compressed representation should allow for quicker mathematical
operations, but does not permit editing the values in the vector.
|
int |
countNonZeros()
Counts the number of non-zero entries in the vector.
|
void |
decompress()
The compressed representation should allow for quicker mathematical
operations, but does not permit editing the values in the vector.
|
double |
dotProduct(DenseVector other)
Type-specific version dotProduct for combining whatever type this is with
the input dense vector.
|
double |
dotProduct(SparseVector other)
Type-specific version dotProduct for combining whatever type this is with
the input sparse vector.
|
double |
dotProduct(Vector other)
The inner product of this vector with the given vector.
|
void |
dotTimesEquals(DenseVector other)
Type-specific version of dotTimesEquals for combining whatever type this
is with the input dense vector.
|
void |
dotTimesEquals(SparseVector other)
Type-specific version of dotTimesEquals for combining whatever type this
is with the input sparse vector.
|
void |
dotTimesEquals(Vector other)
Inline element-wise multiplication of
this and
other |
double |
euclideanDistanceSquared(DenseVector other)
Type-specific version of euclideanDistanceSquared for combining whatever
type this is with the input dense vector.
|
double |
euclideanDistanceSquared(SparseVector other)
Type-specific version of euclideanDistanceSquared for combining whatever
type this is with the input sparse vector.
|
double |
euclideanDistanceSquared(Vector other)
Squared Euclidean distance between
this and
other, which is the 2-norm between the difference of the
Vectors |
double |
get(int index)
Gets the value of element of the vector at the zero-based index.
|
int |
getDimensionality()
Returns the number of elements in the Vector
|
double |
getElement(int index)
Gets the zero-based indexed element from the Vector
|
int |
getEntryCount()
Gets the number of active entries in the vector.
|
double |
getMaxValue()
The maximum value associated with any key in the vector.
|
double |
getMinValue()
The minimum value associated with any key in the vector.
|
VectorFactory<?> |
getVectorFactory()
Gets a vector factory associated with this kind of vector.
|
boolean |
isCompressed()
The compressed representation should allow for quicker mathematical
operations, but does not permit editing the values in the vector.
|
boolean |
isSparse()
Returns true if this vector has a potentially sparse underlying
structure.
|
java.util.Iterator<VectorEntry> |
iterator() |
Vector |
minus(Vector v)
Arithmetic subtraction of
other from this |
void |
minusEquals(DenseVector other)
Type-specific version of minusEquals for combining whatever type this is
with the input dense vector.
|
void |
minusEquals(SparseVector other)
Type-specific version of minusEquals for combining whatever type this is
with the input sparse vector.
|
void |
minusEquals(Vector other)
Inline arithmetic subtraction of
other from
this |
Matrix |
outerProduct(DenseVector other)
Type-specific version of outerProduct for combining whatever type this is
with the input dense vector.
|
Matrix |
outerProduct(SparseVector other)
Type-specific version of outerProduct for combining whatever type this is
with the input sparse vector.
|
Matrix |
outerProduct(Vector other)
Computes the outer matrix product between the two vectors
|
Vector |
plus(Vector v)
Arithmetic addition of
this and other |
void |
plusEquals(DenseVector other)
Type-specific version of plusEquals for combining whatever type this is
with the input dense vector.
|
void |
plusEquals(SparseVector other)
Type-specific version of plusEquals for combining whatever type this is
with the input sparse vector.
|
void |
plusEquals(Vector other)
Inline arithmetic addition of
this and other |
Vector |
scale(double d)
Element-wise scaling of
this by scaleFactor |
void |
scaledPlusEquals(DenseVector other,
double scaleFactor)
Type-specific version of scaledPlusEquals for combining whatever type
this is with the input dense vector.
|
void |
scaledPlusEquals(double scaleFactor,
Vector other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
scaledPlusEquals(SparseVector other,
double scaleFactor)
Type-specific version of scaledPlusEquals for combining whatever type
this is with the input sparse vector.
|
void |
set(int index,
double value)
Sets the value for an element at the zero-based index from the vector.
|
void |
setElement(int index,
double value)
Sets the zero-based indexed element in the Vector from the specified value
|
Vector |
stack(DenseVector other)
Type-specific version of stack for combining whatever type this is with
the input dense vector.
|
Vector |
stack(SparseVector other)
Type-specific version of stack for combining whatever type this is with
the input sparse vector.
|
Vector |
stack(Vector other)
Stacks "other" below "this" and returns the stacked Vector
|
Vector |
subVector(int minIndex,
int maxIndex)
Gets a subvector of "this", specified by the inclusive indices
|
double |
sum()
Computes the sum of the elements in the vector.
|
Vector |
times(Matrix matrix)
Premultiplies the matrix by the vector "this"
|
void |
zero()
Zeros out all elements of
this, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 ); |
assertDimensionalityEquals, assertEqualDimensionality, assertSameDimensionality, checkSameDimensionality, convertFromVector, convertToVector, decrement, decrement, dotDivide, dotDivideEquals, equals, equals, forEachElement, forEachEntry, forEachNonZero, hashCode, increment, increment, toArray, toString, toString, toString, transform, transform, transformEquals, transformEquals, transformNonZeros, transformNonZeros, transformNonZerosEquals, transformNonZerosEquals, valuesAsListangle, cosine, dot, euclideanDistance, isUnitVector, isUnitVector, isZero, norm, norm1, norm2, norm2Squared, normInfinity, scaleEquals, unitVector, unitVectorEqualsdotTimes, isZero, negative, negativeEquals, scaledMinus, scaledMinusEquals, scaledPlusfinalize, getClass, notify, notifyAll, wait, wait, waitangle, cosine, dot, euclideanDistance, isUnitVector, isUnitVector, norm, norm1, norm2, norm2Squared, normInfinity, unitVector, unitVectorEqualsdotTimes, isZero, isZero, negative, negativeEquals, scaledMinus, scaledMinusEquals, scaledPlus, scaleEqualspublic SparseVector(int n)
n - The vector lengthpublic SparseVector(SparseVector v)
v - The sparse vector to copypublic SparseVector(DenseVector v)
v - The sparse vector to copyprotected SparseVector()
public final boolean isCompressed()
public final void compress()
public final void decompress()
public void zero()
Ringthis, so that the following are
equivalent
r1.scaleEquals( 0.0 );
and
r1.zero();
Furthermore,
r1.zero(); anything.dotTimes( r1 ).equals( r1 );public final SparseVector clone()
AbstractCloneableSerializableObject class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone() to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone() as the basis for your implementation.clone in interface Vectorclone in interface Vectorizableclone in interface Ring<Vector>clone in interface CloneableSerializableclone in class AbstractRing<Vector>public final Vector plus(Vector v)
Ringthis and otherpublic final Vector minus(Vector v)
Ringother from thispublic void scaledPlusEquals(DenseVector other, double scaleFactor)
other - A dense vector to add to thisscaleFactor - The scalar to multiply other bypublic void scaledPlusEquals(SparseVector other, double scaleFactor)
other - A sparse vector to add to thisscaleFactor - The scalar to multiply other bypublic final void plusEquals(DenseVector other)
other - A dense vector to add to thispublic final void plusEquals(SparseVector other)
other - A sparse vector to add to thispublic final void minusEquals(DenseVector other)
other - A dense vector to subtract from thispublic final void minusEquals(SparseVector other)
other - A sparse vector to subtract from thispublic final void dotTimesEquals(DenseVector other)
other - A dense vector to dot with thispublic final void dotTimesEquals(SparseVector other)
other - A sparse vector to dot with thispublic final double euclideanDistanceSquared(DenseVector other)
other - A dense vector to calculate the distance from thispublic final double euclideanDistanceSquared(SparseVector other)
other - A sparse vector to calculate the distance from thispublic final Matrix outerProduct(DenseVector other)
other - A dense vector to "outer product" with thispublic final Matrix outerProduct(SparseVector other)
other - A sparse vector to "outer product" with thispublic final Vector stack(DenseVector other)
other - A dense vector to stack below thispublic final Vector stack(SparseVector other)
other - A sparse vector to stack below thispublic final double dotProduct(SparseVector other)
other - A sparse vector to dot with thispublic final double dotProduct(DenseVector other)
other - A dense vector to dot with thispublic final java.util.Iterator<VectorEntry> iterator()
public final int getDimensionality()
Vectorpublic double get(int index)
VectorgetElement.index - The zero-based index. Must be between 0 (inclusive) and the
dimensionality of the vector (exclusive).public final double getElement(int index)
Vectorindex - zero-based indexpublic void set(int index,
double value)
VectorsetElement.index - The zero-based index. Must be between 0 (inclusive) and the
dimensionality of the vector (exclusive).value - The value at the index in the vector.public final void setElement(int index,
double value)
Vectorindex - zero-based indexvalue - value to set the element in the Vectorpublic final Vector subVector(int minIndex, int maxIndex)
VectorminIndex - minimum index to get (inclusive)maxIndex - maximum index to get (inclusive)public int countNonZeros()
Vectorpublic final Vector scale(double d)
Ringthis by scaleFactorpublic boolean isSparse()
Vectorpublic VectorFactory<?> getVectorFactory()
Vectorpublic double sum()
VectorSpacesum in interface VectorSpace<Vector,VectorEntry>sum in class AbstractVectorSpace<Vector,VectorEntry>public double getMinValue()
VectorSpacepublic double getMaxValue()
VectorSpacepublic int getEntryCount()
Vectorpublic final void plusEquals(Vector other)
Ringthis and otherplusEquals in interface Ring<Vector>plusEquals in class AbstractVectorother - object to add to thispublic final void scaledPlusEquals(double scaleFactor,
Vector other)
Ringthis and other after
element-wise scaling of other by scaleFactor.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x += a * y. It is typically a more efficient way of doing
this.plusEquals(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledPlusEquals in interface Ring<Vector>scaledPlusEquals in class AbstractVectorscaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public final void minusEquals(Vector other)
Ringother from
thisminusEquals in interface Ring<Vector>minusEquals in class AbstractVectorother - object to subtract from thispublic final void dotTimesEquals(Vector other)
Ringthis and
otherdotTimesEquals in interface Ring<Vector>dotTimesEquals in class AbstractVectorother - elements of other will be multiplied to the corresponding
elements of thispublic final double euclideanDistanceSquared(Vector other)
VectorSpacethis and
other, which is the 2-norm between the difference of the
VectorseuclideanDistanceSquared in interface VectorSpace<Vector,VectorEntry>euclideanDistanceSquared in class AbstractVectorother - Vector to which to compute the squared distance, must be the
same dimension as thispublic final Matrix outerProduct(Vector other)
VectorouterProduct in interface VectorouterProduct in class AbstractVectorother - post-multiplied Vector with which to compute the outer productpublic final Vector times(Matrix matrix)
Vectortimes in interface Vectortimes in class AbstractVectormatrix - Matrix to premultiply by "this", must have the same number of rows as
the dimensionality of "this"public final Vector stack(Vector other)
Vectorstack in interface Vectorstack in class AbstractVectorother - Vector to stack below "this"public final double dotProduct(Vector other)
VectorSpacedotProduct in interface VectorSpace<Vector,VectorEntry>dotProduct in class AbstractVectorother - The Vector with which to compute the dot product with this.
Must have the same dimensionality as this.