<jupyter_start><jupyter_text>**This was not used**Initial unused implementation of different salience representation metrics<jupyter_code>import numpy as np
import scipy
from scipy import signal
import matplotlib.pyplot as plt
%matplotlib inline
def targets_to_binary(target_matrix):
    binary_matrix = np.zeros(target_matrix.shape)
    binary_matrix[target_matrix == 1.0] = 1.0
    return binary_matrix
def peak_mask(prediction_matrix, binary=False):
    peaks = scipy.signal.argrelmax(prediction_matrix, axis=0)
    mask = np.zeros(prediction_matrix.shape)
    if binary:
        mask[peaks] = 1
    else:
        mask[peaks] = prediction_matrix[peaks]
    return mask
def mask_prediction(prediction_matrix, binary_matrix):
    return prediction_matrix * binary_matrix
def energy_recall(prediction_matrix, target_matrix):
    binary_matrix = targets_to_binary(target_matrix)
    mask = mask_prediction(prediction_matrix, binary_matrix)
    return np.sum(mask.flatten()) / np.sum(binary_matrix.flatten())
def energy_false_alarm(prediction_matrix, target_matrix):
    binary_matrix = 1 - targets_to_binary(target_matrix)
    mask = mask_prediction(prediction_matrix, binary_matrix)
    return np.sum(mask.flatten()) / np.sum((binary_matrix).flatten())
def mean_amplitude_error(prediction_matrix, target_matrix):
    binary_matrix = targets_to_binary(target_matrix)
    mask = mask_prediction(prediction_matrix, binary_matrix)
    n_positive = np.sum(binary_matrix.flatten())
    return np.sum(binary_matrix.flatten() - mask.flatten())/float(n_positive)
def peak_recall(prediction_matrix, target_matrix):
    binary_matrix = targets_to_binary(target_matrix)
    prediction_peak_mask = peak_mask(prediction_matrix, binary=True)
    mask = mask_prediction(prediction_peak_mask, binary_matrix)
    return np.sum(mask.flatten()) / np.sum(binary_matrix.flatten())
def mean_frequency_error(prediction_matrix, target_matrix):
    binary_matrix = targets_to_binary(target_matrix)
    n_positive = np.sum(binary_matrix.flatten())
    prediction_peak_mask = peak_mask(prediction_matrix, binary=True)
    mask = mask_prediction(prediction_peak_mask, target_matrix)
    return np.sum(mask.flatten()) / float(n_positive)
y_pred = np.load('/home/rmb456/repos/multif0/pred_output_example.npy')
y_true = np.load('/home/rmb456/repos/multif0/true_output_example.npy')
e_recall = energy_recall(y_pred, y_true) #average energy of ground truth positives
e_fa = energy_false_alarm(y_pred, y_true) #average energy of ground truth negatives
mae = mean_amplitude_error(y_pred, y_true)
pr = peak_recall(y_pred, y_true)
mfe = mean_frequency_error(y_pred, y_true)
print([e_recall, e_fa, mae, pr, mfe])
plt.figure(figsize=(15, 7))
plt.imshow(mask, origin='lower')
plt.axis('auto')
plt.colorbar()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10085836909871244, 'fraction_numerical': 0.006437768240343348, 'mean_word_length': 6.283854166666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '387491', 'license': 'MIT', 'n_tokens_mistral': 961, 'n_tokens_neox': 935, 'n_words': 166, 'path': 'notebooks/Salience Metrics.ipynb', 'repo_name': 'gdoras/ismir2017-deepsalience', 'size': '2796'}