@CodeReview(reviewer="Kevin R. Dixon",date="2008-02-26",changesNeeded=false,comments={"Minor changes to formatting.","Otherwise, looks good."}) @CodeReview(reviewer="Jonathan McClain",date="2006-05-17",changesNeeded=false,comments="Looks fine.") public interface Vector extends VectorSpace<Vector,VectorEntry>, Vectorizable
Vector interface defines the operations that are expected
on a mathematical vector. The Vector can be thought of as a
collection of doubles of fixed size (the dimensionality) that supports
array-like indexing into the Vector. The Vector
is defined as an interface because there is more than one way to implement
a Vector, in particular if you want to make use of sparseness, which occurs
when most of the elements of a Vector are zero so that they are
not represented.| Modifier and Type | Interface and Description |
|---|---|
static interface |
Vector.IndexValueConsumer
Defines the functionality for a consumer of vector entries, which are an
index and a value.
|
static interface |
Vector.IndexValueTransform
Defines the functionality for a transform of vector entries, which are an
index and a value and return the new value.
|
VectorSpace.Entry| Modifier and Type | Method and Description |
|---|---|
void |
assertDimensionalityEquals(int otherDimensionality)
Asserts that the dimensionality of this vector equals the given
dimensionality.
|
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) |
Vector |
clone()
Returns a smart copy of
this, such that changing the values
of the return class will not effect this |
int |
countNonZeros()
Counts the number of non-zero entries in the vector.
|
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. |
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.
|
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.
|
VectorFactory<?> |
getVectorFactory()
Gets a vector factory associated with this kind of vector.
|
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.
|
boolean |
isSparse()
Returns true if this vector has a potentially sparse underlying
structure.
|
Matrix |
outerProduct(Vector other)
Computes the outer matrix product between the two vectors
|
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(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
|
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() |
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, dotProduct, euclideanDistance, euclideanDistanceSquared, getMaxValue, getMinValue, isUnitVector, isUnitVector, norm, norm1, norm2, norm2Squared, normInfinity, sum, unitVector, unitVectorEqualsdotTimes, dotTimesEquals, equals, equals, isZero, isZero, minus, minusEquals, negative, negativeEquals, plus, plusEquals, scale, scaledMinus, scaledMinusEquals, scaledPlus, scaledPlusEquals, scaleEquals, zeroconvertFromVector, convertToVectorVector clone()
Ringthis, such that changing the values
of the return class will not effect thisclone in interface CloneableSerializableclone in interface Ring<Vector>clone in interface Vectorizablethisint getDimensionality()
double get(int index)
getElement.index - The zero-based index. Must be between 0 (inclusive) and the
dimensionality of the vector (exclusive).void set(int index,
double value)
setElement.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.double getElement(int index)
index - zero-based indexvoid setElement(int index,
double value)
index - zero-based indexvalue - value to set the element in the VectorMatrix outerProduct(Vector other)
other - post-multiplied Vector with which to compute the outer productVector times(Matrix matrix)
matrix - Matrix to premultiply by "this", must have the same number of rows as
the dimensionality of "this"Vector dotDivide(Vector other)
this by other. Note that if
other has zero elements the result will contain NaN
values.other - The other ring whose elements will divide into this one.this divided by the element in
other.void dotDivideEquals(Vector other)
this by other. Note
that if other has zero elements this will contain NaN
values.other - The other vector whose elements will divide into this one.boolean checkSameDimensionality(Vector other)
this and other have the same
number of dimensions (size)other - vector to compare tovoid assertSameDimensionality(Vector other)
DimensionalityMismatchException is thrown.other - The other vector to compare to.void assertDimensionalityEquals(int otherDimensionality)
DimensionalityMismatchException is thrown.otherDimensionality - The dimensionality of the.Vector stack(Vector other)
other - Vector to stack below "this"Vector subVector(int minIndex, int maxIndex)
minIndex - minimum index to get (inclusive)maxIndex - maximum index to get (inclusive)Vector transform(UnivariateScalarFunction function)
function - The function from double to double to apply.Vector transform(Vector.IndexValueTransform function)
function - The function from index and value to double to apply.void transformEquals(UnivariateScalarFunction function)
function - The function from double to double to apply.void transformEquals(Vector.IndexValueTransform function)
function - The function from index and value to double to apply.Vector transformNonZeros(UnivariateScalarFunction function)
function - The function from double to double to apply to the non-zero
elements.Vector transformNonZeros(Vector.IndexValueTransform function)
function - The function from index and value to double to apply to non-zero
elements.void transformNonZerosEquals(UnivariateScalarFunction function)
function - The function from double to double to apply to the non-zero
elements.void transformNonZerosEquals(Vector.IndexValueTransform function)
function - The function from index and value to double to apply to non-zero
elements.void forEachElement(Vector.IndexValueConsumer consumer)
consumer - The consumer for the entries. It is called for each element in
the vector, in order by increasing index.void forEachEntry(Vector.IndexValueConsumer consumer)
consumer - The consumer for the entries. It is called for each active entry in
the vector, in order by increasing index.void forEachNonZero(Vector.IndexValueConsumer consumer)
consumer - The consumer for the non-zero entries. It is called for each
non-zero entry in the vector, in order by increasing index.void increment(int index)
index - The index of the dimension to increment.void increment(int index,
double value)
index - The index of the dimension to increment.value - The value to add.void decrement(int index)
index - The index of the dimension to decrement.void decrement(int index,
double value)
index - The index of the dimension to decrement.value - The value to subtract.boolean isSparse()
int getEntryCount()
int countNonZeros()
double[] toArray()
java.util.List<java.lang.Double> valuesAsList()
java.lang.String toString()
toString in class java.lang.Objectjava.lang.String toString(java.text.NumberFormat format)
String, using the given formatter.format - The number format to use.java.lang.String toString(java.text.NumberFormat format,
java.lang.String delimiter)
String, using the given formatter and
delimiter.format - The number format to use.delimiter - The delimiter to use.VectorFactory<?> getVectorFactory()