utils/clusterer.py
def add(self, value):
        """Add a new value to the cluster."""
        # Increment total values counter
        self.N += 1

        if self.contains(value):
            return

        # Add item to list and inc distinct value counter
        self.clusters.append([value, value])
        self.clusters.sort()
        self.R += 1

        # Merge clusters if necessary to maintain maximum C
        if len(self.clusters) > self.C:
            # Compute distances between each range (ignoring first wraparound)
            distances = [self.clusters[i][0] - self.clusters[i-1][1]
                         for i in range(len(self.clusters))][1:]
            minIndex = distances.index(min(distances))

            self.clusters[minIndex][1] = self.clusters[minIndex + 1][1]
            self.clusters.remove(self.clusters[minIndex + 1])
Add a new value to the cluster.
Add a new value to the cluster.
Add a new value to the cluster .
def add(self, value):
        self.N += 1
        if self.contains(value):
            return
        self.clusters.append([value, value])
        self.clusters.sort()
        self.R += 1
        if len(self.clusters) > self.C:
            distances = [self.clusters[i][0] - self.clusters[i-1][1]
                         for i in range(len(self.clusters))][1:]
            minIndex = distances.index(min(distances))
            self.clusters[minIndex][1] = self.clusters[minIndex + 1][1]
            self.clusters.remove(self.clusters[minIndex + 1])
def add ( self , value ) : self . N += 1 if self . contains ( value ) : return self . clusters . append ( [ value , value ] ) self . clusters . sort ( ) self . R += 1 if len ( self . clusters ) > self . C : distances = [ self . clusters [ i ] [ 0 ] - self . clusters [ i - 1 ] [ 1 ] for i in range ( len ( self . clusters ) ) ] [ 1 : ] minIndex = distances . index ( min ( distances ) ) self . clusters [ minIndex ] [ 1 ] = self . clusters [ minIndex + 1 ] [ 1 ] self . clusters . remove ( self . clusters [ minIndex + 1 ] )
Add a new value to the cluster.
Add a new value to the cluster .
"""Add a new value to the cluster.""" # Increment total values counter # Add item to list and inc distinct value counter # Merge clusters if necessary to maintain maximum C # Compute distances between each range (ignoring first wraparound)
self
value