Skip to content

Instantly share code, notes, and snippets.

@mynameisfiber
Created November 13, 2013 15:46
Show Gist options
  • Save mynameisfiber/7451236 to your computer and use it in GitHub Desktop.
Save mynameisfiber/7451236 to your computer and use it in GitHub Desktop.
simple unnormalized kde evaluation
import numpy as np
def gaussian(x0, sigma):
return lambda x : np.exp(- 0.5 * ((x - x0) / sigma)**2 ) / (sigma * np.sqrt(2 * np.pi))
def kde(points, sigma=.5):
functions = [gaussian(x0, sigma) for x0 in points]
def sampler(x):
return sum(f(x) for f in functions)
return sampler
if __name__ == "__main__":
points = [1, 3, 6, 3, 6, 2, 1, 4, 6]
sampler = kde(points)
print "unnormalized KDE @ x=5 => ", sampler(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment