Skip to content

Commit

Permalink
load_valued_intervals now returns the values as an np.ndarray instead…
Browse files Browse the repository at this point in the history
… of a list, and all relevant methods have been updated accordingly.
  • Loading branch information
justinsalamon committed Feb 15, 2016
1 parent a8f4d68 commit 7802919
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
9 changes: 6 additions & 3 deletions mir_eval/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,9 @@ def load_valued_intervals(filename, delimiter=r'\s+'):
Returns
-------
intervals : np.ndarray, shape=(n_events, 2)
array of event start and end time
values : list of float
list of values
Array of event start and end times
values : np.ndarray, shape=(n_events,)
Array of values
"""
# Use our universal function to load in the events
Expand All @@ -436,4 +436,7 @@ def load_valued_intervals(filename, delimiter=r'\s+'):
except ValueError as error:
warnings.warn(error.args[0])

# return values as np.ndarray
values = np.array(values)

return intervals, values
40 changes: 20 additions & 20 deletions mir_eval/transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
Conventions
-----------
Notes should be provided in the form of an interval array and a pitch list.
Notes should be provided in the form of an interval array and a pitch array.
The interval array contains two columns, one for note onsets and the second
for note offsets (each row represents a single note). The pitch list contains
the corresponding note pitch values (one value per note), represented by their
fundamental frequency (f0) in Hertz.
for note offsets (each row represents a single note). The pitch array contains
one column with the corresponding note pitch values (one value per note),
represented by their fundamental frequency (f0) in Hertz.
Metrics
-------
Expand All @@ -70,28 +70,28 @@ def validate(ref_intervals, ref_pitches, est_intervals, est_pitches):
----------
ref_intervals : np.ndarray, shape=(n,2)
Array of reference notes time intervals (onset and offset times)
ref_pitches: list, len=n
List of reference pitch values in Hertz
ref_pitches: np.ndarray, shape=(n,)
Array of reference pitch values in Hertz
est_intervals : np.ndarray, shape=(m,2)
Array of estimated notes time intervals (onset and offset times)
est_pitches : list, len=m
List of estimated pitch values in Hertz
est_pitches : np.ndarray, shape=(m,)
Array of estimated pitch values in Hertz
"""
# If reference or estimated notes are empty, warn
if ref_intervals.size == 0:
warnings.warn("Reference note intervals are empty.")
if len(ref_pitches) == 0:
if ref_pitches.size == 0:
warnings.warn("Reference note pitches are empty.")
if est_intervals.size == 0:
warnings.warn("Estimate note intervals are empty.")
if len(est_pitches) == 0:
if est_pitches.size == 0:
warnings.warn("Estimate note pitches are empty.")

# Make sure intervals and pitches match in length
if not len(ref_intervals) == len(ref_pitches):
if not ref_intervals.shape[0] == ref_pitches.shape[0]:
warnings.warn("Reference intervals and pitches have different "
"lengths.")
if not len(est_intervals) == len(est_pitches):
if not est_intervals.shape[0] == est_pitches.shape[0]:
warnings.warn("Estimate intervals and pitches have different lengths.")

# Make sure all pitch values are positive
Expand Down Expand Up @@ -134,12 +134,12 @@ def precision_recall_f1(ref_intervals, ref_pitches, est_intervals, est_pitches,
----------
ref_intervals : np.ndarray, shape=(n,2)
Array of reference notes time intervals (onset and offset times)
ref_pitches: list, len=n
List of reference pitch values in Hertz
ref_pitches: np.ndarray, shape=(n,)
Array of reference pitch values in Hertz
est_intervals : np.ndarray, shape=(m,2)
Array of estimated notes time intervals (onset and offset times)
est_pitches : list, len=m
List of estimated pitch values in Hertz
est_pitches : np.ndarray, shape=(m,)
Array of estimated pitch values in Hertz
onset_tolerance : float > 0
The tolerance for an estimated note's onset deviating from the
reference note's onset, in seconds. Default is 0.05 (50 ms).
Expand Down Expand Up @@ -201,12 +201,12 @@ def evaluate(ref_intervals, ref_pitches, est_intervals, est_pitches, **kwargs):
----------
ref_intervals : np.ndarray, shape=(n,2)
Array of reference notes time intervals (onset and offset times)
ref_pitches: list, len=n
List of reference pitch values in Hertz
ref_pitches: np.ndarray, shape=(n,)
Array of reference pitch values in Hertz
est_intervals : np.ndarray, shape=(m,2)
Array of estimated notes time intervals (onset and offset times)
est_pitches : list, len=m
List of estimated pitch values in Hertz
est_pitches : np.ndarray, shape=(m,)
Array of estimated pitch values in Hertz
kwargs
Additional keyword arguments which will be passed to the
appropriate metric or preprocessing functions.
Expand Down
10 changes: 5 additions & 5 deletions mir_eval/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def match_notes(ref_intervals, ref_pitches, est_intervals, est_pitches,
"""Compute a maximum matching between reference and estimated notes,
subject to onset, pitch and (optionally) offset constraints.
Given two note lists represented by ``ref_intervals``, ``ref_pitches``,
Given two note sequences represented by ``ref_intervals``, ``ref_pitches``,
``est_intervals`` and ``est_pitches`` (see ``io.load_valued_intervals``),
we seek the largest set of correspondences ``(i, j)`` such that:
1. The onset of ref note i is within ``onset_tolerance`` of the onset of
Expand All @@ -664,12 +664,12 @@ def match_notes(ref_intervals, ref_pitches, est_intervals, est_pitches,
----------
ref_intervals : np.ndarray, shape=(n,2)
Array of reference notes time intervals (onset and offset times)
ref_pitches: list, len=n
List of reference pitch values in Hertz
ref_pitches: np.ndarray, shape=(n,)
Array of reference pitch values in Hertz
est_intervals : np.ndarray, shape=(m,2)
Array of estimated notes time intervals (onset and offset times)
est_pitches : list, len=m
List of estimated pitch values in Hertz
est_pitches : np.ndarray, shape=(m,)
Array of estimated pitch values in Hertz
onset_tolerance : float > 0
The tolerance for an estimated note's onset deviating from the
reference note's onset, in seconds. Default is 0.05 (50 ms).
Expand Down

0 comments on commit 7802919

Please sign in to comment.