public class SparseVector extends Object implements Serializable, Cloneable
| Modifier and Type | Class and Description |
|---|---|
static interface |
SparseVector.Distance
Computes a distance of two vectors
|
| Modifier and Type | Field and Description |
|---|---|
protected static double[] |
BINARY
Standard values for a binary vector (just 1,1,1,...; gets prolonged if needed)
|
static SparseVector.Distance |
cosineDistance
Computes the cosine distance
|
protected int[] |
dim
dim[i] tells what dimension val[i] belongs to.
|
static SparseVector.Distance |
eucledianDistance
Computes the eucledian distance
|
protected double |
label
Contains a double value associated to this Sparse Vector
|
protected int |
size
Holds the number of non-zero values of this vector
|
protected static int[] |
STANDARDDIM
Standard dimensions 0...
|
protected double |
twonorm_sq
Holds the squared two_norm of this vector, computed on demand
|
protected double[] |
val
Contains the values of this vector (corresponding to dim).
|
| Constructor and Description |
|---|
SparseVector(double[] v,
int[] d)
Creates a Sparse Vector from (sorted) dimensions and values
|
SparseVector(double label,
double... values)
Creates a SparseVector from actual values
|
SparseVector(double l,
int[] d)
Creates a binary Sparse Vector from an unsorted array of dimensions
and a label
Zero-entries and duplicates in the dimension array will be ignored.
|
SparseVector(double l,
int[] d,
double[] v)
Creates a Sparse Vector from (sorted) dimensions, (modifiable) values and a label
|
SparseVector(double l,
List<Integer> dimensions)
Creates a binary Sparse Vector from an (unsorted) list of dimensions and a label
|
SparseVector(SparseVector v)
Duplicates a vector
|
SparseVector(String s)
Creates a Sparse Vector from a SVM-light-like input string of the form
label dim:val ...
|
| Modifier and Type | Method and Description |
|---|---|
SparseVector |
add(SparseVector v)
Adds a vector to this one
|
char |
charLabel()
Returns a char label for the vector
|
SparseVector |
clone()
Clones a vector
|
SparseVector |
compress()
Kicks out 0-entries (without affecting the vector in a mathematical sense)
|
double |
cosine(SparseVector v)
Returns the cosine of this vector with another vector
|
double |
eucledianDistance(SparseVector v)
Returns the distance to another vector
|
double |
get(int i)
Retrieves the i-th value
|
int |
index(int dimension)
Returns the index for a dimension (or -1)
|
boolean |
isBinary()
Tells whether this vector is binary
|
static void |
kMeans(SparseVector[] dots,
SparseVector[] centers)
Does a simple K-means
|
static void |
kMeans(SparseVector[] dots,
SparseVector[] centers,
SparseVector.Distance distanceFunction,
double epsilon,
int iterations)
Does a simple K-means until the number of iterations is exceeded
|
double |
l2norm()
Returns this vector's two-norm
|
static void |
main(String[] argv)
Test method
|
SparseVector |
multiply(double r)
Multiplies this vector by a scalar
|
Iterator<Integer> |
nonZeroIndices()
Gives an iterator over the non-zero indices
|
int |
size()
Returns the number of non-zero elements.
|
double |
sprod(SparseVector v)
Returns the scalar product (dot product) of this vector with another one.
|
double |
squaredl2norm()
Returns this vector's squared two-norm
|
String |
toString()
Returns a String representation in an SVM-light-like format
label dim:val ...
|
protected static void |
updateBINARY(int num)
Ensures that the BINARY array has enough 1's
|
static String |
visualize(List<SparseVector> vectors)
Visualizes two-dimensional vectors
|
static String |
visualize(List<SparseVector> vectors1,
List<SparseVector> vectors2)
Visualizes two-dimensional vectors
|
static String |
visualize(SparseVector... vectors)
Visualizes two-dimensional vectors
|
static String |
visualize(SparseVector[] vectors1,
SparseVector[] vectors2)
Visualizes two-dimensional vectors
|
protected double label
protected double[] val
protected int[] dim
protected static int[] STANDARDDIM
protected static double[] BINARY
protected int size
protected double twonorm_sq
public static final SparseVector.Distance eucledianDistance
public static final SparseVector.Distance cosineDistance
public SparseVector(SparseVector v)
public SparseVector(double l,
List<Integer> dimensions)
public SparseVector(double l,
int[] d)
public SparseVector(double[] v,
int[] d)
public SparseVector(double l,
int[] d,
double[] v)
public SparseVector(double label,
double... values)
public SparseVector(String s)
protected static void updateBINARY(int num)
public SparseVector compress()
public String toString()
public double sprod(SparseVector v)
public boolean isBinary()
public int size()
public double squaredl2norm()
public double l2norm()
public double cosine(SparseVector v)
public double get(int i)
public static String visualize(SparseVector... vectors)
public static String visualize(List<SparseVector> vectors1, List<SparseVector> vectors2)
public static String visualize(SparseVector[] vectors1, SparseVector[] vectors2)
public static String visualize(List<SparseVector> vectors)
public char charLabel()
public static void kMeans(SparseVector[] dots, SparseVector[] centers)
public static void kMeans(SparseVector[] dots, SparseVector[] centers, SparseVector.Distance distanceFunction, double epsilon, int iterations)
public double eucledianDistance(SparseVector v)
public int index(int dimension)
public SparseVector add(SparseVector v)
public SparseVector multiply(double r)
public Iterator<Integer> nonZeroIndices()
public SparseVector clone()
Copyright © 2018. All rights reserved.