Code Duplication    Length = 27-34 lines in 4 locations

pyclustering/cluster/kmedians.py 1 location

@@ 129-155 (lines=27) @@
126
        return self.__medians;
127
128
129
    def __update_clusters(self):
130
        """!
131
        @brief Calculate Manhattan distance to each point from the each cluster. 
132
        @details Nearest points are captured by according clusters and as a result clusters are updated.
133
        
134
        @return (list) updated clusters as list of clusters where each cluster contains indexes of objects from data.
135
        
136
        """
137
        
138
        clusters = [[] for i in range(len(self.__medians))];
139
        for index_point in range(len(self.__pointer_data)):
140
            index_optim = -1;
141
            dist_optim = 0.0;
142
             
143
            for index in range(len(self.__medians)):
144
                dist = euclidean_distance_sqrt(self.__pointer_data[index_point], self.__medians[index]);
145
                 
146
                if ( (dist < dist_optim) or (index is 0)):
147
                    index_optim = index;
148
                    dist_optim = dist;
149
             
150
            clusters[index_optim].append(index_point);
151
            
152
        # If cluster is not able to capture object it should be removed
153
        clusters = [cluster for cluster in clusters if len(cluster) > 0];
154
        
155
        return clusters;
156
    
157
    
158
    def __update_medians(self):

pyclustering/cluster/xmeans.py 1 location

@@ 361-394 (lines=34) @@
358
        return sum(scores);
359
 
360
 
361
    def __update_clusters(self, centers, available_indexes = None):
362
        """!
363
        @brief Calculates Euclidean distance to each point from the each cluster.
364
               Nearest points are captured by according clusters and as a result clusters are updated.
365
               
366
        @param[in] centers (list): Coordinates of centers of clusters that are represented by list: [center1, center2, ...].
367
        @param[in] available_indexes (list): Indexes that defines which points can be used from imput data, if None - then all points are used.
368
        
369
        @return (list) Updated clusters.
370
        
371
        """
372
            
373
        bypass = None;
374
        if (available_indexes is None):
375
            bypass = range(len(self.__pointer_data));
376
        else:
377
            bypass = available_indexes;
378
          
379
        clusters = [[] for i in range(len(centers))];
380
        for index_point in bypass:
381
            index_optim = -1;
382
            dist_optim = 0.0;
383
              
384
            for index in range(len(centers)):
385
                # dist = euclidean_distance(data[index_point], centers[index]);         # Slow solution
386
                dist = euclidean_distance_sqrt(self.__pointer_data[index_point], centers[index]);      # Fast solution
387
                  
388
                if ( (dist < dist_optim) or (index is 0)):
389
                    index_optim = index;
390
                    dist_optim = dist;
391
              
392
            clusters[index_optim].append(index_point);
393
              
394
        return clusters;
395
             
396
     
397
    def __update_centers(self, clusters):

pyclustering/cluster/kmeans.py 1 location

@@ 126-152 (lines=27) @@
123
        return self.__centers;
124
125
126
    def __update_clusters(self):
127
        """!
128
        @brief Calculate Euclidean distance to each point from the each cluster. Nearest points are captured by according clusters and as a result clusters are updated.
129
        
130
        @return (list) updated clusters as list of clusters. Each cluster contains indexes of objects from data.
131
        
132
        """
133
        
134
        clusters = [[] for i in range(len(self.__centers))];
135
        for index_point in range(len(self.__pointer_data)):
136
            index_optim = -1;
137
            dist_optim = 0.0;
138
             
139
            for index in range(len(self.__centers)):
140
                # dist = euclidean_distance(data[index_point], centers[index]);         # Slow solution
141
                dist = euclidean_distance_sqrt(self.__pointer_data[index_point], self.__centers[index]);      # Fast solution
142
                 
143
                if ( (dist < dist_optim) or (index is 0)):
144
                    index_optim = index;
145
                    dist_optim = dist;
146
             
147
            clusters[index_optim].append(index_point);
148
        
149
        # If cluster is not able to capture object it should be removed
150
        clusters = [cluster for cluster in clusters if len(cluster) > 0];
151
        
152
        return clusters;
153
    
154
    
155
    def __update_centers(self):

pyclustering/cluster/kmedoids.py 1 location

@@ 123-149 (lines=27) @@
120
        return self.__medoids;
121
122
123
    def __update_clusters(self):
124
        """!
125
        @brief Calculate distance to each point from the each cluster. 
126
        @details Nearest points are captured by according clusters and as a result clusters are updated.
127
        
128
        @return (list) updated clusters as list of clusters where each cluster contains indexes of objects from data.
129
        
130
        """
131
        
132
        clusters = [[] for i in range(len(self.__medoids))];
133
        for index_point in range(len(self.__pointer_data)):
134
            index_optim = -1;
135
            dist_optim = 0.0;
136
             
137
            for index in range(len(self.__medoids)):
138
                dist = euclidean_distance_sqrt(self.__pointer_data[index_point], self.__medoids[index]);
139
                 
140
                if ( (dist < dist_optim) or (index is 0)):
141
                    index_optim = index;
142
                    dist_optim = dist;
143
             
144
            clusters[index_optim].append(index_point);
145
        
146
        # If cluster is not able to capture object it should be removed
147
        clusters = [cluster for cluster in clusters if len(cluster) > 0];
148
        
149
        return clusters;
150
    
151
    
152
    def __update_medoids(self):