class_docstr: This class implements the spectral clustering with unnormalized affinity matrix.
  Useful when affinity matrix is based on cosine similarities.
  
  Reference
  ---------
  Von Luxburg, U. A tutorial on spectral clustering. Stat Comput 17, 395–416 (2007).
  https://doi.org/10.1007/s11222-007-9033-z
  
  Example
  -------
  >>> from speechbrain.processing import diarization as diar
  >>> clust = diar.Spec_Clust_unorm(min_num_spkrs=2, max_num_spkrs=10)
  >>> emb = [[ 2.1, 3.1, 4.1, 4.2, 3.1],
  ... [ 2.2, 3.1, 4.2, 4.2, 3.2],
  ... [ 2.0, 3.0, 4.0, 4.1, 3.0],
  ... [ 8.0, 7.0, 7.0, 8.1, 9.0],
  ... [ 8.1, 7.1, 7.2, 8.1, 9.2],
  ... [ 8.3, 7.4, 7.0, 8.4, 9.0],
  ... [ 0.3, 0.4, 0.4, 0.5, 0.8],
  ... [ 0.4, 0.3, 0.6, 0.7, 0.8],
  ... [ 0.2, 0.3, 0.2, 0.3, 0.7],
  ... [ 0.3, 0.4, 0.4, 0.4, 0.7],]
  >>> # Estimating similarity matrix
  >>> sim_mat = clust.get_sim_mat(emb)
  >>> print (np.around(sim_mat[5:,5:], decimals=3))
  [[1.    0.957 0.961 0.904 0.966]
   [0.957 1.    0.977 0.982 0.997]
   [0.961 0.977 1.    0.928 0.972]
   [0.904 0.982 0.928 1.    0.976]
   [0.966 0.997 0.972 0.976 1.   ]]
  >>> # Prunning
  >>> pruned_sim_mat = clust.p_pruning(sim_mat, 0.3)
  >>> print (np.around(pruned_sim_mat[5:,5:], decimals=3))
  [[1.    0.    0.    0.    0.   ]
   [0.    1.    0.    0.982 0.997]
   [0.    0.977 1.    0.    0.972]
   [0.    0.982 0.    1.    0.976]
   [0.    0.997 0.    0.976 1.   ]]
  >>> # Symmetrization
  >>> sym_pruned_sim_mat = 0.5 * (pruned_sim_mat + pruned_sim_mat.T)
  >>> print (np.around(sym_pruned_sim_mat[5:,5:], decimals=3))
  [[1.    0.    0.    0.    0.   ]
   [0.    1.    0.489 0.982 0.997]
   [0.    0.489 1.    0.    0.486]
   [0.    0.982 0.    1.    0.976]
   [0.    0.997 0.486 0.976 1.   ]]
  >>> # Laplacian
  >>> laplacian = clust.get_laplacian(sym_pruned_sim_mat)
  >>> print (np.around(laplacian[5:,5:], decimals=3))
  [[ 1.999  0.     0.     0.     0.   ]
   [ 0.     2.468 -0.489 -0.982 -0.997]
   [ 0.    -0.489  0.975  0.    -0.486]
   [ 0.    -0.982  0.     1.958 -0.976]
   [ 0.    -0.997 -0.486 -0.976  2.458]]
  >>> # Spectral Embeddings
  >>> spec_emb, num_of_spk = clust.get_spec_embs(laplacian, 3)
  >>> print(num_of_spk)
  3
  >>> # Clustering
  >>> clust.cluster_embs(spec_emb, num_of_spk)
  >>> # print (clust.labels_) # [0 0 0 2 2 2 1 1 1 1]
  >>> # Complete spectral clustering
  >>> clust.do_spec_clust(emb, k_oracle=3, p_val=0.3)
  >>> # print(clust.labels_) # [0 0 0 2 2 2 1 1 1 1]
class_docstr_tok: ["This","class","implements","the","spectral","clustering","with","unnormalized","affinity","matrix",".","Useful","when","affinity","matrix","is","based","on","cosine","similarities",".","Reference","--","--","--","--","-","Von","Luxburg",",","U",".","A","tutorial","on","spectral","clustering",".","Stat","Comput","17",",","395\u2013416","(","2007",")",".","https",":","\/\/doi.org\/10.1007\/s11222-007-9033-z","Example","--","--","--","-",">",">",">","from","speechbrain.processing","import","diarization","as","diar",">",">",">","clust","=","diar.Spec_Clust_unorm","(","min_num_spkrs=2",",","max_num_spkrs=10",")",">",">",">","emb","=","[","[","2.1",",","3.1",",","4.1",",","4.2",",","3.1","]",",","...","[","2.2",",","3.1",",","4.2",",","4.2",",","3.2","]",",","...","[","2.0",",","3.0",",","4.0",",","4.1",",","3.0","]",",","...","[","8.0",",","7.0",",","7.0",",","8.1",",","9.0","]",",","...","[","8.1",",","7.1",",","7.2",",","8.1",",","9.2","]",",","...","[","8.3",",","7.4",",","7.0",",","8.4",",","9.0","]",",","...","[","0.3",",","0.4",",","0.4",",","0.5",",","0.8","]",",","...","[","0.4",",","0.3",",","0.6",",","0.7",",","0.8","]",",","...","[","0.2",",","0.3",",","0.2",",","0.3",",","0.7","]",",","...","[","0.3",",","0.4",",","0.4",",","0.4",",","0.7","]",",","]",">",">",">","#","Estimating","similarity","matrix",">",">",">","sim_mat","=","clust.get_sim_mat","(","emb",")",">",">",">","print","(","np.around","(","sim_mat","[","5",":",",5",":","]",",","decimals=3",")",")","[","[","1",".","0.957","0.961","0.904","0.966","]","[","0.957","1",".","0.977","0.982","0.997","]","[","0.961","0.977","1",".","0.928","0.972","]","[","0.904","0.982","0.928","1",".","0.976","]","[","0.966","0.997","0.972","0.976","1",".","]","]",">",">",">","#","Prunning",">",">",">","pruned_sim_mat","=","clust.p_pruning","(","sim_mat",",","0.3",")",">",">",">","print","(","np.around","(","pruned_sim_mat","[","5",":",",5",":","]",",","decimals=3",")",")","[","[","1",".","0",".","0",".","0",".","0",".","]","[","0",".","1",".","0",".","0.982","0.997","]","[","0",".","0.977","1",".","0",".","0.972","]","[","0",".","0.982","0",".","1",".","0.976","]","[","0",".","0.997","0",".","0.976","1",".","]","]",">",">",">","#","Symmetrization",">",">",">","sym_pruned_sim_mat","=","0.5","*","(","pruned_sim_mat","+","pruned_sim_mat.T",")",">",">",">","print","(","np.around","(","sym_pruned_sim_mat","[","5",":",",5",":","]",",","decimals=3",")",")","[","[","1",".","0",".","0",".","0",".","0",".","]","[","0",".","1",".","0.489","0.982","0.997","]","[","0",".","0.489","1",".","0",".","0.486","]","[","0",".","0.982","0",".","1",".","0.976","]","[","0",".","0.997","0.486","0.976","1",".","]","]",">",">",">","#","Laplacian",">",">",">","laplacian","=","clust.get_laplacian","(","sym_pruned_sim_mat",")",">",">",">","print","(","np.around","(","laplacian","[","5",":",",5",":","]",",","decimals=3",")",")","[","[","1.999","0",".","0",".","0",".","0",".","]","[","0",".","2.468","-0.489","-0.982","-0.997","]","[","0",".","-0.489","0.975","0",".","-0.486","]","[","0",".","-0.982","0",".","1.958","-0.976","]","[","0",".","-0.997","-0.486","-0.976","2.458","]","]",">",">",">","#","Spectral","Embeddings",">",">",">","spec_emb",",","num_of_spk","=","clust.get_spec_embs","(","laplacian",",","3",")",">",">",">","print","(","num_of_spk",")","3",">",">",">","#","Clustering",">",">",">","clust.cluster_embs","(","spec_emb",",","num_of_spk",")",">",">",">","#","print","(","clust.labels_",")","#","[","0","0","0","2","2","2","1","1","1","1","]",">",">",">","#","Complete","spectral","clustering",">",">",">","clust.do_spec_clust","(","emb",",","k_oracle=3",",","p_val=0.3",")",">",">",">","#","print","(","clust.labels_",")","#","[","0","0","0","2","2","2","1","1","1","1","]"]
docstr: Refine the affinity matrix by zeroing less similar values.
  
  Arguments
  ---------
  A : array
      (n_samples, n_samples).
      Affinity matrix.
  pval : float
      p-value to be retained in each row of the affinity matrix.
  
  Returns
  -------
  A : array
      (n_samples, n_samples).
      pruned affinity matrix based on p_val.
docstr_tok: ["Refine","the","affinity","matrix","by","zeroing","less","similar","values",".","Arguments","--","--","--","--","-","A",":","array","(","n_samples",",","n_samples",")",".","Affinity","matrix",".","pval",":","float","p-value","to","be","retained","in","each","row","of","the","affinity","matrix",".","Returns","--","--","--","-","A",":","array","(","n_samples",",","n_samples",")",".","pruned","affinity","matrix","based","on","p_val","."]
code: def p_pruning(self, A, pval):
      """Refine the affinity matrix by zeroing less similar values.
  
      Arguments
      ---------
      A : array
          (n_samples, n_samples).
          Affinity matrix.
      pval : float
          p-value to be retained in each row of the affinity matrix.
  
      Returns
      -------
      A : array
          (n_samples, n_samples).
          pruned affinity matrix based on p_val.
      """
  
      n_elems = int((1 - pval) * A.shape[0])
  
      # For each row in a affinity matrix
      for i in range(A.shape[0]):
          low_indexes = np.argsort(A[i, :])
          low_indexes = low_indexes[0:n_elems]
  
          # Replace smaller similarity values by 0s
          A[i, low_indexes] = 0
  
      return A
  
imports: import csv
  import numbers
  import warnings
  import scipy
  import pytest
  import numpy
  from scipy import sparse
  from scipy.sparse.linalg import eigsh
  from scipy.sparse.csgraph import connected_components
  from scipy.sparse.csgraph import laplacian
label_desc: Use image node_id 4 for calling the Spec_Clust_unorm obj's underlying member method code with example usage: obj.p_pruning(A, pval) and returns: A