Skip to content

Commit

Permalink
docstyle on patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Mar 20, 2024
1 parent 5afae79 commit d69527c
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions mir_eval/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@


def _n_onset_midi(patterns):
"""Computes the number of onset_midi objects in a pattern
"""Compute the number of onset_midi objects in a pattern
Parameters
----------
Expand All @@ -80,7 +80,7 @@ def _n_onset_midi(patterns):


def validate(reference_patterns, estimated_patterns):
"""Checks that the input annotations to a metric look like valid pattern
"""Check that the input annotations to a metric look like valid pattern
lists, and throws helpful errors if not.
Parameters
Expand All @@ -90,11 +90,6 @@ def validate(reference_patterns, estimated_patterns):
:func:`mir_eval.io.load_patterns()`
estimated_patterns : list
The estimated patterns in the same format
Returns
-------
"""
# Warn if pattern lists are empty
if _n_onset_midi(reference_patterns) == 0:
Expand All @@ -117,7 +112,7 @@ def validate(reference_patterns, estimated_patterns):


def _occurrence_intersection(occ_P, occ_Q):
"""Computes the intersection between two occurrences.
"""Compute the intersection between two occurrences.
Parameters
----------
Expand All @@ -138,7 +133,7 @@ def _occurrence_intersection(occ_P, occ_Q):


def _compute_score_matrix(P, Q, similarity_metric="cardinality_score"):
"""Computes the score matrix between the patterns P and Q.
"""Compute the score matrix between the patterns P and Q.
Parameters
----------
Expand Down Expand Up @@ -175,7 +170,7 @@ def _compute_score_matrix(P, Q, similarity_metric="cardinality_score"):


def standard_FPR(reference_patterns, estimated_patterns, tol=1e-5):
"""Standard F1 Score, Precision and Recall.
"""Compute the standard F1 Score, Precision and Recall.
This metric checks if the prototype patterns of the reference match
possible translated patterns in the prototype patterns of the estimations.
Expand Down Expand Up @@ -244,7 +239,7 @@ def standard_FPR(reference_patterns, estimated_patterns, tol=1e-5):
def establishment_FPR(
reference_patterns, estimated_patterns, similarity_metric="cardinality_score"
):
"""Establishment F1 Score, Precision and Recall.
"""Compute the establishment F1 Score, Precision and Recall.
Examples
--------
Expand Down Expand Up @@ -308,7 +303,7 @@ def occurrence_FPR(
thres=0.75,
similarity_metric="cardinality_score",
):
"""Establishment F1 Score, Precision and Recall.
"""Compute the occurrence F1 Score, Precision and Recall.
Examples
--------
Expand All @@ -327,7 +322,7 @@ def occurrence_FPR(
The estimated patterns in the same format
thres : float
How similar two occcurrences must be in order to be considered
How similar two occurrences must be in order to be considered
equal
(Default value = .75)
Expand All @@ -343,12 +338,11 @@ def occurrence_FPR(
Returns
-------
f_measure : float
The establishment F1 Score
The occurrence F1 Score
precision : float
The establishment Precision
The occurrence Precision
recall : float
The establishment Recall
The occurrence Recall
"""
validate(reference_patterns, estimated_patterns)
# Number of elements in reference
Expand Down Expand Up @@ -417,7 +411,7 @@ def three_layer_FPR(reference_patterns, estimated_patterns):
validate(reference_patterns, estimated_patterns)

def compute_first_layer_PR(ref_occs, est_occs):
"""Computes the first layer Precision and Recall values given the
"""Compute the first layer Precision and Recall values given the
set of occurrences in the reference and the set of occurrences in the
estimation.
Expand All @@ -428,8 +422,8 @@ def compute_first_layer_PR(ref_occs, est_occs):
Returns
-------
precision
recall
"""
# Find the length of the intersection between reference and estimation
s = len(_occurrence_intersection(ref_occs, est_occs))
Expand All @@ -440,7 +434,7 @@ def compute_first_layer_PR(ref_occs, est_occs):
return precision, recall

def compute_second_layer_PR(ref_pattern, est_pattern):
"""Computes the second layer Precision and Recall values given the
"""Compute the second layer Precision and Recall values given the
set of occurrences in the reference and the set of occurrences in the
estimation.
Expand All @@ -451,8 +445,8 @@ def compute_second_layer_PR(ref_pattern, est_pattern):
Returns
-------
precision
recall
"""
# Compute the first layer scores
F_1 = compute_layer(ref_pattern, est_pattern)
Expand All @@ -463,7 +457,7 @@ def compute_second_layer_PR(ref_pattern, est_pattern):
return precision, recall

def compute_layer(ref_elements, est_elements, layer=1):
"""Computes the F-measure matrix for a given layer. The reference and
"""Compute the F-measure matrix for a given layer. The reference and
estimated elements can be either patterns or occurrences, depending
on the layer.
Expand All @@ -479,8 +473,7 @@ def compute_layer(ref_elements, est_elements, layer=1):
Returns
-------
F : F-measure for the given layer
"""
if layer != 1 and layer != 2:
raise ValueError("Layer (%d) must be an integer between 1 and 2" % layer)
Expand Down Expand Up @@ -544,9 +537,7 @@ def first_n_three_layer_P(reference_patterns, estimated_patterns, n=5):
-------
precision : float
The first n three-layer Precision
"""

validate(reference_patterns, estimated_patterns)
# If no patterns were provided, metric is zero
if _n_onset_midi(reference_patterns) == 0 or _n_onset_midi(estimated_patterns) == 0:
Expand Down Expand Up @@ -591,9 +582,7 @@ def first_n_target_proportion_R(reference_patterns, estimated_patterns, n=5):
-------
recall : float
The first n target proportion Recall.
"""

validate(reference_patterns, estimated_patterns)
# If no patterns were provided, metric is zero
if _n_onset_midi(reference_patterns) == 0 or _n_onset_midi(estimated_patterns) == 0:
Expand Down Expand Up @@ -631,9 +620,7 @@ def evaluate(ref_patterns, est_patterns, **kwargs):
scores : dict
Dictionary of scores, where the key is the metric name (str) and
the value is the (float) score achieved.
"""

# Compute all the metrics
scores = collections.OrderedDict()

Expand Down

0 comments on commit d69527c

Please sign in to comment.