def test_exponential(self): k = 11 xs = np.random.exponential(scale=1, size=100000) processor = preprocess.Shifter(compress=False) processor.set_xs(xs, k=k) pmus = processor.get_pmus() ps = pointsolver.PointSolver(len(pmus)) locs, weights = ps.solve(pmus) print(np.min(xs), np.max(xs)) print(repr(processor.invert(locs))) print(repr(weights))
def test_check_discrete(self): k = 11 xs = np.array([100.0, 200.0, 300.0, 400.0, 200.0]).astype(float) processor = preprocess.Shifter(compress=False) processor.set_xs(xs, k=k) pmus = processor.get_pmus() ps = pointsolver.PointSolver(len(pmus)) locs, weights = ps.solve(pmus) self.assertEqual(4, len(locs)) self.assertTrue(ps.is_discrete) self.assertAlmostEqual(200.0, processor.invert(ps.get_quantile(.5)), 4) self.assertAlmostEqual(300.0, processor.invert(ps.get_quantile(.7)), 4)
def test_continuous(self): k = 11 xs = np.linspace(0, 100, 1000) processor = preprocess.Shifter(compress=False) processor.set_xs(xs, k=k) pmus = processor.get_pmus() ps = pointsolver.PointSolver(len(pmus)) locs, weights = ps.solve(pmus) print(locs) print(weights) self.assertFalse(ps.is_discrete) p50 = processor.invert(ps.get_quantile(.5)) self.assertTrue(p50 > 40) self.assertTrue(p50 < 60)
def __init__( self, k: int, compressed: bool = True, integer: bool = False, verbose: bool = False ): self.k = k self.integer = integer self.csolver = csolver.CSolver( k, n=64, n_steps=15, verbose=verbose ) self.psolver = pointsolver.PointSolver( n_mus = k, verbose=verbose ) self.shifter = preprocess.Shifter(compress=compressed, integral=integer)
def test_lognorm(self): n = 10000 k = 10 xs = np.random.normal(loc=1, scale=2, size=n) xs = np.exp(xs) shifter = preprocess.Shifter(xs, compress=True) cxs = shifter.get_cxs() d_mus = np.array([ np.mean(cb(i)(cxs)) for i in range(k) ]) s = csolver.CSolver(k, n=128, verbose=False) s.solve(d_mus) p49 = np.percentile(xs, 49) p51 = np.percentile(xs, 51) p50_est = shifter.invert(s.get_quantile(.5)) self.assertTrue( p49 < p50_est ) self.assertTrue( p51 > p50_est )