Skip to content

Instantly share code, notes, and snippets.

@vlavorini
Last active December 19, 2018 15:50
Show Gist options
  • Save vlavorini/1f2bd4ac469a2f7d2b5d186fe2dd4112 to your computer and use it in GitHub Desktop.
Save vlavorini/1f2bd4ac469a2f7d2b5d186fe2dd4112 to your computer and use it in GitHub Desktop.
def meanshift(data, sigma, steps):
d1 = np.copy(data) # Need to copy the data, don't want to modify the originals
for it in range(steps): # at each step
for i, p in enumerate(d1): # for each point
dists = dist_poinc( p, d1) # we calculate the distance from that point to all the other ones
weights = gaussian(dists, sigma) # then we weight those distances by our gaussian kernel
d1[i] = (np.expand_dims(weights,1)*d1).sum(0) / weight.sum() # and substitute the point with the weighted sum
return d1
@rafariva
Copy link

on line 7, should be weights.sum( )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment