def prepare_dist(dist): if not isinstance(dist._sample_space, dit.samplespace.CartesianProduct): dist = dit.expanded_samplespace(dist, union=True) if not dist.is_dense(): if len(dist._sample_space) > 1e4: # pragma: no cover import warnings msg = "Sample space has more than 10k elements." msg += " This could be slow." warnings.warn(msg) dist.make_dense() # We also need linear probabilities. dist.set_base('linear') return dist
def prepare_dist(dist): if not isinstance(dist._sample_space, dit.samplespace.CartesianProduct): dist = dit.expanded_samplespace(dist, union=True) if not dist.is_dense(): if len(dist._sample_space) > 1e4: import warnings msg = "Sample space has more than 10k elements." msg += " This could be slow." warnings.warn(msg) dist.make_dense() # We also need linear probabilities. dist.set_base('linear') return dist
def test_ilr_inv_underflow(): """ Make sure ilv_inv still works in potential underflow situations. """ # We need a lot of small probabilities so their products will underflow # if we don't use logarithms properly. d = dit.example_dists.summed_dice(.5, 1) d = dit.expanded_samplespace(d, union=True) d.make_dense() prng = d.prng prng.seed(0) tol = 1e-5 pmf_ = dit.math.pmfops.replace_zeros(d.pmf, tol, prng=prng) ilrpmf = dit.math.aitchison.ilr(pmf_) pmf = dit.math.aitchison.ilr_inv(ilrpmf) assert np.allclose(pmf, pmf_)
def test_ilr_inv_underflow(): """ Make sure ilv_inv still works in potential underflow situations. """ # We need a lot of small probabilities so their products will underflow # if we don't use logarithms properly. d = dit.example_dists.summed_dice(.5, 1) d = dit.expanded_samplespace(d, union=True) d.make_dense() prng = d.prng prng.seed(0) tol = 1e-5 pmf_ = dit.math.pmfops.replace_zeros(d.pmf, tol, prng=prng) ilrpmf = dit.math.aitchison.ilr(pmf_) pmf = dit.math.aitchison.ilr_inv(ilrpmf) np.testing.assert_allclose(pmf, pmf_)