mirror of https://github.com/milvus-io/milvus.git
parent
38beb124c9
commit
b4eb20f2c0
|
@ -239,11 +239,12 @@ func CalcTanimotoCoefficient(dim int64, hamming []int32) ([]float32, error) {
|
|||
|
||||
array := make([]float32, len(hamming))
|
||||
for i := 0; i < len(hamming); i++ {
|
||||
if hamming[i] >= int32(dim)*2 {
|
||||
if hamming[i] > int32(dim) {
|
||||
err := errors.New("Invalid hamming for tanimoto")
|
||||
return nil, err
|
||||
}
|
||||
array[i] = float32(hamming[i]) / (float32(dim)*2 - float32(hamming[i]))
|
||||
equalBits := int32(dim) - hamming[i]
|
||||
array[i] = float32(equalBits) / (float32(dim)*2 - float32(equalBits))
|
||||
}
|
||||
|
||||
return array, nil
|
||||
|
|
|
@ -228,7 +228,7 @@ func TestCalcHamming(t *testing.T) {
|
|||
hamming := make([]int32, 1)
|
||||
hamming[0] = n
|
||||
tanimoto, err := CalcTanimotoCoefficient(dim, hamming)
|
||||
realTanimoto := float64(n) / (float64(dim)*2.0 - float64(n))
|
||||
realTanimoto := float64(int32(dim)-n) / (float64(dim)*2.0 - float64(int32(dim)-n))
|
||||
assert.Nil(t, err)
|
||||
assert.Less(t, math.Abs(float64(tanimoto[0])-realTanimoto), float64(PRECISION))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue