def backdoor(G, X, Z, Y, **OptionalPlot): PlotBackDoor = False if (('Plot' in OptionalPlot) and (OptionalPlot['Plot']) == True): PlotBackDoor = True D = G.descendant([X]) tmp = X.nodeout for m in tmp: m.nodein = list(set(m.nodein) - set([X])) X.nodeout = [] if (PlotBackDoor): R = dsep.reachable(G, X, Z, Plot=True) else: R = dsep.reachable(G, X, Z, Plot=False) reachable = (Y not in R) X.nodeout = tmp for m in tmp: m.nodein = list(set(m.nodein) | set([X])) desc = True for z in Z: if z in D: desc = False # if (PlotBackDoor): # direct=G.BFS(X,Y) # for d in direct: # R=list(set(R)|set(d)) # plot.plotRGBColor(G,R , Z) result = reachable and desc return result
def rule3(G, X, Z, W, Y): G1=copy.deepcopy(G) result=[] ancestor=[] Wname=[] subset=[] for w in W: Wname.append(w.name) for j in G1.nodelist: if(j.name==X.name): subset=list(set(subset)|set([X])) for i in j.nodein: i.nodeout = list(set(i.nodeout) - set([j])) j.nodein=[] for j in G1.nodelist: if(j.name in Wname): subset=list(set(subset)|set([j])) ancW=G1.ancestor(j) ancestor=list(set(ancestor)|set(ancW)) nodeZ=list(set(G1.nodelist)- set(ancestor)) for z in nodeZ: for i in z.nodein: i.nodeout = list(set(i.nodeout) - set([z])) z.nodein=[] R=dsep.reachable(G, Z, subset) if(Y not in R): result.append(R)
def rule2(G, X, Z, W, Y): result=[] tmpX=X.nodein X.nodein=[] for x in tmpX: x.nodeout = list(set(j.nodeout) - set([X])) tmpZ=Z.nodeout Z.nodeout=[] for z in tmpZ: z.nodeout = list(set(z.nodeout) - set([Z])) subset=list(set(W)|set([X])) R=dsep.reachable(G, Z, subset) if(Y not in R): result.append(R)
def rule1 (G, X, Z, W, Y): result = [] tmp = X.nodein X.nodein = [] for j in tmp: j.nodeout = list(set(j.nodeout) - set([X])) subset=list(set(W)|set([X])) R=dsep.reachable(G, Z, subset) if(Y not in R): result.append(R) for j in tmp: j.nodeout = list(set(j.nodeout)|set([X])) X.nodein = tmp return result