public class DenseVector extends AbstractVector implements Serializable
DenseVector is a vector implementation suitable for
vectors with primarily non-zero values. The dimensioanality of
a dense vector is set at construction time and immutable afterwards.
Values may be specified at construction time or given default values.
Values may be set later.
Implementation Note: A dense vector represents the values with an array of primitive double values.
DenseVector.| Constructor and Description |
|---|
DenseVector(DenseVector v)
Constructs a deep copy of the specified vector.
|
DenseVector(double[] values)
Construct a dense vector with the specified values.
|
DenseVector(int numDimensions)
Construct a dense vector with the specified number of
dimensions.
|
DenseVector(Vector v)
Cosntruct a deep copy of the specified vector as a dense vector.
|
| Modifier and Type | Method and Description |
|---|---|
Vector |
add(Vector v)
Returns the result of adding the specified vector to this
vector.
|
double |
dotProduct(Vector v)
Returns the dot product (inner product) of this vector with the
specified vector.
|
void |
increment(double scale,
Vector v)
Adds the specified vector multiplied by the specified scalar to
this vector.
|
int |
numDimensions()
Returns the number of dimensions for this dense vector.
|
void |
setValue(int dimension,
double value)
Sets the value of the specified dimension to the specified
value.
|
String |
toString()
Returns a string representation of the values
in this vector.
|
double |
value(int dimension)
Returns the value of this dense vector for the specified
dimension.
|
cosine, equals, hashCode, length, nonZeroDimensionspublic DenseVector(int numDimensions)
0.0
initially.numDimensions - The number of dimensions in this vector.IllegalArgumentException - If the number of dimensions is
not positive.public DenseVector(double[] values)
values - Array of values for the vector.IllegalArgumentException - If the specified values array
is zero length.public DenseVector(DenseVector v)
v - Vector to copy.public DenseVector(Vector v)
v - Vector to copy.public double dotProduct(Vector v)
AbstractVectorImplementation Note: This method iterates over the dimensions, accessing values for this vector and the specified vector for each dimension.
dotProduct in interface VectordotProduct in class AbstractVectorv - The specified vector.public void setValue(int dimension,
double value)
setValue in interface VectorsetValue in class AbstractVectordimension - The specified dimension.value - The new value for the specified dimension.IndexOutOfBoundsException - If the dimension is less than
0 or greather than or equal to the number of dimensions of this
vector.public int numDimensions()
numDimensions in interface VectornumDimensions in class AbstractVectorpublic void increment(double scale,
Vector v)
Implementation Note: This class implements this
operationg sparsely if the specified argument vector is
an instance of SparseFloatVector. Otherwise, it
visits every dimension of the specified vector and this
vector.
increment in interface Vectorincrement in class AbstractVectorscale - 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 Vector add(Vector v)
AbstractVectorImplementation 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 Vectoradd in class AbstractVectorv - Vector to add to this vector.public double value(int dimension)
value in interface Vectorvalue in class AbstractVectordimension - Specified dimension.IndexOutOfBoundsException - If the dimension is less than
0 or greather than or equal to the number of dimensions of this
vector.Copyright © 2019 Alias-i, Inc.. All rights reserved.