corelay.pipeline.spectral

A module that contains Pipeline implementations for spectral embeddings, SpectralEmbedding, and spectral clustering, SpectralClustering. These are specific to Spectral Relevance Analysis (SprAy), an explainable artificial intelligence (XAI) method for bridging the gap between local and global XAI.

Classes

SpectralClustering

A pipeline for spectral clustering a spectral embedding, which is customizable with a custom clustering function.

SpectralEmbedding

A pipeline for spectral embeddings, which is customizable with different pre-processing, pairwise distance, affinity, laplacian, and embedding functions.

class corelay.pipeline.spectral.SpectralEmbedding[source]

Bases: Pipeline

A pipeline for spectral embeddings, which is customizable with different pre-processing, pairwise distance, affinity, laplacian, and embedding functions. When an instance of the pipeline is called, it will return eigenvalues and eigenvectors of the spectral embedding, as instances of ndarray.

Parameters:
  • preprocessing (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom pre-processing function to be applied to the data before computing the pairwise distance. Defaults to the identity function.

  • pairwise_distance (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A pairwise distance function to be applied to the data. Defaults to the euclidean distance.

  • affinity (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom affinity function to be applied to the pairwise distance matrix. Defaults to a sparse k-nearest neighbors graph with 10 neighbors.

  • laplacian (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom graph laplacian function to be applied to the affinity matrix. Defaults to a symmetric normal laplacian.

  • embedding (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom embedding function to be applied to the graph laplacian. Defaults to an eigen-decomposition with 32 eigenvalues.

Notes

Pre-computed distance matrices can be supplied by passing pairwise_distance=lambda x: x. Pre-computed affinity matrices can be supplied by additionally passing affinity=lambda x: x. Pre-computed graph laplacian matrices can be supplied by further passing laplacian=lambda x: x.

preprocessing: Annotated[Processor, Task]

A pre-processing task to be applied to the data before computing the pairwise distance task. Defaults to the identity function.

Parameters:
Return type:

TaskPlug

pairwise_distance: Annotated[Processor, Task]

A pairwise distance task to be applied to the data. Defaults to the euclidean distance.

Parameters:
Return type:

TaskPlug

affinity: Annotated[Processor, Task]

An affinity task to be applied to the pairwise distance matrix. Defaults to a sparse k-nearest neighbors graph with 10 neighbors.

Parameters:
Return type:

TaskPlug

laplacian: Annotated[Processor, Task]

A graph laplacian task to be applied to the affinity matrix. Defaults to a symmetric normal laplacian.

Parameters:
Return type:

TaskPlug

__tracked__: collections.OrderedDict[str, Any]

An collections.OrderedDict with all public class attributes, i.e., all class attributes not enclosed with double underscores.

embedding: Annotated[Processor, Task]

An embedding task to be applied to the graph laplacian matrix. Defaults to an eigen decomposition with 32 eigenvalues.

Parameters:
Return type:

TaskPlug

class corelay.pipeline.spectral.SpectralClustering[source]

Bases: SpectralEmbedding

A pipeline for spectral clustering a spectral embedding, which is customizable with a custom clustering function. When an instance of the pipeline is called, it will return eigenvalues and eigenvectors of the spectral embedding, and the labels of the spectral clustering, as NumPy arrays.

Parameters:
  • preprocessing (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom pre-processing function to be applied to the data before computing the pairwise distance. Defaults to the identity function.

  • pairwise_distance (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom pairwise distance function to be applied to the data. Defaults to the euclidean distance.

  • affinity (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom affinity function to be applied to the pairwise distance matrix. Defaults to a sparse k-nearest neighbors graph with 10 neighbors.

  • laplacian (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom graph laplacian function to be applied to the affinity matrix. Defaults to a symmetric normal laplacian.

  • embedding (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom embedding function to be applied to the graph laplacian. Defaults to an eigen decomposition with 32 eigenvalues.

  • select_eigenvector (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom task to select the eigenvectors from the output of the spectral embedding. Defaults to the second output of the spectral embedding.

  • clustering (Processor | Callable[[numpy.ndarray[Any, Any]], Any]) – A custom clustering function to be applied to the spectral embedding. Defaults to a k-Means clustering with 2 clusters.

__tracked__: collections.OrderedDict[str, Any]

An collections.OrderedDict with all public class attributes, i.e., all class attributes not enclosed with double underscores.

select_eigenvector: Annotated[Processor, Task]

A task to select the eigenvector from the spectral embedding. Defaults to the second output of the spectral embedding.

Parameters:
Return type:

TaskPlug

clustering: Annotated[Processor, Task]

A clustering task to be applied to the spectral embedding. Defaults to a k-Means clustering with 2 clusters.

Parameters:
Return type:

TaskPlug