Class Vectors

java.lang.Object
com.oracle.coherence.ai.util.Vectors

public class Vectors extends Object
Utility methods for supporting vectors.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    A very small value to use to avoid divide by zero errors.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static BitVector
    binaryQuant(byte[] vector)
    Quantize an Int8 vector to a bit vector.
    static BitVector
    binaryQuant(float[] vector)
    Quantize a float vector to a bit vector.
    static double
    dotProduct(byte[] v1, byte[] v2)
    Calculate the dot product of two Int8 vectors.
    static double
    dotProduct(float[] v1, float[] v2)
    Calculate the dot product of two float vectors.
    static double
    Calculate the dot product of two bit vectors.
    static int
    Calculate the hamming distance between two bit vectors.
    static int
    Calculate the hamming distance between two bit vectors.
    static double
    l2squared(byte[] v1, byte[] v2)
    Calculate the L2 Squared value for two Int8 vectors.
    static double
    l2squared(float[] v1, float[] v2)
    Calculate the L2 Squared value for two float vectors.
    static double
    Calculate the L2 Squared value for two bit vectors.
    static double
    magnitude(byte[] v)
    Calculate the magnitude of an Int8 vector.
    static double
    magnitude(float[] v)
    Calculate the magnitude of a float vector.
    static double
    Calculate the magnitude of a bit vector.
    static float[]
    normalize(byte[] array)
    Normalize an Int8 vector.
    static float[]
    normalize(float[] array)
    Normalize a float vector.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EPSILON

      public static final float EPSILON
      A very small value to use to avoid divide by zero errors.
      See Also:
  • Constructor Details

    • Vectors

      public Vectors()
  • Method Details

    • magnitude

      public static double magnitude(BitSet v)
      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

      public static double dotProduct(BitSet v1, BitSet v2)
      Calculate the dot product of two bit vectors.
      Parameters:
      v1 - the first bit vector
      v2 - 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 vector
      v2 - 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 vector
      v2 - the second float vector
      Returns:
      the magnitude of the float vectors
    • l2squared

      public static double l2squared(BitSet v1, BitSet v2)
      Calculate the L2 Squared value for two bit vectors.
      Parameters:
      v1 - the first bit vector
      v2 - 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 vector
      v2 - 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 vector
      v2 - 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

      public static BitVector binaryQuant(float[] vector)
      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

      public static BitVector binaryQuant(byte[] vector)
      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

      public static int hammingDistance(Vector<BitSet> x, Vector<BitSet> y)
      Calculate the hamming distance between two bit vectors.
      Parameters:
      x - the first bit vector
      y - the second bit vector
      Returns:
      the hamming distance between the two vectors
    • hammingDistance

      public static int hammingDistance(BitSet x, BitSet y)
      Calculate the hamming distance between two bit vectors.
      Parameters:
      x - the first bit vector
      y - the second bit vector
      Returns:
      the hamming distance between the two vectors