clustering#

class sparx.clustering.AgglomerativeClusterer#

Bases: Clusterer

Agglomerative clustering algorithm.

static cluster_layer(num_clusters: int, data: ndarray, seed: Optional[int] = None) ndarray#

Clusters the given layer

Parameters:
  • num_clusters (int) – the number of clusters to create

  • data (np.ndarray) – the data to cluster from each layer

  • seed (Optional[int], optional) – the seed to use to cluster the current layer, defaults to None

Raises:

NotImplementedError

Returns:

the label for that layer

Return type:

np.ndarray

class sparx.clustering.Clusterer#

Bases: object

Abstract class for clustering algorithms.

classmethod cluster(mlp: FFNN, shrink_to_percentage: float, seed: Optional[int] = None) list[numpy.ndarray]#

Clusters the given model

Parameters:
  • mlp (FFNN) – the mlp model to be clustered

  • shrink_to_percentage (float) – the percentatge of the original size to shrink to

  • seed (Optional[int], optional) – the seed to use for the clustering algorithm, defaults to None

Returns:

a list of labels for each layer of the network

Return type:

list[np.ndarray]

abstract static cluster_layer(num_clusters: int, data: ndarray, seed: Optional[int] = None) ndarray#

Clusters the given layer

Parameters:
  • num_clusters (int) – the number of clusters to create

  • data (np.ndarray) – the data to cluster from each layer

  • seed (Optional[int], optional) – the seed to use to cluster the current layer, defaults to None

Raises:

NotImplementedError

Returns:

the label for that layer

Return type:

np.ndarray

class sparx.clustering.KMeansClusterer#

Bases: Clusterer

KMeans clustering algorithm.

static cluster_layer(num_clusters: int, data: ndarray, seed: Optional[int] = None) ndarray#

Clusters the given layer

Parameters:
  • num_clusters (int) – the number of clusters to create

  • data (np.ndarray) – the data to cluster from each layer

  • seed (Optional[int], optional) – the seed to use to cluster the current layer, defaults to None

Raises:

NotImplementedError

Returns:

the label for that layer

Return type:

np.ndarray