Debian Codegraph @

dwtest/test_NMF.praat

raw
1 # test_NMF.praat
2 # djmw 20190312
3
4 appendInfoLine: "test_NMF.praat"
5
6 appendInfoLine: tab$, "Simple interface test"
7 @test_simple
8 appendInfoLine: tab$, "Diagonals "
9 @test_diagonal
10
11 appendInfoLine: "test_NMF.praat OK"
12
13 procedure test_simple
14 for .i to 10
15 .ncol = 10
16 .nrow = randomInteger (1, 100)
17 .nfeatures = randomInteger(1,5)
18 .mat = Create simple Matrix: "xy", .nrow, .ncol, "randomUniform (1,10)"
19 .nmf = To NMF (m.u.): .nfeatures, 500, 1e-09, 1e-09, "RandomUniform", "yes"
20 plusObject: .mat
21 .dist = Get Euclidean distance
22 Improve factorization (m.u.): 10, 1e-09, 1e-09, "yes"
23 .dist2 = Get Euclidean distance
24 # if we are very near the minimum assert .dist2 <= .dist is not always true
25 # abs (.dist2 - .dist) <= 1e-09 makes sure that we are within tolerace to the minimum.
26 assert .dist2 <= .dist || abs (.dist2 - .dist) <= 1e-09
27 appendInfoLine: tab$, tab$, .nrow, "x", .ncol, ", aprox = ", .nfeatures, " 2-norm=", .dist2
28 removeObject: .mat, .nmf
29 endfor
30 endproc
31
32 procedure test_diagonal
33 for .i to 10
34 .ncol = .i + 1
35 .nrow = .ncol
36 .nfeatures = .ncol - 1
37 .mat = Create simple Matrix: string$(.nrow)+"x"+string$(.ncol), .nrow, .ncol, "if row = col then randomUniform(0,10) else 0 fi"
38 .nmf = To NMF (ALS): .nfeatures, 1000, 1e-09, 1e-09, "RandomUniform", "yes"
39 plusObject: .mat
40 .dist = Get Euclidean distance
41 appendInfoLine: tab$, tab$, .nrow, "x", .ncol, ", aprox = ", .nfeatures, " 2-norm=", .dist
42 removeObject: .mat, .nmf
43 endfor
44 endproc