@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-27",changesNeeded=false,comments={"Minor changes to formatting and documentation for equals().","Otherwise, looks good."}) @CodeReview(reviewer="Jonathan McClain",date="2006-05-16",changesNeeded=false,comments="Added some documentation and other minor changes. Looks ok.") public abstract class AbstractVector extends AbstractVectorSpace<Vector,VectorEntry> implements Vector
Vector.IndexValueConsumer, Vector.IndexValueTransformVectorSpace.Entry| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_DELIMITER
The default delimiter for a vector.
|
| Constructor and Description |
|---|
AbstractVector() |
| Modifier and Type | Method and Description |
|---|---|
void |
assertDimensionalityEquals(int otherDimensionality)
Asserts that the dimensionality of this vector equals the given
dimensionality.
|
static void |
assertEqualDimensionality(Vector first,
Vector second)
Throws a DimensionalityMismatchException if
first.getDimensionality() != second.getDimensionality(),
otherwise this function has no effect
|
void |
assertSameDimensionality(Vector other)
Asserts that this vector has the same dimensionality as the given
vector.
|
boolean |
checkSameDimensionality(Vector other)
Determines if
this and other have the same
number of dimensions (size) |
void |
convertFromVector(Vector parameters)
Assigns the values in the provided vector into this.
|
Vector |
convertToVector()
Returns this.
|
void |
decrement(int index)
Decrements the value of the given index by 1.
|
void |
decrement(int index,
double value)
Decrements the value of the given index by the given value.
|
Vector |
dotDivide(Vector other)
Element-wise division of
this by other. |
void |
dotDivideEquals(Vector other)
Inline element-wise division of
this by other. |
double |
dotProduct(Vector other)
The inner product of this vector with the given vector.
|
void |
dotTimesEquals(Vector other)
Inline element-wise multiplication of
this and
other |
boolean |
equals(java.lang.Object other)
Determines if two RingType objects are equal
|
boolean |
equals(Vector other,
double effectiveZero)
Determines if two RingType objects are effectively equal
|
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 |
hashCode() |
void |
increment(int index)
Increments the value of the given index by 1.
|
void |
increment(int index,
double value)
Increments the value of the given index by the given value.
|
void |
minusEquals(Vector other)
Inline arithmetic subtraction of
other from
this |
Matrix |
outerProduct(Vector other)
Computes the outer matrix product between the two vectors
|
void |
plusEquals(Vector other)
Inline arithmetic addition of
this and other |
void |
scaledPlusEquals(double scaleFactor,
Vector other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
Vector |
stack(Vector other)
Stacks "other" below "this" and returns the stacked Vector
|
Vector |
times(Matrix matrix)
Premultiplies the matrix by the vector "this"
|
double[] |
toArray()
Converts this vector to a new array of doubles, in the same order as they
are in the vector.
|
java.lang.String |
toString()
Converts a vector to a string that consists of each value in the vector
|
java.lang.String |
toString(java.text.NumberFormat format)
Converts the vector to a
String, using the given formatter. |
java.lang.String |
toString(java.text.NumberFormat format,
java.lang.String delimiter)
Converts the vector to a
String, using the given formatter and
delimiter. |
Vector |
transform(UnivariateScalarFunction function)
Applies the given function to each of the elements of this vector and
returns a new vector with the result.
|
Vector |
transform(Vector.IndexValueTransform function)
Applies the given function to each of the elements of this vector and
returns a new vector with the result.
|
void |
transformEquals(UnivariateScalarFunction function)
Applies the given function to each of the elements of this vector and
sets them to the result.
|
void |
transformEquals(Vector.IndexValueTransform function)
Applies the given function to each of the elements of this vector and
sets them to the result.
|
Vector |
transformNonZeros(UnivariateScalarFunction function)
Applies the given function to each of the non-zero elements of this
vector and returns a new vector with the result.
|
Vector |
transformNonZeros(Vector.IndexValueTransform function)
Applies the given function to each of the non-zero elements of this
vector and returns a new vector with the result.
|
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.
|
java.util.List<java.lang.Double> |
valuesAsList()
Gets a view of this vector as a list.
|
angle, cosine, dot, euclideanDistance, isUnitVector, isUnitVector, isZero, norm, norm1, norm2, norm2Squared, normInfinity, scaleEquals, sum, unitVector, unitVectorEqualsclone, dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zerofinalize, getClass, notify, notifyAll, wait, wait, waitclone, countNonZeros, get, getDimensionality, getElement, getEntryCount, getVectorFactory, isSparse, set, setElement, subVectorangle, cosine, dot, euclideanDistance, getMaxValue, getMinValue, isUnitVector, isUnitVector, norm, norm1, norm2, norm2Squared, normInfinity, sum, unitVector, unitVectorEqualsdotTimes, isZero, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaleEquals, zeropublic static final java.lang.String DEFAULT_DELIMITER
public boolean equals(java.lang.Object other)
Ringequals in interface Ring<Vector>equals in class AbstractVectorSpace<Vector,VectorEntry>other - RingType to compare against thispublic boolean equals(Vector other, double effectiveZero)
Ringequals in interface Ring<Vector>equals in class AbstractVectorSpace<Vector,VectorEntry>other - RingType to compare against thiseffectiveZero - tolerance threshold for element-wise equalitypublic int hashCode()
hashCode in class java.lang.Objectpublic boolean checkSameDimensionality(Vector other)
Vectorthis and other have the same
number of dimensions (size)checkSameDimensionality in interface Vectorother - vector to compare topublic void assertSameDimensionality(Vector other)
VectorDimensionalityMismatchException is thrown.assertSameDimensionality in interface Vectorother - The other vector to compare to.public void assertDimensionalityEquals(int otherDimensionality)
VectorDimensionalityMismatchException is thrown.assertDimensionalityEquals in interface VectorotherDimensionality - The dimensionality of the.public static void assertEqualDimensionality(Vector first, Vector second)
first - first vector to considersecond - second vector to considerpublic void plusEquals(Vector other)
Ringthis and otherplusEquals in interface Ring<Vector>other - object to add to thispublic void minusEquals(Vector other)
Ringother from
thisminusEquals in interface Ring<Vector>other - object to subtract from thispublic void dotTimesEquals(Vector other)
Ringthis and
otherdotTimesEquals in interface Ring<Vector>other - elements of other will be multiplied to the corresponding
elements of thispublic 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>scaleFactor - 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 double dotProduct(Vector other)
VectorSpacedotProduct in interface VectorSpace<Vector,VectorEntry>other - The Vector with which to compute the dot product with this.
Must have the same dimensionality as this.public double euclideanDistanceSquared(Vector other)
VectorSpacethis and
other, which is the 2-norm between the difference of the
VectorseuclideanDistanceSquared in interface VectorSpace<Vector,VectorEntry>other - Vector to which to compute the squared distance, must be the
same dimension as thispublic Vector times(Matrix matrix)
Vectorpublic Matrix outerProduct(Vector other)
VectorouterProduct in interface Vectorother - post-multiplied Vector with which to compute the outer productpublic Vector dotDivide(Vector other)
Vectorthis by other. Note that if
other has zero elements the result will contain NaN
values.public void dotDivideEquals(Vector other)
Vectorthis by other. Note
that if other has zero elements this will contain NaN
values.dotDivideEquals in interface Vectorother - The other vector whose elements will divide into this one.public Vector transform(UnivariateScalarFunction function)
Vectorpublic Vector transform(Vector.IndexValueTransform function)
Vectorpublic void transformEquals(UnivariateScalarFunction function)
VectortransformEquals in interface Vectorfunction - The function from double to double to apply.public void transformEquals(Vector.IndexValueTransform function)
VectortransformEquals in interface Vectorfunction - The function from index and value to double to apply.public Vector transformNonZeros(UnivariateScalarFunction function)
VectortransformNonZeros in interface Vectorfunction - The function from double to double to apply to the non-zero
elements.public Vector transformNonZeros(Vector.IndexValueTransform function)
VectortransformNonZeros in interface Vectorfunction - The function from index and value to double to apply to non-zero
elements.public void transformNonZerosEquals(UnivariateScalarFunction function)
VectortransformNonZerosEquals in interface Vectorfunction - The function from double to double to apply to the non-zero
elements.public void transformNonZerosEquals(Vector.IndexValueTransform function)
VectortransformNonZerosEquals in interface Vectorfunction - The function from index and value to double to apply to non-zero
elements.public void forEachElement(Vector.IndexValueConsumer consumer)
VectorforEachElement in interface Vectorconsumer - 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)
VectorforEachEntry in interface Vectorconsumer - 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)
VectorforEachNonZero in interface Vectorconsumer - The consumer for the non-zero entries. It is called for each
non-zero entry in the vector, in order by increasing index.public void increment(int index)
Vectorpublic void increment(int index,
double value)
Vectorpublic void decrement(int index)
Vectorpublic void decrement(int index,
double value)
Vectorpublic Vector stack(Vector other)
Vectorpublic double[] toArray()
Vectorpublic java.util.List<java.lang.Double> valuesAsList()
VectorvaluesAsList in interface Vectorpublic java.lang.String toString()
public java.lang.String toString(java.text.NumberFormat format)
VectorString, using the given formatter.public java.lang.String toString(java.text.NumberFormat format,
java.lang.String delimiter)
VectorString, using the given formatter and
delimiter.public Vector convertToVector()
convertToVector in interface Vectorizablepublic void convertFromVector(Vector parameters)
convertFromVector in interface Vectorizableparameters - The vector to convert.