Package com.oracle.coherence.ai.util
Class Vectors
java.lang.Object
com.oracle.coherence.ai.util.Vectors
Utility methods for supporting vectors.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatA very small value to use to avoid divide by zero errors. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BitVectorbinaryQuant(byte[] vector) Quantize an Int8 vector to a bit vector.static BitVectorbinaryQuant(float[] vector) Quantize a float vector to a bit vector.static doubledotProduct(byte[] v1, byte[] v2) Calculate the dot product of two Int8 vectors.static doubledotProduct(float[] v1, float[] v2) Calculate the dot product of two float vectors.static doubledotProduct(BitSet v1, BitSet v2) Calculate the dot product of two bit vectors.static inthammingDistance(Vector<BitSet> x, Vector<BitSet> y) Calculate the hamming distance between two bit vectors.static inthammingDistance(BitSet x, BitSet y) Calculate the hamming distance between two bit vectors.static doublel2squared(byte[] v1, byte[] v2) Calculate the L2 Squared value for two Int8 vectors.static doublel2squared(float[] v1, float[] v2) Calculate the L2 Squared value for two float vectors.static doubleCalculate the L2 Squared value for two bit vectors.static doublemagnitude(byte[] v) Calculate the magnitude of an Int8 vector.static doublemagnitude(float[] v) Calculate the magnitude of a float vector.static doubleCalculate the magnitude of a bit vector.static float[]normalize(byte[] array) Normalize an Int8 vector.static float[]normalize(float[] array) Normalize a float vector.
-
Field Details
-
EPSILON
public static final float EPSILONA very small value to use to avoid divide by zero errors.- See Also:
-
-
Constructor Details
-
Vectors
public Vectors()
-
-
Method Details
-
magnitude
Calculate the magnitude of a bit vector.- Parameters:
v- the bit vector- Returns:
- the magnitude of the bit vector
-
magnitude
public static double magnitude(byte[] v) Calculate the magnitude of an Int8 vector.- Parameters:
v- the Int8 vector- Returns:
- the magnitude of the Int8 vector
-
magnitude
public static double magnitude(float[] v) Calculate the magnitude of a float vector.- Parameters:
v- the float vector- Returns:
- the magnitude of the float vector
-
dotProduct
Calculate the dot product of two bit vectors.- Parameters:
v1- the first bit vectorv2- the second bit vector- Returns:
- the dot product of the bit vectors
-
dotProduct
public static double dotProduct(byte[] v1, byte[] v2) Calculate the dot product of two Int8 vectors.- Parameters:
v1- the first Int8 vectorv2- the second Int8 vector- Returns:
- the dot product of the bit vectors
-
dotProduct
public static double dotProduct(float[] v1, float[] v2) Calculate the dot product of two float vectors.- Parameters:
v1- the first float vectorv2- the second float vector- Returns:
- the magnitude of the float vectors
-
l2squared
Calculate the L2 Squared value for two bit vectors.- Parameters:
v1- the first bit vectorv2- the second bit vector- Returns:
- the L2 Squared value for the two bit vectors
-
l2squared
public static double l2squared(byte[] v1, byte[] v2) Calculate the L2 Squared value for two Int8 vectors.- Parameters:
v1- the first Int8 vectorv2- the second Int8 vector- Returns:
- the L2 Squared value for the two bit vectors
-
l2squared
public static double l2squared(float[] v1, float[] v2) Calculate the L2 Squared value for two float vectors.- Parameters:
v1- the first float vectorv2- the second float vector- Returns:
- the L2 Squared value for the two bit vectors
-
normalize
public static float[] normalize(byte[] array) Normalize an Int8 vector.- Parameters:
array- the Int8 vector to normalize.- Returns:
- the Int8 vector normalized to a float vector
-
normalize
public static float[] normalize(float[] array) Normalize a float vector. Note, the vector is normalized in place, so the values in the array parameter will be updated and the same array returned.- Parameters:
array- the float vector to normalize.- Returns:
- the normalized to a float vector
-
binaryQuant
Quantize a float vector to a bit vector.- Parameters:
vector- the float vector to quantize- Returns:
- the result of the binary quantization of the float vector
-
binaryQuant
Quantize an Int8 vector to a bit vector.- Parameters:
vector- the Int8 vector to quantize- Returns:
- the result of the binary quantization of the Int8 vector
-
hammingDistance
Calculate the hamming distance between two bit vectors.- Parameters:
x- the first bit vectory- the second bit vector- Returns:
- the hamming distance between the two vectors
-
hammingDistance
Calculate the hamming distance between two bit vectors.- Parameters:
x- the first bit vectory- the second bit vector- Returns:
- the hamming distance between the two vectors
-