public abstract class SparseVector extends Vector
Modifier and Type | Field and Description |
---|---|
protected int |
cardinality |
Constructor and Description |
---|
SparseVector(int length) |
SparseVector(int length,
int cardinality) |
Modifier and Type | Method and Description |
---|---|
Vector |
add(double value)
Adds given
value (v) to this vector (X). |
<T> T |
apply(VectorMatrixOperation<T> operation,
Matrix that)
Pipes this vector to a given
operation . |
<T> T |
apply(VectorOperation<T> operation)
Pipes this vector to a given
operation . |
<T> T |
apply(VectorVectorOperation<T> operation,
Vector that)
Pipes this vector to a given
operation . |
int |
cardinality()
Returns the cardinality (the number of non-zero elements)
of this sparse vector.
|
double |
density()
Returns the density (non-zero elements divided by total elements)
of this sparse vector.
|
void |
eachNonZero(VectorProcedure procedure)
Applies given
procedure to each non-zero element of this vector. |
protected void |
ensureIndexIsInBounds(int i)
Ensures the provided index is in the bounds of this
SparseVector . |
double |
euclideanNorm()
Calculates an Euclidean norm of this vector.
|
double |
foldNonZero(VectorAccumulator accumulator)
Folds non-zero elements of this vector with given
accumulator . |
static SparseVector |
fromArray(double[] array)
Creates a new
SparseVector from the given array with
compressing (copying) the underlying array. |
static SparseVector |
fromCollection(Collection<? extends Number> list)
Creates new
SparseVector from collection |
static SparseVector |
fromCSV(String csv)
Parses
SparseVector from the given CSV string. |
static SparseVector |
fromMap(Map<Integer,? extends Number> map,
int length)
Creates new
SparseVector from given index-value map |
static SparseVector |
fromMatrixMarket(String mm)
Parses
SparseVector from the given Matrix Market string. |
double |
get(int i)
Gets the specified element of this vector.
|
abstract double |
getOrElse(int i,
double defaultValue)
Gets the specified element, or a
defaultValue if there
is no actual element at index i in this sparse vector. |
int |
hashCode()
Calculates the hash-code of this vector.
|
double |
infinityNorm()
Calculates an Infinity norm of this vector.
|
boolean |
isZeroAt(int i)
Whether or not the specified element is zero.
|
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.
|
Vector |
multiply(double value)
Multiplies this vector (X) by given
value (v). |
abstract boolean |
nonZeroAt(int i)
* Whether or not the specified element is not zero.
|
abstract VectorIterator |
nonZeroIterator()
Returns a non-zero vector iterator.
|
static SparseVector |
random(int length,
double density,
Random random)
|
<T extends Vector> |
to(VectorFactory<T> factory)
Converts this vector using the given
factory . |
Matrix |
toColumnMatrix()
Converts this vector to matrix with only one column.
|
Matrix |
toDiagonalMatrix()
Converts this vector to a diagonal matrix.
|
String |
toMatrixMarket(NumberFormat formatter)
Converts this vector into the string in Matrix Market format
using the given
formatter ; |
Matrix |
toRowMatrix()
Converts this vector to matrix with only one row.
|
static SparseVector |
zero(int length)
Creates a zero
SparseVector of the given length . |
static SparseVector |
zero(int length,
int capacity)
|
add, blank, blankOfLength, constant, copy, copyOfLength, divide, each, ensureLengthIsCorrect, equals, equals, fail, fold, hadamardProduct, innerProduct, is, iterator, length, mkString, mkString, multiply, non, norm, outerProduct, product, random, select, set, setAll, shuffle, slice, sliceLeft, sliceRight, subtract, subtract, sum, swapElements, toBinary, toCSV, toCSV, toDenseVector, toMatrixMarket, toSparseVector, toString, transform, unit, update, updateAt
public SparseVector(int length)
public SparseVector(int length, int cardinality)
public static SparseVector zero(int length)
SparseVector
of the given length
.public static SparseVector zero(int length, int capacity)
public static SparseVector random(int length, double density, Random random)
public static SparseVector fromArray(double[] array)
SparseVector
from the given array
with
compressing (copying) the underlying array.public static SparseVector fromCSV(String csv)
SparseVector
from the given CSV string.csv
- the CSV string representing a vectorpublic static SparseVector fromMatrixMarket(String mm)
SparseVector
from the given Matrix Market string.mm
- the string in Matrix Market formatpublic static SparseVector fromCollection(Collection<? extends Number> list)
SparseVector
from collectionlist
- value listpublic static SparseVector fromMap(Map<Integer,? extends Number> map, int length)
SparseVector
from given index-value mapmap
- public int cardinality()
public double density()
public double get(int i)
Vector
public abstract double getOrElse(int i, double defaultValue)
defaultValue
if there
is no actual element at index i
in this sparse vector.i
- the element's indexdefaultValue
- the default valuepublic boolean isZeroAt(int i)
i
- element's indextrue
if specified element is zero, false
otherwisepublic abstract boolean nonZeroAt(int i)
i
- element's indextrue
if specified element is zero, false
otherwisepublic double foldNonZero(VectorAccumulator accumulator)
accumulator
.accumulator
- the vector accumulatorpublic void eachNonZero(VectorProcedure procedure)
procedure
to each non-zero element of this vector.procedure
- the vector procedurepublic Vector add(double value)
Vector
value
(v) to this vector (X).public Vector multiply(double value)
Vector
value
(v).public double max()
Vector
public double min()
Vector
public double euclideanNorm()
Vector
euclideanNorm
in class Vector
public double manhattanNorm()
Vector
manhattanNorm
in class Vector
public double infinityNorm()
Vector
infinityNorm
in class Vector
public abstract VectorIterator nonZeroIterator()
public <T extends Vector> T to(VectorFactory<T> factory)
Vector
factory
.public int hashCode()
Vector
public <T> T apply(VectorOperation<T> operation)
Vector
operation
.public <T> T apply(VectorVectorOperation<T> operation, Vector that)
Vector
operation
.public <T> T apply(VectorMatrixOperation<T> operation, Matrix that)
Vector
operation
.apply
in class Vector
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 Matrix toRowMatrix()
Vector
toRowMatrix
in class Vector
public Matrix toColumnMatrix()
Vector
toColumnMatrix
in class Vector
public Matrix toDiagonalMatrix()
Vector
toDiagonalMatrix
in class Vector
public String toMatrixMarket(NumberFormat formatter)
Vector
formatter
;toMatrixMarket
in class Vector
formatter
- the number formaterprotected void ensureIndexIsInBounds(int i)
SparseVector
.i
- The index to check.Copyright © 2015. All rights reserved.