@@ -28,35 +28,38 @@ function meek_rules!(g; rule4=false)
2828end
2929
3030"""
31- meek_rule1(dg , v, w)
31+ meek_rule1(g , v, w)
3232
3333Rule 1: Orient v-w into v->w whenever there is u->v
3434such that u and w are not adjacent
3535(otherwise a new v-structure is created.)
3636"""
37- function meek_rule1 (dg, v, w)
38- for u in inneighbors (dg, v)
39- has_edge (dg, v => u) && continue # not directed
40- isadjacent (dg, u, w) && continue
37+ function meek_rule1 (g, v, w)
38+ for u in inneighbors (g, v)
39+ u == w && continue
40+ has_edge (g, v => u) && continue # not directed
41+ isadjacent (g, u, w) && continue
4142 return true
4243 end
4344 return false
4445end
4546
4647"""
47- meek_rule2(dg , v, w)
48+ meek_rule2(g , v, w)
4849
4950Rule 2: Orient v-w into v->w whenever there is a chain v->k->w
5051(otherwise a directed cycle is created.)
5152"""
52- function meek_rule2 (dg , v, w)
53+ function meek_rule2 (g , v, w)
5354 outs = Int[]
54- for k in outneighbors (dg, v)
55- ! has_edge (dg, k => v) && push! (outs, k)
55+ for k in outneighbors (g, v)
56+ k == w && continue
57+ ! has_edge (g, k => v) && push! (outs, k)
5658 end
5759 ins = Int[]
58- for k in inneighbors (dg, w)
59- ! has_edge (dg, w => k) && push! (ins, k)
60+ for k in inneighbors (g, w)
61+ k == v && continue
62+ ! has_edge (g, w => k) && push! (ins, k)
6063 end
6164 if ! disjoint_sorted (ins, outs)
6265 return true
@@ -65,42 +68,42 @@ function meek_rule2(dg, v, w)
6568end
6669
6770"""
68- meek_rule3(dg , v, w)
71+ meek_rule3(g , v, w)
6972
7073Rule 3 (Diagonal): Orient v-w into v->w whenever there are two chains
7174v-k->w and v-l->w such that k and l are nonadjacent
7275(otherwise a new v-structure or a directed cycle is created.)
7376"""
74- function meek_rule3 (dg , v, w)
75- fulls = [] # Find nodes k where v-k
76- for k in outneighbors (dg , v)
77- has_edge (dg , k => v) || continue
77+ function meek_rule3 (g , v, w)
78+ fulls = Int [] # Find nodes k where v-k
79+ for k in outneighbors (g , v)
80+ has_edge (g , k => v) || continue
7881 # Skip if not k->w (or if not l->w)
79- if has_edge (dg , w => k) || ! has_edge (dg , k => w)
82+ if has_edge (g , w => k) || ! has_edge (g , k => w)
8083 continue
8184 end
8285 push! (fulls, k)
8386 end
8487 for (k, l) in combinations (fulls, 2 ) # FIXME :
85- isadjacent (dg , k, l) && continue
88+ isadjacent (g , k, l) && continue
8689 return true
8790 end
8891 return false
8992end
9093
9194"""
92- meek_rule4(dg , v, w)
95+ meek_rule4(g , v, w)
9396
9497Rule 4: Orient v-w into v→w if v-k→l→w where adj(v,l) and not adj(k,w) [check].
9598"""
96- function meek_rule4 (dg , v, w)
97- for l in inneighbors (dg , w)
98- has_edge (dg , w => l) && continue # undirected
99- ! isadjacent (dg , v, l) && continue # not adjacent to v
100- for k in inneighbors (dg , l)
101- has_edge (dg , l => k) && continue # undirected
102- ! has_both (dg , v, k) && continue # not undirected to v
103- isadjacent (dg , k, w) && continue # adjacent to w
99+ function meek_rule4 (g , v, w)
100+ for l in inneighbors (g , w)
101+ has_edge (g , w => l) && continue # undirected
102+ ! isadjacent (g , v, l) && continue # not adjacent to v
103+ for k in inneighbors (g , l)
104+ has_edge (g , l => k) && continue # undirected
105+ ! has_both (g , v, k) && continue # not undirected to v
106+ isadjacent (g , k, w) && continue # adjacent to w
104107 return true
105108 end
106109 end
0 commit comments