Created
April 15, 2014 22:17
-
-
Save bmcfee/10782851 to your computer and use it in GitHub Desktop.
Maximal matching for boundary detection
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
def matching(ref, est, window=0.5): | |
n_ref, n_est = len(ref), len(est) | |
D = np.zeros((n_ref + n_est, n_ref + n_est)) | |
M = (np.abs(np.subtract.outer(ref, est)) <= window).astype(int) | |
# If we build the skew-symmetric adjacency matrix D, then rank(D) = 2 * maximum matching | |
D[:n_ref, n_ref:] = M | |
D[n_ref:, :n_ref] = -M.T | |
vals = np.abs(scipy.linalg.eig(D)[0]) | |
rank = sum(vals > 1e-10) | |
matching_size = rank / 2.0 | |
precision = matching_size / len(est) | |
recall = matching_size / len(ref) | |
f_measure = mir_eval.util.f_measure(precision, recall) | |
return precision, recall, f_measure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment