public class Vector extends Object implements MatrixLike<Vector>, Serializable
Modifier and Type | Field and Description |
---|---|
protected double[] |
elements
Array for internal storage of elements.
|
private static long |
serialVersionUID
Serial version
|
Constructor and Description |
---|
Vector(double... values)
Construct a vector from a given array.
|
Vector(int m)
Provides an m x 1 vector.
|
Modifier and Type | Method and Description |
---|---|
private void |
checkDimensions(Vector v)
Check if this.getDimensionality() == v.getDimensionality().
|
Vector |
clone()
Clone the Vector object.
|
Vector |
copy()
Returns a copy of this vector.
|
boolean |
equals(Object obj) |
double |
euclideanLength()
Returns the length of this vector.
|
double |
get(int i)
Returns the value at the specified row.
|
double |
get(int i,
int j)
Get a single element.
|
double[] |
getArrayCopy()
Copy the internal two-dimensional array.
|
double[] |
getArrayRef()
Access the internal two-dimensional array.
|
int |
getColumnDimensionality()
Returns the dimensionality of the columns of this matrix.
|
Vector |
getColumnVector(int i)
Returns the
i th column of this matrix as vector. |
int |
getDimensionality()
Returns the dimensionality of this vector.
|
int |
getRowDimensionality()
Returns the dimensionality of the rows of this matrix.
|
int |
hashCode() |
Vector |
increment(int i,
int j,
double s)
Increments a single element.
|
Vector |
inverseVector()
Inverts every element of the vector.
|
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.
|
double |
normF()
Frobenius norm
|
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
|
double |
scalarProduct(Vector v)
Returns the scalar product of this vector and the specified vector v.
|
Vector |
set(int i,
double value)
Sets the value at the specified row.
|
Vector |
set(int i,
int j,
double s)
Set a single element.
|
void |
setZero()
Reset the Vector to 0.
|
Vector |
sqrtVector()
Square roots every element of the vector.
|
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
|
String |
toString()
Returns a string representation of this vector.
|
String |
toStringNoWhitespace()
Returns a string representation of this vector without adding extra
whitespace
|
Matrix |
transpose()
Matrix transpose.
|
Matrix |
transposeTimes(Matrix B)
Linear algebraic matrix multiplication, AT * B
|
double |
transposeTimes(Vector B)
Linear algebraic matrix multiplication, AT * B
|
static Vector |
unitVector(int dimensionality,
int i)
Returns the ith unit vector of the specified dimensionality.
|
private static final long serialVersionUID
protected final double[] elements
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()
copy
in interface MatrixLike<Vector>
public Vector clone()
clone
in interface MatrixLike<Vector>
clone
in class Object
public final double[] getArrayRef()
public final double[] getArrayCopy()
public final int getDimensionality()
public final int getRowDimensionality()
MatrixLike
getRowDimensionality
in interface MatrixLike<Vector>
public final int getColumnDimensionality()
MatrixLike
getColumnDimensionality
in interface MatrixLike<Vector>
public final double get(int i)
i
- the row indexpublic final double get(int i, int j)
MatrixLike
get
in interface MatrixLike<Vector>
i
- Row index.j
- Column index.public final Vector set(int i, double value)
i
- the row indexvalue
- the value to be setpublic final Vector set(int i, int j, double s)
MatrixLike
set
in interface MatrixLike<Vector>
i
- Row index.j
- Column index.s
- A(i,j).public final Vector increment(int i, int j, double s)
MatrixLike
increment
in interface MatrixLike<Vector>
i
- the row indexj
- the column indexs
- the increment value: A(i,j) = A(i.j) + s.public final Vector getColumnVector(int i)
MatrixLike
i
th column of this matrix as vector.getColumnVector
in interface MatrixLike<Vector>
i
- the index of the column to be returnedi
th column of this matrixpublic final Matrix transpose()
MatrixLike
transpose
in interface MatrixLike<Vector>
public final Vector plus(Vector v)
plus
in interface MatrixLike<Vector>
v
- the vector to be addedpublic final Vector plusTimes(Vector v, double s)
plusTimes
in interface MatrixLike<Vector>
v
- the vector to be addeds
- the scalarpublic final Vector plusEquals(Vector B)
plusEquals
in interface MatrixLike<Vector>
B
- another matrixpublic final Vector plusTimesEquals(Vector B, double s)
plusTimesEquals
in interface MatrixLike<Vector>
B
- another matrixs
- Scalarpublic final Vector plusEquals(double d)
d
- Value to addpublic final Vector minus(Vector v)
minus
in interface MatrixLike<Vector>
v
- the vector to be subtracted from this vectorpublic final Vector minusTimes(Vector v, double s)
minusTimes
in interface MatrixLike<Vector>
v
- the vector to be subtracted from this vectors
- the scaling factorpublic final Vector minusEquals(Vector B)
minusEquals
in interface MatrixLike<Vector>
B
- another matrixpublic final Vector minusTimesEquals(Vector B, double s)
minusTimesEquals
in interface MatrixLike<Vector>
B
- another matrixs
- Scalarpublic final Vector minusEquals(double d)
d
- Value to subtractpublic final Vector times(double s)
times
in interface MatrixLike<Vector>
s
- the scalar to be multipliedpublic final Vector timesEquals(double s)
timesEquals
in interface MatrixLike<Vector>
s
- scalarpublic final Matrix times(Matrix B)
B
- another matrixIllegalArgumentException
- Matrix inner dimensions must agree.public final Matrix transposeTimes(Matrix B)
B
- another matrixIllegalArgumentException
- Matrix inner dimensions must agree.public final double transposeTimes(Vector B)
B
- another vectorIllegalArgumentException
- Matrix inner dimensions must agree.public final Matrix timesTranspose(Matrix B)
B
- another matrixIllegalArgumentException
- Matrix inner dimensions must agree.public final double scalarProduct(Vector v)
v
- the vectorpublic final Vector inverseVector()
public final Vector sqrtVector()
public final double euclideanLength()
public double normF()
public final Vector normalize()
public final Vector projection(Matrix v)
v
- the subspace matrixIllegalArgumentException
- if this matrix is no row vector, i.e. this
matrix has more than one column or this matrix and v have different
length of rowsprivate final void checkDimensions(Vector v)
IllegalArgumentException
- if the dimensions do not agreepublic final String toString()
public final String toStringNoWhitespace()
public void setZero()