def test_counts(counts): estimator = ndd.estimators.AutoEstimator() assert ndd.entropy(counts.nk) == approx( counts.entropy(estimator=estimator))
def test_unnormalized_pmf(): counts = numpy.random.random(size=100) # pylint: disable=no-member pk = counts / counts.sum() assert ndd.entropy(counts) == approx(Pmf().entropy_from_pmf(pk))
def test_pmf(pmf): ref = pmf.entropy assert ndd.entropy(pmf.pk) == approx(ref)
def test_pmf_with_zeros(pmf_with_zeros): ref = pmf_with_zeros.entropy print(pmf_with_zeros.pk.sum()) assert ndd.entropy(pmf_with_zeros.pk) == approx(ref)
def test_nsb(counts_1d, multi_1d): estimate_from_counts = fnsb.nsb(counts_1d, K)[0] estimate_from_multiplicities = fnsb.nsb_from_multiplicities( multi_1d[0], multi_1d[1], K)[0] assert estimate_from_multiplicities == approx(estimate_from_counts)
def test_PmfPlugin(pmf): """Test estimator from PMF.""" estimator = ndd.estimators.PmfPlugin() ref = pmf.entropy assert estimator(pmf.pk) == approx(ref)
def test_millermadow_estimator(counts_1d, multi_1d): est = MillerMadow() estimate_from_counts = est(counts_1d, k=K) nk, zk = multi_1d estimate_from_multiplicities = est(nk, zk=zk, k=K) assert estimate_from_multiplicities == approx(estimate_from_counts)
def test_nsb_from_multiplicities(data_1d): frequencies = compute_frequencies(data_1d) hn, hz = compute_multiplicities(data_1d) estimate_from_counts = fnsb.nsb(frequencies, K)[0] estimate_from_multiplicities = fnsb.nsb_from_multiplicities(hn, hz, K)[0] assert estimate_from_multiplicities == approx(estimate_from_counts)
def test_plugin_estimator(counts_1d, multi_1d): est = Plugin() estimate_from_counts = est(counts_1d, k=K) nk, zk = multi_1d estimate_from_multiplicities = est(nk, zk=zk, k=K) assert estimate_from_multiplicities == approx(estimate_from_counts)
def test_grassberger_estimator(counts_1d, multi_1d): est = Grassberger() estimate_from_counts = est(counts_1d, k=K) nk, zk = multi_1d estimate_from_multiplicities = est(nk, zk=zk, k=K) assert estimate_from_multiplicities == approx(estimate_from_counts)
def test_ww_estimator(counts_1d, multi_1d): alpha = 0.1 estimate_from_counts = Nsb(alpha=alpha)(counts_1d, k=K) nk, zk = multi_1d estimate_from_multiplicities = Nsb(alpha=alpha)(nk, zk=zk, k=K) assert estimate_from_multiplicities == approx(estimate_from_counts)
def test_ww(counts_1d, multi_1d): alpha = 0.1 estimate_from_counts = fnsb.ww(counts_1d, K, alpha)[0] estimate_from_multiplicities = fnsb.ww_from_multiplicities( multi_1d[0], multi_1d[1], K, alpha)[0] assert estimate_from_multiplicities == approx(estimate_from_counts)
def test_nsb_estimator(counts_1d, multi_1d): estimate_from_counts = Nsb()(counts_1d, k=K) nk, zk = multi_1d estimate_from_multiplicities = Nsb()(nk, zk=zk, k=K) assert estimate_from_multiplicities == approx(estimate_from_counts)