def test_cumaltive_to_point1(): """ can we determine cumulative 1-d pdf at a set of points""" #generate a fake df, flat across the 500 bins pdf = np.ones(500, dtype=float) pdf = pdf / np.sum(pdf) #calcalate cumulative df of this, up to 0, 1, 2, 3,.. ngals etc for i in np.arange(40) + 1: res = pval.cumaltive_to_point(pdf, np.arange(500) + 0.5, i) print i, np.sum(pdf[0:i]) / 500.0, res np.testing.assert_almost_equal(res, np.sum(pdf[0:i]) / 500.0, 3)
def test_cumaltive_to_point2(): """ can we determine cumulative n-d pdf at a set of points""" #generate a fake df, flat across the 500 bins ngals = 56 pdfs = np.zeros((ngals, 500)) binCenters = np.arange(500) + 0.5 for i in np.arange(ngals): pdfs[i, :] = i + 1 #npfds = pval.normalisepdfs(pdfs, binCenters) #calcalate cumulative df of this, up to 0, 1, 2, 3,.. ngals etc res = pval.cumaltive_to_point(npfds, binCenters, np.arange(ngals) + 0.5) for i in np.arange(ngals - 1) + 1: print i, res[i], np.sum(npfds[i, 0:i + 1]) np.testing.assert_almost_equal(res[i], np.sum(npfds[i, 0:i + 1]), 1)
def test_cumaltive_to_point0(): """check we can we draw a set of z_mc from a pdf, that are flat in histogram heights <h> e.g. Bordoloi test""" from scipy.stats import entropy ngals = 20 sigs = np.random.uniform(size=ngals) * 0.5 + 0.1 x = np.arange(0.01, 3.01, 0.01) dx = (x[1] - x[0]) / 2.0 print 'sigs', sigs for i in range(ngals): pdf = mlab.normpdf(x, sigs[i], 0.02) z_mc = pval.get_mc(pdf, x, N=100000) c = pval.cumaltive_to_point(pdf, x, z_mc) h = np.histogram(c, bins=np.arange(0, 1.05, 0.05)) print h print len(h), 'len(h)' h = h[0] res = entropy(h, [np.mean(h)] * len(h)) print 'res', res np.testing.assert_array_less(res, 0.005)
def test_cumaltive_to_point01(): """check we can we draw a set of z_mc from a pdf, that are flat in histogram heights <h> e.g. Bordoloi test for sets of pdfs with 2 bins values """ from scipy.stats import entropy x = np.arange(0.01, 3.01, 0.01) dx = (x[1] - x[0]) / 2.0 for i in range(len(x) - 2): pdf = np.zeros_like(x) pdf[i:i + 2] = [0.1, 0.2] z_mc = pval.get_mc(pdf, x, N=100000) c = pval.cumaltive_to_point(pdf, x, z_mc) h = np.histogram(c, bins=np.arange(0, 1.05, 0.05)) print h print len(h), 'len(h)' h = h[0] res = entropy(h, [np.mean(h)] * len(h)) print 'res', res np.testing.assert_array_less(res, 0.005)