Code Duplication    Length = 30-32 lines in 3 locations

pyclustering/cluster/kmedians.py 1 location

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

pyclustering/cluster/kmeans.py 1 location

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

pyclustering/cluster/kmedoids.py 1 location

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