def test_fromrandom(): mus = [0, 0] cov = [[1, 0], [0, 1]] h = Hist2D.from_random("multivariate_normal", params=[mus, cov], size=1e4, random_state=42) for axis in ["x", "y"]: assert abs(h.projection(axis).mean()) < 0.1 assert 0.9 < h.projection(axis).std() < 1.1 h = Hist2D.from_random("norm", params=[(2, 2)], bins=50) assert h.rebin(5).projection("x") == h.projection("x").rebin(5)
def test_sample(): np.random.seed(0) h1 = Hist2D.from_random(size=1e5) h2 = Hist2D(h1.sample(1e5), bins=h1.edges) result = (h1.projection() / h2.projection()).fit("a+b*x") slope = result["params"]["b"] assert abs(slope["error"]) > abs(slope["value"])
def test_cumulativelookup(): h = Hist2D.from_random(bins="5,0,5") assert h.cumulative().counts.max() == h.integral assert h.cumulative(forwardx=True, forwardy=True).lookup(4.9, 4.9) == h.integral assert h.cumulative(forwardx=False, forwardy=False).lookup(0.1, 0.1) == h.integral assert h.cumulative(forwardx=True, forwardy=False).lookup(4.9, 0.1) == h.integral assert h.cumulative(forwardx=False, forwardy=True).lookup(0.1, 4.9) == h.integral
def test_smooth(): h = Hist2D.from_random(bins="5,0,5") assert h == h.smooth(window=1, ntimes=1) assert h == h.smooth(window=1, ntimes=10) m = np.array([ [2, 2], ]) h = Hist2D(m, bins="5,-0.5,4.5") h = h.smooth(window=3, ntimes=1) assert h.lookup(2 + 1, 2) == h.lookup(2 - 1, 2) assert h.lookup(2, 2 + 1) == h.lookup(2, 2 - 1)
def test_cumulative(): h = Hist2D.from_random(bins="5,0,5") assert h == h.cumulative(forwardx=None, forwardy=None)