def test_calculate_EZZT(): big_phi = lm.calculate_big_phi(phi1[0], phi2[0]) out = lm.calculate_EZZT(big_phi) e = 8.0 / 9.0 t = 2.0 / 9.0 h = 3.0 / 2.0 answer = (1.0 / 25) * np.array([ [e, t, t, 1, 1], [t, e, t, 1, 1], [t, t, e, 1, 1], [1, 1, 1, 3, h], [1, 1, 1, h, 3], ]) assert same(out, answer) out = lm.calculate_EZZT_from_small_phis(phi1[0], phi2[0]) assert same(out, answer) # try it on logs out = lm.calculate_EZZT_from_small_log_phis(log_phi1, log_phi2) assert same(out, np.log(answer)) # now try a harder random matrix r1 = answer.copy() r1[0,0] = 5 r1[1,1] = 9 r1 = graphlib.row_normalize(r1) r2 = r1.copy() r1[1,1] = 2 r1[1,0] = 1 r1 = graphlib.row_normalize(r1) big_phi = lm.calculate_big_phi(r1, r2) answer = lm.calculate_EZZT(big_phi) out = lm.calculate_EZZT_from_small_phis(r1, r2) assert same(out, answer) # test out same anwer on logs out = lm.calculate_EZZT_from_small_log_phis(np.log(r1), np.log(r2)) assert same(out, np.log(answer))
def test_calculate_EZ(): big_phi = lm.calculate_big_phi(phi1[0], phi2[0]) out = lm.calculate_EZ(big_phi) answer = (1.0 / 25) * np.array([30.0/9, 30.0/9, 30.0/9, 7.5, 7.5]) assert same(out, answer) out = lm.calculate_EZ_from_small_phis(phi1[0], phi2[0]) assert same(out, answer) # now test log phis big_log_phi = lm.calculate_big_log_phi(log_phi1, log_phi2) out = lm.calculate_EZ_from_big_log_phi(big_log_phi) assert same(out, np.log(answer)) out = lm.calculate_EZ_from_small_log_phis(log_phi1, log_phi2) assert same(out, np.log(answer))
def test_calculate_big_phi(): a = np.ones((2,3)) b = np.ones((6,4)) a[0, 2] = 5 b[4,1] = 8 out = lm.calculate_big_phi(a, b) answer = np.array([ [1, 1, 5, 0, 0, 0, 0,], [1, 1, 1, 0, 0, 0, 0,], [0, 0, 0, 1, 1, 1, 1,], [0, 0, 0, 1, 1, 1, 1,], [0, 0, 0, 1, 1, 1, 1,], [0, 0, 0, 1, 1, 1, 1,], [0, 0, 0, 1, 8, 1, 1,], [0, 0, 0, 1, 1, 1, 1,], ]) assert same(out, answer)