-
Notifications
You must be signed in to change notification settings - Fork 0
/
hypothesis_test.go
64 lines (57 loc) · 1.33 KB
/
hypothesis_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
package main
import (
"testing"
"github.com/gonum/matrix/mat64"
)
func TestHypothesis(t *testing.T) {
for _, test := range []struct {
theta *mat64.Vector
x *mat64.Vector
y float64
}{
{
mat64.NewVector(2, []float64{0, 2}),
mat64.NewVector(2, []float64{0, 1}),
2.0,
}, {
mat64.NewVector(2, []float64{0, 2}),
mat64.NewVector(2, []float64{0, 2}),
4.0,
}, {
mat64.NewVector(2, []float64{0, 2}),
mat64.NewVector(2, []float64{0, 10}),
20.0,
}, {
mat64.NewVector(2, []float64{1, 2}),
mat64.NewVector(2, []float64{1, 10}),
21.0,
}, {
mat64.NewVector(3, []float64{1, 2.5, 5}),
mat64.NewVector(3, []float64{10, 20, 0}),
60.0,
},
} {
h := Hypothesis(test.x, test.theta)
if h != test.y {
t.Errorf("Hypothesis(%v,%v) is expected to be equal to %v, found %v", test.x, test.theta, test.y, h)
}
}
}
func TestMultiHypothesis(t *testing.T) {
for _, test := range []struct {
theta *mat64.Vector
x *mat64.Dense
y *mat64.Vector
}{
{
mat64.NewVector(2, []float64{0, 2}),
mat64.NewDense(2, 3, []float64{0, 0, 0, 1, 2, 10}),
mat64.NewVector(3, []float64{2, 4, 20}),
},
} {
h := MultiHypothesis(test.x, test.theta)
if !mat64.Equal(h, test.y) {
t.Errorf("MultiHypothesis(%v,%v) is expected to be equal to %v, found %v", test.x, test.theta, test.y, h)
}
}
}