def test_balanced_tree_maxmin(): """ max-min epistemic closure on a balanced tree with branching factor 3 and depth 2. """ G = np.matrix([[0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) G = sp.csr_matrix(G, dtype=np.double) G = weighted(G, undirected=True) expect = np.matrix( [[1., 1., 1., 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2], [1., 1., 0.25, 0.25, 1., 1., 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2], [1., 0.25, 1., 0.25, 0.2, 0.2, 0.2, 1., 1., 1., 0.2, 0.2, 0.2], [1., 0.25, 0.25, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 1., 1., 1.0], [0.2, 1., 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 1., 0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 1., 0.2, 0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2], [0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2], [0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 1., 0.2, 0.2], [0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 1., 0.2], [0.2, 0.2, 0.2, 1., 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 1.0]]) run_test(G, expect)
def test_graph5_maxmin(): """ max-min epistemic closure on an arbitraty graph (ex. #5). """ G = np.matrix([[0, 0, 1, 1, 1], [0, 0, 1, 1, 0], [1, 1, 0, 0, 0], [1, 1, 0, 0, 1], [1, 0, 0, 1, 0]]) G = sp.csr_matrix(G, dtype=np.double) G = weighted(G, undirected=True) expect = np.matrix([[1., 0.33, 1., 1., 1.00], [0.33, 1., 1., 1., 0.25], [1., 1., 1., 0.33, 0.25], [1., 1., 0.33, 1., 1.00], [1., 0.25, 0.25, 1., 1.00]]) run_test(G, expect)
def test_cycle_graph_maxmin(): """ max-min epistemic closure on a 4-cycle. """ G = np.matrix([[False, True, False, False, True], [True, False, True, False, False], [False, True, False, True, False], [False, False, True, False, True], [True, False, False, True, False]]) G = sp.csr_matrix(G, dtype=np.double) G = weighted(G, undirected=True) expect = np.matrix([[1., 1., 0.33, 0.33, 1.00], [1., 1., 1., 0.33, 0.33], [0.33, 1., 1., 1., 0.33], [0.33, 0.33, 1., 1., 1.00], [1., 0.33, 0.33, 1., 1.00]]) run_test(G, expect)
def test_graph2_maxmin(): """ max-min epistemic closure on an arbitraty graph (ex. #2). """ data = np.ones(12, dtype=np.double) ptr = np.array([0, 3, 6, 9, 10, 11, 12]) idx = np.array([1, 2, 3, 0, 2, 4, 0, 1, 5, 0, 1, 2]) N = 6 G = sp.csr_matrix((data, idx, ptr), shape=(N, N)) G = weighted(G, undirected=True) expect = np.matrix([[1., 1., 1., 1., 0.25, 0.25], [1., 1., 1., 0.25, 1., 0.25], [1., 1., 1., 0.25, 0.25, 1.00], [1., 0.25, 0.25, 1., 0.25, 0.25], [0.25, 1., 0.25, 0.25, 1., 0.25], [0.25, 0.25, 1., 0.25, 0.25, 1.00]]) run_test(G, expect)
def test_graph1_maxmin(): """ max-min epistemic closure on an arbitraty graph (ex. #1). """ G = np.matrix( [[0., 1., 0., 0., 0., 1., 0., 0.], [1., 0., 1., 0., 0., 0., 1., 0.], [0., 1., 0., 1., 0., 0., 0., 0.], [0., 0., 1., 0., 1., 1., 1., 0.], [0., 0., 0., 1., 0., 0., 0., 0.], [1., 0., 0., 1., 0., 0., 0., 1.], [0., 1., 0., 1., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 1., 0., 0.]], dtype=np.double) G = weighted(G, undirected=True) expect = np.matrix([[1., 1., 0.25, 0.25, 0.2, 1., 0.25, 0.25], [1., 1., 1., 0.33, 0.2, 0.33, 1., 0.25], [0.25, 1., 1., 1., 0.2, 0.25, 0.25, 0.25], [0.25, 0.33, 1., 1., 1., 1., 1., 0.25], [0.2, 0.2, 0.2, 1., 1., 0.2, 0.2, 0.20], [1., 0.33, 0.25, 1., 0.2, 1., 0.25, 1.00], [0.25, 1., 0.25, 1., 0.2, 0.25, 1., 0.25], [0.25, 0.25, 0.25, 0.25, 0.2, 1., 0.25, 1.00]]) run_test(G, expect)