java.lang.Object
de.lmu.ifi.dbs.elki.math.linearalgebra.Vector
- All Implemented Interfaces:
FeatureVector<Double>
,NumberVector<Double>
,SpatialComparable
Provides a vector object that encapsulates an m x 1 - matrix object.
- Author:
- Elke Achtert
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.lmu.ifi.dbs.elki.data.NumberVector
NumberVector.Factory<V extends NumberVector<? extends N>,
N extends Number> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte
byteValue
(int dimension) Returns the value in the specified dimension as byte.clone()
final Vector
copy()
Returns a copy of this vector.Cross product for 3d vectors, i.e.double
doubleValue
(int dimension) Returns the value in the specified dimension as double.boolean
final double
Returns the length of this vector.float
floatValue
(int dimension) Returns the value in the specified dimension as float.final double
get
(int i) Returns the value at the specified row.final double[]
Copy the internal two-dimensional array.final double[]
Access the internal two-dimensional array.Returns a Vector representing in one column andgetDimensionality()
rows the values of this NumberVector of V.final int
Returns the dimensionality of this vector.double
getMax
(int dimension) Returns the maximum coordinate at the specified dimension.double
getMin
(int dimension) Returns the minimum coordinate at the specified dimension.getValue
(int dimension) Deprecated.int
hashCode()
int
intValue
(int dimension) Returns the value in the specified dimension as int.long
longValue
(int dimension) Returns the value in the specified dimension as long.final Vector
Returns this vector minus the specified vector v.final Vector
minusEquals
(double d) Subtract a constant value from all dimensions.final Vector
a = a - b.final Vector
minusTimes
(Vector v, double s) Returns this vector minus the specified vector v times s.final Vector
minusTimesEquals
(Vector b, double s) a = a - s * b.final Vector
Normalizes this vector to the length of 1.0.final Vector
Returns a new vector which is the result of this vector plus the specified vector.final Vector
plusEquals
(double d) Add a constant value to all dimensions.final Vector
plusEquals
(Vector b) a = a + b.final Vector
Returns a new vector which is the result of this vector plus the specified vector times the given factor.final Vector
plusTimesEquals
(Vector b, double s) a = a + s * b.final Vector
projection
(Matrix v) Projects this row vector into the subspace formed by the specified matrix v.static final Vector
randomNormalizedVector
(int dimensionality) Returns a randomly created vector of length 1.0.Rotate vector by 90 degrees.final Vector
set
(int i, double value) Sets the value at the specified row.void
setZero()
Reset the Vector to 0.short
shortValue
(int dimension) Returns the value in the specified dimension as short.final Vector
times
(double s) Returns a new vector which is the result of this vector multiplied by the specified scalar.final Matrix
Linear algebraic matrix multiplication, A * B.final Vector
timesEquals
(double s) Multiply a matrix by a scalar in place, A = s*A.final Matrix
Linear algebraic matrix multiplication, A * B^T.final Matrix
Linear algebraic matrix multiplication, A * B^T.final String
toString()
Returns a string representation of this vector.final String
Returns a string representation of this vector without adding extra whitespace.final Matrix
Linear algebraic matrix multiplication, AT * B.final double
Linear algebraic matrix multiplication, AT * B.final double
transposeTimesTimes
(Matrix B, Vector c) Linear algebraic matrix multiplication, aT * B * c.static final Vector
unitVector
(int dimensionality, int i) Returns the ith unit vector of the specified dimensionality.
-
Field Details
-
elements
protected final double[] elementsArray for internal storage of elements. -
ERR_VEC_DIMENSIONS
Error message (in assertions!) when vector dimensionalities do not agree.- See Also:
-
ERR_MATRIX_INNERDIM
Error message (in assertions!) when matrix dimensionalities do not agree.- See Also:
-
-
Constructor Details
-
Vector
public Vector(double... values) Construct a vector from a given array.- Parameters:
values
- array of doubles
-
Vector
public Vector(int m) Provides an m x 1 vector.- Parameters:
m
- the number of rows
-
-
Method Details
-
randomNormalizedVector
Returns a randomly created vector of length 1.0.- Parameters:
dimensionality
- dimensionality- Returns:
- the dimensionality of the vector
-
unitVector
Returns the ith unit vector of the specified dimensionality.- Parameters:
dimensionality
- the dimensionality of the vectori
- the index- Returns:
- the ith unit vector of the specified dimensionality
-
copy
Returns a copy of this vector.- Returns:
- a copy of this vector
-
clone
-
getArrayRef
public final double[] getArrayRef()Access the internal two-dimensional array.- Returns:
- Pointer to the two-dimensional array of matrix elements.
-
getArrayCopy
public final double[] getArrayCopy()Copy the internal two-dimensional array.- Returns:
- Two-dimensional array copy of matrix elements.
-
getDimensionality
public final int getDimensionality()Returns the dimensionality of this vector.- Specified by:
getDimensionality
in interfaceFeatureVector<Double>
- Specified by:
getDimensionality
in interfaceSpatialComparable
- Returns:
- the dimensionality of this vector
-
get
public final double get(int i) Returns the value at the specified row.- Parameters:
i
- the row index- Returns:
- the value at row i
-
set
Sets the value at the specified row.- Parameters:
i
- the row indexvalue
- the value to be set- Returns:
- the modified vector
-
plus
Returns a new vector which is the result of this vector plus the specified vector.- Parameters:
v
- the vector to be added- Returns:
- the resulting vector
-
plusTimes
Returns a new vector which is the result of this vector plus the specified vector times the given factor.- Parameters:
v
- the vector to be addeds
- the scalar- Returns:
- the resulting vector
-
plusEquals
a = a + b.- Parameters:
b
- another vector- Returns:
- a + b in this vector
-
plusTimesEquals
a = a + s * b.- Parameters:
b
- another vectors
- Scalar- Returns:
- a + s * b in this vector
-
plusEquals
Add a constant value to all dimensions.- Parameters:
d
- Value to add- Returns:
- Modified vector
-
minus
Returns this vector minus the specified vector v.- Parameters:
v
- the vector to be subtracted from this vector- Returns:
- this vector minus the specified vector v
-
minusTimes
Returns this vector minus the specified vector v times s.- Parameters:
v
- the vector to be subtracted from this vectors
- the scaling factor- Returns:
- this vector minus the specified vector v
-
minusEquals
a = a - b.- Parameters:
b
- another vector- Returns:
- a - b in this vector
-
minusTimesEquals
a = a - s * b.- Parameters:
b
- another vectors
- Scalar- Returns:
- a - s * b in this vector
-
minusEquals
Subtract a constant value from all dimensions.- Parameters:
d
- Value to subtract- Returns:
- Modified vector
-
times
Returns a new vector which is the result of this vector multiplied by the specified scalar.- Parameters:
s
- the scalar to be multiplied- Returns:
- the resulting vector
-
timesEquals
Multiply a matrix by a scalar in place, A = s*A.- Parameters:
s
- scalar- Returns:
- replace A by s*A
-
times
Linear algebraic matrix multiplication, A * B.- Parameters:
B
- another matrix- Returns:
- Matrix product, A * B
-
transposeTimes
Linear algebraic matrix multiplication, AT * B.- Parameters:
B
- another matrix- Returns:
- Matrix product, AT * B
-
transposeTimesTimes
Linear algebraic matrix multiplication, aT * B * c.- Parameters:
B
- matrixc
- vector on the right- Returns:
- Matrix product, aT * B * c
-
transposeTimes
Linear algebraic matrix multiplication, AT * B.- Parameters:
B
- another vector- Returns:
- Matrix product, AT * B
-
timesTranspose
Linear algebraic matrix multiplication, A * B^T.- Parameters:
B
- another matrix- Returns:
- Matrix product, A * B^T
-
timesTranspose
Linear algebraic matrix multiplication, A * B^T.- Parameters:
B
- another matrix- Returns:
- Matrix product, A * B^T
-
euclideanLength
public final double euclideanLength()Returns the length of this vector.- Returns:
- the length of this vector
-
normalize
Normalizes this vector to the length of 1.0.- Returns:
- this vector
-
projection
Projects this row vector into the subspace formed by the specified matrix v.- Parameters:
v
- the subspace matrix- Returns:
- the projection of p into the subspace formed by v
-
hashCode
public int hashCode() -
equals
-
toString
Returns a string representation of this vector.- Specified by:
toString
in interfaceFeatureVector<Double>
- Overrides:
toString
in classObject
- Returns:
- a string representation of this vector.
-
toStringNoWhitespace
Returns a string representation of this vector without adding extra whitespace.- Returns:
- a string representation of this vector.
-
setZero
public void setZero()Reset the Vector to 0. -
rotate90Equals
Rotate vector by 90 degrees.- Returns:
- self, for operation chaining.
-
cross3D
Cross product for 3d vectors, i.e.this x other
- Parameters:
other
- Other vector- Returns:
- Cross product of this vector and the other vector
-
getMin
public double getMin(int dimension) Description copied from interface:SpatialComparable
Returns the minimum coordinate at the specified dimension.- Specified by:
getMin
in interfaceSpatialComparable
- Parameters:
dimension
- the dimension for which the coordinate should be returned, where 0 ≤ dimension <getDimensionality()
- Returns:
- the minimum coordinate at the specified dimension
-
getMax
public double getMax(int dimension) Description copied from interface:SpatialComparable
Returns the maximum coordinate at the specified dimension.- Specified by:
getMax
in interfaceSpatialComparable
- Parameters:
dimension
- the dimension for which the coordinate should be returned, where 0 ≤ dimension <getDimensionality()
- Returns:
- the maximum coordinate at the specified dimension
-
getValue
Deprecated.Description copied from interface:FeatureVector
Returns the value in the specified dimension.- Specified by:
getValue
in interfaceFeatureVector<Double>
- Specified by:
getValue
in interfaceNumberVector<Double>
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension ≤this.getDimensionality()-1
- Returns:
- the value in the specified dimension
-
doubleValue
public double doubleValue(int dimension) Description copied from interface:NumberVector
Returns the value in the specified dimension as double. Note: this might seem redundant with respect togetValue(dim).doubleValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
doubleValue
in interfaceNumberVector<Double>
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
floatValue
public float floatValue(int dimension) Description copied from interface:NumberVector
Returns the value in the specified dimension as float. Note: this might seem redundant with respect togetValue(dim).floatValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
floatValue
in interfaceNumberVector<Double>
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
intValue
public int intValue(int dimension) Description copied from interface:NumberVector
Returns the value in the specified dimension as int. Note: this might seem redundant with respect togetValue(dim).intValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
intValue
in interfaceNumberVector<Double>
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
longValue
public long longValue(int dimension) Description copied from interface:NumberVector
Returns the value in the specified dimension as long. Note: this might seem redundant with respect togetValue(dim).longValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
longValue
in interfaceNumberVector<Double>
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
shortValue
public short shortValue(int dimension) Description copied from interface:NumberVector
Returns the value in the specified dimension as short. Note: this might seem redundant with respect togetValue(dim).shortValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
shortValue
in interfaceNumberVector<Double>
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
byteValue
public byte byteValue(int dimension) Description copied from interface:NumberVector
Returns the value in the specified dimension as byte. Note: this might seem redundant with respect togetValue(dim).byteValue()
, but usually this is much more efficient due to boxing/unboxing cost.- Specified by:
byteValue
in interfaceNumberVector<Double>
- Parameters:
dimension
- the desired dimension, where 0 ≤ dimension <this.getDimensionality()
- Returns:
- the value in the specified dimension
-
getColumnVector
Description copied from interface:NumberVector
Returns a Vector representing in one column andgetDimensionality()
rows the values of this NumberVector of V.- Specified by:
getColumnVector
in interfaceNumberVector<Double>
- Returns:
- a Matrix representing in one column and
getDimensionality()
rows the values of this NumberVector of V
-