def test_valid_insert_operators_5(self): # Define A and cache A = np.zeros_like(self.true_A) A[2, 4], A[4, 2] = 1, 1 # x2 - x4 A[4, 3] = 1 # x4 -> x3 cache = GaussObsL0Pen(self.obs_data) # Should fail as 2,4 are adjacent try: ges.score_valid_insert_operators(2, 4, A, cache, debug=False) self.fail() except ValueError as e: print("OK:", e) try: ges.score_valid_insert_operators(4, 2, A, cache, debug=False) self.fail() except ValueError as e: print("OK:", e) # Should fail as 3,4 are adjacent try: ges.score_valid_insert_operators(3, 4, A, cache, debug=False) self.fail() except ValueError as e: print("OK:", e) try: ges.score_valid_insert_operators(4, 3, A, cache, debug=False) self.fail() except ValueError as e: print("OK:", e)
def test_valid_insert_operators_8(self): A = np.array([[0, 0, 1, 0], [0, 0, 0, 1], [1, 1, 0, 0], [0, 0, 0, 0]]) data = self.obs_data[:, 0:4] cache = GaussObsL0Pen(data) # There should no valid operator for x2 -> x3 # 1. na_yx = set(), T0 = {0} # 2. for T=set(), na_yx U T = set() which is a clique, but does not # contain a node in the semi-directed path 2->1->3 # 3. for T = {0}, na_yx U T = {0} which is a clique, but does not # contain a node in the semi-directed path 2->1->3 valid_operators = ges.score_valid_insert_operators(3, 2, A, cache, debug=False) self.assertEqual(0, len(valid_operators))
def test_valid_insert_operators_1b(self): # Define A and cache A = np.zeros_like(self.true_A) A[2, 4], A[4, 2] = 1, 1 # x2 - x4 A[4, 3] = 1 # x4 -> x3 cache = GaussObsL0Pen(self.obs_data) # there should only be one valid operator, as # 1. X0 has no neighbors in A, so T0 = {set()} # 2. na_yx is also an empty set, thus na_yx U T is a clique # 3. there are no semi-directed paths from y to x valid_operators = ges.score_valid_insert_operators(1, 0, A, cache, debug=False) self.assertEqual(1, len(valid_operators)) _, new_A, _, _, _ = valid_operators[0] true_new_A = A.copy() true_new_A[1, 0] = 1 self.assertTrue((new_A == true_new_A).all())
def test_valid_insert_operators_4b(self): # Define A and cache A = np.zeros_like(self.true_A) A[2, 4], A[4, 2] = 1, 1 # x2 - x4 A[4, 3] = 1 # x4 -> x3 cache = GaussObsL0Pen(self.obs_data) # there should be one valid operator, as T0 = set(), na_yx = set() # 1. insert(X2,X3,set()) should be valid # 2. na_yx U T = set() should be a clique # 3. there are no semi-directed paths between X3 and X2 valid_operators = ges.score_valid_insert_operators(2, 3, A, cache, debug=False) self.assertEqual(1, len(valid_operators)) # Test outcome of insert(2,3,set()) _, new_A, _, _, _ = valid_operators[0] true_new_A = A.copy() true_new_A[2, 3] = 1 self.assertTrue((new_A == true_new_A).all())
def test_valid_insert_operators_4a(self): # Define A and cache A = np.zeros_like(self.true_A) A[2, 4], A[4, 2] = 1, 1 # x2 - x4 A[4, 3] = 1 # x4 -> x3 cache = GaussObsL0Pen(self.obs_data) # there should be one valid operator, as T0 = set(), na_yx = {4} # 1. insert(X0,X2,set()) should be valid # 2. na_yx U T = {X4} should be a clique # 3. the semi-directed path X2-X4->X3 contains one node in na_yx U T valid_operators = ges.score_valid_insert_operators(3, 2, A, cache, debug=False) self.assertEqual(1, len(valid_operators)) # Test outcome of insert(3,2,set()) _, new_A, _, _, _ = valid_operators[0] true_new_A = A.copy() true_new_A[3, 2] = 1 self.assertTrue((new_A == true_new_A).all())
def test_valid_insert_operators_6(self): A = np.array([[0, 0, 1, 0], [0, 0, 1, 1], [1, 1, 0, 0], [0, 0, 0, 0]]) data = self.obs_data[:, 0:4] cache = GaussObsL0Pen(data) # There should be one valid operator for x3 -> x2 # 1. na_yx = {1}, T0 = {0} # 2. for T=set(), na_yx U T = {1} which is a clique, and # contains a node in the semi-directed path 2-1->3 # 3. for T = {0}, na_yx U T = {0,1} which is not a clique valid_operators = ges.score_valid_insert_operators(3, 2, A, cache, debug=False) self.assertEqual(1, len(valid_operators)) # Test outcome of insert(3,2,set()) _, new_A, _, _, _ = valid_operators[0] true_new_A = A.copy() true_new_A[3, 2] = 1 self.assertTrue((new_A == true_new_A).all())
def test_valid_insert_operators_3a(self): # Define A and cache A = np.zeros_like(self.true_A) A[2, 4], A[4, 2] = 1, 1 # x2 - x4 A[4, 3] = 1 # x4 -> x3 cache = GaussObsL0Pen(self.obs_data) # there should be two valid operators, as T0 = {X4} # 1. insert(X1,X2,set()) should be valid # 2. and also insert(X1,X2,{X4}), as na_yx U T = {X4} and is a clique # 3. there are no semi-directed paths from y to x valid_operators = ges.score_valid_insert_operators(1, 2, A, cache, debug=False) self.assertEqual(2, len(valid_operators)) # Test outcome of insert(0,2,set()) _, new_A, _, _, _ = valid_operators[0] true_new_A = A.copy() true_new_A[1, 2] = 1 self.assertTrue((new_A == true_new_A).all()) # Test outcome of insert(1,2,4) _, new_A, _, _, _ = valid_operators[1] true_new_A = A.copy() true_new_A[1, 2], true_new_A[2, 4] = 1, 0 self.assertTrue((new_A == true_new_A).all())