-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move test_match_notes, rename no_offset metrics
In addition to moving test_match_notes it has also been updated.
- Loading branch information
1 parent
1f3faeb
commit 73318a1
Showing
6 changed files
with
66 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,73 @@ | ||
# CREATED: 2/9/16 2:27 PM by Justin Salamon <[email protected]> | ||
|
||
import mir_eval | ||
import json | ||
import numpy as np | ||
|
||
A_TOL = 1e-12 | ||
|
||
|
||
def _load_unit_test_reference(): | ||
|
||
ref = np.array([ | ||
[0.100, 0.300, 220.000], | ||
[0.300, 0.400, 246.942], | ||
[0.500, 0.600, 277.183], | ||
[0.550, 0.650, 293.665]]) | ||
|
||
return ref[:, :2], ref[:, 2] | ||
|
||
|
||
def _load_unit_test_estimate(): | ||
|
||
est = np.array([ | ||
[0.120, 0.290, 225.000], | ||
[0.300, 0.350, 246.942], | ||
[0.500, 0.600, 500.000], | ||
[0.550, 0.600, 293.665], | ||
[0.560, 0.650, 293.665]]) | ||
|
||
return est[:, :2], est[:, 2] | ||
|
||
|
||
def _load_unit_test_scores(): | ||
|
||
scores = { | ||
"Precision": 0.4, | ||
"Recall": 0.5, | ||
"F-measure": 0.4444444444444445, | ||
"Precision_no_offset": 0.6, | ||
"Recall_no_offset": 0.75, | ||
"F-measure_no_offset": 0.6666666666666665 | ||
} | ||
|
||
return scores | ||
|
||
|
||
def test_match_notes(): | ||
|
||
ref_int, ref_pitch = _load_unit_test_reference() | ||
est_int, est_pitch = _load_unit_test_estimate() | ||
|
||
matching = \ | ||
mir_eval.transcription.match_notes(ref_int, ref_pitch, est_int, | ||
est_pitch) | ||
|
||
assert matching == [(0, 0), (3, 4)] | ||
|
||
matching = \ | ||
mir_eval.transcription.match_notes(ref_int, ref_pitch, est_int, | ||
est_pitch, offset_ratio=None) | ||
|
||
assert matching == [(0, 0), (1, 1), (3, 3)] | ||
|
||
|
||
def test_precision_recall_f1(): | ||
|
||
ref_int, ref_pitch = mir_eval.io.load_valued_intervals( | ||
'tests/data/transcription/ref00.txt') | ||
est_int, est_pitch = mir_eval.io.load_valued_intervals( | ||
'tests/data/transcription/est00.txt') | ||
# load test data | ||
ref_int, ref_pitch = _load_unit_test_reference() | ||
est_int, est_pitch = _load_unit_test_estimate() | ||
|
||
# load expected results | ||
scores = json.load(open('tests/data/transcription/output00.json', 'rb')) | ||
scores = _load_unit_test_scores() | ||
|
||
precision, recall, f_measure = \ | ||
mir_eval.transcription.precision_recall_f1(ref_int, ref_pitch, est_int, | ||
|
@@ -32,7 +84,7 @@ def test_precision_recall_f1(): | |
offset_ratio=None) | ||
|
||
scores_gen = np.array([precision, recall, f_measure]) | ||
scores_exp = np.array([scores['Precision_nooffset'], | ||
scores['Recall_nooffset'], | ||
scores['F-measure_nooffset']]) | ||
scores_exp = np.array([scores['Precision_no_offset'], | ||
scores['Recall_no_offset'], | ||
scores['F-measure_no_offset']]) | ||
assert np.allclose(scores_exp, scores_gen, atol=A_TOL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters