Skip to content

Commit 227fd37

Browse files
authored
Add test for split and merge (#80)
* Add test for split and merge * Add test
1 parent d252f43 commit 227fd37

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Matrix from '../../../lib/util/matrix.js'
2+
import SplitAndMerge from '../../../lib/model/split_merge.js'
3+
4+
import { randIndex } from '../../../lib/evaluate/clustering.js'
5+
6+
test.each(['variance', 'uniformity'])('predict %s', method => {
7+
const model = new SplitAndMerge(method)
8+
const n = 100
9+
const x = Matrix.zeros(n, n).toArray()
10+
const t = []
11+
for (let i = 0, p = 0; i < n; i++) {
12+
for (let j = 0; j < n; j++, p++) {
13+
if ((i - n / 2) ** 2 + (j - n / 2) ** 2 < (n / 4) ** 2) {
14+
x[i][j] = 255
15+
t[p] = 1
16+
} else {
17+
t[p] = 0
18+
}
19+
}
20+
}
21+
22+
const y = model.predict(x)
23+
const ri = randIndex(y.flat(), t)
24+
expect(ri).toBeGreaterThan(0.9)
25+
})

0 commit comments

Comments
 (0)