Created
April 23, 2018 16:02
-
-
Save thesamovar/aa6cc7e773280c7c550950528f5966a5 to your computer and use it in GitHub Desktop.
gaussian_kde sample code
This file contains 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 numpy as np | |
from scipy import stats | |
def measure(n): | |
"Measurement model, return two coupled measurements." | |
m1 = np.random.normal(size=n) | |
m2 = np.random.normal(scale=0.5, size=n) | |
return m1+m2, m1-m2 | |
m1, m2 = measure(20) | |
xmin = m1.min() | |
xmax = m1.max() | |
ymin = m2.min() | |
ymax = m2.max() | |
X, Y = np.mgrid[xmin:xmax:10j, ymin:ymax:10j] | |
positions = np.vstack([X.ravel(), Y.ravel()]) | |
values = np.vstack([m1, m2]) | |
kernel = stats.gaussian_kde(values) | |
Z = np.reshape(kernel(positions).T, X.shape) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment