-
Notifications
You must be signed in to change notification settings - Fork 92
/
benchmarks_test.go
84 lines (60 loc) · 1.8 KB
/
benchmarks_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
74
75
76
77
78
79
80
81
82
83
84
package CloudForest
import (
"strings"
"testing"
)
func BenchmarkIris(b *testing.B) {
candidates := []int{1, 2, 3, 4}
// irisreader := strings.NewReader(irisarff)
// fm := ParseARFF(irisreader)
// targeti := 4
irisreader := strings.NewReader(irislibsvm)
fm := ParseLibSVM(irisreader)
targeti := 0
target := fm.Data[targeti]
cases := make([]int, 0, 150)
for i := 0; i < fm.Data[0].Length(); i++ {
cases = append(cases, i)
}
allocs := NewBestSplitAllocs(len(cases), target)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tree := NewTree()
tree.Grow(fm, target, cases, candidates, nil, 2, 1, 0, false, false, false, false, false, nil, nil, allocs)
}
}
func BenchmarkBoston(b *testing.B) {
boston := strings.NewReader(boston_housing)
fm := ParseARFF(boston)
candidates := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
target := fm.Data[fm.Map["class"]]
cases := make([]int, 0, fm.Data[0].Length())
for i := 0; i < fm.Data[0].Length(); i++ {
cases = append(cases, i)
}
allocs := NewBestSplitAllocs(len(cases), target)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tree := NewTree()
tree.Grow(fm, target, cases, candidates, nil, 2, 1, 0, false, false, false, false, false, nil, nil, allocs)
}
}
func BenchmarkBestNumSplit(b *testing.B) {
// irisreader := strings.NewReader(irisarff)
// fm := ParseARFF(irisreader)
// targeti := 4
irisreader := strings.NewReader(irislibsvm)
fm := ParseLibSVM(irisreader)
targeti := 0
targetf := fm.Data[targeti]
cases := make([]int, 0, 150)
for i := 0; i < fm.Data[0].Length(); i++ {
cases = append(cases, i)
}
allocs := NewBestSplitAllocs(len(cases), targetf)
parentImp := targetf.Impurity(&cases, allocs.Counter)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, _ = fm.Data[1].BestSplit(targetf, &cases, parentImp, 1, false, allocs)
}
}