|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpitt.search.semanticvectors.VectorUtils
public class VectorUtils
This class provides standard vector methods, e.g., cosine measure, normalization, tensor utils.
Constructor Summary | |
---|---|
VectorUtils()
|
Method Summary | |
---|---|
static float[] |
addVectors(float[] vector1,
float[] vector2,
int weight)
Add two vectors. |
static float[] |
addVectors(float[] vector1,
short[] sparseVector,
int weight)
Add two vectors. |
static float[][] |
createZeroTensor(int dim)
|
static float[] |
createZeroVector()
|
static float |
euclideanDistance(float[] vec1,
float[] vec2)
|
static float[] |
Floats(double[] vector)
|
static float[][] |
Floats(double[][] matrix)
|
static short[] |
floatVectorToSparseVector(float[] floatVector,
int seedLength)
Take a vector of floats and simplify by quantizing to a sparse format. |
static short[] |
generateRandomVector(int seedLength,
java.util.Random random)
Generates a basic sparse vector (dimension = Flags.dimension) with mainly zeros and some 1 and -1 entries (seedLength/2 of each) each vector is an array of length seedLength containing 1+ the index of a non-zero value, signed according to whether this is a + or -1. |
static float[] |
getConvolutionFromTensor(float[][] tensor)
Returns the convolution of two vectors; see Plate, Holographic Reduced Representation, p. |
static float[] |
getConvolutionFromVectors(float[] vec1,
float[] vec2)
Returns the convolution of two vectors; see Plate, Holographic Reduced Representation, p. |
static float |
getInnerProduct(float[][] ten1,
float[][] ten2)
Returns the inner product of two tensors. |
static int |
getNearestVector(float[] vector,
float[][] candidates)
Get nearest vector from list of candidates. |
static short[] |
getNLargestPositions(float[] values,
int numResults)
Given an array of floats, return an array of indices to the n largest values. |
static float[][] |
getNormalizedTensor(float[][] tensor)
Returns the normalized version of a 2 tensor, i.e. |
static float[] |
getNormalizedVector(float[] vec)
Returns the normalized version of a vector, i.e. |
static float[][] |
getOuterProduct(float[] vec1,
float[] vec2)
Returns a 2-tensor which is the outer product of 2 vectors. |
static float |
getSumScalarProduct(float[] testVector,
java.util.ArrayList<float[]> vectors)
Sums the scalar products of a vector and each member of a list of vectors. |
static float[][] |
getTensorSum(float[][] ten1,
float[][] ten2)
Returns the sum of two tensors. |
static boolean |
isZeroTensor(float[][] ten)
|
static boolean |
isZeroVector(float[] vec)
|
static boolean |
orthogonalizeVectors(java.util.ArrayList<float[]> vectors)
The orthogonalize function takes an array of vectors and orthogonalizes them using the Gram-Schmidt process. |
static float[] |
permuteVector(float[] indexVector,
int rotation)
This method implements rotation as a form of vector permutation, as described in Sahlgren, Holst and Kanervi 2008. |
static short[] |
permuteVector(short[] indexVector,
int rotation)
This method implements rotation as a form of vector permutation, as described in Sahlgren, Holst and Kanervi 2008. |
static void |
printMatrix(float[][] matrix)
|
static void |
printVector(float[] vector)
|
static float |
scalarProduct(float[] vec1,
float[] vec2)
Returns the scalar product (dot product) of two vectors for normalized vectors this is the same as cosine similarity. |
static float[] |
sparseVectorToFloatVector(short[] sparseVector,
int dimension)
Translate sparse format (listing of offsets) into full float vector. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public VectorUtils()
Method Detail |
---|
public static void printVector(float[] vector)
public static void printMatrix(float[][] matrix)
public static float[] Floats(double[] vector)
public static float[][] Floats(double[][] matrix)
public static boolean isZeroVector(float[] vec)
public static float[] createZeroVector()
public static boolean isZeroTensor(float[][] ten)
public static float[][] createZeroTensor(int dim)
public static float scalarProduct(float[] vec1, float[] vec2)
vec1
- First vector.vec2
- Second vector.public static float euclideanDistance(float[] vec1, float[] vec2)
public static int getNearestVector(float[] vector, float[][] candidates)
vector
- The vector whose nearest neighbor is to be found.candidates
- The list of vectors from whoe the nearest is to be chosen.
public static float[] getNormalizedVector(float[] vec)
vec
- Vector whose normalized version is requested.public static float[][] getNormalizedTensor(float[][] tensor)
public static float[][] getOuterProduct(float[] vec1, float[] vec2)
public static float[][] getTensorSum(float[][] ten1, float[][] ten2)
public static float getInnerProduct(float[][] ten1, float[][] ten2)
public static float[] getConvolutionFromTensor(float[][] tensor)
public static float[] getConvolutionFromVectors(float[] vec1, float[] vec2)
public static float getSumScalarProduct(float[] testVector, java.util.ArrayList<float[]> vectors)
public static boolean orthogonalizeVectors(java.util.ArrayList<float[]> vectors)
vectors
- ArrayList of vectors (which are themselves arrays of
floats) to be orthogonalized in place.public static short[] generateRandomVector(int seedLength, java.util.Random random)
public static short[] getNLargestPositions(float[] values, int numResults)
public static short[] floatVectorToSparseVector(float[] floatVector, int seedLength)
public static float[] sparseVectorToFloatVector(short[] sparseVector, int dimension)
public static short[] permuteVector(short[] indexVector, int rotation)
indexVector
- the sparse vector to be permutedrotation
- the direction and number of places to rotate
public static float[] permuteVector(float[] indexVector, int rotation)
indexVector
- the sparse vector to be permutedrotation
- the direction and number of places to rotate
public static float[] addVectors(float[] vector1, float[] vector2, int weight)
vector1
- initial vectorvector2
- vector to be addedweight
- weight (presently only term frequency implemented - may need this to take floats later)
public static float[] addVectors(float[] vector1, short[] sparseVector, int weight)
vector1
- initial vectorsparseVector
- vector to be addedweight
- weight (presently only term frequency implemented - may need this to take floats later)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |