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 int
COSINE
static int
EUCLIDEAN
static int
EUCLIDEAN_FAST
static java.util.Random
RANDOM
static int
TANIMOTO
static int
TANIMOTO_INV
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteVec
add(ByteVec dvVec)
void
append(java.lang.String s)
int
compareTo(ByteVec o)
static double
Cosine(ByteVec dVec1, ByteVec dVec2)
Vectors have to be normed!static double
cubicDistance(ByteVec dVec1, ByteVec dVec2)
static ByteVec
devide(ByteVec dVec1, ByteVec dVec2)
static double
distance(ByteVec dVec1, ByteVec dVec2, int metric)
boolean
equal(ByteVec dv)
boolean
equals(java.lang.Object o)
static double
euclideanDistance(ByteVec dVec1, ByteVec dVec2)
Euclidean distancestatic double
EuclideanDistanceFast(ByteVec dVec1, ByteVec dVec2)
Euclidean distance without sqrtbyte[]
get()
byte
get(int col)
int
getBitsSet()
static int
getHashCode(byte[] a)
double
getNorm()
static double
getTanimotoDist(byte[] a1, byte[] a2)
static double
getTanimotoDist(ByteVec bv1, ByteVec bv2)
Calculates the Tanimoto coefficientstatic double
getTanimotoDistBitWise(ByteVec bv1, ByteVec bv2)
Calculates the Tanimoto coefficientstatic double
getTanimotoDistInv(ByteVec bv1, ByteVec bv2)
Byte wise inverse Tanimoto distance.int
hashCode()
The hash code has to be calculated before.void
initRND(byte min, byte max)
static java.util.List<ByteVec>
initRND(byte min, byte max, int lenByteVec, int numelements)
static double
manhattanBlockDistance(ByteVec dVec1, ByteVec dVec2)
static ByteVec
meanClust()
static ByteVec
minus(ByteVec dVec1, ByteVec dVec2)
static double
mult(byte[] a1, byte[] a2)
ByteVec
mult(double dFactor)
static double
mult(ByteVec bv1, ByteVec bv2)
static ByteVec
multEl(ByteVec dVec1, ByteVec dVec2)
Elementwise multiplicationvoid
norm2One()
static ByteVec
plus(ByteVec dVec1, ByteVec dVec2)
void
reduce(java.util.Vector<java.lang.Integer> vecIndices)
static byte[]
reverse(byte[] a)
void
set(byte dVal)
void
set(int col, byte val)
Hash value has to be recalculated!void
setRNDvalue(double dRange)
void
setRNDvalue(double dCenter, double dRange)
int
size()
ByteVec
sub(ByteVec dvSub)
Substractionstatic ByteVec
test01()
static ByteVec
testS1()
static ByteVec
testTakeda1()
byte[]
toArray()
java.lang.String
toBinaryString()
java.lang.String
toBinaryStringDense()
static byte[]
toByteArray(double[] data)
static byte[]
toByteArray(int data)
static byte[]
toByteArray(int[] data)
static byte[]
toByteArray(long data)
java.lang.String
toString()
Converts a byte into its decimal.static java.lang.String
toString(byte[] a)
static java.lang.String
toString(byte[] a, java.lang.String seperator)
java.lang.String
toString(int iNumDigits)
java.lang.String
toStringString()
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:
compareTo
in 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:
equals
in 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:
hashCode
in 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:
toString
in 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()
-
-