|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javatools.datatypes.SparseVector
public class SparseVector
This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class represents a Sparse Vector, i.e. a vector that has only few non-zero entries. Supports special (space-)optimized routines for binary vectors. Supports k-means with eucledian, cosine or other distances.
Nested Class Summary | |
---|---|
static interface |
SparseVector.Distance
Computes a distance of two vectors |
Field Summary | |
---|---|
static SparseVector.Distance |
cosineDistance
Computes the cosine distance |
static SparseVector.Distance |
eucledianDistance
Computes the eucledian distance |
Constructor Summary | |
---|---|
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,
java.util.List<java.lang.Integer> dimensions)
Creates a binary Sparse Vector from an (unsorted) list of dimensions and a label |
|
SparseVector(SparseVector v)
Duplicates a vector |
|
SparseVector(java.lang.String s)
Creates a Sparse Vector from a SVM-light-like input string of the form label dim:val ... |
Method Summary | |
---|---|
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(java.lang.String[] argv)
Test method |
SparseVector |
multiply(double r)
Multiplies this vector by a scalar |
java.util.Iterator<java.lang.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 |
java.lang.String |
toString()
Returns a String representation in an SVM-light-like format label dim:val ... |
static java.lang.String |
visualize(java.util.List<SparseVector> vectors)
Visualizes two-dimensional vectors |
static java.lang.String |
visualize(java.util.List<SparseVector> vectors1,
java.util.List<SparseVector> vectors2)
Visualizes two-dimensional vectors |
static java.lang.String |
visualize(SparseVector... vectors)
Visualizes two-dimensional vectors |
static java.lang.String |
visualize(SparseVector[] vectors1,
SparseVector[] vectors2)
Visualizes two-dimensional vectors |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final SparseVector.Distance eucledianDistance
public static final SparseVector.Distance cosineDistance
Constructor Detail |
---|
public SparseVector(SparseVector v)
public SparseVector(double l, java.util.List<java.lang.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(java.lang.String s)
Method Detail |
---|
public SparseVector compress()
public java.lang.String toString()
toString
in class java.lang.Object
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 java.lang.String visualize(SparseVector... vectors)
public static java.lang.String visualize(java.util.List<SparseVector> vectors1, java.util.List<SparseVector> vectors2)
public static java.lang.String visualize(SparseVector[] vectors1, SparseVector[] vectors2)
public static java.lang.String visualize(java.util.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 java.util.Iterator<java.lang.Integer> nonZeroIndices()
public SparseVector clone()
clone
in class java.lang.Object
public static void main(java.lang.String[] argv) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |