-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcovariance_test.go
58 lines (48 loc) · 1.03 KB
/
covariance_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
package lti
import (
"fmt"
"testing"
"gonum.org/v1/gonum/mat"
)
func TestCovariancePredict(t *testing.T) {
md := mat.NewDense(3, 3, []float64{
0, 1, 0,
0, 0, 1,
1, 0, 0,
})
systemNoise := NewCovariance(md)
p := mat.NewDense(3, 3, []float64{
1, 0, 0,
0, 1, 0,
0, 0, 1,
})
var pmt, mpmt mat.Dense
pNext := systemNoise.Predict(p, nil, &pmt, &mpmt)
expected1 := mat.NewDense(3, 3, []float64{
1, 0, 0,
0, 1, 0,
0, 0, 1,
})
if !mat.EqualApprox(pNext, expected1, 1e-8) {
fmt.Println("received:", pNext)
fmt.Println("expected:", expected1)
t.Error("predict failed without noise")
}
// test with extra noise
noise := mat.NewDense(3, 3, []float64{
0.1, 0.1, 0.3,
0.1, 0.2, 0.1,
0.3, 0.1, 0.1,
})
pNext = systemNoise.Predict(p, noise, &pmt, &mpmt)
expected2 := mat.NewDense(3, 3, []float64{
1.1, 0.1, 0.3,
0.1, 1.2, 0.1,
0.3, 0.1, 1.1,
})
if !mat.EqualApprox(pNext, expected2, 1e-8) {
fmt.Println("received:", pNext)
fmt.Println("expected:", expected2)
t.Error("predict failed with noise")
}
}