corelay.processor.affinity

A module that contains processors for computing affinity, i.e., similarity, matrices for sets of measurements.

Classes

Affinity

The abstract base class for processors that compute affinity (i.e., similarity) matrices.

RadialBasisFunction

A processor for computing an affinity matrix using the Radial Basis Function (RBF) kernel.

SparseKNN

A processor for computing an affinity matrix using the sparse k-nearest neighbors (KNN) method.

class corelay.processor.affinity.Affinity[source]

Bases: Processor

The abstract base class for processors that compute affinity (i.e., similarity) matrices.

Note

Each sub-class has to implement a Processor.__call__ method to compute its corresponding affinity matrix of some data.

Parameters:
  • is_output (bool) – A value indicating whether this Affinity processor is the output of a Pipeline. Defaults to False.

  • is_checkpoint (bool | None) – A value indicating whether check-pointed pipeline computations should start at this point, if there exists a previously computed checkpoint value. Defaults to False.

  • io (Storable | None) – An IO object that is used to cache intermediate results of the Pipeline, which can then be re-used in this run or in subsequent runs of the Pipeline. Defaults to an instance of NoStorage.

__tracked__: collections.OrderedDict[str, Any]

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

class corelay.processor.affinity.SparseKNN[source]

Bases: Affinity

A processor for computing an affinity matrix using the sparse k-nearest neighbors (KNN) method.

Parameters:
  • is_output (bool) – A value indicating whether this SparseKNN affinity processor is the output of a Pipeline. Defaults to False.

  • is_checkpoint (bool | None) – A value indicating whether check-pointed pipeline computations should start at this point, if there exists a previously computed checkpoint value. Defaults to False.

  • io (Storable | None) – An IO object that is used to cache intermediate results of the Pipeline, which can then be re-used in this run or in subsequent runs of the Pipeline. Defaults to an instance of NoStorage.

  • n_neighbors (int) – Number of neighbors to consider. Defaults to 10.

  • symmetric (bool) – If True, the affinity matrix is set to the mean of itself and its transpose. Defaults to True.

n_neighbors: Annotated[int, Param]

A parameter for the number of neighbors to consider. Defaults to 10.

Parameters:
Return type:

Plug

symmetric: Annotated[bool, Param]

A parameter for whether to make the affinity matrix symmetric. Defaults to True.

Parameters:
Return type:

Plug

function(data: Any) Any[source]

Compute Sparse K-Nearest-Neighbors affinity matrix.

Parameters:

data (Any) – A NumPy array ndarray containing the pairwise distances between samples, which is used to compute the affinity matrix.

Returns:

Returns a sparse CSR representation csr_matrix of the KNN affinity matrix.

Return type:

Any

__tracked__: collections.OrderedDict[str, Any]

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

class corelay.processor.affinity.RadialBasisFunction[source]

Bases: Affinity

A processor for computing an affinity matrix using the Radial Basis Function (RBF) kernel.

Parameters:
  • is_output (bool) – A value indicating whether this RadialBasisFunction affinity processor is the output of a Pipeline. Defaults to False.

  • is_checkpoint (bool | None) – A value indicating whether check-pointed pipeline computations should start at this point, if there exists a previously computed checkpoint value. Defaults to False.

  • io (Storable | None) – An IO object that is used to cache intermediate results of the Pipeline, which can then be re-used in this run or in subsequent runs of the Pipeline. Defaults to an instance of NoStorage.

  • sigma (float) – The scale of the RBF kernel. Defaults to 1.0.

__tracked__: collections.OrderedDict[str, Any]

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

sigma: Annotated[float, Param]

A parameter for the scale of the RBF kernel. Defaults to 1.0.

Parameters:
Return type:

Plug

function(data: Any) Any[source]

Compute Radial Basis Function affinity matrix.

Parameters:

data (Any) – A NumPy array ndarray containing the pairwise distances between samples, which is used to compute the affinity matrix. The data is expected to be a square matrix of shape (number_of_samples, number_of_samples).

Returns:

Returns a NumPy array ndarray containing the RBF affinity matrix.

Return type:

Any