Class IntVec

  • All Implemented Interfaces:
    java.lang.Comparable<IntVec>

    public class IntVec
    extends java.lang.Object
    implements java.lang.Comparable<IntVec>
    • Constructor Detail

      • IntVec

        public IntVec()
      • IntVec

        public IntVec​(IntVec iv)
        Deep copy, hash code is calculated.
        Parameters:
        iv -
      • IntVec

        public IntVec​(int size)
        Don't forget to calculate the hash code after setting the bits!
        Parameters:
        size -
      • IntVec

        public IntVec​(int[] arr)
        Deep copy, hash code is calculated.
        Parameters:
        arr -
      • IntVec

        public IntVec​(int[] arr,
                      boolean binary)
        If true each int contains only a 0 or a 1. The binary information is summarized by factor 32 (Integer.size).
        Parameters:
        arr -
        binary -
        Throws:
        java.lang.Exception
      • IntVec

        public IntVec​(boolean[] arr)
        Puts an boolean array into an int array.
        Parameters:
        arr -
        Throws:
        java.lang.Exception
      • IntVec

        public IntVec​(java.util.List<java.lang.Integer> vec)
    • Method Detail

      • copy

        public void copy​(IntVec ivOrigin)
      • clear

        public void clear()
      • compareTo

        public int compareTo​(IntVec iv)
        Specified by:
        compareTo in interface java.lang.Comparable<IntVec>
        Parameters:
        iv - IntVec
        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.
      • equal

        public boolean equal​(IntVec iv)
      • equals

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

        public static double getEuclidDist​(IntVec iv1,
                                           IntVec iv2)
        Euclidean distance
        Parameters:
        iv1 -
        iv2 -
        Returns:
      • getEuclidDistBitWise

        public static double getEuclidDistBitWise​(IntVec iv1,
                                                  IntVec iv2)
      • getEuclidDistFast

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

        public static IntVec OR​(IntVec iv1,
                                IntVec iv2)
        Makes an logical OR and calculates the hash code.
        Returns:
      • OR

        public static IntVec OR​(java.util.List<IntVec> li)
        Makes an logical OR and calculates the hash code.
        Parameters:
        li -
        Returns:
      • AND

        public static IntVec AND​(IntVec iv1,
                                 IntVec iv2)
        Makes an logical AND and calculates the hash code.
        Parameters:
        iv1 -
        iv2 -
        Returns:
      • getRND

        public static int[] getRND​(int size)
      • get

        public int[] get()
      • getByte

        public int getByte​(int indexBytes)
      • getByte

        public static int getByte​(int[] data,
                                  int indexBytes)
      • getByteVec

        public byte[] getByteVec()
      • getByteVec

        public static byte[] getByteVec​(int intVal)
      • getByteVec

        public static byte[] getByteVec​(int[] a)
      • getSizeForBits

        public static int getSizeForBits​(int bits)
      • getNumberAbove

        public static int getNumberAbove​(int[] a,
                                         int val)
      • getInt

        public static int getInt​(byte[] arr)
      • getBitsSet

        public int getBitsSet()
      • getByteWise

        public int[] getByteWise()
      • getBitWise

        public int[] getBitWise()
      • extractForGivenResolution

        public static int[] extractForGivenResolution​(IntVec iv,
                                                      int nValues,
                                                      int bitsResolution)
        Converts the IntVec into an array. Each field in the array contains a value that was derived with the given resolution from IntVec.
        Parameters:
        iv -
        nValues - so many values are encoded in IntVec.
        bitsResolution - So many bits were used to encode a single value.
        Returns:
      • allFieldsEquals

        public boolean allFieldsEquals​(int v)
      • get

        public int get​(int col)
      • getNorm

        public double getNorm()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • calculateHashCode

        public void calculateHashCode()
      • getCosine

        public static double getCosine​(IntVec iv1,
                                       IntVec iv2)
        Parameters:
        iv1 - normed vector1
        iv2 - normed vector2
        Returns:
        Cosine
      • cubicDistance

        public static double cubicDistance​(IntVec dVec1,
                                           IntVec dVec2)
      • calculateHashCode

        public static int calculateHashCode​(IntVec iv)
      • readBitStringDense

        public static IntVec readBitStringDense​(java.lang.String s)
      • manhattanBlockDistance

        public static double manhattanBlockDistance​(IntVec iv1,
                                                    IntVec iv2)
      • mult

        public IntVec mult​(double factor)
      • mult

        public static double mult​(IntVec iv1,
                                  IntVec iv2)
      • mult

        public static double mult​(int[] a,
                                  int[] b)
      • multByteWise

        public static double multByteWise​(IntVec iv1,
                                          IntVec iv2)
      • multByteWise

        public static double multByteWise​(int[] iv1,
                                          int[] iv2)
      • getSimilarityBytewiseOverlap

        public static double getSimilarityBytewiseOverlap​(int[] a1,
                                                          int[] a2)
      • multEl

        public static IntVec multEl​(IntVec iv1,
                                    IntVec iv2)
        Elementwise multiplication
        Parameters:
        iv1 - input vector
        iv2 - input vector
        Returns:
        IntVec
      • norm2One

        public void norm2One()
      • read

        public void read​(java.lang.String s)
      • read

        public static IntVec[] read​(java.io.File file)
      • reduce

        public void reduce​(java.util.List<java.lang.Integer> liIndices)
        Removes all values with no corresponding index in the list.
        Parameters:
        liIndices - list with indices for values that will be kept.
      • resize

        public void resize​(int newlen)
      • set

        public void set​(int val)
        Don't forget to set the hash code!
        Parameters:
        val -
      • set

        public void set​(IntVec v)
        Don't forget to set the hash code!
        Parameters:
        v -
      • set

        public void set​(int col,
                        int val)
        Don't forget to set the hash code!
        Parameters:
        col -
        val -
      • setBit

        public void setBit​(int i)
        Counts from the left to the right Don't forget to set the hash code!
        Parameters:
        i - index bit
      • unsetBit

        public void unsetBit​(int i)
        Don't forget to set the hash code!
        Parameters:
        i -
      • isValidBitIndex

        public boolean isValidBitIndex​(int i)
      • setByte

        public void setByte​(int i,
                            int val)
        Counts from the left to the right Don't forget to set the hash code!
        Parameters:
        i - index byte
        val - value
      • setBytes

        public static void setBytes​(int[] data,
                                    int val)
      • setByte

        public static void setByte​(int[] data,
                                   int i,
                                   int val)
      • getIndicesBitsSet

        public java.util.List<java.lang.Integer> getIndicesBitsSet()
      • isBitSet

        public boolean isBitSet​(int i)
      • switchBit

        public void switchBit​(int i)
      • setBits

        public void setBits​(int iStart,
                            int num)
      • setBytes

        public void setBytes​(int iStart,
                             int num,
                             int val)
      • setRNDvalue

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

        public int size()
      • sizeBits

        public int sizeBits()
      • sizeBytes

        public int sizeBytes()
      • setRNDvalue

        public void setRNDvalue​(double dRange)
      • sub

        public IntVec sub​(IntVec dvSub)
        Substraction
        Parameters:
        dvSub -
        Returns:
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toStringHex

        public java.lang.String toStringHex()
      • toStringBinary

        public java.lang.String toStringBinary()
      • toStringBinaryDense

        public java.lang.String toStringBinaryDense()
      • toStringBytes

        public java.lang.String toStringBytes()
      • toDoubleBitWise

        public double[] toDoubleBitWise()
      • toIntByteWise

        public int[] toIntByteWise()
      • 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
      • write2String

        public java.lang.String write2String()
                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • toArray

        public int[] toArray()
      • getTanimotoDistBitWise

        public static double getTanimotoDistBitWise​(IntVec iv1,
                                                    IntVec iv2)
        Calculates the Tanimoto coefficient
        Parameters:
        iv1 - vector1
        iv2 - vector2
        Returns:
        Tanimoto: 1.0: identical bits are set. 0.0 no matching bits are set. Calculation according http://www.pnylab.com/pny/papers/nmet/nmet/ Congruent with DoubleVec
      • getTanimotoDistBitWise

        public static final double getTanimotoDistBitWise​(int[] arr1,
                                                          int[] arr2)
        Parameters:
        arr1 -
        arr2 -
        Returns:
        Tanimoto: 1: identical bits are set. 0 no matching bits are set.
      • getTanimotoDistInvBitWise

        public static double getTanimotoDistInvBitWise​(IntVec iv1,
                                                       IntVec iv2)
        Calculates the Inverse Tanimoto coefficient
        Parameters:
        iv1 - vector1
        iv2 - vector2
        Returns:
        Inverse Tanimoto: 0: identical bits are set. 1 no matching bits are set. Calculation according Duda, Hart, Stork; Pattern Classification; Wiley 2001 p188.
      • getTanimotoDistInvBitWise

        public static double getTanimotoDistInvBitWise​(int[] arr1,
                                                       int[] arr2)
      • getTanimotoDist

        public static double getTanimotoDist​(IntVec iv1,
                                             IntVec iv2)
        Calculates the Inverse Tanimoto coefficient
        Parameters:
        iv1 - vector1
        iv2 - vector2
        Returns:
        Tanimoto: 1: identical bits are set. 0 no matching bits are set.
      • getTanimotoDist

        public static double getTanimotoDist​(int[] a,
                                             int[] b)
      • getTanimotoDistInv

        public static final double getTanimotoDistInv​(IntVec iv1,
                                                      IntVec iv2)
        Parameters:
        iv1 -
        iv2 -
        Returns:
        Inverse Tanimoto: 0: identical bits are set. 1 no matching bits are set.
      • getScoreQueryInBaseByteWise

        public static double getScoreQueryInBaseByteWise​(IntVec query,
                                                         IntVec base)
      • getScoreQueryInBase

        public static double getScoreQueryInBase​(IntVec query,
                                                 IntVec base)
      • getScoreQueryInBaseBitWise

        public static double getScoreQueryInBaseBitWise​(IntVec query,
                                                        IntVec base)
      • getScoreQueryInBaseBitWise

        public static double getScoreQueryInBaseBitWise​(int[] query,
                                                        int[] base)
        (sum bits set only in query) / (sum bits set in query)
        Parameters:
        query -
        base -
        Returns:
      • getScoreFracBitsInCommonBitWise

        public static double getScoreFracBitsInCommonBitWise​(IntVec v1,
                                                             IntVec v2)
        (sum bits set common) / (sum bits set in both)
        Returns:
      • getTanimotoDistInvByteWise

        public static double getTanimotoDistInvByteWise​(IntVec iv1,
                                                        IntVec iv2)
        Parameters:
        iv1 -
        iv2 -
        Returns:
        Inverse Tanimoto: 0: identical bits are set. 1 no matching bits are set.
      • getTanimotoDistInvByteWise

        public static double getTanimotoDistInvByteWise​(int[] iv1,
                                                        int[] iv2)
        Parameters:
        iv1 -
        iv2 -
        Returns:
        Inverse Tanimoto: 0: identical bits are set. 1 no matching bits are set.
      • getScoreFracBitsCommonQuery

        public static double getScoreFracBitsCommonQuery​(IntVec query,
                                                         IntVec base)
        (sum bits set common) / (sum bits set in query)
        Parameters:
        query -
        base -
        Returns:
      • getOverlap

        public static int getOverlap​(IntVec iv1,
                                     IntVec iv2)
        Parameters:
        iv1 -
        iv2 -
        Returns:
        number of overlapping bits.
      • incrementByte

        public static void incrementByte​(int[] data,
                                         int i)
      • writeBitStringDense

        public static void writeBitStringDense​(java.io.File fi,
                                               java.util.List<IntVec> li)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readBitStringDense

        public static java.util.List<IntVec> readBitStringDense​(java.io.File fi)
                                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • read

        public static IntVec read​(java.io.InputStream s)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • isBitSet

        public static boolean isBitSet​(int[] a,
                                       int i)
      • isBitSet

        public static boolean isBitSet​(int val,
                                       int index)
        Parameters:
        val -
        index -
        Returns:
      • setBit

        public static void setBit​(int[] data,
                                  int i)
      • toStringBinary

        public static java.lang.String toStringBinary​(int v)
      • toStringBinary

        public static java.lang.String toStringBinary​(int v,
                                                      boolean space)