Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import math
from pyinclude.draw import *
from pyinclude.point import *
K = 3
POINTS = 100
RANGE = 640
if __name__ == "__main__":
points = [ Point() for i in range(POINTS) ]
centroids = [ Centroid() for i in range(K) ]
maxIterations = 10
# set random point positions
# generate K initial points and then position the rest of the
# points around the initial K
assert( len(points) >= len(centroids) )
for p in points[:len(centroids)]:
p.randomise( RANGE )
for i in range( len(centroids), len(points) ):
points[i].randomise( RANGE, points[i%len(centroids)] )
# set random starting positions for the centroids
for c in centroids:
c.randomise( RANGE )
print( c )
# clustering iterations
for i in range( maxIterations ):
# kmeans
# display centroid positions
print( f"Iteration {i}" )
for c in centroids:
print( c )
draw( points, centroids, RANGE, RANGE, f"{i:0{int(math.log(maxIterations,10)+1)}d}_clusters.bmp" )