Package com.oracle.coherence.ai.distance
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 -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
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
writeExternal
(PofWriter out) Save the contents of a POF user type instance by writing its state using the specified PofWriter object.void
writeExternal
(DataOutput out) Save the contents of this object by storing the object's state into the passed DataOutput object.
-
Constructor Details
-
AbstractDistance
public AbstractDistance()
-
-
Method Details
-
distance
Description copied from interface:DistanceAlgorithm
Calculate the distance between the specified vectors.- Specified by:
distance
in interfaceDistanceAlgorithm<T>
- Parameters:
v1
- the vector to calculate the distance fromv2
- the vector to calculate the distance to- Returns:
- the distance between the specified vectors
-
distance
Calculate the distance between two bit vectors.- Parameters:
v1
- the first bit vectorv2
- 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 vectorv2
- 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 vectorv2
- the second Float32 vector- Returns:
- the distance between the two Float32 vectors
-
readExternal
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 interfacePortableObject
- Parameters:
in
- the PofReader from which to read the object's state
-
writeExternal
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 interfacePortableObject
- Parameters:
out
- the PofWriter to which to write the object's state- Throws:
IOException
- if an I/O error occurs
-
readExternal
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 interfaceExternalizableLite
- 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
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 interfaceExternalizableLite
- Parameters:
out
- the DataOutput stream to write the state of this object to- Throws:
IOException
- if an I/O exception occurs
-