@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.IndexValueTransform
VectorSpace.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, unitVectorEquals
clone, dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zero
finalize, getClass, notify, notifyAll, wait, wait, wait
clone, countNonZeros, get, getDimensionality, getElement, getEntryCount, getVectorFactory, isSparse, set, setElement, subVector
angle, cosine, dot, euclideanDistance, getMaxValue, getMinValue, isUnitVector, isUnitVector, norm, norm1, norm2, norm2Squared, normInfinity, sum, unitVector, unitVectorEquals
dotTimes, isZero, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaleEquals, zero
public static final java.lang.String DEFAULT_DELIMITER
public boolean equals(java.lang.Object other)
Ring
equals
in interface Ring<Vector>
equals
in class AbstractVectorSpace<Vector,VectorEntry>
other
- RingType to compare against this
public boolean equals(Vector other, double effectiveZero)
Ring
equals
in interface Ring<Vector>
equals
in class AbstractVectorSpace<Vector,VectorEntry>
other
- RingType to compare against this
effectiveZero
- tolerance threshold for element-wise equalitypublic int hashCode()
hashCode
in class java.lang.Object
public boolean checkSameDimensionality(Vector other)
Vector
this
and other
have the same
number of dimensions (size)checkSameDimensionality
in interface Vector
other
- vector to compare topublic void assertSameDimensionality(Vector other)
Vector
DimensionalityMismatchException
is thrown.assertSameDimensionality
in interface Vector
other
- The other vector to compare to.public void assertDimensionalityEquals(int otherDimensionality)
Vector
DimensionalityMismatchException
is thrown.assertDimensionalityEquals
in interface Vector
otherDimensionality
- 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)
Ring
this
and other
plusEquals
in interface Ring<Vector>
other
- object to add to this
public void minusEquals(Vector other)
Ring
other
from
this
minusEquals
in interface Ring<Vector>
other
- object to subtract from this
public void dotTimesEquals(Vector other)
Ring
this
and
other
dotTimesEquals
in interface Ring<Vector>
other
- elements of other will be multiplied to the corresponding
elements of this
public void scaledPlusEquals(double scaleFactor, Vector other)
Ring
this
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)
VectorSpace
dotProduct
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)
VectorSpace
this
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)
Vector
public Matrix outerProduct(Vector other)
Vector
outerProduct
in interface Vector
other
- post-multiplied Vector with which to compute the outer productpublic Vector dotDivide(Vector other)
Vector
this
by other
. Note that if
other
has zero elements the result will contain NaN
values.public void dotDivideEquals(Vector other)
Vector
this
by other
. Note
that if other
has zero elements this will contain NaN
values.dotDivideEquals
in interface Vector
other
- The other vector whose elements will divide into this one.public Vector transform(UnivariateScalarFunction function)
Vector
public Vector transform(Vector.IndexValueTransform function)
Vector
public void transformEquals(UnivariateScalarFunction function)
Vector
transformEquals
in interface Vector
function
- The function from double to double to apply.public void transformEquals(Vector.IndexValueTransform function)
Vector
transformEquals
in interface Vector
function
- The function from index and value to double to apply.public Vector transformNonZeros(UnivariateScalarFunction function)
Vector
transformNonZeros
in interface Vector
function
- The function from double to double to apply to the non-zero
elements.public Vector transformNonZeros(Vector.IndexValueTransform function)
Vector
transformNonZeros
in interface Vector
function
- The function from index and value to double to apply to non-zero
elements.public void transformNonZerosEquals(UnivariateScalarFunction function)
Vector
transformNonZerosEquals
in interface Vector
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
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
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
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
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 void increment(int index)
Vector
public void increment(int index, double value)
Vector
public void decrement(int index)
Vector
public void decrement(int index, double value)
Vector
public Vector stack(Vector other)
Vector
public double[] toArray()
Vector
public java.util.List<java.lang.Double> valuesAsList()
Vector
valuesAsList
in interface Vector
public java.lang.String toString()
public java.lang.String toString(java.text.NumberFormat format)
Vector
String
, using the given formatter.public java.lang.String toString(java.text.NumberFormat format, java.lang.String delimiter)
Vector
String
, using the given formatter and
delimiter.public Vector convertToVector()
convertToVector
in interface Vectorizable
public void convertFromVector(Vector parameters)
convertFromVector
in interface Vectorizable
parameters
- The vector to convert.