<jupyter_start><jupyter_text>Demonstration of (generic) interfaces Go to:      - [Notebook configuration](interface_demo.ipynbNotebook-configuration)  Notebook configuration<jupyter_code>import sys

import numpy as np

import cnnclustering
from cnnclustering import cluster
from cnnclustering import _types, _fit<jupyter_output><empty_output><jupyter_text>Print Python and package version information:<jupyter_code># Version information
print("Python: ", *sys.version.split("\n"))

print("Packages:")
for package in [np, cnnclustering]:
    print(f"    {package.__name__}: {package.__version__}")<jupyter_output>Python:  3.8.8 (default, Mar 11 2021, 08:58:19)  [GCC 8.3.0]
Packages:
    numpy: 1.20.1
    cnnclustering: 0.4.3<jupyter_text>Labels `_types.Labels` is used to store cluster label assignments next to a *consider* indicator and meta information. It also provides a few transformational methods.Initialize `Labels` as  - `Labels(labels)`  - `Labels(labels, consider=consider)`  - `Labels(labels, consider=consider, meta=meta)`  - `Labels.from_sequence(labels_list, consider=consider_list, meta=meta)` Technically, `Labels` is not used as a generic class. A clustering, i.e. the assignments of cluster labels to points through a fitter (using a bunch of generic interfaces), uses an instance of `Labels` by directly modifying the underlying array of labels, a Cython memoryview that can be accessed from the C level as `Labels._labels`. `Labels.labels` provides a NumPy array view to `Labels._labels`.Examples:<jupyter_code># Requires labels to be initialised
labels = _types.Labels()
labels = _types.Labels(np.array([1, 1, 2, 2, 2, 0]))
labels
labels = _types.Labels.from_sequence([1, 1, 2, 2, 2, 0])
labels
print(labels)
labels.labels
labels.consider
labels.meta
labels.set
labels.mapping
labels.sort_by_size()
print(labels)<jupyter_output>[2 2 1 1 1 0]<jupyter_text>Cluster parameters An instance of `_types.ClusterParameters` is used during a clustering to pass around cluster parameters.Initialise `ClusterParameters` as:  - `ClusterParameters(radius_cutoff)`  - `ClusterParameters(radius_cutoff, similarity_cutoff)`  - ... `ClusterParameters` is a simple struct like class that offers collective access and passing of cluster parameters.Examples:<jupyter_code># Requires at least a radius
_types.ClusterParameters()
cluster_params = _types.ClusterParameters(1)
print(cluster_params)<jupyter_output>{'radius_cutoff': 1.0, 'similarity_cutoff': 0, 'similarity_cutoff_continuous': 0.0, 'n_member_cutoff': 0, 'current_start': 1}<jupyter_text>Input data Common-nearest-neighbours clustering can be done on data in a variety of different input formats with variations in the actual execution of the procedure. A typical case for example, would be to use the coordinates of a number of points in some feature space. These coordinates may be stored in a 2-dimensional (NumPy-)array but they could be also held in a database. Maybe instead of point coordinates, we can also begin the clustering with pre-computed pairwise distances between the points. The present implementation in the `cnnclustering` package is aimed to be generic and widely agnostic about the source of input data. This is achieved by wrapping the input data structure into an *input data* object that complies with a universal *input data interface*. The input data interface is on the Python level defined through the abstract base class `_types.InputData` and specialised through its abstract subclasses `InputDataComponents`, `InputDataPairwiseDistances`, `InputDataPairwiseComuter`, `InputDataNeighbourhoods`, and `InputDataNeighbourhoodsComputer`. Valid input data types inherit from one of these abstract types and provide concrete implementation for the required methods. On the Cython level, the input data interface is universally defined through `_types.InputDataExtInterface`. Realisations of the interface by Cython extension types inherit from `InputDataExtInterface` and should be registered as a concrete implementation of on of the Python abstract base classes. `InputData` objects should expose the following (typed) attributes:      - `data` (any): If applicable, a representation of the underlying data, preferably as NumPy array. Not strictly required for the clustering.  - `n_points` (`int`): The total number of points in the data set.  - `meta` (`dict`): A Python dictionary storing meta-information about the data. Used keys are for example:    - `"access_coords"`: Can point coordinates be retrieved from the input data (bool)?    - `"edges"`: If stored input data points are actually belonging to more than one data source, a list of integers can state the number of points per parts.      - (`InputData`) `get_subset(indices: Container)`: Return an instance of the same type holding only a subset of points (as given by indices). Used by `Clustering.isolate()`. `InputDataComponents` objects should expose the following additional attributes:  - `n_dim` (`int`): The total number of dimensions.  - (`float`) `get_component(point: int, dimension: int)`: Return one component of a point with respect to a given dimension.  - (`NumPy ndarray`) `to_components_array()`: Transform/return underlying data as a 2D NumPy array.   InputDataExtComponentsMemoryview Examples:<jupyter_code># Requires data to initialise
_types.InputDataExtComponentsMemoryview()
input_data = _types.InputDataExtComponentsMemoryview(np.random.random(size=(10, 3)))
print(input_data)
input_data.data
input_data.meta
input_data.n_points
input_data.n_dim<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08153347732181425, 'fraction_numerical': 0.010079193664506839, 'mean_word_length': 5.868974042027194, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '241094', 'license': 'MIT', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1478, 'n_words': 626, 'path': 'docsrc/_build/html/tutorial/interface_demo.ipynb', 'repo_name': 'janjoswig/CNN', 'size': '5556'}