From f8844285d77aa80ac6567a9056b4259f14eca55a Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 24 Nov 2022 11:38:16 +0100 Subject: [PATCH] putting understanding of hybridIA into code --- python/tests/test_util.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/python/tests/test_util.py b/python/tests/test_util.py index b2e689471..eff6a1bd4 100644 --- a/python/tests/test_util.py +++ b/python/tests/test_util.py @@ -43,7 +43,7 @@ class TestUtil: @pytest.mark.parametrize('rv',[stats.rayleigh(),stats.weibull_min(1.2),stats.halfnorm(),stats.pareto(2.62)]) - def test_hybridIA(self,rv): + def test_hybridIA_distribution(self,rv): bins = np.linspace(0,10,100000) centers = (bins[1:]+bins[:-1])/2 N_samples = bins.shape[0]-1000 @@ -52,6 +52,21 @@ class TestUtil: dist_sampled = np.histogram(centers[selected],bins)[0]/N_samples*np.sum(dist) assert np.sqrt(((dist - dist_sampled) ** 2).mean()) < .025 and selected.shape[0]==N_samples + def test_hybridIA_constant(self): + N_bins = np.random.randint(20,400) + m = np.random.randint(1,20) + N_samples = m * N_bins + dist = np.ones(N_bins)*np.random.rand() + assert np.all(np.sort(util.hybrid_IA(dist,N_samples))==np.arange(N_samples).astype(int)//m) + + def test_hybridIA_linear(self): + N_points = np.random.randint(10,200) + m = np.random.randint(1,20) + dist = np.arange(N_points) + N_samples = m * np.sum(dist) + assert np.all(np.bincount(util.hybrid_IA(dist*np.random.rand(),N_samples)) == dist*m) + + @pytest.mark.parametrize('point,direction,normalize,keepdims,answer', [ ([1,0,0],'z',False,True, [1,0,0]),