def test_distributions_lognormal_random_sample(): d = LogNormalDistribution(0, 1) x = numpy.array([1.55461432, 0.71829843, 11.36764528, 0.77717313, 1.11584263]) assert_array_almost_equal(d.sample(5, random_state=5), x) assert_raises(AssertionError, assert_array_almost_equal, d.sample(5), x)
def test_distributions_independent_random_sample(): d = IndependentComponentsDistribution([NormalDistribution(5, 2), UniformDistribution(0, 10), ExponentialDistribution(7), LogNormalDistribution(0, 0.4)]) x = numpy.array([[5.882455, 2.219932, 0.03586 , 1.193024], [4.33826 , 8.707323, 0.292267, 0.876036], [9.861542, 2.067192, 0.033083, 2.644041]]) assert_array_almost_equal(d.sample(3, random_state=5), x) assert_raises(AssertionError, assert_array_almost_equal, d.sample(5), x)
def test_lognormal(): d = LogNormalDistribution(5, 2) assert_equal(round(d.log_probability(5), 4), -4.6585) d.fit([5.1, 5.03, 4.98, 5.05, 4.91, 5.2, 5.1, 5., 4.8, 5.21]) assert_equal(round(d.parameters[0], 4), 1.6167) assert_equal(round(d.parameters[1], 4), 0.0237) d.summarize([5.1, 5.03, 4.98, 5.05]) d.summarize([4.91, 5.2, 5.1]) d.summarize([5., 4.8, 5.21]) d.from_summaries() assert_equal(round(d.parameters[0], 4), 1.6167) assert_equal(round(d.parameters[1], 4), 0.0237) e = Distribution.from_json(d.to_json()) assert_equal(e.name, "LogNormalDistribution") assert_equal(round(e.parameters[0], 4), 1.6167) assert_equal(round(e.parameters[1], 4), 0.0237) f = pickle.loads(pickle.dumps(e)) assert_equal(f.name, "LogNormalDistribution") assert_equal(round(f.parameters[0], 4), 1.6167) assert_equal(round(f.parameters[1], 4), 0.0237)