public class CompressedVector extends SparseVector
CompressedVector stores the underlying data in a two arrays: A values
array and a indices array. The values array matches the indices array, and
they're both sorted by the indices array. To get a value at an index, the
index is found in the indices array with a binary search and the respective
value is obtained from the values array.cardinality| Constructor and Description |
|---|
CompressedVector() |
CompressedVector(int length) |
CompressedVector(int length,
int capacity) |
CompressedVector(int length,
int cardinality,
double[] values,
int[] indices) |
| Modifier and Type | Method and Description |
|---|---|
Vector |
blankOfLength(int length)
Creates a blank (an empty vector) copy of this vector with the given
length. |
Vector |
copyOfLength(int length)
Copies this vector into the new vector with specified
length. |
void |
each(VectorProcedure procedure)
Applies given
procedure to each element of this vector. |
void |
eachNonZero(VectorProcedure procedure)
Applies given
procedure to each non-zero element of this vector. |
static CompressedVector |
fromArray(double[] array)
Creates a new
CompressedVector from the given array with
compressing (copying) the underlying array. |
static CompressedVector |
fromBinary(byte[] array)
Decodes
CompressedVector from the given byte array. |
static CompressedVector |
fromCollection(Collection<? extends Number> list)
Creates new
CompressedVector from collection |
static CompressedVector |
fromCSV(String csv)
Parses
CompressedVector from the given CSV string. |
static CompressedVector |
fromMap(Map<Integer,? extends Number> map,
int length)
Creates new
CompressedVector from index-value map |
static CompressedVector |
fromMatrixMarket(String mm)
Parses
CompressedVector from the given Matrix Market string. |
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. |
VectorIterator |
iterator()
Returns a vector iterator.
|
boolean |
nonZeroAt(int i)
* Whether or not the specified element is not zero.
|
VectorIterator |
nonZeroIterator()
Returns a non-zero vector iterator.
|
static CompressedVector |
random(int length,
double density,
Random random)
|
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. |
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. |
byte[] |
toBinary()
Encodes this vector into a byte array.
|
void |
updateAt(int i,
VectorFunction function)
Updates the specified element of this vector by applying given
function. |
static CompressedVector |
zero(int length)
Creates a zero
CompressedVector of the given length. |
static CompressedVector |
zero(int length,
int capacity)
|
add, apply, apply, apply, cardinality, density, ensureIndexIsInBounds, euclideanNorm, foldNonZero, get, hashCode, infinityNorm, isZeroAt, manhattanNorm, max, min, multiply, toColumnMatrix, toDiagonalMatrix, toMatrixMarket, toRowMatrixadd, blank, constant, copy, divide, ensureLengthIsCorrect, equals, equals, fail, fold, hadamardProduct, innerProduct, is, length, mkString, mkString, multiply, non, norm, outerProduct, product, random, select, shuffle, slice, sliceLeft, sliceRight, subtract, subtract, sum, toCSV, toCSV, toDenseVector, toMatrixMarket, toSparseVector, toString, transform, unit, updatepublic CompressedVector()
public CompressedVector(int length)
public CompressedVector(int length,
int capacity)
public CompressedVector(int length,
int cardinality,
double[] values,
int[] indices)
public static CompressedVector zero(int length)
CompressedVector of the given length.public static CompressedVector zero(int length, int capacity)
public static CompressedVector random(int length, double density, Random random)
public static CompressedVector fromArray(double[] array)
CompressedVector from the given array with
compressing (copying) the underlying array.public static CompressedVector fromBinary(byte[] array)
CompressedVector from the given byte array.array - the byte array representing a vectorpublic static CompressedVector fromCSV(String csv)
CompressedVector from the given CSV string.csv - the CSV string representing a vectorpublic static CompressedVector fromMatrixMarket(String mm)
CompressedVector from the given Matrix Market string.mm - the string in Matrix Market formatpublic static CompressedVector fromCollection(Collection<? extends Number> list)
CompressedVector from collectionlist - value listpublic static CompressedVector fromMap(Map<Integer,? extends Number> map, int length)
CompressedVector from index-value mapmap - index-value maplength - vector lengthpublic double getOrElse(int i,
double defaultValue)
SparseVectordefaultValue if there
is no actual element at index i in this sparse vector.getOrElse in class SparseVectori - the element's indexdefaultValue - the default valuepublic void set(int i,
double value)
Vectorvalue.public void setAll(double value)
Vectorvalue.public void swapElements(int i,
int j)
VectorswapElements in class Vectori - element's indexj - element's indexpublic Vector copyOfLength(int length)
Vectorlength.copyOfLength in class Vectorlength - the length of new vectorpublic void each(VectorProcedure procedure)
Vectorprocedure to each element of this vector.public void eachNonZero(VectorProcedure procedure)
SparseVectorprocedure to each non-zero element of this vector.eachNonZero in class SparseVectorprocedure - the vector procedurepublic void updateAt(int i,
VectorFunction function)
Vectorfunction.public boolean nonZeroAt(int i)
SparseVectornonZeroAt in class SparseVectori - element's indextrue if specified element is zero, false otherwisepublic <T extends Vector> T to(VectorFactory<T> factory)
Vectorfactory.to in class SparseVectorT - type of the result vectorfactory - the factory that creates an output vectorpublic Vector blankOfLength(int length)
Vectorlength.blankOfLength in class Vectorlength - the length of the blank vectorpublic byte[] toBinary()
Vectorpublic VectorIterator nonZeroIterator()
SparseVectornonZeroIterator in class SparseVectorCopyright © 2015. All rights reserved.