Class ByteVec
- java.lang.Object
-
- com.actelion.research.util.datamodel.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
-
-
Field Summary
Fields Modifier and Type Field Description static intCOSINEstatic intEUCLIDEANstatic intEUCLIDEAN_FASTstatic java.util.RandomRANDOMstatic intTANIMOTOstatic intTANIMOTO_INV
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteVecadd(ByteVec dvVec)voidappend(java.lang.String s)intcompareTo(ByteVec o)static doubleCosine(ByteVec dVec1, ByteVec dVec2)Vectors have to be normed!static doublecubicDistance(ByteVec dVec1, ByteVec dVec2)static ByteVecdevide(ByteVec dVec1, ByteVec dVec2)static doubledistance(ByteVec dVec1, ByteVec dVec2, int metric)booleanequal(ByteVec dv)booleanequals(java.lang.Object o)static doubleeuclideanDistance(ByteVec dVec1, ByteVec dVec2)Euclidean distancestatic doubleEuclideanDistanceFast(ByteVec dVec1, ByteVec dVec2)Euclidean distance without sqrtbyte[]get()byteget(int col)intgetBitsSet()static intgetHashCode(byte[] a)doublegetNorm()static doublegetTanimotoDist(byte[] a1, byte[] a2)static doublegetTanimotoDist(ByteVec bv1, ByteVec bv2)Calculates the Tanimoto coefficientstatic doublegetTanimotoDistBitWise(ByteVec bv1, ByteVec bv2)Calculates the Tanimoto coefficientstatic doublegetTanimotoDistInv(ByteVec bv1, ByteVec bv2)Byte wise inverse Tanimoto distance.inthashCode()The hash code has to be calculated before.voidinitRND(byte min, byte max)static java.util.List<ByteVec>initRND(byte min, byte max, int lenByteVec, int numelements)static doublemanhattanBlockDistance(ByteVec dVec1, ByteVec dVec2)static ByteVecmeanClust()static ByteVecminus(ByteVec dVec1, ByteVec dVec2)static doublemult(byte[] a1, byte[] a2)ByteVecmult(double dFactor)static doublemult(ByteVec bv1, ByteVec bv2)static ByteVecmultEl(ByteVec dVec1, ByteVec dVec2)Elementwise multiplicationvoidnorm2One()static ByteVecplus(ByteVec dVec1, ByteVec dVec2)voidreduce(java.util.Vector<java.lang.Integer> vecIndices)static byte[]reverse(byte[] a)voidset(byte dVal)voidset(int col, byte val)Hash value has to be recalculated!voidsetRNDvalue(double dRange)voidsetRNDvalue(double dCenter, double dRange)intsize()ByteVecsub(ByteVec dvSub)Substractionstatic ByteVectest01()static ByteVectestS1()static ByteVectestTakeda1()byte[]toArray()java.lang.StringtoBinaryString()java.lang.StringtoBinaryStringDense()static byte[]toByteArray(double[] data)static byte[]toByteArray(int data)static byte[]toByteArray(int[] data)static byte[]toByteArray(long data)java.lang.StringtoString()Converts a byte into its decimal.static java.lang.StringtoString(byte[] a)static java.lang.StringtoString(byte[] a, java.lang.String seperator)java.lang.StringtoString(int iNumDigits)java.lang.StringtoStringString()Converts the bytes into chars.
-
-
-
Field Detail
-
RANDOM
public static final java.util.Random RANDOM
-
COSINE
public static final int COSINE
- See Also:
- Constant Field Values
-
EUCLIDEAN
public static final int EUCLIDEAN
- See Also:
- Constant Field Values
-
EUCLIDEAN_FAST
public static final int EUCLIDEAN_FAST
- See Also:
- Constant Field Values
-
TANIMOTO
public static final int TANIMOTO
- See Also:
- Constant Field Values
-
TANIMOTO_INV
public static final int TANIMOTO_INV
- See Also:
- Constant Field Values
-
-
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:
compareToin interfacejava.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:
equalsin classjava.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:
hashCodein classjava.lang.Object
-
Cosine
public static double Cosine(ByteVec dVec1, ByteVec dVec2)
Vectors have to be normed!- Parameters:
dVec1- normed vector1dVec2- normed vector2- Returns:
- Cosine
-
initRND
public void initRND(byte min, byte max)
-
initRND
public static java.util.List<ByteVec> initRND(byte min, byte max, int lenByteVec, int numelements)
-
mult
public ByteVec mult(double dFactor)
-
mult
public static final double mult(byte[] a1, byte[] a2)
-
multEl
public static ByteVec multEl(ByteVec dVec1, ByteVec dVec2)
Elementwise multiplication- Parameters:
dVec1- input vectordVec2- 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)
-
getTanimotoDistBitWise
public static double getTanimotoDistBitWise(ByteVec bv1, ByteVec bv2)
Calculates the Tanimoto coefficient- Parameters:
bv1- vector1bv2- 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- vector1bv2- 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:
toStringin classjava.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()
-
-