def test_megkde_1d_changing_weights():
# Draw from normal, fit KDE, see if sampling from kde's pdf recovers norm
np.random.seed(0)
xs = np.linspace(-3, 3, 1000)
weights = norm.pdf(xs)
ys = MegKDE(xs, weights=weights).evaluate(xs)
cs = ys.cumsum()
cs /= cs[-1]
cs[0] = 0
samps = interp1d(cs, xs)(np.random.uniform(size=10000))
mu, std = norm.fit(samps)
assert np.isclose(mu, 0, atol=0.1)
assert np.isclose(std, 1.0, atol=0.1)
评论列表
文章目录