-
Notifications
You must be signed in to change notification settings - Fork 4
/
emperical_test.go
60 lines (53 loc) · 1.33 KB
/
emperical_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
package bbq
import (
"math"
"testing"
)
func TestEmpericalCountBitmapConstant(t *testing.T) {
vecs := NewRandVectorSet(*nVectors, *dim, nil)
be := NewMemoryBackend(*dim)
store, err := NewVectorStore(be, *nBasis)
if err != nil {
t.Fatal(err)
}
for i, v := range vecs {
store.AddVector(ID(i), v)
}
count := 0
n := 0
for _, basisbms := range store.bms {
for _, bm := range basisbms {
count += int(bm.GetCardinality())
n += 1
}
}
t.Logf("Expected avg bitmap count: %0.2f", float64(len(vecs))/float64(2**dim))
t.Logf("Average bitmap count: %0.2f", float64(count)/float64(n))
// now we get into the weeds
buf := make([]float32, store.dimensions)
maxes := make([]int, 1)
target := NewRandVector(*dim, nil)
counts := NewCountingBitmap(*nBasis)
for i, basis := range store.bases {
store.findIndexesForBasis(target, basis, buf, maxes)
for _, m := range maxes {
if v, ok := store.bms[i][m]; ok {
counts.Or(v)
}
}
printPredicted(i+1, t)
t.Logf("got %#v", counts.cardinalities())
}
}
const k = 0.83
func printPredicted(i int, t *testing.T) {
f := make([]float64, i)
for j := 0; j < i; j++ {
f[j] = (math.Pow(float64(i), (k*float64(j))+1.0) * float64(*nVectors)) / math.Pow(float64(2**dim), float64(j+1))
}
strs := make([]int, i)
for i, g := range f {
strs[i] = int(g)
}
t.Logf("exp %#v", strs)
}