Class ByteVec

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<ByteVec>

    public class ByteVec
    extends java.lang.Object
    implements java.lang.Comparable<ByteVec>, java.io.Serializable

    ByteVec:

    Description: Vector with byte values

    Author:
    Modest von Korff 05.04.2005 start implementation
    See Also:
    Serialized Form
    • Constructor Detail

      • ByteVec

        public ByteVec​(ByteVec v)
        Deep copy
        Parameters:
        v -
      • ByteVec

        public ByteVec​(java.lang.String s)
        Hash code is calculated.
        Parameters:
        s -
      • ByteVec

        public ByteVec​(int iSize)
      • ByteVec

        public ByteVec​(byte[] arr)
      • ByteVec

        public ByteVec​(int[] arr)
    • Method Detail

      • append

        public void append​(java.lang.String s)
      • compareTo

        public int compareTo​(ByteVec o)
        Specified by:
        compareTo in interface java.lang.Comparable<ByteVec>
        Parameters:
        o - ByteVec
        Returns:
        -1 if the first different value is smaller than the corresponding value in dv. 0 if bot vectors are equal. 1 if the first different value is bigger than the corresponding value in dv.
      • distance

        public static double distance​(ByteVec dVec1,
                                      ByteVec dVec2,
                                      int metric)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • equal

        public boolean equal​(ByteVec dv)
      • euclideanDistance

        public static double euclideanDistance​(ByteVec dVec1,
                                               ByteVec dVec2)
        Euclidean distance
        Parameters:
        dVec1 -
        dVec2 -
        Returns:
      • EuclideanDistanceFast

        public static double EuclideanDistanceFast​(ByteVec dVec1,
                                                   ByteVec dVec2)
                                            throws java.lang.ArrayIndexOutOfBoundsException
        Euclidean distance without sqrt
        Parameters:
        dVec1 -
        dVec2 -
        Returns:
        Throws:
        java.lang.ArrayIndexOutOfBoundsException
      • get

        public byte[] get()
      • get

        public byte get​(int col)
      • getNorm

        public double getNorm()
      • getHashCode

        public static int getHashCode​(byte[] a)
      • hashCode

        public int hashCode()
        The hash code has to be calculated before. Should be done automatically in any of the ByteVec functions changing a value, but please check.
        Overrides:
        hashCode in class java.lang.Object
      • Cosine

        public static double Cosine​(ByteVec dVec1,
                                    ByteVec dVec2)
        Vectors have to be normed!
        Parameters:
        dVec1 - normed vector1
        dVec2 - normed vector2
        Returns:
        Cosine
      • cubicDistance

        public static double cubicDistance​(ByteVec dVec1,
                                           ByteVec dVec2)
      • initRND

        public void initRND​(byte min,
                            byte max)
      • initRND

        public static java.util.List<ByteVec> initRND​(byte min,
                                                      byte max,
                                                      int lenByteVec,
                                                      int numelements)
      • manhattanBlockDistance

        public static double manhattanBlockDistance​(ByteVec dVec1,
                                                    ByteVec dVec2)
      • mult

        public ByteVec mult​(double dFactor)
      • mult

        public static final double mult​(ByteVec bv1,
                                        ByteVec bv2)
      • mult

        public static final double mult​(byte[] a1,
                                        byte[] a2)
      • multEl

        public static ByteVec multEl​(ByteVec dVec1,
                                     ByteVec dVec2)
        Elementwise multiplication
        Parameters:
        dVec1 - input vector
        dVec2 - input vector
        Returns:
        ByteVec
      • norm2One

        public void norm2One()
      • reduce

        public void reduce​(java.util.Vector<java.lang.Integer> vecIndices)
      • set

        public void set​(byte dVal)
      • set

        public void set​(int col,
                        byte val)
        Hash value has to be recalculated!
        Parameters:
        col -
        val -
      • setRNDvalue

        public void setRNDvalue​(double dCenter,
                                double dRange)
      • size

        public int size()
      • setRNDvalue

        public void setRNDvalue​(double dRange)
      • sub

        public ByteVec sub​(ByteVec dvSub)
        Substraction
        Parameters:
        dvSub -
        Returns:
      • getTanimotoDistBitWise

        public static double getTanimotoDistBitWise​(ByteVec bv1,
                                                    ByteVec bv2)
        Calculates the Tanimoto coefficient
        Parameters:
        bv1 - vector1
        bv2 - vector2
        Returns:
        Tanimoto: 0.0: maximum distance, 1.0: maximum similarity. Calculation according http://www.pnylab.com/pny/papers/nmet/nmet/ Congruent with DoubleVec
      • getBitsSet

        public int getBitsSet()
      • getTanimotoDist

        public static double getTanimotoDist​(ByteVec bv1,
                                             ByteVec bv2)
        Calculates the Tanimoto coefficient
        Parameters:
        bv1 - vector1
        bv2 - vector2
        Returns:
        Tanimoto: 0.0: maximum distance, 1.0: maximum similarity.
      • getTanimotoDist

        public static double getTanimotoDist​(byte[] a1,
                                             byte[] a2)
      • getTanimotoDistInv

        public static double getTanimotoDistInv​(ByteVec bv1,
                                                ByteVec bv2)
        Byte wise inverse Tanimoto distance.
        Parameters:
        bv1 -
        bv2 -
        Returns:
      • toString

        public java.lang.String toString()
        Converts a byte into its decimal.
        Overrides:
        toString in class java.lang.Object
      • toStringString

        public java.lang.String toStringString()
        Converts the bytes into chars. The original string is reconstructed.
        Returns:
      • toBinaryString

        public java.lang.String toBinaryString()
      • toBinaryStringDense

        public java.lang.String toBinaryStringDense()
      • toString

        public java.lang.String toString​(int iNumDigits)
        Parameters:
        iNumDigits - number of decimal places
        Returns:
        String with doubles in 0.0 notation 16.10.2003 MvK
      • toArray

        public byte[] toArray()
      • toByteArray

        public static byte[] toByteArray​(long data)
      • toByteArray

        public static byte[] toByteArray​(double[] data)
      • toByteArray

        public static byte[] toByteArray​(int[] data)
      • toByteArray

        public static byte[] toByteArray​(int data)
      • reverse

        public static byte[] reverse​(byte[] a)
      • toString

        public static java.lang.String toString​(byte[] a,
                                                java.lang.String seperator)
      • toString

        public static java.lang.String toString​(byte[] a)
      • testS1

        public static ByteVec testS1()
      • testTakeda1

        public static ByteVec testTakeda1()
      • test01

        public static ByteVec test01()
      • meanClust

        public static ByteVec meanClust()