Skip to content

Instantly share code, notes, and snippets.

@conradlee
Created November 18, 2011 14:14
Show Gist options
  • Save conradlee/1376552 to your computer and use it in GitHub Desktop.
Save conradlee/1376552 to your computer and use it in GitHub Desktop.
Mean shift kernel update functions
import numpy as np
from sklearn.metrics.pairwise import euclidean_distances
def gaussian_kernel_update(x, points, bandwidth):
distances = euclidean_distances(points, x)
weights = np.exp(-1 * (distances ** 2 / bandwidth ** 2))
return np.sum(points * weights, axis=0) / np.sum(weights)
def flat_kernel_update(x, points, bandwidth):
return np.mean(points, axis=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment