annoviko / annoviko/pyclustering
Kmedians ccore implementation, calculate_median simple bug
- Langage dominant
- Python
- Étoiles
- 1.2k
- Forks
- 262
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Should a new version of pyclustering be released in the future. I would like to report a bug on the component-wise median calculation of the ccore implementation of KMedians in kmedians.cpp, which is inconsistent with the Python implementation. The issue is that the ccore flag is by default set to True, so the ccore implementation is used by default.
In lines 150-154, the sort is a lexicographical sort, instead of sorting on a dimension basis for component-wise median calculation.
https://github.com/annoviko/pyclustering/blob/906532e4a5422479cc6813e852f9c3cb48ea7a64/ccore/src/cluster/kmedians.cpp#L149-L154
Simple proposed fix
for (size_t index_dimension = 0; index_dimension < dimension; index_dimension++) {
std::sort(current_cluster.begin(), current_cluster.end(),
[this, &index_dimension](std::size_t index_object1, std::size_t index_object2)
{
return (*m_ptr_data)[index_object1][index_dimension] > (*m_ptr_data)[index_object2][index_dimension];
});
...
Minimum reproducible code
_median1_ is the ccore implementation output, and _median2_ is the python implementation output
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Évaluation
Cette issue n'a pas encore été évaluée.