Code Duplication    Length = 19-22 lines in 2 locations

pyclustering/cluster/xmeans.py 1 location

@@ 397-418 (lines=22) @@
394
            p = (K - 1) + dimension * K + 1;
395
            
396
            # splitting criterion    
397
            for index_cluster in range(0, len(clusters), 1):
398
                n = len(clusters[index_cluster]);
399
                
400
                L = n * log(n) - n * log(N) - n * 0.5 * log(2.0 * numpy.pi) - n * dimension * 0.5 * log(sigma_sqrt) - (n - K) * 0.5;
401
                
402
                # BIC calculation
403
                scores[index_cluster] = L - p * 0.5 * log(N);
404
                
405
        return sum(scores);
406
 
407
 
408
    def __update_clusters(self, centers, available_indexes = None):
409
        """!
410
        @brief Calculates Euclidean distance to each point from the each cluster.
411
               Nearest points are captured by according clusters and as a result clusters are updated.
412
               
413
        @param[in] centers (list): Coordinates of centers of clusters that are represented by list: [center1, center2, ...].
414
        @param[in] available_indexes (list): Indexes that defines which points can be used from imput data, if None - then all points are used.
415
        
416
        @return (list) Updated clusters.
417
        
418
        """
419
            
420
        bypass = None;
421
        if (available_indexes is None):

pyclustering/cluster/kmeans.py 1 location

@@ 155-173 (lines=19) @@
152
        for index_point in range(len(self.__pointer_data)):
153
            index_optim = -1;
154
            dist_optim = 0.0;
155
             
156
            for index in range(len(self.__centers)):
157
                # dist = euclidean_distance(data[index_point], centers[index]);         # Slow solution
158
                dist = euclidean_distance_sqrt(self.__pointer_data[index_point], self.__centers[index]);      # Fast solution
159
                 
160
                if ( (dist < dist_optim) or (index is 0)):
161
                    index_optim = index;
162
                    dist_optim = dist;
163
             
164
            clusters[index_optim].append(index_point);
165
        
166
        # If cluster is not able to capture object it should be removed
167
        clusters = [cluster for cluster in clusters if len(cluster) > 0];
168
        
169
        return clusters;
170
    
171
    
172
    def __update_centers(self):
173
        """!
174
        @brief Calculate centers of clusters in line with contained objects.
175
        
176
        @return (list) Updated centers as list of centers.