18
18
19
19
@pytest .mark .parametrize ("window" , [5 , 10 , 15 , 30 , 90 , None ])
20
20
@pytest .mark .parametrize ("frame_size" , [0.1 , 0.5 , 1.0 ])
21
- def test_tmeasure_pass (window , frame_size ):
21
+ @pytest .mark .parametrize ("strict_mono" , [True , False ])
22
+ def test_tmeasure_pass (window , frame_size , strict_mono ):
22
23
# The estimate here gets none of the structure correct.
23
24
ref = [[[0 , 30 ]], [[0 , 15 ], [15 , 30 ]]]
24
25
# convert to arrays
@@ -27,13 +28,17 @@ def test_tmeasure_pass(window, frame_size):
27
28
est = ref [:1 ]
28
29
29
30
# The estimate should get 0 score here
30
- scores = mir_eval .hierarchy .tmeasure (ref , est , window = window , frame_size = frame_size )
31
+ scores = mir_eval .hierarchy .tmeasure (
32
+ ref , est , window = window , frame_size = frame_size , strict_mono = strict_mono
33
+ )
31
34
32
35
for k in scores :
33
36
assert k == 0.0
34
37
35
38
# The reference should get a perfect score here
36
- scores = mir_eval .hierarchy .tmeasure (ref , ref , window = window , frame_size = frame_size )
39
+ scores = mir_eval .hierarchy .tmeasure (
40
+ ref , ref , window = window , frame_size = frame_size , strict_mono = strict_mono
41
+ )
37
42
38
43
for k in scores :
39
44
assert k == 1.0
@@ -91,7 +96,8 @@ def test_tmeasure_fail_frame_size(window, frame_size):
91
96
92
97
93
98
@pytest .mark .parametrize ("frame_size" , [0.1 , 0.5 , 1.0 ])
94
- def test_lmeasure_pass (frame_size ):
99
+ @pytest .mark .parametrize ("strict_mono" , [True , False ])
100
+ def test_lmeasure_pass (frame_size , strict_mono ):
95
101
# The estimate here gets none of the structure correct.
96
102
ref = [[[0 , 30 ]], [[0 , 15 ], [15 , 30 ]]]
97
103
ref_lab = [["A" ], ["a" , "b" ]]
@@ -104,15 +110,15 @@ def test_lmeasure_pass(frame_size):
104
110
105
111
# The estimate should get 0 score here
106
112
scores = mir_eval .hierarchy .lmeasure (
107
- ref , ref_lab , est , est_lab , frame_size = frame_size
113
+ ref , ref_lab , est , est_lab , frame_size = frame_size , strict_mono = strict_mono
108
114
)
109
115
110
116
for k in scores :
111
117
assert k == 0.0
112
118
113
119
# The reference should get a perfect score here
114
120
scores = mir_eval .hierarchy .lmeasure (
115
- ref , ref_lab , ref , ref_lab , frame_size = frame_size
121
+ ref , ref_lab , ref , ref_lab , frame_size = frame_size , strict_mono = strict_mono
116
122
)
117
123
118
124
for k in scores :
@@ -286,6 +292,101 @@ def test_meet():
286
292
assert np .all (meet == meet_truth )
287
293
288
294
295
+ def test_strict_mono ():
296
+ frame_size = 1
297
+ int_hier = [
298
+ np .array ([[0 , 10 ]]),
299
+ np .array ([[0 , 6 ], [6 , 10 ]]),
300
+ np .array ([[0 , 2 ], [2 , 4 ], [4 , 8 ], [8 , 10 ]]),
301
+ ]
302
+
303
+ lab_hier = [["X" ], ["A" , "B" ], ["a" , "b" , "c" , "b" ]]
304
+
305
+ # Target output
306
+ meet_truth = np .asarray (
307
+ [
308
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
309
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
310
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 3 , 3 ], # (XAb)
311
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 3 , 3 ], # (XAb)
312
+ [2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 1 , 1 ], # (XAc)
313
+ [2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 1 , 1 ], # (XAc)
314
+ [1 , 1 , 1 , 1 , 3 , 3 , 3 , 3 , 2 , 2 ], # (XBc)
315
+ [1 , 1 , 1 , 1 , 3 , 3 , 3 , 3 , 2 , 2 ], # (XBc)
316
+ [1 , 1 , 3 , 3 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBb)
317
+ [1 , 1 , 3 , 3 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBb)
318
+ ]
319
+ )
320
+ meet_truth_strict_mono = np .asarray (
321
+ [
322
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
323
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
324
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAb)
325
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAb)
326
+ [2 , 2 , 2 , 2 , 3 , 3 , 1 , 1 , 1 , 1 ], # (XAc)
327
+ [2 , 2 , 2 , 2 , 3 , 3 , 1 , 1 , 1 , 1 ], # (XAc)
328
+ [1 , 1 , 1 , 1 , 1 , 1 , 3 , 3 , 2 , 2 ], # (XBc)
329
+ [1 , 1 , 1 , 1 , 1 , 1 , 3 , 3 , 2 , 2 ], # (XBc)
330
+ [1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBb)
331
+ [1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBb)
332
+ ]
333
+ )
334
+ lca_truth = np .asarray (
335
+ [
336
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
337
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
338
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAb)
339
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAb)
340
+ [2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 1 , 1 ], # (XAc)
341
+ [2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 1 , 1 ], # (XAc)
342
+ [1 , 1 , 1 , 1 , 3 , 3 , 3 , 3 , 2 , 2 ], # (XBc)
343
+ [1 , 1 , 1 , 1 , 3 , 3 , 3 , 3 , 2 , 2 ], # (XBc)
344
+ [1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBd)
345
+ [1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBd)
346
+ ]
347
+ )
348
+ lca_truth_strict_mono = np .asarray (
349
+ [
350
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
351
+ [3 , 3 , 2 , 2 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAa)
352
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAb)
353
+ [2 , 2 , 3 , 3 , 2 , 2 , 1 , 1 , 1 , 1 ], # (XAb)
354
+ [2 , 2 , 2 , 2 , 3 , 3 , 1 , 1 , 1 , 1 ], # (XAc)
355
+ [2 , 2 , 2 , 2 , 3 , 3 , 1 , 1 , 1 , 1 ], # (XAc)
356
+ [1 , 1 , 1 , 1 , 1 , 1 , 3 , 3 , 2 , 2 ], # (XBc)
357
+ [1 , 1 , 1 , 1 , 1 , 1 , 3 , 3 , 2 , 2 ], # (XBc)
358
+ [1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBd)
359
+ [1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 3 , 3 ], # (XBd)
360
+ ]
361
+ )
362
+
363
+ meet = mir_eval .hierarchy ._meet (int_hier , lab_hier , frame_size , strict_mono = False )
364
+ meet_strict_mono = mir_eval .hierarchy ._meet (
365
+ int_hier , lab_hier , frame_size , strict_mono = True
366
+ )
367
+ lca = mir_eval .hierarchy ._lca (int_hier , frame_size , strict_mono = False )
368
+ lca_strict_mono = mir_eval .hierarchy ._lca (int_hier , frame_size , strict_mono = True )
369
+ # Is it the right type?
370
+ assert isinstance (meet , scipy .sparse .csr_matrix )
371
+ meet = meet .toarray ()
372
+ meet_strict_mono = meet_strict_mono .toarray ()
373
+ assert isinstance (lca_strict_mono , scipy .sparse .csr_matrix )
374
+ lca = lca .toarray ()
375
+ lca_strict_mono = lca_strict_mono .toarray ()
376
+
377
+ # Does it have the right shape?
378
+ assert meet .shape == (10 , 10 )
379
+ assert meet_strict_mono .shape == (10 , 10 )
380
+ assert lca .shape == (10 , 10 )
381
+ assert lca_strict_mono .shape == (10 , 10 )
382
+
383
+ # Does it have the right value?
384
+ assert np .all (meet == meet_truth )
385
+ assert np .all (meet_strict_mono == meet_truth_strict_mono )
386
+ assert np .all (lca == lca_truth )
387
+ assert np .all (lca_strict_mono == lca_truth_strict_mono )
388
+
389
+
289
390
def test_compare_frame_rankings ():
290
391
# number of pairs (i, j)
291
392
# where ref[i] < ref[j] and est[i] >= est[j]
0 commit comments