COP-Kmeans
COP-Kmeans copied to clipboard
ZeroDivisionError: float division by zero with kmpp initialiser
When using kmpp
initialisation, chances
vector keeps decreasing till the point at which the following code line:
chances = [x/sum(chances) for x in chances]
produces a ZeroDivisionError
error because sum(chances) == 0
, and execution is broken.
In my case, the following chances
and sum(chances)
values where computed across iterations:
> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] 20
> [0.0, 0.0, 0.0, 0.0, 0.0, 0.7805784783006152, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0518003539299652, 0.0, 0.0, 1.367544467966324, 0.0, 0.0] 5.199923300196905
> [0.0, 0.0, 0.0, 0.0, 0.0, 0.7805784783006152, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0518003539299652, 0.0, 0.0, 0.0, 0.0, 0.0] 3.8323788322305807
> [0.0, 0.0, 0.0, 0.0, 0.0, 0.7805784783006152, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.23905780015564948, 0.0, 0.0, 0.0, 0.0, 0.0] 1.0196362784562647
> [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.23905780015564948, 0.0, 0.0, 0.0, 0.0, 0.0] 0.23905780015564948
> [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 0.0
As it is seeable, sum(chances)
plummits to 0.0
at the end.
Same issue