| @@ 397-418 (lines=22) @@ | ||
| 394 | @return (list) Updated clusters. |
|
| 395 | ||
| 396 | """ |
|
| 397 | ||
| 398 | bypass = None; |
|
| 399 | if (available_indexes is None): |
|
| 400 | bypass = range(len(self.__pointer_data)); |
|
| 401 | else: |
|
| 402 | bypass = available_indexes; |
|
| 403 | ||
| 404 | clusters = [[] for i in range(len(centers))]; |
|
| 405 | for index_point in bypass: |
|
| 406 | index_optim = -1; |
|
| 407 | dist_optim = 0.0; |
|
| 408 | ||
| 409 | for index in range(len(centers)): |
|
| 410 | # dist = euclidean_distance(data[index_point], centers[index]); # Slow solution |
|
| 411 | dist = euclidean_distance_sqrt(self.__pointer_data[index_point], centers[index]); # Fast solution |
|
| 412 | ||
| 413 | if ( (dist < dist_optim) or (index is 0)): |
|
| 414 | index_optim = index; |
|
| 415 | dist_optim = dist; |
|
| 416 | ||
| 417 | clusters[index_optim].append(index_point); |
|
| 418 | ||
| 419 | return clusters; |
|
| 420 | ||
| 421 | ||
| @@ 155-173 (lines=19) @@ | ||
| 152 | for index_point in range(len(self.__pointer_data)): |
|
| 153 | index_optim = -1; |
|
| 154 | dist_optim = 0.0; |
|
| 155 | ||
| 156 | for index in range(len(self.__centers)): |
|
| 157 | # dist = euclidean_distance(data[index_point], centers[index]); # Slow solution |
|
| 158 | dist = euclidean_distance_sqrt(self.__pointer_data[index_point], self.__centers[index]); # Fast solution |
|
| 159 | ||
| 160 | if ( (dist < dist_optim) or (index is 0)): |
|
| 161 | index_optim = index; |
|
| 162 | dist_optim = dist; |
|
| 163 | ||
| 164 | clusters[index_optim].append(index_point); |
|
| 165 | ||
| 166 | # If cluster is not able to capture object it should be removed |
|
| 167 | clusters = [cluster for cluster in clusters if len(cluster) > 0]; |
|
| 168 | ||
| 169 | return clusters; |
|
| 170 | ||
| 171 | ||
| 172 | def __update_centers(self): |
|
| 173 | """! |
|
| 174 | @brief Calculate centers of clusters in line with contained objects. |
|
| 175 | ||
| 176 | @return (list) Updated centers as list of centers. |
|