@CodeReview(reviewer="Justin Basilico", date="2006-07-27", changesNeeded=false, comments="Looks good.") public class SparseVector extends AbstractMTJVector
Vector.IndexValueConsumer, Vector.IndexValueTransform
VectorSpace.Entry
DEFAULT_DELIMITER
Modifier | Constructor and Description |
---|---|
protected |
SparseVector(int numDimensions)
Creates a new instance of SparseVector with no initial size.
|
protected |
SparseVector(int numDimensions,
int initialNonZeros)
Creates a new instance of SparseVector with a specified initial size.
|
protected |
SparseVector(no.uib.cipr.matrix.sparse.SparseVector internalVector)
Creates a new copy of SparseVector.
|
protected |
SparseVector(Vector vector)
Creates a new copy of SparseVector.
|
Modifier and Type | Method and Description |
---|---|
void |
compact()
Compacts the SparseVector, getting rid of any zero'ed elements.
|
int |
countNonZeros()
Counts the number of non-zero entries in the vector.
|
double |
euclideanDistanceSquared(Vector other)
Squared Euclidean distance between
this and
other , which is the 2-norm between the difference of the
Vectors |
void |
forEachElement(Vector.IndexValueConsumer consumer)
Applies the given function to each element in this vector.
|
void |
forEachEntry(Vector.IndexValueConsumer consumer)
Applies the given function to each active entry in this vector.
|
void |
forEachNonZero(Vector.IndexValueConsumer consumer)
Applies the given function to each non-zero entry in this vector.
|
int |
getEntryCount()
Gets the number of active entries in the vector.
|
protected no.uib.cipr.matrix.sparse.SparseVector |
getInternalVector()
Getter for internalVector
|
double |
getMaxValue()
The maximum value associated with any key in the vector.
|
double |
getMinValue()
The minimum value associated with any key in the vector.
|
int |
getNumElementsUsed()
Deprecated.
|
SparseVectorFactory<?> |
getVectorFactory()
Gets a vector factory associated with this kind of vector.
|
boolean |
isSparse()
Returns true if this vector has a potentially sparse underlying
structure.
|
SparseRowMatrix |
outerProduct(AbstractMTJVector other)
Computes the outer matrix product between the two vectors
|
void |
setElement(int index,
double value)
Sets the zero-based indexed element in the Vector from the specified value
|
protected void |
setInternalVector(no.uib.cipr.matrix.sparse.SparseVector internalVector)
Setter for the internal MTJ vector.
|
protected void |
setInternalVector(no.uib.cipr.matrix.Vector internalVector)
Setter for internalVector
|
SparseVector |
stack(Vector other)
Stacks "other" below "this" and returns the stacked Vector
|
SparseVector |
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.
|
java.lang.String |
toString()
Prints the SparseVector in "Index: Value" format.
|
void |
transformNonZerosEquals(UnivariateScalarFunction function)
Applies the given function to each of the non-zero elements of this
vector and sets them to the result.
|
void |
transformNonZerosEquals(Vector.IndexValueTransform function)
Applies the given function to each of the non-zero elements of this
vector and sets them to the result.
|
clone, dotProduct, dotProduct, dotTimesEquals, get, getDimensionality, getElement, increment, iterator, minusEquals, minusEquals, norm2, norm2Squared, outerProduct, plusEquals, plusEquals, scaledMinusEquals, scaledPlusEquals, scaledPlusEquals, scaleEquals, set, times, times, zero
assertDimensionalityEquals, assertEqualDimensionality, assertSameDimensionality, checkSameDimensionality, convertFromVector, convertToVector, decrement, decrement, dotDivide, dotDivideEquals, equals, equals, hashCode, increment, toArray, toString, toString, transform, transform, transformEquals, transformEquals, transformNonZeros, transformNonZeros, valuesAsList
angle, cosine, dot, euclideanDistance, isUnitVector, isUnitVector, isZero, norm, norm1, normInfinity, unitVector, unitVectorEquals
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
finalize, getClass, notify, notifyAll, wait, wait, wait
angle, cosine, dot, euclideanDistance, isUnitVector, isUnitVector, norm, norm1, normInfinity, unitVector, unitVectorEquals
dotTimes, isZero, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus
protected SparseVector(int numDimensions)
numDimensions
- Maximum number of entries in the SparseVector.protected SparseVector(int numDimensions, int initialNonZeros)
numDimensions
- Maximum number of entries in the SparseVector.initialNonZeros
- Initial size of the SparseVector.protected SparseVector(no.uib.cipr.matrix.sparse.SparseVector internalVector)
internalVector
- Internal MTJ-based vector to set into this.protected SparseVector(Vector vector)
vector
- Vector to copy into this, will not be modified.public int getEntryCount()
Vector
@Deprecated public int getNumElementsUsed()
public void setElement(int index, double value)
Vector
setElement
in interface Vector
setElement
in class AbstractMTJVector
index
- zero-based indexvalue
- value to set the element in the Vectorprotected no.uib.cipr.matrix.sparse.SparseVector getInternalVector()
AbstractMTJVector
getInternalVector
in class AbstractMTJVector
protected void setInternalVector(no.uib.cipr.matrix.Vector internalVector)
AbstractMTJVector
setInternalVector
in class AbstractMTJVector
internalVector
- internal MTJ-based vector that does the heavy liftingprotected void setInternalVector(no.uib.cipr.matrix.sparse.SparseVector internalVector)
internalVector
- Internal MTJ-based vector.public double euclideanDistanceSquared(Vector other)
VectorSpace
this
and
other
, which is the 2-norm between the difference of the
VectorseuclideanDistanceSquared
in interface VectorSpace<Vector,VectorEntry>
euclideanDistanceSquared
in class AbstractVector
other
- Vector to which to compute the squared distance, must be the
same dimension as thispublic SparseRowMatrix outerProduct(AbstractMTJVector other)
AbstractMTJVector
outerProduct
in class AbstractMTJVector
other
- post-multiplied Vector with which to compute the outer productpublic java.lang.String toString()
toString
in interface Vector
toString
in class AbstractVector
public void compact()
public SparseVector stack(Vector other)
Vector
stack
in interface Vector
stack
in class AbstractVector
other
- Vector to stack below "this"public void transformNonZerosEquals(UnivariateScalarFunction function)
Vector
transformNonZerosEquals
in interface Vector
transformNonZerosEquals
in class AbstractVector
function
- The function from double to double to apply to the non-zero
elements.public void transformNonZerosEquals(Vector.IndexValueTransform function)
Vector
transformNonZerosEquals
in interface Vector
transformNonZerosEquals
in class AbstractVector
function
- The function from index and value to double to apply to non-zero
elements.public void forEachElement(Vector.IndexValueConsumer consumer)
Vector
forEachElement
in interface Vector
forEachElement
in class AbstractVector
consumer
- The consumer for the entries. It is called for each element in
the vector, in order by increasing index.public void forEachEntry(Vector.IndexValueConsumer consumer)
Vector
forEachEntry
in interface Vector
forEachEntry
in class AbstractVector
consumer
- The consumer for the entries. It is called for each active entry in
the vector, in order by increasing index.public void forEachNonZero(Vector.IndexValueConsumer consumer)
Vector
forEachNonZero
in interface Vector
forEachNonZero
in class AbstractVector
consumer
- The consumer for the non-zero entries. It is called for each
non-zero entry in the vector, in order by increasing index.public boolean isSparse()
Vector
public double sum()
VectorSpace
sum
in interface VectorSpace<Vector,VectorEntry>
sum
in class AbstractVectorSpace<Vector,VectorEntry>
public double getMinValue()
VectorSpace
public double getMaxValue()
VectorSpace
public int countNonZeros()
Vector
public SparseVectorFactory<?> getVectorFactory()
Vector
public SparseVector subVector(int minIndex, int maxIndex)
Vector
minIndex
- minimum index to get (inclusive)maxIndex
- maximum index to get (inclusive)