-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystole_test.go
186 lines (177 loc) · 4.84 KB
/
systole_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package golsv
import (
"log"
"testing"
)
func emptyTriangle() (d1, d2 BinaryMatrix) {
return NewDenseBinaryMatrixFromString(
`1 0 1
1 1 0
0 1 1`),
NewDenseBinaryMatrix(3, 0)
}
func filledTriangle() (d1, d2 BinaryMatrix) {
return NewDenseBinaryMatrixFromString(
`1 0 1
1 1 0
0 1 1`),
NewDenseBinaryMatrixFromString(
`1
1
1`)
}
func TestSystoleSearchSmallExamples(t *testing.T) {
tests := []struct {
ctor func() (d1, d2 BinaryMatrix)
wantSystole, wantCosystole int
}{
{emptyTriangle, 3, 1},
{filledTriangle, 0, 0},
}
for i, test := range tests {
verbose := false
d1, d2 := test.ctor()
U, B, _, _, _, _ := UBDecomposition(d1, d2, verbose)
gotSystoleRandom := SystoleRandomSearch(U, B, 100, verbose)
if gotSystoleRandom != test.wantSystole {
t.Errorf("systole random search [%d] got=%d want=%d", i, gotSystoleRandom, test.wantSystole)
}
gotSystoleExhaustive := SystoleExhaustiveSearch(U, B, verbose)
if gotSystoleExhaustive != test.wantSystole {
t.Errorf("systole exhaustive search [%d] got=%d want=%d", i, gotSystoleExhaustive, test.wantSystole)
}
delta0 := d1.Transpose().Dense()
delta1 := d2.Transpose().Dense()
U, B, _, _, _, _ = UBDecomposition(delta1, delta0, verbose)
gotCosystoleRandom := SystoleRandomSearch(U, B, 100, verbose)
if gotCosystoleRandom != test.wantCosystole {
t.Errorf("cosystole random search [%d] got=%d want=%d", i, gotCosystoleRandom, test.wantCosystole)
}
gotCosystoleExhaustive := SystoleExhaustiveSearch(U, B, verbose)
if gotCosystoleExhaustive != test.wantCosystole {
t.Errorf("cosystole exhaustive search [%d] got=%d want=%d", i, gotCosystoleExhaustive, test.wantCosystole)
}
}
}
func TestSystoleCyclicGraphs(t *testing.T) {
verbose := false
maxLength := 10
for i := 3; i < maxLength; i++ {
d1, d2 := cyclicGraph(i)
U, B, _, _, _, _ := UBDecomposition(d1, d2, verbose)
gotSystole := SystoleExhaustiveSearch(U, B, verbose)
if gotSystole != i {
t.Errorf("systole search for cyclic graph %d got=%d want=%d", i, gotSystole, i)
}
delta0 := d1.Transpose().Dense()
delta1 := d2.Transpose().Dense()
U, B, _, _, _, _ = UBDecomposition(delta1, delta0, verbose)
gotCosystole := SystoleExhaustiveSearch(U, B, verbose)
if gotCosystole != 1 {
t.Errorf("cosystole search for cyclic graph %d got=%d want=1", i, gotCosystole)
}
}
}
func cyclicGraph(n int) (d1, d2 BinaryMatrix) {
d1 = NewDenseBinaryMatrix(n, n)
d2 = NewDenseBinaryMatrix(n, 0)
for i := 0; i < n; i++ {
d1.Set(i, i, 1)
d1.Set((i+1)%n, i, 1)
}
return
}
func TestSystoleTorus(t *testing.T) {
verbose := false
T := NewZComplexFromMaximalSimplices([][]int{
{0, 3, 4}, {3, 6, 7}, {0, 6, 7},
{0, 1, 4}, {3, 4, 7}, {0, 1, 7},
{1, 4, 5}, {4, 7, 8}, {1, 7, 8},
{1, 2, 5}, {4, 5, 8}, {1, 2, 8},
{2, 5, 3}, {5, 6, 8}, {2, 6, 8},
{0, 2, 3}, {3, 5, 6}, {0, 2, 6},
})
visualize := false
if visualize {
WriteComplexGraphvizFile(T, "torus.dot", verbose)
}
D1, D2 := T.D1(), T.D2()
systole, dimZ1, dimB1, dimH1 := ComputeFirstSystole(D1, D2, verbose)
wantSystole := 3
if systole != wantSystole {
t.Errorf("systole=%d want=%d", systole, wantSystole)
}
wantDimZ1 := 19
if dimZ1 != wantDimZ1 {
t.Errorf("dimZ1=%d want=%d", dimZ1, wantDimZ1)
}
wantDimB1 := 17
if dimB1 != wantDimB1 {
t.Errorf("dimB1=%d want=%d", dimB1, wantDimB1)
}
wantDimH1 := 2
if dimH1 != wantDimH1 {
t.Errorf("dimH1=%d want=%d", dimH1, wantDimH1)
}
cosystole := ComputeFirstCosystole(D1, D2, verbose)
if verbose {
log.Printf("systole=%d cosystole=%d", systole, cosystole)
}
}
func TestSystoleKernelBasis(t *testing.T) {
tests := []struct {
M BinaryMatrix
Exp BinaryMatrix
}{
{
NewDenseBinaryMatrixFromString(
`1 0 1
0 1 1
0 0 0`),
NewDenseBinaryMatrixFromString(
`1
1
1`),
},
{
NewDenseBinaryMatrix(3, 0),
NewDenseBinaryMatrix(0, 0),
},
}
verbose := false
for i, test := range tests {
K := kernelBasis(test.M, verbose)
if !K.Equal(test.Exp) {
t.Errorf("kernel basis [%d] got=%v:\n%swant=%v:\n%s", i, K, dumpMatrix(K), test.Exp, dumpMatrix(test.Exp))
}
}
}
func TestSystolePlanarTwoHoles(t *testing.T) {
verbose := false
X := NewZComplexFromMaximalSimplices([][]int{
{0, 3, 4}, {0, 6, 7}, {0, 1, 8},
{1, 2, 3}, {4, 5, 6},
})
D1, D2 := X.D1(), X.D2()
systole, dimZ1, dimB1, dimH1 := ComputeFirstSystole(D1, D2, verbose)
wantSystole := 3
if systole != wantSystole {
t.Errorf("systole=%d want=%d", systole, wantSystole)
}
wantDimZ1 := 7
if dimZ1 != wantDimZ1 {
t.Errorf("dimZ1=%d want=%d", dimZ1, wantDimZ1)
}
wantDimB1 := 5
if dimB1 != wantDimB1 {
t.Errorf("dimB1=%d want=%d", dimB1, wantDimB1)
}
wantDimH1 := 2
if dimH1 != wantDimH1 {
t.Errorf("dimH1=%d want=%d", dimH1, wantDimH1)
}
cosystole := ComputeFirstCosystole(D1, D2, verbose)
if verbose {
log.Printf("systole=%d cosystole=%d", systole, cosystole)
}
}