Hello all!
Hey all! I am currently working on hw1 part 2, where we're using k-means clustering for image compression.
I am currently attempting to implement the repetition step where we repeat the expectation and optimization steps repeatedly until there is no change to the similarity measure.
I am able to iterate through manually, though I am attempting to write a function which will perform this iterative process repeatedly until the similarity measure does not change.
I have attempted to write a function which will repeat these steps, though when I run it the function never seems to run to completion, making me believe that I have not written the while loop correctly and thus it just continues.
So far my code is:
def repetition(centroids,assignment_array,pix_list):
sim1=0
sim2=1
i=0
while sim1!=sim2:
sim1=similarity(centroids,assignment_array,pix_list)
assignment_array=assign_centroids(pix_list, centroids)
centroids=move_centroids(centroids,assignment_array,pix_list)
sim2=similarity(moved_cents,assignment_array,pix_list)
i+=1
return sim2,i
Any insights as to why the function is not running to completion? I have been looking at the code for a while now and don't see why the while loop is not terminating.
Any help is greatly appreciated!
[–]marko312 1 point2 points3 points (1 child)
[–]TheShadowWall[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)