// Convert intervals to boundaries
reference_boundaries = util.intervals_to_boundaries(reference_intervals)[0]
estimated_boundaries = util.intervals_to_boundaries(estimated_intervals)[0]
// Suppress the first and last intervals
if trim:
reference_boundaries = reference_boundaries[1:-1]
estimated_boundaries = estimated_boundaries[1:-1]
// If we have no boundaries, we get no score.
if len(reference_boundaries) == 0 or len(estimated_boundaries) == 0:
return 0.0, 0.0, 0.0
// Compute the hits
dist = np.abs( np.subtract.outer(reference_boundaries, estimated_boundaries)) <= window
// Precision: how many estimated intervals were hits?
precision = np.mean(dist.max(axis=0))
// Recall: how many of the intervals did we catch?
recall = np.mean(dist.max(axis=1))
// And the f-measure
f_measure = util.f_measure(precision, recall, beta=beta)
return precision, recall, f_measure
After Change
// Convert intervals to boundaries
reference_boundaries = util.intervals_to_boundaries(reference_intervals)
estimated_boundaries = util.intervals_to_boundaries(estimated_intervals)
// Suppress the first and last intervals
if trim:
reference_boundaries = reference_boundaries[1:-1]
estimated_boundaries = estimated_boundaries[1:-1]
// If we have no boundaries, we get no score.
if len(reference_boundaries) == 0 or len(estimated_boundaries) == 0:
return 0.0, 0.0, 0.0
// Compute the hits
dist = np.abs( np.subtract.outer(reference_boundaries, estimated_boundaries)) <= window
// Precision: how many estimated intervals were hits?
precision = np.mean(dist.max(axis=0))
// Recall: how many of the intervals did we catch?
recall = np.mean(dist.max(axis=1))
// And the f-measure
f_measure = util.f_measure(precision, recall, beta=beta)
return precision, recall, f_measure