Code Duplication    Length = 30-32 lines in 3 locations

pyclustering/cluster/kmedians.py 1 location

@@ 75-106 (lines=32) @@
72
        self.__ccore = ccore;
73
74
75
    def process(self):
76
        """!
77
        @brief Performs cluster analysis in line with rules of K-Medians algorithm.
78
        
79
        @remark Results of clustering can be obtained using corresponding get methods.
80
        
81
        @see get_clusters()
82
        @see get_medians()
83
        
84
        """
85
        
86
        if (self.__ccore is True):
87
            self.__clusters = wrapper.kmedians(self.__pointer_data, self.__medians, self.__tolerance);
88
            self.__medians = self.__update_medians();
89
            
90
        else:
91
            changes = float('inf');
92
             
93
            stop_condition = self.__tolerance * self.__tolerance;   # Fast solution
94
            #stop_condition = self.__tolerance;              # Slow solution
95
             
96
            # Check for dimension
97
            if (len(self.__pointer_data[0]) != len(self.__medians[0])):
98
                raise NameError('Dimension of the input data and dimension of the initial cluster medians must be equal.');
99
             
100
            while (changes > stop_condition):
101
                self.__clusters = self.__update_clusters();
102
                updated_centers = self.__update_medians();  # changes should be calculated before asignment
103
             
104
                changes = max([euclidean_distance_sqrt(self.__medians[index], updated_centers[index]) for index in range(len(updated_centers))]);    # Fast solution
105
                 
106
                self.__medians = updated_centers;
107
108
109
    def get_clusters(self):

pyclustering/cluster/kmeans.py 1 location

@@ 72-103 (lines=32) @@
69
        self.__ccore = ccore;
70
71
72
    def process(self):
73
        """!
74
        @brief Performs cluster analysis in line with rules of K-Means algorithm.
75
        
76
        @remark Results of clustering can be obtained using corresponding get methods.
77
        
78
        @see get_clusters()
79
        @see get_centers()
80
        
81
        """
82
        
83
        if (self.__ccore is True):
84
            self.__clusters = wrapper.kmeans(self.__pointer_data, self.__centers, self.__tolerance);
85
            self.__centers = self.__update_centers();
86
        else: 
87
            changes = float('inf');
88
             
89
            stop_condition = self.__tolerance * self.__tolerance;   # Fast solution
90
            #stop_condition = self.__tolerance;              # Slow solution
91
             
92
            # Check for dimension
93
            if (len(self.__pointer_data[0]) != len(self.__centers[0])):
94
                raise NameError('Dimension of the input data and dimension of the initial cluster centers must be equal.');
95
             
96
            while (changes > stop_condition):
97
                self.__clusters = self.__update_clusters();
98
                updated_centers = self.__update_centers();  # changes should be calculated before asignment
99
             
100
                #changes = max([euclidean_distance(self.__centers[index], updated_centers[index]) for index in range(len(self.__centers))]);        # Slow solution
101
                changes = max([euclidean_distance_sqrt(self.__centers[index], updated_centers[index]) for index in range(len(updated_centers))]);    # Fast solution
102
                 
103
                self.__centers = updated_centers;
104
105
106
    def get_clusters(self):

pyclustering/cluster/kmedoids.py 1 location

@@ 77-106 (lines=30) @@
74
        self.__ccore = ccore;
75
76
77
    def process(self):
78
        """!
79
        @brief Performs cluster analysis in line with rules of K-Medoids algorithm.
80
        
81
        @remark Results of clustering can be obtained using corresponding get methods.
82
        
83
        @see get_clusters()
84
        @see get_medoids()
85
        
86
        """
87
        
88
        if (self.__ccore is True):
89
            self.__clusters = wrapper.kmedoids(self.__pointer_data, self.__medoids, self.__tolerance);
90
            self.__medoids = self.__update_medoids();
91
        
92
        else:
93
            self.__medoids = [ self.__pointer_data[medoid_index] for medoid_index in self.__medoids ];
94
            
95
            changes = float('inf');
96
             
97
            stop_condition = self.__tolerance * self.__tolerance;   # Fast solution
98
            #stop_condition = self.__tolerance;              # Slow solution
99
             
100
            while (changes > stop_condition):
101
                self.__clusters = self.__update_clusters();
102
                updated_medoids = self.__update_medoids();  # changes should be calculated before asignment
103
             
104
                changes = max([euclidean_distance_sqrt(self.__medoids[index], updated_medoids[index]) for index in range(len(updated_medoids))]);    # Fast solution
105
                 
106
                self.__medoids = updated_medoids;
107
108
109
    def get_clusters(self):