public abstract class Vector extends Object implements Iterable<Double>
Modifier and Type | Field and Description |
---|---|
protected int |
length
Length of this vector.
|
Constructor and Description |
---|
Vector()
Creates a vector of zero length.
|
Vector(int length)
Creates a vector of given
length . |
Modifier and Type | Method and Description |
---|---|
Vector |
add(double value)
Adds given
value (v) to this vector (X). |
Vector |
add(Vector that)
Adds given
vector (X) to this vector (Y). |
abstract <T> T |
apply(VectorMatrixOperation<T> operation,
Matrix that)
Pipes this vector to a given
operation . |
abstract <T> T |
apply(VectorOperation<T> operation)
Pipes this vector to a given
operation . |
abstract <T> T |
apply(VectorVectorOperation<T> operation,
Vector that)
Pipes this vector to a given
operation . |
Vector |
blank()
Creates a blank (an empty vector with same length) copy of this vector.
|
abstract Vector |
blankOfLength(int length)
Creates a blank (an empty vector) copy of this vector with the given
length . |
static Vector |
constant(int length,
double value)
|
Vector |
copy()
Copies this vector.
|
abstract Vector |
copyOfLength(int length)
Copies this vector into the new vector with specified
length . |
Vector |
divide(double value)
Divides this vector (X) by given
value (v). |
void |
each(VectorProcedure procedure)
Applies given
procedure to each element of this vector. |
protected void |
ensureLengthIsCorrect(int length) |
boolean |
equals(Object o)
Checks where this vector is equal to the given object
o . |
boolean |
equals(Vector that,
double precision)
Returns true when vector is equal to given
that vector with given
precision . |
double |
euclideanNorm()
Calculates an Euclidean norm of this vector.
|
protected void |
fail(String message) |
double |
fold(VectorAccumulator accumulator)
Folds all elements of this vector with given
accumulator . |
static Vector |
fromArray(double[] array)
Creates a new
Vector from the given array w/o
copying the underlying array. |
static Vector |
fromCollection(Collection<? extends Number> list)
Creates new
BasicVector from list |
static Vector |
fromCSV(String csv)
Parses
Vector from the given CSV string. |
static Vector |
fromMap(Map<Integer,? extends Number> map,
int length)
Creates new
SparseVector from list |
static Vector |
fromMatrixMarket(String mm)
Parses
Vector from the given Matrix Market string. |
abstract double |
get(int i)
Gets the specified element of this vector.
|
Vector |
hadamardProduct(Vector that)
Calculates the Hadamard (element-wise) product of this vector and given
that . |
int |
hashCode()
Calculates the hash-code of this vector.
|
double |
infinityNorm()
Calculates an Infinity norm of this vector.
|
double |
innerProduct(Vector that)
Calculates the inner product of this vector and given
that . |
boolean |
is(VectorPredicate predicate)
Checks whether this vector compiles with given
predicate or not. |
VectorIterator |
iterator()
Returns a vector iterator.
|
int |
length()
Returns the length of this vector.
|
double |
manhattanNorm()
Calculates a Manhattan norm of this vector.
|
double |
max()
Searches for the maximum value of the elements of this vector.
|
double |
min()
Searches for the minimum value of the elements of this vector.
|
String |
mkString(NumberFormat formatter)
Converts this vector into the string representation.
|
String |
mkString(NumberFormat formatter,
String delimiter)
Converts this vector into the string representation.
|
Vector |
multiply(double value)
Multiplies this vector (X) by given
value (v). |
Vector |
multiply(Matrix that)
Multiples this vector (X) by given
that (A). |
boolean |
non(VectorPredicate predicate)
Checks whether this vector compiles with given
predicate or not. |
double |
norm()
Calculates an Euclidean norm of this vector.
|
Matrix |
outerProduct(Vector that)
Calculates the outer product of this vector and given
that . |
double |
product()
Multiplies up all elements of this vector.
|
static Vector |
random(int length,
Random random)
|
Vector |
select(int[] indices)
Returns a new vector with the selected elements.
|
abstract void |
set(int i,
double value)
Sets the specified element of this matrix to given
value . |
void |
setAll(double value)
Sets all elements of this vector to given
value . |
Vector |
shuffle()
Shuffles this vector.
|
Vector |
slice(int from,
int until)
Retrieves the specified sub-vector of this vector.
|
Vector |
sliceLeft(int until)
Retrieves the specified sub-vector of this vector.
|
Vector |
sliceRight(int from)
Retrieves the specified sub-vector of this vector.
|
Vector |
subtract(double value)
Subtracts given
value (v) from this vector (X). |
Vector |
subtract(Vector that)
Subtracts given
that (Y) from this vector (X). |
double |
sum()
Summarizes all elements of the vector
|
void |
swapElements(int i,
int j)
Swaps the specified elements of this vector.
|
<T extends Vector> |
to(VectorFactory<T> factory)
Converts this vector using the given
factory . |
abstract byte[] |
toBinary()
Encodes this vector into a byte array.
|
abstract Matrix |
toColumnMatrix()
Converts this vector to matrix with only one column.
|
String |
toCSV()
Converts this vector into the CSV (Comma Separated Value) string.
|
String |
toCSV(NumberFormat formatter)
Converts this vector into the CSV (Comma Separated Value) string
using the given
formatter . |
DenseVector |
toDenseVector()
Converts this vector into a
DenseVector . |
abstract Matrix |
toDiagonalMatrix()
Converts this vector to a diagonal matrix.
|
String |
toMatrixMarket()
Converts this vector into the string in Matrix Market format.
|
abstract String |
toMatrixMarket(NumberFormat formatter)
Converts this vector into the string in Matrix Market format
using the given
formatter ; |
abstract Matrix |
toRowMatrix()
Converts this vector to matrix with only one row.
|
SparseVector |
toSparseVector()
Converts this vector into a
SparseVector . |
String |
toString()
Converts this vector into a string representation.
|
Vector |
transform(VectorFunction function)
Builds a new vector by applying given
function to each element
of this vector. |
static Vector |
unit(int length)
Creates an unit
Vector of the given length . |
void |
update(VectorFunction function)
Updates all elements of this vector by applying given
function . |
void |
updateAt(int i,
VectorFunction function)
Updates the specified element of this vector by applying given
function . |
static Vector |
zero(int length)
Creates a zero
Vector of the given length . |
public Vector()
public Vector(int length)
length
.length
- the length of the vectorpublic static Vector constant(int length, double value)
public static Vector fromArray(double[] array)
Vector
from the given array
w/o
copying the underlying array.public static Vector fromCSV(String csv)
Vector
from the given CSV string.csv
- the CSV string representing a vectorpublic static Vector fromMatrixMarket(String mm)
Vector
from the given Matrix Market string.mm
- the string in Matrix Market formatpublic static Vector fromCollection(Collection<? extends Number> list)
BasicVector
from list
public static Vector fromMap(Map<Integer,? extends Number> map, int length)
SparseVector
from list
public abstract double get(int i)
i
- element's indexpublic abstract void set(int i, double value)
value
.i
- element's indexvalue
- element's new valuepublic abstract Vector blankOfLength(int length)
length
.length
- the length of the blank vectorpublic abstract Vector copyOfLength(int length)
length
.length
- the length of new vectorpublic abstract Matrix toRowMatrix()
public abstract Matrix toColumnMatrix()
public abstract Matrix toDiagonalMatrix()
public abstract <T> T apply(VectorOperation<T> operation)
operation
.T
- the result typeoperation
- the vector operation
(an operation that take vector and returns T
)public abstract <T> T apply(VectorVectorOperation<T> operation, Vector that)
operation
.T
- the result typeoperation
- the vector-vector operation
(an operation that takes two vectors and returns T
)that
- the right hand vector for the given operationthat
vectorpublic abstract <T> T apply(VectorMatrixOperation<T> operation, Matrix that)
operation
.T
- the result typeoperation
- the vector-matrix operation
(an operation that takes vector and matrix and returns T
)that
- the right hand matrix for the given operationthat
matrixpublic abstract byte[] toBinary()
public abstract String toMatrixMarket(NumberFormat formatter)
formatter
;formatter
- the number formaterpublic void setAll(double value)
value
.value
- the element's new valuepublic int length()
public Vector add(double value)
value
(v) to this vector (X).value
- the right hand value for additionpublic Vector add(Vector that)
vector
(X) to this vector (Y).that
- the right hand vector for additionpublic Vector multiply(double value)
value
(v).value
- the right hand value for multiplicationpublic Vector hadamardProduct(Vector that)
that
.that
- the right hand vector for Hadamard productpublic Vector multiply(Matrix that)
that
(A).that
- the right hand matrix for multiplicationpublic Vector subtract(double value)
value
(v) from this vector (X).value
- the right hand value for subtractionpublic Vector subtract(Vector that)
that
(Y) from this vector (X).that
- the right hand vector for subtractionpublic Vector divide(double value)
value
(v).value
- the right hand value for divisionpublic double product()
public double sum()
public double innerProduct(Vector that)
that
.that
- the right hand vector for inner productpublic Matrix outerProduct(Vector that)
that
.that
- the the right hand vector for outer productpublic double norm()
public double euclideanNorm()
public double manhattanNorm()
public double infinityNorm()
public void swapElements(int i, int j)
i
- element's indexj
- element's indexpublic Vector blank()
public Vector copy()
public Vector shuffle()
Copies this vector in the new vector that contains the same elements but with the elements shuffled around (which might also result in the same vector (all outcomes are equally probable)).
public Vector slice(int from, int until)
from
- the beginning of indices intervaluntil
- the ending of indices intervalpublic Vector sliceLeft(int until)
until
- the ending of indices intervalpublic Vector sliceRight(int from)
from
- the beginning of indices intervalpublic Vector select(int[] indices)
indices
- the array of indicespublic void each(VectorProcedure procedure)
procedure
to each element of this vector.procedure
- the vector procedurepublic double max()
public double min()
public Vector transform(VectorFunction function)
function
to each element
of this vector.function
- the vector functionpublic void update(VectorFunction function)
function
.function
- the the vector functionpublic void updateAt(int i, VectorFunction function)
function
.i
- element's indexfunction
- the vector functionpublic double fold(VectorAccumulator accumulator)
accumulator
.accumulator
- the vector accumulatorpublic boolean is(VectorPredicate predicate)
predicate
or not.predicate
- the vector predicatepublic boolean non(VectorPredicate predicate)
predicate
or not.predicate
- the vector predicatepublic boolean equals(Vector that, double precision)
that
vector with given
precision
.that
- vectorprecision
- given precisionpublic String mkString(NumberFormat formatter)
formatter
- the number formatterpublic String mkString(NumberFormat formatter, String delimiter)
formatter
- the number formatterdelimiter
- the element's delimiterpublic String toString()
public boolean equals(Object o)
o
.public int hashCode()
public VectorIterator iterator()
public <T extends Vector> T to(VectorFactory<T> factory)
factory
.T
- type of the result vectorfactory
- the factory that creates an output vectorpublic DenseVector toDenseVector()
DenseVector
.public SparseVector toSparseVector()
SparseVector
.public String toCSV()
public String toCSV(NumberFormat formatter)
formatter
.public String toMatrixMarket()
protected void ensureLengthIsCorrect(int length)
protected void fail(String message)
Copyright © 2015. All rights reserved.