<commit_before># -*- coding: utf-8 -*-
'''
CREATED: 2013-08-13 12:31:25 by <NAME> <<EMAIL>>

Source separation evaluation:
    BSS-EVAL -- SDR (Source-to-Distortion Ratio), SIR (Source-to-Interferences
                Ratio), and SAR (Source-to-Artifacts Ratio)

'''

import numpy as np
import scipy.linalg
import itertools

import util


def bss_eval_sources(estimated_sources, sources):
    '''BSS_EVAL_SOURCES
        MATLAB translation of BSS_EVAL Toolbox

        Ordering and measurement of the separation quality for estimated source
        signals in terms of filtered true source, interference and artifacts.

        The decomposition allows a time-invariant filter distortion of length
        512, as described in Section III.B of the reference below.

    :parameters:
      - estimated_sources: ndarray
          nsrc x nsampl matrix containing estimated sources
      - sources: ndarray
          nsrc x nsampl matrix containing true sources

    :returns:
      - SDR: ndarray
          (nsrc, ) vector of Signal to Distortion Ratios
      - SIR: ndarray
          (nsrc, ) vector of Source to Interference Ratios
      - SAR: ndarray
          (nsrc, ) vector of Sources to Artifacts Ratios
      - perm: ndarray
          (nsrc, ) vector containing the best ordering of estimated sources in
          the mean SIR sense (estimated source number perm[j] corresponds to
          true source number j)

    :raises:
      - ValueError
          if the shape of estimated sources and the true sources doesn't match.

    Reference:
        <NAME>, <NAME>, and <NAME>, "Performance
        measurement in blind audio source separation," IEEE Trans. on Audio,
        Speech and Language Processing, 14(4):1462-1469, 2006.

    '''

    # make sure the input is of shape (nsrc, nsampl)
    if estimated_sources.ndim == 1:
        estimated_sources = estimated_sources[np.newaxis, :]
    if sources.ndim == 1:
        sources = sources[np.newaxis, :]

    nsrc, nsampl = estimated_sources.shape
    if sources.shape != estimated_sources.shape:
        raise ValueError('The shape of estimated sources and the true sources '
                         'should match.')

    # compute criteria for all possible pair matches
    SDR = np.empty((nsrc, nsrc))
    SIR = np.empty((nsrc, nsrc))
    SAR = np.empty((nsrc, nsrc))<commit_msg>checked the parameter first<commit_after># -*- coding: utf-8 -*-
'''
CREATED: 2013-08-13 12:31:25 by <NAME> <<EMAIL>>

Source separation evaluation:
    BSS-EVAL -- SDR (Source-to-Distortion Ratio), SIR (Source-to-Interferences
                Ratio), and SAR (Source-to-Artifacts Ratio)

'''

import numpy as np
import scipy.linalg
import itertools

import util


def bss_eval_sources(estimated_sources, sources):
    '''BSS_EVAL_SOURCES
        MATLAB translation of BSS_EVAL Toolbox

        Ordering and measurement of the separation quality for estimated source
        signals in terms of filtered true source, interference and artifacts.

        The decomposition allows a time-invariant filter distortion of length
        512, as described in Section III.B of the reference below.

    :parameters:
      - estimated_sources: ndarray
          nsrc x nsampl matrix containing estimated sources
      - sources: ndarray
          nsrc x nsampl matrix containing true sources

    :returns:
      - SDR: ndarray
          (nsrc, ) vector of Signal to Distortion Ratios
      - SIR: ndarray
          (nsrc, ) vector of Source to Interference Ratios
      - SAR: ndarray
          (nsrc, ) vector of Sources to Artifacts Ratios
      - perm: ndarray
          (nsrc, ) vector containing the best ordering of estimated sources in
          the mean SIR sense (estimated source number perm[j] corresponds to
          true source number j)

    :raises:
      - ValueError
          if the shape of estimated sources and the true sources doesn't match.

    Reference:
        <NAME>, <NAME>, and <NAME>, "Performance
        measurement in blind audio source separation," IEEE Trans. on Audio,
        Speech and Language Processing, 14(4):1462-1469, 2006.

    '''

    # make sure the input is of shape (nsrc, nsampl)
    if estimated_sources.ndim == 1:
        estimated_sources = estimated_sources[np.newaxis, :]
    if sources.ndim == 1:
        sources = sources[np.newaxis, :]

    if sources.shape != estimated_sources.shape:
        raise ValueError('The shape of estimated sources and the true sources '
                         'should match.')
    nsrc, nsampl = estimated_sources.shape

    # compute criteria for all possible pair matches
    SDR = np.empty((nsrc, nsrc))
    SIR = np.empty((nsrc, nsrc))
    SAR = np.empty((nsrc, nsrc))
{'fraction_non_alphanumeric': 0.07829787234042553, 'fraction_numerical': 0.014893617021276596, 'mean_word_length': 2.5667678300455234, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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}}
{'dir': 'git-commits-cleaned', 'id': '6681493', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1275, 'n_words': 488}