Skip to content

Instantly share code, notes, and snippets.

@vlavorini
Last active September 27, 2017 16:15
Show Gist options
  • Save vlavorini/d35605dad53ec508ade71633a6e8988d to your computer and use it in GitHub Desktop.
Save vlavorini/d35605dad53ec508ade71633a6e8988d to your computer and use it in GitHub Desktop.
def __shift(points, sigma, beg, end):
dists=dist_batch(points, beg, end) # the distance function just defined
weights = gaussian(dists, sigma)
expd_w=np.dot(weights.T, points)
summed_weight=np.sum(weights,0)
return expd_w/np.expand_dims(summed_weight,1) # we return the shifted points
def meanshift_batch(points, batches):
for i in range(0,n_samples,batches): # we need to loop for each batch, until reach the end
last=min(i+batches,n_samples) # we have to select which is the last vector for feeding the following functions
points[i:last]=__shift(points, sigma, i, last) # we dinamically update the vectors
return points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment