def test_bad_marginal(): epsilon = 0.01 pXY = BEC_joint(epsilon) pXY.set_rv_names('XY') pX, pYgX = pXY.condition_on('X') pX['0'] = 0 # Now make its length disagree with the number of cdists. pX.make_sparse() with pytest.raises(ditException): channel_capacity(pYgX, pX)
def test_bad_marginal(): epsilon = 0.01 pXY = BEC_joint(epsilon) pXY.set_rv_names('XY') pX, pYgX = pXY.condition_on('X') pX['0'] = 0 # Now make its length disagree with the number of cdists. pX.make_sparse() with pytest.raises(ditException): channel_capacity(pYgX, pX)
def test_channel_capacity_array1(): epsilon = 0.3 pXY = BEC_joint(epsilon) pX, pYgX = pXY.condition_on([0]) cc, pXopt_pmf = channel_capacity(pYgX) # Verify channel capacity. assert np.allclose(cc, 1 - epsilon) # Verify maximizing distribution. assert np.allclose(pX.pmf, pXopt_pmf)
def test_channel_capacity_array1(): epsilon = 0.3 pXY = BEC_joint(epsilon) pX, pYgX = pXY.condition_on([0]) cc, pXopt_pmf = channel_capacity(pYgX) # Verify channel capacity. assert np.allclose(cc, 1 - epsilon) # Verify maximizing distribution. assert np.allclose(pX.pmf, pXopt_pmf)
def test_channel_capacity_array2(): epsilon = 0.3 pXY = BEC_joint(epsilon) pX, pYgX = pXY.condition_on([0]) pYgX = cdist_array(pYgX, base='linear', mode='dense') cc, pXopt_pmf = channel_capacity(pYgX, atol=1e-9, rtol=1e-9) # Verify channel capacity. assert np.allclose(cc, 1 - epsilon) # Verify maximizing distribution. assert np.allclose(pX.pmf, pXopt_pmf)
def test_channel_capacity_array2(): epsilon = 0.3 pXY = BEC_joint(epsilon) pX, pYgX = pXY.condition_on([0]) pYgX = cdist_array(pYgX, base='linear', mode='dense') cc, pXopt_pmf = channel_capacity(pYgX, atol=1e-9, rtol=1e-9) # Verify channel capacity. assert np.allclose(cc, 1 - epsilon) # Verify maximizing distribution. assert np.allclose(pX.pmf, pXopt_pmf)
def test_channel_capacity_no_rvnames(): epsilon = 0.3 pXY = BEC_joint(epsilon) pX, pYgX = pXY.condition_on([0]) cc, pXopt = channel_capacity(pYgX, pX) # Verify channel capacity. assert np.allclose(cc, 1 - epsilon) # Verify maximizing distribution. assert pX.is_approx_equal(pXopt) # Verify joint distribution at channel capacity. pXYopt = joint_from_factors(pXopt, pYgX) assert pXY.is_approx_equal(pXYopt)
def test_channel_capacity_no_rvnames(): epsilon = 0.3 pXY = BEC_joint(epsilon) pX, pYgX = pXY.condition_on([0]) cc, pXopt = channel_capacity(pYgX, pX) # Verify channel capacity. assert np.allclose(cc, 1 - epsilon) # Verify maximizing distribution. assert pX.is_approx_equal(pXopt) # Verify joint distribution at channel capacity. pXYopt = joint_from_factors(pXopt, pYgX) assert pXY.is_approx_equal(pXYopt)