Package org.apache.spark.mllib.linalg
Class SparseVector
Object
org.apache.spark.mllib.linalg.SparseVector
- All Implemented Interfaces:
Serializable
,Vector
A sparse vector represented by an index array and a value array.
param: size size of the vector. param: indices index array, assume to be strictly increasing. param: values value array, must have the same length as the index array.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble
apply
(int i) Gets the value of the ith element.int
argmax()
Find the index of a maximal element.asML()
Convert this vector to the new mllib-local representation.copy()
Makes a deep copy of this vector.boolean
static SparseVector
Convert new linalg type to spark.mllib type.int
hashCode()
Returns a hash code value for the vector.int[]
indices()
int
Number of active entries.int
Number of nonzero elements.int
size()
Size of the vector.double[]
toArray()
Converts the instance to a double array.toJson()
Converts the vector to a JSON string.toString()
static scala.Option<scala.Tuple3<Object,
int[], double[]>> unapply
(SparseVector sv) double[]
values()
Methods inherited from interface org.apache.spark.mllib.linalg.Vector
compressed, dot, foreach, foreachActive, foreachNonZero, nonZeroIterator, sparsity, toDense, toSparse
-
Constructor Details
-
SparseVector
public SparseVector(int size, int[] indices, double[] values)
-
-
Method Details
-
unapply
-
fromML
Convert new linalg type to spark.mllib type. Light copy; only copies references- Parameters:
v
- (undocumented)- Returns:
- (undocumented)
-
size
public int size()Description copied from interface:Vector
Size of the vector. -
indices
public int[] indices() -
values
public double[] values() -
toString
-
toArray
public double[] toArray()Description copied from interface:Vector
Converts the instance to a double array. -
copy
Description copied from interface:Vector
Makes a deep copy of this vector. -
apply
public double apply(int i) Description copied from interface:Vector
Gets the value of the ith element. -
equals
-
hashCode
public int hashCode()Description copied from interface:Vector
Returns a hash code value for the vector. The hash code is based on its size and its first 128 nonzero entries, using a hash algorithm similar tojava.util.Arrays.hashCode
. -
numActives
public int numActives()Description copied from interface:Vector
Number of active entries. An "active entry" is an element which is explicitly stored, regardless of its value.- Specified by:
numActives
in interfaceVector
- Returns:
- (undocumented)
-
numNonzeros
public int numNonzeros()Description copied from interface:Vector
Number of nonzero elements. This scans all active values and count nonzeros.- Specified by:
numNonzeros
in interfaceVector
- Returns:
- (undocumented)
-
argmax
public int argmax()Description copied from interface:Vector
Find the index of a maximal element. Returns the first maximal element in case of a tie. Returns -1 if vector has length 0. -
toJson
Description copied from interface:Vector
Converts the vector to a JSON string. -
asML
Description copied from interface:Vector
Convert this vector to the new mllib-local representation. This does NOT copy the data; it copies references.
-