Class AbstractDistance<T>

java.lang.Object
com.oracle.coherence.ai.distance.AbstractDistance<T>
Type Parameters:
T - the type of the vector the algorithm uses
All Implemented Interfaces:
DistanceAlgorithm<T>, ExternalizableLite, PortableObject, Serializable
Direct Known Subclasses:
CosineDistance, InnerProductDistance, L2SquaredDistance

public abstract class AbstractDistance<T> extends Object implements DistanceAlgorithm<T>, ExternalizableLite, PortableObject
A base class for distance algorithm implementations.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract double
    distance(byte[] v1, byte[] v2)
    Calculate the distance between two Int8 (byte) vectors.
    protected abstract double
    distance(float[] v1, float[] v2)
    Calculate the distance between two Float32 (float) vectors.
    double
    distance(Vector<T> v1, Vector<T> v2)
    Calculate the distance between the specified vectors.
    protected abstract double
    Calculate the distance between two bit vectors.
    void
    Restore the contents of a user type instance by reading its state using the specified PofReader object.
    void
    Restore the contents of this object by loading the object's state from the passed DataInput object.
    void
    Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
    void
    Save the contents of this object by storing the object's state into the passed DataOutput object.

    Methods inherited from class java.lang.Object

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

    • AbstractDistance

      public AbstractDistance()
  • Method Details

    • distance

      public double distance(Vector<T> v1, Vector<T> v2)
      Description copied from interface: DistanceAlgorithm
      Calculate the distance between the specified vectors.
      Specified by:
      distance in interface DistanceAlgorithm<T>
      Parameters:
      v1 - the vector to calculate the distance from
      v2 - the vector to calculate the distance to
      Returns:
      the distance between the specified vectors
    • distance

      protected abstract double distance(BitSet v1, BitSet v2)
      Calculate the distance between two bit vectors.
      Parameters:
      v1 - the first bit vector
      v2 - the second bit vector
      Returns:
      the distance between the two bit vectors
    • distance

      protected abstract double distance(byte[] v1, byte[] v2)
      Calculate the distance between two Int8 (byte) vectors.
      Parameters:
      v1 - the first Int8 vector
      v2 - the second Int8 vector
      Returns:
      the distance between the two Int8 vectors
    • distance

      protected abstract double distance(float[] v1, float[] v2)
      Calculate the distance between two Float32 (float) vectors.
      Parameters:
      v1 - the first Float32 vector
      v2 - the second Float32 vector
      Returns:
      the distance between the two Float32 vectors
    • readExternal

      public void readExternal(PofReader in)
      Description copied from interface: PortableObject
      Restore the contents of a user type instance by reading its state using the specified PofReader object.
      Specified by:
      readExternal in interface PortableObject
      Parameters:
      in - the PofReader from which to read the object's state
    • writeExternal

      public void writeExternal(PofWriter out) throws IOException
      Description copied from interface: PortableObject
      Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
      Specified by:
      writeExternal in interface PortableObject
      Parameters:
      out - the PofWriter to which to write the object's state
      Throws:
      IOException - if an I/O error occurs
    • readExternal

      public void readExternal(DataInput in) throws IOException
      Description copied from interface: ExternalizableLite
      Restore the contents of this object by loading the object's state from the passed DataInput object.
      Specified by:
      readExternal in interface ExternalizableLite
      Parameters:
      in - the DataInput stream to read data from in order to restore the state of this object
      Throws:
      IOException - if an I/O exception occurs
    • writeExternal

      public void writeExternal(DataOutput out) throws IOException
      Description copied from interface: ExternalizableLite
      Save the contents of this object by storing the object's state into the passed DataOutput object.
      Specified by:
      writeExternal in interface ExternalizableLite
      Parameters:
      out - the DataOutput stream to write the state of this object to
      Throws:
      IOException - if an I/O exception occurs