Esempio n. 1
0
def test_distributions_uniform_kernel_random_sample():
	d = UniformKernelDensity([0, 4, 3, 5, 7, 4, 2])

	x = numpy.array([4.223488, 2.531816, 4.036836, 1.593601, 4.375442])

	assert_array_almost_equal(d.sample(5, random_state=5), x)
	assert_raises(AssertionError, assert_array_almost_equal, d.sample(5), x)
Esempio n. 2
0
def test_distributions_uniform_kernel_random_sample():
	d = UniformKernelDensity([0, 4, 3, 5, 7, 4, 2])

	x = numpy.array([4.223488, 2.531816, 4.036836, 1.593601, 4.375442])

	assert_array_almost_equal(d.sample(5, random_state=5), x)
	assert_raises(AssertionError, assert_array_almost_equal, d.sample(5), x)
def test_uniform_kernel():
    d = UniformKernelDensity([1, 3, 5, 6, 2, 2, 3, 2, 2])

    assert_equal(round(d.log_probability(2.2), 4), -0.4055)
    assert_equal(round(d.log_probability(6.2), 4), -2.1972)
    assert_equal(d.log_probability(10), float('-inf'))

    d = UniformKernelDensity([1, 100, 200])
    assert_not_equal(round(d.log_probability(2.2), 4), -0.4055)
    assert_not_equal(round(d.log_probability(6.2), 4), -2.1972)

    d.summarize([1, 3, 5, 6, 2])
    d.summarize([2, 3, 2, 2])
    d.from_summaries()
    assert_equal(round(d.log_probability(2.2), 4), -0.4055)
    assert_equal(round(d.log_probability(6.2), 4), -2.1972)

    e = Distribution.from_json(d.to_json())
    assert_equal(e.name, "UniformKernelDensity")
    assert_equal(round(e.log_probability(2.2), 4), -0.4055)
    assert_equal(round(e.log_probability(6.2), 4), -2.1972)

    f = pickle.loads(pickle.dumps(e))
    assert_equal(e.name, "UniformKernelDensity")
    assert_equal(round(f.log_probability(2.2), 4), -0.4055)
    assert_equal(round(f.log_probability(6.2), 4), -2.1972)
Esempio n. 4
0
def test_uniform_kernel():
	d = UniformKernelDensity([1, 3, 5, 6, 2, 2, 3, 2, 2])

	assert_equal(round(d.log_probability(2.2), 4), -0.4055)
	assert_equal(round(d.log_probability(6.2), 4), -2.1972)
	assert_equal(d.log_probability(10), float('-inf'))

	d = UniformKernelDensity([1, 100, 200])
	assert_not_equal(round(d.log_probability(2.2), 4), -0.4055)
	assert_not_equal(round(d.log_probability(6.2), 4), -2.1972)

	d.summarize([1, 3, 5, 6, 2])
	d.summarize([2, 3, 2, 2])
	d.from_summaries()
	assert_equal(round(d.log_probability(2.2), 4), -0.4055)
	assert_equal(round(d.log_probability(6.2), 4), -2.1972)

	e = Distribution.from_json(d.to_json())
	assert_equal(e.name, "UniformKernelDensity")
	assert_equal(round(e.log_probability(2.2), 4), -0.4055)
	assert_equal(round(e.log_probability(6.2), 4), -2.1972)

	f = pickle.loads(pickle.dumps(e))
	assert_equal(e.name, "UniformKernelDensity")
	assert_equal(round(f.log_probability(2.2), 4), -0.4055)
	assert_equal(round(f.log_probability(6.2), 4), -2.1972)