Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identification algorithms #82

Merged
merged 31 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
69fb4c8
initial commit identification algorithms
mwien Jan 25, 2023
73003f5
start adding gensearch
mwien May 24, 2023
054194e
Merge branch 'mschauer:master' into idalgorithms
mwien May 24, 2023
536625d
add gensearch and first algorithms
May 24, 2023
e957bf3
structure gensearch file
mwien May 24, 2023
0969229
added min stuff plus frontdoor
mwien May 27, 2023
679b015
added listing algorithms for adjustment sets
mwien May 28, 2023
6ae0a86
started testing
mwien May 28, 2023
304cb95
introduce veto function
mwien Jun 5, 2023
e006d33
code golfing
mwien Jun 5, 2023
32229da
further testing and polishing
Jun 6, 2023
d0ac2b4
started with testing
mwien Jun 6, 2023
dfbbb7e
testing
Jun 7, 2023
4e558e9
first draft done
mwien Jun 7, 2023
cccef28
minor changes
Jun 8, 2023
ce3284f
work on documentation
Jun 14, 2023
20d1b9a
fix comment
mwien Jun 15, 2023
d1851ae
change strings to symbols
mwien Jun 15, 2023
e7e0a98
implement simple version of Chickering's dag-to-cpdag
mwien Jun 25, 2023
8312c0b
fix error in listing algorithms e.g. for backdoor and frontdoor
mwien Jun 25, 2023
e8fdc0b
typo
mwien Jun 25, 2023
e5ee3b0
new topological sort
Jun 26, 2023
c843d8f
add summary for run-time discussion on cpdag(g)
mwien Jun 28, 2023
ab5f4c9
minor optimizations
mwien Jul 3, 2023
7f7c4ac
remove incorrect comment about minimal bd
Jul 4, 2023
a84910d
add minimal bd function
Jul 4, 2023
e82caa4
start adding second test set
Jul 6, 2023
3f9b6b5
second test set done
Jul 6, 2023
e4c33a8
make functions wallable with ints and vectors
Jul 9, 2023
f5d84dd
polish code
mwien Jul 10, 2023
a47e6ca
polishing docs
mwien Jul 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/CausalInference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ using Graphs.SimpleGraphs
using Combinatorics
using Base.Iterators

export ancestors, descendants, alt_test_dsep, test_covariate_adjustment, alt_test_backdoor, find_dsep, find_min_dsep, find_covariate_adjustment, find_backdoor_adjustment, find_min_covariate_adjustment, find_frontdoor_adjustment, list_dseps, list_covariate_adjustment, list_backdoor_adjustment, list_frontdoor_adjustment
export dsep, skeleton, gausscitest, dseporacle, partialcor
export unshielded, pcalg, vskel
export cpdag
export cpdag, alt_cpdag
export digraph, vpairs, skel_oracle, pc_oracle, randdag
export cmitest, kl_entropy, kl_renyi, kl_mutual_information
export kl_cond_mi, kl_perm_mi_test, kl_perm_cond_mi_test
Expand All @@ -30,6 +31,7 @@ include("fci.jl")
include("misc.jl")
include("recantingwitness.jl")
include("backdoor.jl")
include("gensearch.jl")

# Compatibility with the new "Package Extensions" (https://github.com/JuliaLang/julia/pull/47695)
const EXTENSIONS_SUPPORTED = isdefined(Base, :get_extension)
Expand Down
5 changes: 5 additions & 0 deletions src/backdoor.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export backdoor_criterion
export backdoors

# TODOs
# - start with implementing a general Bayes-Ball type graph search
# - then implement efficient algorithms for finding backdoor adjustment sets


function backdoors(g::AbstractGraph{T}, U::Vector) where {T}
seen = zeros(Bool, nv(g))
bd = zeros(Bool, nv(g))
Expand Down
49 changes: 49 additions & 0 deletions src/cpdag.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
import Base: iterate, length

"""
alt_cpdag(g::DiGraph)

Computes CPDAG from a DAG using a simpler adaption of Chickering's conversion algorithm without ordering all edges
(equivalent to the PC algorithm with `d`-seperation as independence test, see `pc_oracle`.)
mschauer marked this conversation as resolved.
Show resolved Hide resolved

Reference: M. Chickering: Learning equivalence classes of Bayesian
network structures. Journal of Machine Learning Research 2 (2002).
M. Chickering: A Transformational Characterization of Equivalent Bayesian Network Structures. (1995).
"""
function alt_cpdag(g)
compelled = SimpleDiGraph(nv(g))
reversible = SimpleDiGraph(nv(g))
to = topological_sort_by_dfs(g)
invto = invperm(to)
iscompelled = falses(nv(g))
for y in to
indegree(g, y) == 0 && continue
x = argmax(x -> invto[x], inneighbors(g, y))
iscompelled[inneighbors(g, y)] .= false
for w in inneighbors(compelled, x)
if !has_edge(g, w, y)
iscompelled[inneighbors(g, y)] .= true
@goto add_edges
else
iscompelled[w] = true
end
end
for z in inneighbors(g, y)
z == x && continue
if !has_edge(g, z, x)
iscompelled[inneighbors(g, y)] .= true
@goto add_edges
end
end
@label add_edges
for v in inneighbors(g, y)
if iscompelled[v]
add_edge!(compelled, v, y)
else
add_edge!(reversible, v, y)
add_edge!(reversible, y, v)
end
end
end
return union(compelled, reversible)
end


"""
ordered_edges(dag)

Expand Down
Loading