def test_tc7(): """ Test T = I with two variables """ outcomes = ['00', '01', '11'] pmf = [1 / 3] * 3 d = D(outcomes, pmf) assert_almost_equal(T(d), I(d, [0], [1])) d.set_rv_names("XY") assert_almost_equal(T(d), I(d, ['X'], ['Y']))
def test_tc7(): """ Test T = I with two variables """ outcomes = ['00', '01', '11'] pmf = [1/3] * 3 d = D(outcomes, pmf) assert T(d) == pytest.approx(I(d, [0], [1])) d.set_rv_names("XY") assert T(d) == pytest.approx(I(d, ['X'], ['Y']))
def total_correlation(Xs): pmf = [] Xs = np.asarray(Xs) for stock in range(len(Xs)): s = pd.Series(Xs[stock]) b = (s.groupby(s).transform('count') / len(s)).values pmf.append(b) pmf = np.asarray(pmf) pmf /= pmf.sum() custm = stats.rv_discrete(name='custm', values=(Xs, pmf)) d = Distribution.from_ndarray(pmf) t = T(d) return t
def test_mis1(d): """ Test that all the mutual informations match for bivariate distributions. """ i = I(d) t = T(d) b = B(d) j = J(d) ii = II(d) assert i == pytest.approx(t) assert t == pytest.approx(b) assert b == pytest.approx(j) assert j == pytest.approx(ii)
def test_tc8(): """ Test that T fails on SDs """ d = SD([1/3]*3) with pytest.raises(ditException): T(d)
def test_tc6(): """ Test T with overlapping subvariables """ d = n_mod_m(4, 2) assert T(d, [[0, 1, 2], [1, 2, 3]]) == pytest.approx(3.0) d.set_rv_names("XYZW") assert T(d, [['X', 'Y', 'Z'], ['Y', 'Z', 'W']]) == pytest.approx(3.0)
def test_tc5(): """ Test T with subvariables """ d = n_mod_m(4, 2) assert T(d, [[0, 1], [2], [3]]) == pytest.approx(1.0) d.set_rv_names("XYZW") assert T(d, [['X', 'Y'], ['Z'], ['W']]) == pytest.approx(1.0)
def test_tc4(): """ Test conditional T """ d = n_mod_m(4, 2) assert T(d, [[0], [1]], [2, 3]) == pytest.approx(1.0) d.set_rv_names("XYZW") assert T(d, [['X'], ['Y']], ['Z', 'W']) == pytest.approx(1.0)
def test_tc2(): """ Test T of subvariables, with names """ d = n_mod_m(4, 2) assert T(d, [[0], [1], [2]]) == pytest.approx(0.0) d.set_rv_names("XYZW") assert T(d, [['X'], ['Y'], ['Z']]) == pytest.approx(0.0)
def test_tc1(n): """ Test T of parity distributions """ d = n_mod_m(n, 2) assert T(d) == pytest.approx(1.0)
def test_caekl_4(d): """ Test that CAEKL is always less than or equal to the normalized total correlation. """ assert J(d) <= (T(d) / 3) + 1e-6
def test_tc6(): """ Test T with overlapping subvariables """ d = n_mod_m(4, 2) assert_almost_equal(T(d, [[0, 1, 2], [1, 2, 3]]), 3.0) d.set_rv_names("XYZW") assert_almost_equal(T(d, [['X', 'Y', 'Z'], ['Y', 'Z', 'W']]), 3.0)
def test_tc5(): """ Test T with subvariables """ d = n_mod_m(4, 2) assert_almost_equal(T(d, [[0, 1], [2], [3]]), 1.0) d.set_rv_names("XYZW") assert_almost_equal(T(d, [['X', 'Y'], ['Z'], ['W']]), 1.0)
def test_tc4(): """ Test conditional T """ d = n_mod_m(4, 2) assert_almost_equal(T(d, [[0], [1]], [2, 3]), 1.0) d.set_rv_names("XYZW") assert_almost_equal(T(d, [['X'], ['Y']], ['Z', 'W']), 1.0)
def test_tc2(): """ Test T of subvariables, with names """ d = n_mod_m(4, 2) assert_almost_equal(T(d, [[0], [1], [2]]), 0.0) d.set_rv_names("XYZW") assert_almost_equal(T(d, [['X'], ['Y'], ['Z']]), 0.0)
def test_tc1(): """ Test T of parity distributions """ for n in range(3, 7): d = n_mod_m(n, 2) yield assert_almost_equal, T(d), 1.0