@@ 90-120 (lines=31) @@ | ||
87 | self.__ccore = ccore_library.workable() |
|
88 | ||
89 | ||
90 | def process(self): |
|
91 | """! |
|
92 | @brief Performs cluster analysis in line with rules of K-Medians algorithm. |
|
93 | ||
94 | @remark Results of clustering can be obtained using corresponding get methods. |
|
95 | ||
96 | @see get_clusters() |
|
97 | @see get_medians() |
|
98 | ||
99 | """ |
|
100 | ||
101 | if self.__ccore is True: |
|
102 | ccore_metric = metric_wrapper.create_instance(self.__metric) |
|
103 | ||
104 | self.__clusters = wrapper.kmedians(self.__pointer_data, self.__medians, self.__tolerance, ccore_metric.get_pointer()) |
|
105 | self.__medians = self.__update_medians() |
|
106 | ||
107 | else: |
|
108 | changes = float('inf') |
|
109 | ||
110 | # Check for dimension |
|
111 | if len(self.__pointer_data[0]) != len(self.__medians[0]): |
|
112 | raise NameError('Dimension of the input data and dimension of the initial medians must be equal.') |
|
113 | ||
114 | while changes > self.__tolerance: |
|
115 | self.__clusters = self.__update_clusters() |
|
116 | updated_centers = self.__update_medians() |
|
117 | ||
118 | changes = max([self.__metric(self.__medians[index], updated_centers[index]) for index in range(len(updated_centers))]) |
|
119 | ||
120 | self.__medians = updated_centers |
|
121 | ||
122 | ||
123 | def get_clusters(self): |
@@ 133-161 (lines=29) @@ | ||
130 | self.__ccore = ccore_library.workable() |
|
131 | ||
132 | ||
133 | def process(self): |
|
134 | """! |
|
135 | @brief Performs cluster analysis in line with rules of K-Medoids algorithm. |
|
136 | ||
137 | @remark Results of clustering can be obtained using corresponding get methods. |
|
138 | ||
139 | @see get_clusters() |
|
140 | @see get_medoids() |
|
141 | ||
142 | """ |
|
143 | ||
144 | if self.__ccore is True: |
|
145 | ccore_metric = metric_wrapper.create_instance(self.__metric) |
|
146 | ||
147 | self.__clusters = wrapper.kmedoids(self.__pointer_data, self.__medoid_indexes, self.__tolerance, ccore_metric.get_pointer(), self.__data_type) |
|
148 | self.__medoid_indexes = self.__update_medoids() |
|
149 | ||
150 | else: |
|
151 | changes = float('inf') |
|
152 | ||
153 | stop_condition = self.__tolerance |
|
154 | ||
155 | while changes > stop_condition: |
|
156 | self.__clusters = self.__update_clusters() |
|
157 | update_medoid_indexes = self.__update_medoids() |
|
158 | ||
159 | changes = max([self.__distance_calculator(self.__medoid_indexes[index], update_medoid_indexes[index]) for index in range(len(update_medoid_indexes))]) |
|
160 | ||
161 | self.__medoid_indexes = update_medoid_indexes |
|
162 | ||
163 | ||
164 | def get_clusters(self): |