Package elki.data
Class VectorUtil
- java.lang.Object
-
- elki.data.VectorUtil
-
public final class VectorUtil extends java.lang.Object
Utility functions for use with vectors.Note: obviously, many functions are class methods or database related.
TODO: add more precise but slower O(n^2) angle computation according to:
Computing the Angle between Vectors
P. Schatte
Journal of Computing, Volume 63, Number 1 (1999)- Since:
- 0.3
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
VectorUtil.SortDBIDsBySingleDimension
Compare number vectors by a single dimension.static class
VectorUtil.SortVectorsBySingleDimension
Compare number vectors by a single dimension.
-
Constructor Summary
Constructors Modifier Constructor Description private
VectorUtil()
Fake constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
angle(NumberVector v1, NumberVector v2, NumberVector o)
Compute the angle between two vectors with respect to a reference point.static double
angleDense(NumberVector v1, NumberVector v2)
Compute the absolute cosine of the angle between two dense vectors.static double
angleSparse(SparseNumberVector v1, SparseNumberVector v2)
Compute the angle for sparse vectors.static double
angleSparseDense(SparseNumberVector v1, NumberVector v2)
Compute the angle for a sparse and a dense vector.static double
cosAngle(NumberVector v1, NumberVector v2)
Compute the absolute cosine of the angle between two vectors.static double
dot(NumberVector v1, double[] v2)
Compute the dot product of the angle between two vectors.static double
dot(NumberVector v1, NumberVector v2)
Compute the dot product of the angle between two vectors.static double
dotDense(NumberVector v1, double[] v2)
Compute the dot product of two dense vectors.static double
dotDense(NumberVector v1, NumberVector v2)
Compute the dot product of two dense vectors.static double
dotSparse(SparseNumberVector v1, SparseNumberVector v2)
Compute the dot product for two sparse vectors.static double
dotSparseDense(SparseNumberVector v1, double[] v2)
Compute the dot product for a sparse and a dense vector.static double
dotSparseDense(SparseNumberVector v1, NumberVector v2)
Compute the dot product for a sparse and a dense vector.static double
minCosAngle(SpatialComparable v1, SpatialComparable v2)
Compute the minimum angle between two rectangles.static double
minDot(SpatialComparable v1, SpatialComparable v2)
Compute the minimum angle between two rectangles, assuming unit length vectorsstatic <V extends NumberVector>
Vproject(V v, long[] selectedAttributes, NumberVector.Factory<V> factory)
Project a number vector to the specified attributes.static <V extends NumberVector>
VrandomVector(NumberVector.Factory<V> factory, int dim)
Produce a new vector based on random numbers in [0:1].static <V extends NumberVector>
VrandomVector(NumberVector.Factory<V> factory, int dim, java.util.Random r)
Produce a new vector based on random numbers in [0:1].
-
-
-
Method Detail
-
randomVector
public static <V extends NumberVector> V randomVector(NumberVector.Factory<V> factory, int dim, java.util.Random r)
Produce a new vector based on random numbers in [0:1].- Type Parameters:
V
- vector type- Parameters:
factory
- Vector factorydim
- desired dimensionalityr
- Random generator- Returns:
- new instance
-
randomVector
public static <V extends NumberVector> V randomVector(NumberVector.Factory<V> factory, int dim)
Produce a new vector based on random numbers in [0:1].- Type Parameters:
V
- vector type- Parameters:
factory
- Vector factorydim
- desired dimensionality- Returns:
- new instance
-
angleDense
public static double angleDense(NumberVector v1, NumberVector v2)
Compute the absolute cosine of the angle between two dense vectors.To convert it to radians, use
Math.acos(angle)
!- Parameters:
v1
- first vectorv2
- second vector- Returns:
- Angle
-
angleSparse
public static double angleSparse(SparseNumberVector v1, SparseNumberVector v2)
Compute the angle for sparse vectors.- Parameters:
v1
- First vectorv2
- Second vector- Returns:
- angle
-
angleSparseDense
public static double angleSparseDense(SparseNumberVector v1, NumberVector v2)
Compute the angle for a sparse and a dense vector.- Parameters:
v1
- Sparse first vectorv2
- Dense second vector- Returns:
- angle
-
cosAngle
public static double cosAngle(NumberVector v1, NumberVector v2)
Compute the absolute cosine of the angle between two vectors.To convert it to radians, use
Math.acos(angle)
!- Parameters:
v1
- first vectorv2
- second vector- Returns:
- Angle
-
minCosAngle
public static double minCosAngle(SpatialComparable v1, SpatialComparable v2)
Compute the minimum angle between two rectangles.- Parameters:
v1
- first rectanglev2
- second rectangle- Returns:
- Angle
-
angle
public static double angle(NumberVector v1, NumberVector v2, NumberVector o)
Compute the angle between two vectors with respect to a reference point.- Parameters:
v1
- first vectorv2
- second vectoro
- Origin- Returns:
- Angle
-
dotDense
public static double dotDense(NumberVector v1, NumberVector v2)
Compute the dot product of two dense vectors.- Parameters:
v1
- first vectorv2
- second vector- Returns:
- dot product
-
dotDense
public static double dotDense(NumberVector v1, double[] v2)
Compute the dot product of two dense vectors.- Parameters:
v1
- first vectorv2
- second vector- Returns:
- dot product
-
dotSparse
public static double dotSparse(SparseNumberVector v1, SparseNumberVector v2)
Compute the dot product for two sparse vectors.- Parameters:
v1
- First vectorv2
- Second vector- Returns:
- dot product
-
dotSparseDense
public static double dotSparseDense(SparseNumberVector v1, NumberVector v2)
Compute the dot product for a sparse and a dense vector.- Parameters:
v1
- Sparse first vectorv2
- Dense second vector- Returns:
- dot product
-
dotSparseDense
public static double dotSparseDense(SparseNumberVector v1, double[] v2)
Compute the dot product for a sparse and a dense vector.- Parameters:
v1
- Sparse first vectorv2
- Dense second vector- Returns:
- dot product
-
dot
public static double dot(NumberVector v1, NumberVector v2)
Compute the dot product of the angle between two vectors.- Parameters:
v1
- first vectorv2
- second vector- Returns:
- Dot product
-
dot
public static double dot(NumberVector v1, double[] v2)
Compute the dot product of the angle between two vectors.- Parameters:
v1
- first vectorv2
- second vector- Returns:
- Dot product
-
minDot
public static double minDot(SpatialComparable v1, SpatialComparable v2)
Compute the minimum angle between two rectangles, assuming unit length vectors- Parameters:
v1
- first rectanglev2
- second rectangle- Returns:
- Angle
-
project
public static <V extends NumberVector> V project(V v, long[] selectedAttributes, NumberVector.Factory<V> factory)
Project a number vector to the specified attributes.- Type Parameters:
V
- Vector type- Parameters:
v
- a NumberVector to projectselectedAttributes
- the attributes selected for projectionfactory
- Vector factory- Returns:
- a new NumberVector as a projection on the specified attributes
-
-