<commit_before># -*- coding: utf-8 -*-

"""Clustering structure."""

#------------------------------------------------------------------------------
# Imports
#------------------------------------------------------------------------------

import numpy as np

from ..ext import six


#------------------------------------------------------------------------------
# Clustering class
#------------------------------------------------------------------------------<commit_msg>WIP: clustering class.<commit_after># -*- coding: utf-8 -*-

"""Clustering structure."""

#------------------------------------------------------------------------------
# Imports
#------------------------------------------------------------------------------

import numpy as np

from ..ext import six


#------------------------------------------------------------------------------
# Clustering class
#------------------------------------------------------------------------------

class Clustering(object):
    """Object representing a mapping from spike to cluster labels."""

    def __init__(self, spike_clusters=None):
        self._cluster_counts = None
        self._cluster_labels = None
        self._spike_clusters = spike_clusters
        if spike_clusters is not None:
            self.update()

    def update(self):
        """Update the cluster counts and labels."""
        if self._spike_clusters is not None:
            self._cluster_counts = np.bincount(self._spike_clusters)
            self._cluster_labels = np.nonzero(self._cluster_counts)[0]

    @property
    def spike_clusters(self):
        """Mapping spike to cluster labels."""
        return self._spike_clusters

    @spike_clusters.setter
    def spike_clusters(self, value):
        self._spike_clusters = value
        self.update()

    @property
    def cluster_labels(self):
        """Labels of all clusters, sorted by label."""
        return self._cluster_labels

    @cluster_labels.setter
    def cluster_labels(self, value):
        raise NotImplementedError("Relabeling clusters has not been "
                                  "implemented yet.")

    def new_cluster_label(self):
        """Return a new cluster label."""
        return np.max(self._cluster_labels) + 1

    @property
    def n_clusters(self):
        """Number of different clusters."""
        return len(self._cluster_labels)

    def merge(cluster_labels, to=None):
        """Merge several clusters to a new cluster."""
        raise NotImplementedError("Merging has not been implemented yet.")

    def split(spike_labels, to=None):
        """Split a number of spikes into a new cluster."""
        raise NotImplementedError("Splitting has not been implemented yet.")
{'fraction_non_alphanumeric': 0.31038291605301915, 'fraction_numerical': 0.0014727540500736377, 'mean_word_length': 1.2774518021793797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4710156', 'n_tokens_mistral': 616, 'n_tokens_neox': 586, 'n_words': 173}