nussl/separation/primitive/repet_sim.py
def compute_similarity_matrix(matrix):
        """Computes the cosine similarity matrix using the cosine similarity for any given input matrix X.

        Parameters:
            matrix (np.array): 2D matrix containing the magnitude spectrogram of the audio signal
        Returns:
            S (np.array): 2D similarity matrix
        """
        # ignore the 'divide by zero' warning
        with np.errstate(divide='ignore'):
            # Code below is adopted from http://stackoverflow.com/a/20687984/5768001

            # base similarity matrix (all dot products)
            similarity = np.dot(matrix, matrix.T)

            # inverse_mask of the squared magnitude of preference vectors (number of occurrences)
            inv_square_mag = 1 / np.diag(similarity)

            # if it doesn't occur, set it's inverse_mask magnitude to zero (instead of inf)
            inv_square_mag[np.isinf(inv_square_mag)] = 0

            # inverse_mask of the magnitude
            inv_mag = np.sqrt(inv_square_mag)

            # cosine similarity (element-wise multiply by inverse_mask magnitudes)
            cosine = similarity * inv_mag
            cosine = cosine.T * inv_mag

            return cosine
Computes the cosine similarity matrix using the cosine similarity for any given input matrix X.

        Parameters:
            matrix (np.array): 2D matrix containing the magnitude spectrogram of the audio signal
        Returns:
            S (np.array): 2D similarity matrix
        
Computes the cosine similarity matrix using the cosine similarity for any given input matrix X.
Computes the cosine similarity matrix using the cosine similarity for any given input matrix X .
def compute_similarity_matrix(matrix):
        with np.errstate(divide='ignore'):
            similarity = np.dot(matrix, matrix.T)
            inv_square_mag = 1 / np.diag(similarity)
            inv_square_mag[np.isinf(inv_square_mag)] = 0
            inv_mag = np.sqrt(inv_square_mag)
            cosine = similarity * inv_mag
            cosine = cosine.T * inv_mag
            return cosine
def compute_similarity_matrix ( matrix ) : with np . errstate ( divide = 'ignore' ) : similarity = np . dot ( matrix , matrix . T ) inv_square_mag = 1 / np . diag ( similarity ) inv_square_mag [ np . isinf ( inv_square_mag ) ] = 0 inv_mag = np . sqrt ( inv_square_mag ) cosine = similarity * inv_mag cosine = cosine . T * inv_mag return cosine
Computes the cosine similarity matrix using the cosine similarity for any given input matrix X.
Computes the cosine similarity matrix using the cosine similarity for any given input matrix X .
"""Computes the cosine similarity matrix using the cosine similarity for any given input matrix X.

        Parameters:
            matrix (np.array): 2D matrix containing the magnitude spectrogram of the audio signal
        Returns:
            S (np.array): 2D similarity matrix
        """ # ignore the 'divide by zero' warning # Code below is adopted from http://stackoverflow.com/a/20687984/5768001 # base similarity matrix (all dot products) # inverse_mask of the squared magnitude of preference vectors (number of occurrences) # if it doesn't occur, set it's inverse_mask magnitude to zero (instead of inf) # inverse_mask of the magnitude # cosine similarity (element-wise multiply by inverse_mask magnitudes)
S (np.array): 2D similarity matrix
S ( np . array ) : 2D similarity matrix
matrix
2D matrix containing the magnitude spectrogram of the audio signal
2D matrix containing the magnitude spectrogram of the audio signal