-
Notifications
You must be signed in to change notification settings - Fork 0
optimumSpeaker
Inspired from https://github.com/wq2012/SpectralCluster
- class eigengap
- class AffinityRefinementOperation
- class CropDiagonal
- class GaussianBlur
- class RowWiseThreshold
- class Symmetrize
- class Diffuse
- class RowWiseNormalize
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:
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 |
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 |
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 |
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 |
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_clusters ≤ k ≤ self.max_clusters
|
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:
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 |
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(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:
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(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:
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(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:
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 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:
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(AffinityRefinementOperation)
Defined in optimumSpeaker.py
Operator to return a diffused symmetric matrix XTX from a given input matrix X.
Class Functions:
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(AffinityRefinementOperation)
Defined in optimumSpeaker.py
Operator to normalize each row of input matrix X by the maximum value in the corresponding rows.
Class Functions:
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 |