corelay.processor.affinity
A module that contains processors for computing affinity, i.e., similarity, matrices for sets of measurements.
Classes
The abstract base class for processors that compute affinity (i.e., similarity) matrices. |
|
A processor for computing an affinity matrix using the Radial Basis Function (RBF) kernel. |
|
A processor for computing an affinity matrix using the sparse k-nearest neighbors (KNN) method. |
- class corelay.processor.affinity.Affinity[source]
Bases:
ProcessorThe 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
Affinityprocessor is the output of aPipeline. Defaults toFalse.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 thePipeline. Defaults to an instance ofNoStorage.
- __tracked__: collections.OrderedDict[str, Any]
An
collections.OrderedDictwith all public class attributes, i.e., all class attributes not enclosed with double underscores.
- class corelay.processor.affinity.SparseKNN[source]
Bases:
AffinityA processor for computing an affinity matrix using the sparse k-nearest neighbors (KNN) method.
- Parameters:
is_output (bool) – A value indicating whether this
SparseKNNaffinity processor is the output of aPipeline. Defaults toFalse.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 thePipeline. Defaults to an instance ofNoStorage.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 toTrue.
- n_neighbors: Annotated[int, Param]
A parameter for the number of neighbors to consider. Defaults to 10.
- symmetric: Annotated[bool, Param]
A parameter for whether to make the affinity matrix symmetric. Defaults to
True.
- function(data: Any) Any[source]
Compute Sparse K-Nearest-Neighbors affinity matrix.
- Parameters:
data (Any) – A NumPy array
ndarraycontaining the pairwise distances between samples, which is used to compute the affinity matrix.- Returns:
Returns a sparse CSR representation
csr_matrixof the KNN affinity matrix.- Return type:
- __tracked__: collections.OrderedDict[str, Any]
An
collections.OrderedDictwith all public class attributes, i.e., all class attributes not enclosed with double underscores.
- class corelay.processor.affinity.RadialBasisFunction[source]
Bases:
AffinityA processor for computing an affinity matrix using the Radial Basis Function (RBF) kernel.
- Parameters:
is_output (bool) – A value indicating whether this
RadialBasisFunctionaffinity processor is the output of aPipeline. Defaults toFalse.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 thePipeline. Defaults to an instance ofNoStorage.sigma (float) – The scale of the RBF kernel. Defaults to 1.0.
- __tracked__: collections.OrderedDict[str, Any]
An
collections.OrderedDictwith all public class attributes, i.e., all class attributes not enclosed with double underscores.
- function(data: Any) Any[source]
Compute Radial Basis Function affinity matrix.
- Parameters:
data (Any) – A NumPy array
ndarraycontaining 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
ndarraycontaining the RBF affinity matrix.- Return type: