-
Notifications
You must be signed in to change notification settings - Fork 15
/
multiprobe_test.go
47 lines (43 loc) · 1.07 KB
/
multiprobe_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package lsh
import (
"strconv"
"testing"
)
func Test_NewMultiprobeLsh(t *testing.T) {
lsh := NewMultiprobeLsh(100, 5, 5, 5.0, 64)
if len(lsh.tables) != 5 {
t.Error("Lsh init fail")
}
t.Logf("Scores %v", lsh.scores)
t.Logf("Perturbation sets: %v", lsh.perturbSets)
for i, v := range lsh.perturbSets {
t.Logf("Set: %d, Score: %f, Set contents: %v", i, lsh.getScore(&v), v)
}
for i, perSet := range lsh.perturbVecs {
for j, perTable := range perSet {
t.Logf("Set: %d, Table: %d, Vec: %v", i, j, perTable)
}
}
}
func Test_MultiprobeLshQueryKnn(t *testing.T) {
lsh := NewMultiprobeLsh(100, 5, 5, 5.0, 10)
points := randomPoints(10, 100, 32.0)
insertedKeys := make([]string, 10)
for i, p := range points {
lsh.Insert(p, strconv.Itoa(i))
insertedKeys[i] = strconv.Itoa(i)
}
// Use the inserted points as queries, and
// verify that we can get back each query itself
for i, key := range insertedKeys {
found := false
for _, foundKey := range lsh.Query(points[i]) {
if foundKey == key {
found = true
}
}
if !found {
t.Error("Query fail")
}
}
}