public class Vector extends Object implements NumberVector
Modifier and Type | Class and Description |
---|---|
private static class |
Vector.Factory
Vector factory for Vectors.
|
static class |
Vector.ShortSerializer
Serialization class for dense double vectors with up to
Short.MAX_VALUE dimensions, by using a short for storing the
dimensionality. |
static class |
Vector.SmallSerializer
Serialization class for dense double vectors with up to 127 dimensions, by
using a byte for storing the dimensionality.
|
protected static class |
Vector.VariableSerializer
Serialization class for variable dimensionality by using VarInt encoding.
|
Modifier and Type | Field and Description |
---|---|
static ByteBufferSerializer<Vector> |
BYTE_SERIALIZER
Serializer for up to 127 dimensions.
|
protected double[] |
elements
Array for internal storage of elements.
|
private static String |
ERR_DIMENSIONS
Error message (in assertions!)
|
static String |
ERR_MATRIX_INNERDIM
Error message (in assertions!)
|
static String |
ERR_VEC_DIMENSIONS
Error message (in assertions!)
|
static Vector.Factory |
FACTORY
Static vector factory.
|
static ByteBufferSerializer<Vector> |
SHORT_SERIALIZER
Serializer for up to 2^15-1 dimensions.
|
static ByteBufferSerializer<Vector> |
VARIABLE_SERIALIZER
Serializer using varint encoding.
|
Constructor and Description |
---|
Vector(double... values)
Construct a vector from a given array.
|
Vector(int m)
Constructor
|
Modifier and Type | Method and Description |
---|---|
byte |
byteValue(int dimension)
Returns the value in the specified dimension as byte.
|
Vector |
clone() |
Vector |
copy()
Returns a copy of this vector.
|
Vector |
cross3D(Vector other)
Cross product for 3d vectors, i.e.
|
double |
doubleValue(int dimension)
Returns the value in the specified dimension as double.
|
boolean |
equals(Object obj) |
double |
euclideanLength()
Returns the length of this vector.
|
float |
floatValue(int dimension)
Returns the value in the specified dimension as float.
|
double |
get(int i)
Returns the value at the specified row.
|
double[] |
getArrayCopy()
Copy the internal two-dimensional array.
|
double[] |
getArrayRef()
Access the internal two-dimensional array.
|
Vector |
getColumnVector()
Returns a Vector representing in one column and
getDimensionality() rows the values of this NumberVector of V. |
int |
getDimensionality()
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.
|
Double |
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.
|
Vector |
minus(Vector v)
Returns this vector minus the specified vector v.
|
Vector |
minusEquals(double d)
Subtract a constant value from all dimensions.
|
Vector |
minusEquals(Vector b)
a = a - b.
|
Vector |
minusTimes(Vector v,
double s)
Returns this vector minus the specified vector v times s.
|
Vector |
minusTimesEquals(Vector b,
double s)
a = a - s * b.
|
Vector |
normalize()
Normalizes this vector to the length of 1.0.
|
Vector |
plus(Vector v)
Returns a new vector which is the result of this vector plus the specified
vector.
|
Vector |
plusEquals(double d)
Add a constant value to all dimensions.
|
Vector |
plusEquals(Vector b)
a = a + b.
|
Vector |
plusTimes(Vector v,
double s)
Returns a new vector which is the result of this vector plus the specified
vector times the given factor.
|
Vector |
plusTimesEquals(Vector b,
double s)
a = a + s * b.
|
Vector |
projection(Matrix v)
Projects this row vector into the subspace formed by the specified matrix
v.
|
static Vector |
randomNormalizedVector(int dimensionality)
Returns a randomly created vector of length 1.0.
|
Vector |
rotate90Equals()
Rotate vector by 90 degrees.
|
Vector |
set(int i,
double value)
Sets the value at the specified row.
|
Vector |
set(Vector v)
Copy the values of another vector into the current vector.
|
void |
setZero()
Reset the Vector to 0.
|
short |
shortValue(int dimension)
Returns the value in the specified dimension as short.
|
double |
squaredEuclideanLength()
Returns the squared length of this vector: v^T * v.
|
Vector |
times(double s)
Returns a new vector which is the result of this vector multiplied by the
specified scalar.
|
Matrix |
times(Matrix B)
Linear algebraic matrix multiplication, A * B.
|
Vector |
timesEquals(double s)
Multiply a matrix by a scalar in place, A = s*A.
|
Matrix |
timesTranspose(Matrix B)
Linear algebraic matrix multiplication, A * B^T.
|
Matrix |
timesTranspose(Vector B)
Linear algebraic matrix multiplication, A * B^T.
|
String |
toString()
Returns a string representation of this vector.
|
String |
toStringNoWhitespace()
Returns a string representation of this vector without adding extra
whitespace.
|
Matrix |
transposeTimes(Matrix B)
Linear algebraic matrix multiplication, AT * B.
|
double |
transposeTimes(Vector B)
Linear algebraic matrix multiplication, AT * B.
|
double |
transposeTimesTimes(Matrix B,
Vector c)
Linear algebraic matrix multiplication, aT * B * c.
|
static Vector |
unitVector(int dimensionality,
int i)
Returns the ith unit vector of the specified dimensionality.
|
public static final Vector.Factory FACTORY
public static final ByteBufferSerializer<Vector> BYTE_SERIALIZER
public static final ByteBufferSerializer<Vector> SHORT_SERIALIZER
public static final ByteBufferSerializer<Vector> VARIABLE_SERIALIZER
protected final double[] elements
public static final String ERR_VEC_DIMENSIONS
public static final String ERR_MATRIX_INNERDIM
private static final String ERR_DIMENSIONS
public Vector(double... values)
values
- array of doublespublic Vector(int m)
m
- the number of rowspublic static final Vector randomNormalizedVector(int dimensionality)
dimensionality
- dimensionalitypublic static final Vector unitVector(int dimensionality, int i)
dimensionality
- the dimensionality of the vectori
- the indexpublic final Vector copy()
public final double[] getArrayRef()
public final double[] getArrayCopy()
public final int getDimensionality()
getDimensionality
in interface FeatureVector<Number>
getDimensionality
in interface SpatialComparable
public final double get(int i)
i
- the row indexpublic final Vector set(int i, double value)
i
- the row indexvalue
- the value to be setpublic final Vector set(Vector v)
v
- Other vectorpublic final Vector plus(Vector v)
v
- the vector to be addedpublic final Vector plusTimes(Vector v, double s)
v
- the vector to be addeds
- the scalarpublic final Vector plusEquals(Vector b)
b
- another vectorpublic final Vector plusTimesEquals(Vector b, double s)
b
- another vectors
- Scalarpublic final Vector plusEquals(double d)
d
- Value to addpublic final Vector minus(Vector v)
v
- the vector to be subtracted from this vectorpublic final Vector minusTimes(Vector v, double s)
v
- the vector to be subtracted from this vectors
- the scaling factorpublic final Vector minusEquals(Vector b)
b
- another vectorpublic final Vector minusTimesEquals(Vector b, double s)
b
- another vectors
- Scalarpublic final Vector minusEquals(double d)
d
- Value to subtractpublic final Vector times(double s)
s
- the scalar to be multipliedpublic final Vector timesEquals(double s)
s
- scalarpublic final Matrix times(Matrix B)
B
- another matrixpublic final Matrix transposeTimes(Matrix B)
B
- another matrixpublic final double transposeTimesTimes(Matrix B, Vector c)
B
- matrixc
- vector on the rightpublic final double transposeTimes(Vector B)
B
- another vectorpublic final Matrix timesTranspose(Matrix B)
B
- another matrixpublic final Matrix timesTranspose(Vector B)
B
- another matrixpublic final double squaredEuclideanLength()
public final double euclideanLength()
public final Vector normalize()
public final Vector projection(Matrix v)
v
- the subspace matrixpublic final String toString()
toString
in interface FeatureVector<Number>
toString
in class Object
public final String toStringNoWhitespace()
public void setZero()
public Vector rotate90Equals()
public Vector cross3D(Vector other)
this x other
other
- Other vectorpublic double getMin(int dimension)
SpatialComparable
getMin
in interface SpatialComparable
dimension
- the dimension for which the coordinate should be returned,
where 0 ≤ dimension < getDimensionality()
public double getMax(int dimension)
SpatialComparable
getMax
in interface SpatialComparable
dimension
- the dimension for which the coordinate should be returned,
where 0 ≤ dimension < getDimensionality()
@Deprecated public Double getValue(int dimension)
FeatureVector
getValue
in interface FeatureVector<Number>
getValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension ≤
this.getDimensionality()-1
public double doubleValue(int dimension)
NumberVector
getValue(dim).doubleValue()
, but usually this is much more
efficient due to boxing/unboxing cost.doubleValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public float floatValue(int dimension)
NumberVector
getValue(dim).floatValue()
, but usually this is much more efficient
due to boxing/unboxing cost.floatValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public int intValue(int dimension)
NumberVector
getValue(dim).intValue()
, but usually this is much more efficient
due to boxing/unboxing cost.intValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public long longValue(int dimension)
NumberVector
getValue(dim).longValue()
, but usually this is much more efficient
due to boxing/unboxing cost.longValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public short shortValue(int dimension)
NumberVector
getValue(dim).shortValue()
, but usually this is much more efficient
due to boxing/unboxing cost.shortValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public byte byteValue(int dimension)
NumberVector
getValue(dim).byteValue()
, but usually this is much more efficient
due to boxing/unboxing cost.byteValue
in interface NumberVector
dimension
- the desired dimension, where 0 ≤ dimension <
this.getDimensionality()
public Vector getColumnVector()
NumberVector
getDimensionality()
rows the values of this NumberVector of V.getColumnVector
in interface NumberVector
getDimensionality()
rows the values of this
NumberVector of VCopyright © 2015 ELKI Development Team, Lehr- und Forschungseinheit für Datenbanksysteme, Ludwig-Maximilians-Universität München. License information.