-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlshforest_test.go
73 lines (64 loc) · 1.31 KB
/
lshforest_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package lshensemble
import (
"math/rand"
"testing"
)
func randomSignature(size int, seed int64) []uint64 {
r := rand.New(rand.NewSource(seed))
sig := make([]uint64, size)
for i := range sig {
sig[i] = uint64(r.Int63())
}
return sig
}
func Test_HashKeyFunc16(t *testing.T) {
sig := randomSignature(2, 1)
f := hashKeyFuncGen(2)
hashKey := f(sig)
if len(hashKey) != 2*2 {
t.Fatal(len(hashKey))
}
}
func Test_HashKeyFunc64(t *testing.T) {
sig := randomSignature(2, 1)
f := hashKeyFuncGen(8)
hashKey := f(sig)
if len(hashKey) != 8*2 {
t.Fatal(len(hashKey))
}
}
func Test_LshForest(t *testing.T) {
f := NewLshForest16(2, 4, 3)
sig1 := randomSignature(8, 2)
sig2 := randomSignature(8, 1)
sig3 := randomSignature(8, 1)
f.Add("sig1", sig1)
f.Add("sig2", sig2)
f.Add("sig3", sig3)
f.Index()
for i := range f.hashTables {
if len(f.hashTables[i]) != 3 {
t.Fatal(f.hashTables[i])
}
}
keys := make(chan interface{})
done := make(chan struct{})
defer close(done)
go func() {
f.Query(sig3, 1, 4, keys, done)
close(keys)
}()
found := 0
for key := range keys {
if key == "sig2" || key == "sig3" {
found++
}
}
if found != 2 {
t.Fatal("unable to retrieve inserted keys")
}
}
func Test_LshForest_OptimalKL(t *testing.T) {
f := NewLshForest16(2, 32, 1)
t.Log(f.OptimalKL(32, 12, 0.5))
}