Created
May 16, 2023 08:40
-
-
Save syrte/04fe67fc8ebf795b83d8ac37771a83e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import np | |
def kern_smooth(x, xp, yp, bw=1, return_std=False): | |
w = np.exp(-0.5 * ((xp - x.reshape(-1, 1)) / bw)**2) | |
w = w / w.sum(1, keepdims=True) | |
y = (yp * w).sum(1) | |
if not return_std: | |
return y | |
else: | |
# x should cover the range of xp to validate interp of dy | |
assert x[0] <= xp[0] and x[-1] >= xp[-1] | |
dy = yp - np.interp(xp, x, y) # needed if y varies fast | |
ystd = ((dy**2 * w).sum(1) - (dy * w).sum(1)**2)**0.5 | |
return y, ystd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment