def test_distributions_triangle_kernel_random_sample(): d = TriangleKernelDensity([0, 4, 3, 5, 7, 4, 2]) x = numpy.array([4.118801, 2.31576 , 4.018591, 1.770455, 4.612734]) assert_array_almost_equal(d.sample(5, random_state=5), x) assert_raises(AssertionError, assert_array_almost_equal, d.sample(5), x)
def test_triangular_kernel(): d = TriangleKernelDensity([1, 6, 3, 4, 5, 2]) assert_equal(round(d.log_probability(6.5), 4), -2.4849) d = TriangleKernelDensity([1, 8, 100]) assert_not_equal(round(d.log_probability(6.5), 4), -2.4849) d.summarize([1, 6]) d.summarize([3, 4, 5]) d.summarize([2]) d.from_summaries() assert_equal(round(d.log_probability(6.5), 4), -2.4849) d.freeze() d.fit([1, 4, 6, 7, 3, 5, 7, 8, 3, 3, 4]) assert_equal(round(d.log_probability(6.5), 4), -2.4849) e = Distribution.from_json(d.to_json()) assert_equal(e.name, "TriangleKernelDensity") assert_equal(round(e.log_probability(6.5), 4), -2.4849) f = pickle.loads(pickle.dumps(e)) assert_equal(f.name, "TriangleKernelDensity") assert_equal(round(f.log_probability(6.5), 4), -2.4849)