Skip to content

optimumSpeaker

Aditya Singh edited this page May 12, 2021 · 3 revisions

Defined in optimumSpeaker.py

Inspired from https://github.com/wq2012/SpectralCluster

Index

class eigengap()

class eigengap(min_clusters=1, 
               max_clusters=100, 
               p_percentile=0.9, 
               gaussian_blur_sigma=2, 
               stop_eigenvalue=1e-2,
               thresholding_soft_multiplier=0.01, 
               thresholding_with_row_max=True)

Defined in optimumSpeaker.py

Utility function to decide the optimal number of speakers for clustering based on maximization of eigen-gap of the affinity matrix

Parameters:

Argument Detail
min_clusters: int, Minimum number of output clusters
max_clusters: int, Maximum number of output clusters
p_percentile: float, Parameter to computing p-th percentile for percentile based thresholding
gaussian_blur_sigma: float, sigma value for standard deviation of gaussian kernel in scipy gaussian filter
stop_eigenvalue: float, Minimum value of eigenvalue of Affinity matrix for its eigenvector to be considered in clustering
thresholding_soft_mutiplier: float, Factor to multiply to cells with value less than threshold in row/percentile thresholding. Parameter value of 0.0 turn cells less than threshold to zero in the matrix
thresholding_with_row_max: bool, True for row-max thresholding, False for percentile thresholding

Class Functions:

  1. _get_refinement_operator:
def _get_refinement_operator(self, name)

Parameters:

Argument Detail
name: str, Get the input refinement operator. Available refinements- 'CropDiagonal', 'GaussianBlur', 'RowWiseThreshold', 'Symmetrize', 'Diffuse', 'RowWiseNormalize'

Returns:

Variable Detail
CropDiagonal()/GaussianBlur()/
RowWiseThreshold()/Symmetrize()/
Diffuse()/RowWiseNormalize()
optimumSpeaker.AffinityRefinementOperation, Returns specified refinement method class
  1. compute_affinity_matrix:
def compute_affinity_matrix(self, X)

Compute the affinity matrix for a matrix X with row as each instance and column as features by calculating cosine similarity between pair of l2 normalized columns of X

Parameters:

Argument Detail
X: numpy.ndarray, (n_windows, n_features) Input matrix with column as features to compute affinity matrix between pair of columns

Returns:

Variable Detail
affinity: numpy.ndarray, (n_windows, n_windows) Symmetric array with (i,j)th value equal to cosine similiarity between i-th and j-th row
  1. compute_sorted_eigenvectors:
def compute_sorted_eigenvectors(self, A)

Parameters:

Argument Detail
A: numpy.ndarray, (n_windows, n_windows) Symmetric array with (i,j)th value equal to cosine similiarity between i-th and j-th row

Returns:

Variable Detail
w: numpy.ndarray, Decreasing order sorted eigen values of affinity matrix A
v: numpy.ndarray, Eigen vectors corresponding to eigen values returned
  1. compute_number_of_clusters:
def compute_number_of_clusters(self, eigenvalues, max_clusters, stop_eigenvalue)

Parameters:

Argument Detail
eigenvalues: numpy.ndarray, Decreasing order sorted eigen values of affinity matrix between different windows
max_clusters: int, Maximum number of clusters required. Default 'None' puts no such limit to the number of clusters
stop_eigenvalue: float, Minimum value of eigenvalue to be considered for deciding number of clusters. Eigenvalues below this value are discarded

Returns:

Variable Detail
max_delta_index: int, Index to the eigenvalue such that eigen gap is maximized. It gives the number of clusters determined by the function
  1. find
def find(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, (n_windows, n_features) Input matrix with column as features to compute affinity matrix between pair of columns

Returns:

Variable Detail
k: int, Number of clusters calculated after creating the affinity matrix, applying refinements, and using eigen-gap maximization. self.min_clusterskself.max_clusters

class AffinityRefinementOperation()

class AffinityRefinementOperation(metaclass=abc.ABCMeta)

Defined in optimumSpeaker.py

Meta class to the refinement operation classes passed as input to be perfomed on the data

Class Functions:

  1. check_input:
def check_input(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be refined by refinement operators

Returns:

Variable Detail
ValueError()\ TypeError() ValueError/TypeError, Type Error if X is not a numpy array. Value error if X is not a 2D square matrix
  1. refine:
def refine(self, X)

Abstract function redefined in various child classes of class AffinityRefinementOperation

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be refined by refinement operators

class CropDiagonal()

class Cropdiagonal(AffinityRefinementOperation)

Defined in optimumSpeaker.py

Operator to replace diagonal element by the max non-diagonal value of row. Post operation, the matrix has similar properties to a standard Laplacian matrix. This also helps to avoid the bias during Gaussian blur and normalization.

Class Functions:

  1. refine:
def refine(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be refined by refinement operators

Returns:

Variable Detail
Y: numpy.ndarray, Output array with Crop diagonal refinement applied

class GaussianBlur()

class GaussianBlur(AffinityRefinementOperation)
      def __init__(self, sigma = 1)

Defined in optimumSpeaker.py

Operator to apply gaussian filter to the input array. Uses scipy.ndimage.gaussian_filter

Parameters:

Argument Detail
sigma: float, Standard deviation for Gaussian kernel

Class Functions:

  1. refine:
def refine(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be refined by refinement operators

Returns:

Variable Detail
Y: numpy.ndarray, Output array with gaussian filter applied

class RowWiseThreshold()

class RowWiseThreshold(AffinityRefinementOperation)
      def __init__(self,
                 p_percentile=0.95,
                 thresholding_soft_multiplier=0.01,
                 thresholding_with_row_max=False)

Defined in optimumSpeaker.py

Operator to apply row wise thresholding based on either percentile or row-max thresholding.

Parameters:

Argument Detail
p_percentile: float, Standard deviation for Gaussian kernel
thresholding_soft_multiplier: float, Factor to multiply to cells with value less than threshold in row/percentile thresholding. Parameter value of 0.0 turn cells less than threshold to zero in the matrix
thresholding_with_row_max: bool, True applies row-max based thresholding, False applies percentile based thresholding

Class Functions:

  1. refine:
def refine(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be refined by refinement operators

Returns:

Variable Detail
Y: numpy.ndarray, Output array with row wise threshold applied

class Symmetrize()

class Cropdiagonal(AffinityRefinementOperation)

Defined in optimumSpeaker.py

Operator to return a symmetric matrix based on max{ X, XT } from a given input matrix X.

Class Functions:

  1. refine:
def refine(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be used to create a symmetric matrix

Returns:

Variable Detail
Y: numpy.ndarray, Output symmetric array

class Diffuse()

class Diffuse(AffinityRefinementOperation)

Defined in optimumSpeaker.py

Operator to return a diffused symmetric matrix XTX from a given input matrix X.

Class Functions:

  1. refine:
def refine(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be used to create a diffused symmetric matrix

Returns:

Variable Detail
Y: numpy.ndarray, Output diffused symmetric array

class RowWiseNormalize()

class RowWiseNormalize(AffinityRefinementOperation)

Defined in optimumSpeaker.py

Operator to normalize each row of input matrix X by the maximum value in the corresponding rows.

Class Functions:

  1. refine:
def refine(self, X)

Parameters:

Argument Detail
X: numpy.ndarray, Input array to be row normalized

Returns:

Variable Detail
Y: numpy.ndarray, Output row normalized array