Newer
Older
from matplotlib.pyplot import figure, hist, plot, show, subplot, title
X = np.empty((N, M))
m = np.array([1, 3, 6])
s = np.array([1, 0.5, 2])
c_sizes = np.random.multinomial(N, [1.0 / 3, 1.0 / 3, 1.0 / 3])
X[
c_sizes.cumsum()[c_id] - c_sizes[c_id] : c_sizes.cumsum()[c_id], :
] = np.random.normal(m[c_id], np.sqrt(s[c_id]), (c_size, M))
# x-values to evaluate the KDE
xe = np.linspace(-10, 10, 100)
# Compute kernel density estimate
kde = gaussian_kde(X.ravel())
# Plot kernel density estimate
figure(figsize=(6, 7))
subplot(2, 1, 1)
hist(X, x)
title("Data histogram")
subplot(2, 1, 2)