public abstract class AbstractVector extends Object implements Vector
AbstractVector
implements most of a vector's
functionality in terms of methods for dimensionality and values.Modifier | Constructor and Description |
---|---|
protected |
AbstractVector()
Construct an abstract vector.
|
Modifier and Type | Method and Description |
---|---|
Vector |
add(Vector v)
Returns the result of adding the specified vector to this
vector.
|
double |
cosine(Vector v)
Returns the cosine of this vector and the specified vector.
|
double |
dotProduct(Vector v)
Returns the dot product (inner product) of this vector with the
specified vector.
|
boolean |
equals(Object that)
Returns
true if the specified object is a vector
with the same dimensionality and values as this vector. |
int |
hashCode()
Returns the hash code for this vector according to the
specification.
|
void |
increment(double scale,
Vector v)
Adds the specified vector multiplied by the specified scalar to
this vector.
|
double |
length()
Returns the length of this vector.
|
int[] |
nonZeroDimensions()
Returns an array with the non-zero dimensions of this vector.
|
abstract int |
numDimensions()
Returns the number of dimensions of this vector.
|
void |
setValue(int dimension,
double value)
Throws an unsupported operation exception.
|
abstract double |
value(int dimension)
The value of this vector for the specified dimension.
|
public int[] nonZeroDimensions()
nonZeroDimensions
in interface Vector
public void increment(double scale, Vector v)
increment
in interface Vector
scale
- The scalar multiplier for the added vector.v
- Vector to scale and add to this vector.IllegalArgumentException
- If the specified vector is not
of the same dimensionality as this vector.public abstract int numDimensions()
value(int)
.numDimensions
in interface Vector
public abstract double value(int dimension)
numDimensions()
.value
in interface Vector
dimension
- Dimension whose value is returned.IndexOutOfBoundsException
- If the dimension is less than
zero or greater than or equal to the number of dimensions.public void setValue(int dimension, double value)
setValue
in interface Vector
dimension
- Ignored.value
- Ignored.UnsupportedOperationException
- Always.public double length()
the implementation iterates over the dimensions once accessing each value.
public Vector add(Vector v)
Implementation Note: The result is a dense vector and this method iterates over the dimensions adding. Subclasses may override this with a more specific implementation and then fall back on this implementation for the general case.
add
in interface Vector
v
- Vector to add to this vector.IllegalArgumentException
- If the specified vector does
not have the same dimensionality as this vector.public double dotProduct(Vector v)
Implementation Note: This method iterates over the dimensions, accessing values for this vector and the specified vector for each dimension.
dotProduct
in interface Vector
v
- The specified vector.IllegalArgumentException
- If the specified vector
is not of the same dimensionality as this vector.public double cosine(Vector v)
Implementation Note: This method iterates over the dimensions once and accesses the value of each vector once per dimension.
cosine
in interface Vector
v
- The specified vector.IllegalArgumentException
- If the specified vector
is not of the same dimensionality as this vector.public boolean equals(Object that)
true
if the specified object is a vector
with the same dimensionality and values as this vector. Note
that labels are not considered for equality. This
implementation is consistent with hash codes.public int hashCode()