_fit

This module provides a set of types that can be used as building blocks in the aggregation of a Clustering object.

Go to:

Fitter

class commonnn._fit.FitterExtInterface
fit(self, Bundle bundle, **kwargs) -> (float, Type['ClusterParameters'])
make_parameters(self, **kwargs) Type['ClusterParameters']
class commonnn._fit.FitterExtCommonNNInterface
fit(self, Bundle bundle, **kwargs) -> (float, Type['ClusterParameters'])
get_fit_signature(self)
make_parameters(self, **kwargs) Type['ClusterParameters']
class commonnn._fit.Fitter

Defines the fitter interface

abstract fit(self, Bundle bundle, **kwargs) -> (float, Type['ClusterParameters'])

Generic clustering outer function

abstract make_parameters(self, **kwargs) Type['ClusterParameters']

Create fitter specific cluster parameters

class commonnn._fit.FitterCommonNN

Further differentiates the fitter interface for CommonNN clusterings

fit(self, Bundle bundle, *, purge=True, info=True, **kwargs) -> (float, Type['ClusterParameters'])
get_fit_signature(self)
make_parameters(self, similarity_offset=0, original=False, **kwargs) Type['ClusterParameters']
class commonnn._fit.FitterExtCommonNNBFS

Concrete implementation of the fitter interface

Realises a CommonNN clustering using a breadth-first-search

Parameters:
  • neighbours_getter – Any extension type implementing the neighbours getter interface.

  • neighbours – Any extension type implementing the neighbours interface.

  • neighbour_neighbourss – Any extension type implementing the neighbours interface.

  • similarity_checker – Any extension type implementing the similarity checker interface.

  • queue – Any extension type implementing the queue interface. Used during the clustering procedure.

classmethod get_builder_kwargs(cls)
class commonnn._fit.FitterCommonNNBFS(neighbours_getter: Type['NeighboursGetter'], neighbours: Type['Neighbours'], neighbour_neighbours: Type['Neighbours'], similarity_checker: Type['SimilarityChecker'], queue: Type['Queue'])

Concrete implementation of the fitter interface

Parameters:
  • neighbours_getter – Any object implementing the neighbours getter interface.

  • neighbours – Any object implementing the neighbours interface.

  • neighbour_neighbourss – Any object implementing the neighbours interface.

  • similarity_checker – Any object implementing the similarity checker interface.

  • queue – Any object implementing the queue interface.

classmethod get_builder_kwargs(cls)
class commonnn._fit.FitterCommonNNBFSDebug(neighbours_getter: Type['NeighboursGetter'], neighbours: Type['Neighbours'], neighbour_neighbours: Type['Neighbours'], similarity_checker: Type['SimilarityChecker'], queue: Type['Queue'], verbose=True, yielding=True)

Concrete implementation of the fitter interface

Yields/prints information during the clustering.

Parameters:
  • neighbours_getter – Any extension type implementing the neighbours getter interface.

  • neighbours – Any extension type implementing the neighbours interface.

  • neighbour_neighbourss – Any extension type implementing the neighbours interface.

  • similarity_checker – Any extension type implementing the similarity checker interface.

  • queue – Any extension type implementing the queue interface. Used during the clustering procedure.

classmethod get_builder_kwargs(cls)

Hierarchical fitter

class commonnn._fit.HierarchicalFitter

Defines the hierarchical fitter interface

abstract fit(self, Bundle bundle, **kwargs) None

Generic clustering

class commonnn._fit.HierarchicalFitterCommonNNMSTPrim(neighbours_getter: Type['NeighboursGetter'], neighbours: Type['Neighbours'], neighbour_neighbours: Type['Neighbours'], similarity_checker: Type['SimilarityChecker'], priority_queue: Type['PriorityQueue'], priority_queue_tree: Type['PriorityQueue'])

Concrete implementation of the hierarchical fitter interface

Builds a minimum spanning tree on the density estimate using Prim’s algorithm and creates a cluster hierarchy via single linkage clustering.

Note

This is still experimental.

fit(self, Bundle bundle, *, info=True, member_cutoff=10, scipy_hierarchy=True, bundle_hierarchy=True, make_labels=True, **kwargs) None

Orchestrates hierarchical clustering

Parameters:
  • bundle – Bundle object containing the input data and labels.

  • info – If True, store the parameters in the labels meta dictionary.

  • member_cutoff – Minimum number of members for clusters to be considered valid. Only considered for hierarchy building if bundle_hierarchy=True.

  • scipy_hierarchy – If True, build a SciPy-compatible linkage hierarchy Z-matrix from MST edges that will be put into _artifacts["Z"].

  • bundle_hierarchy – If True, build a bundle hierarchy from the MST edges or (if present) a previously computed Scipy Z-matrix. Note that currently, we only recommend the latter option for which scipy_hierarchy=True is required.

  • make_labels – If True, create root labels from all leaf nodes after a bundle hierarchy has been built (bundle_hierarchy=True).

classmethod get_builder_kwargs(cls)
make_parameters(self, **kwargs) Type['ClusterParameters']
scipy_to_bundle_hierarchy(self, Bundle bundle, *, AVALUE[:, ::1] Z, AINDEX member_cutoff=10) None

Build a hierarchy of bundles from a SciPy-compatible linkage matrix Z

Parameters:
  • bundle – Root bundle

  • Z – SciPy-compatible linkage matrix

Keyword Arguments:

member_cutoff – Minimum number of members in a bundle to consider it as independent cluster. Clusters with fewer members are merged into their parent cluster or respectively split off as noise.

class commonnn._fit.HierarchicalFitterRepeat(fitter: Type['Fitter'])
fit(self, Bundle bundle, *, radius_cutoffs, similarity_cutoffs, sort_by_size=True, member_cutoff=None, max_clusters=None, info=True, **kwargs) None
classmethod get_builder_kwargs(cls)

Predictor

class commonnn._fit.Predictor

Defines the predictor interface

abstract make_parameters(self, **kwargs) Type['ClusterParameters']

Create fitter specific cluster parameters

abstract predict(self, Bundle bundle, Bundle other, **kwargs)

Generic prediction

class commonnn._fit.PredictorCommonNN
get_fit_signature(self)
make_parameters(self, **kwargs) Type['ClusterParameters']
predict(self, Bundle bundle, Bundle other, *, clusters=None, purge=True, info=True, **kwargs)
class commonnn._fit.PredictorCommonNNFirstmatch(neighbours_getter: Type['NeighboursGetter'], neighbours_getter_other: Type['NeighboursGetter'], neighbours: Type['Neighbours'], neighbour_neighbours: Type['Neighbours'], similarity_checker: Type['SimilarityChecker'])
classmethod get_builder_kwargs(cls)