Code Duplication    Length = 27-27 lines in 2 locations

pyclustering/cluster/kmedoids.py 1 location

@@ 221-247 (lines=27) @@
218
            raise TypeError("Unknown type of data is specified '%s'" % self.__data_type)
219
220
221
    def __update_clusters(self):
222
        """!
223
        @brief Calculate distance to each point from the each cluster. 
224
        @details Nearest points are captured by according clusters and as a result clusters are updated.
225
        
226
        @return (list) updated clusters as list of clusters where each cluster contains indexes of objects from data.
227
        
228
        """
229
        
230
        clusters = [[self.__medoid_indexes[i]] for i in range(len(self.__medoid_indexes))]
231
        for index_point in range(len(self.__pointer_data)):
232
            if index_point in self.__medoid_indexes:
233
                continue
234
235
            index_optim = -1
236
            dist_optim = float('Inf')
237
            
238
            for index in range(len(self.__medoid_indexes)):
239
                dist = self.__distance_calculator(index_point, self.__medoid_indexes[index])
240
                
241
                if dist < dist_optim:
242
                    index_optim = index
243
                    dist_optim = dist
244
            
245
            clusters[index_optim].append(index_point)
246
        
247
        return clusters
248
    
249
    
250
    def __update_medoids(self):

pyclustering/cluster/kmedians.py 1 location

@@ 160-186 (lines=27) @@
157
        return type_encoding.CLUSTER_INDEX_LIST_SEPARATION
158
159
160
    def __update_clusters(self):
161
        """!
162
        @brief Calculate Manhattan distance to each point from the each cluster. 
163
        @details Nearest points are captured by according clusters and as a result clusters are updated.
164
        
165
        @return (list) updated clusters as list of clusters where each cluster contains indexes of objects from data.
166
        
167
        """
168
        
169
        clusters = [[] for i in range(len(self.__medians))]
170
        for index_point in range(len(self.__pointer_data)):
171
            index_optim = -1
172
            dist_optim = 0.0
173
             
174
            for index in range(len(self.__medians)):
175
                dist = self.__metric(self.__pointer_data[index_point], self.__medians[index])
176
                 
177
                if (dist < dist_optim) or (index is 0):
178
                    index_optim = index
179
                    dist_optim = dist
180
             
181
            clusters[index_optim].append(index_point)
182
            
183
        # If cluster is not able to capture object it should be removed
184
        clusters = [cluster for cluster in clusters if len(cluster) > 0]
185
        
186
        return clusters
187
    
188
    
189
    def __update_medians(self):