nussl/ml/confidence.py
def dpcl_classic_confidence(audio_signal, features, num_sources, threshold=95, 
                            **kwargs):
    """
    Computes the clusterability in two steps:

    1. Cluster the feature space using KMeans into assignments
    2. Compute the classic deep clustering loss between the features and the assignments.
    
    Args:
        audio_signal (AudioSignal): AudioSignal object which will be used to compute
          the mask over which to compute the confidence measure. This can be None, if
          and only if ``representation`` is passed as a keyword argument to this 
          function.
        features (np.ndarray): Numpy array containing the features to be clustered. 
          Should have the same dimensions as the representation.
        n_sources (int): Number of sources to cluster the features into.
        threshold (int, optional): Threshold by loudness. Points below the threshold are
          excluded from being used in the confidence measure. Defaults to 95.
        kwargs: Keyword arguments to `_get_loud_bins_mask`. Namely, representation can
          go here as a keyword argument.
    
    Returns:
        float: Confidence given by deep clustering loss.
    """
    mask, representation = _get_loud_bins_mask(threshold, audio_signal, **kwargs)
    embedding_size = features.shape[-1]
    features = features[mask].reshape(-1, embedding_size)
    weights = representation[mask].reshape(-1)

    kmeans = KMeans(num_sources)
    distances = kmeans.fit_transform(features)
    assignments = (distances == distances.max(axis=-1, keepdims=True))

    loss_func = loss.DeepClusteringLoss()

    features = torch.from_numpy(features).unsqueeze(0).float()
    assignments = torch.from_numpy(assignments).unsqueeze(0).float()
    weights = torch.from_numpy(weights).unsqueeze(0).float()

    loss_val = loss_func(features, assignments, weights).item()
    confidence = 1 - loss_val
    return confidence

    Computes the clusterability in two steps:

    1. Cluster the feature space using KMeans into assignments
    2. Compute the classic deep clustering loss between the features and the assignments.
    
    Args:
        audio_signal (AudioSignal): AudioSignal object which will be used to compute
          the mask over which to compute the confidence measure. This can be None, if
          and only if ``representation`` is passed as a keyword argument to this 
          function.
        features (np.ndarray): Numpy array containing the features to be clustered. 
          Should have the same dimensions as the representation.
        n_sources (int): Number of sources to cluster the features into.
        threshold (int, optional): Threshold by loudness. Points below the threshold are
          excluded from being used in the confidence measure. Defaults to 95.
        kwargs: Keyword arguments to `_get_loud_bins_mask`. Namely, representation can
          go here as a keyword argument.
    
    Returns:
        float: Confidence given by deep clustering loss.
    
Computes the clusterability in two steps:
1. Cluster the feature space using KMeans into assignments
2. Compute the classic deep clustering loss between the features and the assignments.
Computes the clusterability in two steps : 1 . Cluster the feature space using KMeans into assignments 2 . Compute the classic deep clustering loss between the features and the assignments .
def dpcl_classic_confidence(audio_signal, features, num_sources, threshold=95, 
                            **kwargs):
    mask, representation = _get_loud_bins_mask(threshold, audio_signal, **kwargs)
    embedding_size = features.shape[-1]
    features = features[mask].reshape(-1, embedding_size)
    weights = representation[mask].reshape(-1)
    kmeans = KMeans(num_sources)
    distances = kmeans.fit_transform(features)
    assignments = (distances == distances.max(axis=-1, keepdims=True))
    loss_func = loss.DeepClusteringLoss()
    features = torch.from_numpy(features).unsqueeze(0).float()
    assignments = torch.from_numpy(assignments).unsqueeze(0).float()
    weights = torch.from_numpy(weights).unsqueeze(0).float()
    loss_val = loss_func(features, assignments, weights).item()
    confidence = 1 - loss_val
    return confidence
def dpcl_classic_confidence ( audio_signal , features , num_sources , threshold = 95 , ** kwargs ) : mask , representation = _get_loud_bins_mask ( threshold , audio_signal , ** kwargs ) embedding_size = features . shape [ - 1 ] features = features [ mask ] . reshape ( - 1 , embedding_size ) weights = representation [ mask ] . reshape ( - 1 ) kmeans = KMeans ( num_sources ) distances = kmeans . fit_transform ( features ) assignments = ( distances == distances . max ( axis = - 1 , keepdims = True ) ) loss_func = loss . DeepClusteringLoss ( ) features = torch . from_numpy ( features ) . unsqueeze ( 0 ) . float ( ) assignments = torch . from_numpy ( assignments ) . unsqueeze ( 0 ) . float ( ) weights = torch . from_numpy ( weights ) . unsqueeze ( 0 ) . float ( ) loss_val = loss_func ( features , assignments , weights ) . item ( ) confidence = 1 - loss_val return confidence
Computes the clusterability in two steps:
1.
Computes the clusterability in two steps : 1 .
"""
    Computes the clusterability in two steps:

    1. Cluster the feature space using KMeans into assignments
    2. Compute the classic deep clustering loss between the features and the assignments.
    
    Args:
        audio_signal (AudioSignal): AudioSignal object which will be used to compute
          the mask over which to compute the confidence measure. This can be None, if
          and only if ``representation`` is passed as a keyword argument to this 
          function.
        features (np.ndarray): Numpy array containing the features to be clustered. 
          Should have the same dimensions as the representation.
        n_sources (int): Number of sources to cluster the features into.
        threshold (int, optional): Threshold by loudness. Points below the threshold are
          excluded from being used in the confidence measure. Defaults to 95.
        kwargs: Keyword arguments to `_get_loud_bins_mask`. Namely, representation can
          go here as a keyword argument.
    
    Returns:
        float: Confidence given by deep clustering loss.
    """
Confidence given by deep clustering loss.
Confidence given by deep clustering loss .
float
audio_signal
AudioSignal object which will be used to compute
the mask over which to compute the confidence measure. This can be None, if
and only if ``representation`` is passed as a keyword argument to this
function.
AudioSignal object which will be used to compute the mask over which to compute the confidence measure . This can be None if and only if ` ` representation ` ` is passed as a keyword argument to this function .
features
Numpy array containing the features to be clustered.
Should have the same dimensions as the representation.
Numpy array containing the features to be clustered . Should have the same dimensions as the representation .
num_sources
threshold
Threshold by loudness. Points below the threshold are
excluded from being used in the confidence measure. Defaults to 95.
Threshold by loudness . Points below the threshold are excluded from being used in the confidence measure . Defaults to 95 .
n_sources
Number of sources to cluster the features into.
Number of sources to cluster the features into .
kwargs
Keyword arguments to `_get_loud_bins_mask`. Namely, representation can
go here as a keyword argument.
Keyword arguments to ` _get_loud_bins_mask ` . Namely representation can go here as a keyword argument .