Skip to content

Instantly share code, notes, and snippets.

@vlavorini
Created August 18, 2017 13:06
Show Gist options
  • Save vlavorini/b11d44ee6e9741f70a75d201260c908d to your computer and use it in GitHub Desktop.
Save vlavorini/b11d44ee6e9741f70a75d201260c908d to your computer and use it in GitHub Desktop.
def gaussian(d, bw):
return np.exp(-0.5*(d/bw)**2) / (bw*np.sqrt(2*np.pi))
def meanshift_vec(points):
dists=poinc_dist_vec(points) #the matrix of the distances
weights = gaussian(dists, sigma) #the matrix of the weights
expd_w=np.dot(weights, points) #the weighted vectors
summed_weight=np.sum(weights,0) # the array of the summed weights, for normalize the weighted vectors
shifted_pts=expd_w/np.expand_dims(summed_weight,1) #the normalized vectors
return shifted_pts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment