gaussian filter on irregularly spaced (x,y) series?
Emily Wong
is there an easy way in python to apply a gaussian filter to a set of points (x,y), or more specifically (x,f(x)) that are not regularly spaced along the x-axis? In response to the request for clarification on what I mean, maybe a better way to describe what I'm looking for is as a "gaussian-weighted average", Fgwa(Xj), of a series of points (Xi,F(Xi)) where for each point in the provided series (Xi,F(Xi)) a sum essentially is taken over all the provided points such that
Fgwa(Xj) = Σi [ e-[(Xj-Xi)/σ]^2 * F(Xi) ] / Σi [ exp-[(Xj-Xi)/σ]^2 ]
(Note - if the points in (Xi,F(Xi)) happen to be evenly spaced, I believe that the end result of the above definition would be the same as what "scipy.ndimage.filters.gaussian_filter1d" does). Is there a nice, already-optimized, numpy or scipy way to do this?
31 Answer
This looks like Nadaraya-Watson Kernel Regression, and one available python implementation is in the statsmodels package.
You can do a similar kernel smoothing operation with pandas rolling window.
2