D-separation
D-Separation is a method to find from causal DAG which variables are indendent on each other given some set of conditioned variables.
Dagitty.is_d_separated
— Functionis_d_separated(dag, x, y, cond; ignore_edges)
Checks that X variables are independent on Y variables being conditioned on third set of variables. Three sets could be given as vectors of node labels (Symbol
) or as vectors of node indices in the underlying graph. Used NetworkX d_separated
implementation.
Argument ignore_edges
can contain list of node pairs of edges to be ignored during the test.
Examples
julia> using Dagitty
julia> g = DAG(:A => :C, :C => :B)
DAG: {3, 2} directed simple Int64 graph with labels [:A, :B, :C])
julia> is_d_separated(g, [:A], [:B], [:C])
true
julia> is_d_separated(g, [:A], [:C], [:B])
false
julia> is_d_separated(g, [1], [2], [3])
true
julia> g = DAG(:A => :B, :A => :C, :C => :B)
DAG: {3, 3} directed simple Int64 graph with labels [:A, :B, :C])
julia> is_d_separated(g, [:A], [:B], [:C], ignore_edges=[:A => :B])
true
Dagitty.ConditionalIndependence
— TypeConditionalIndependence
Structure representing conditional independency between two variables given conditioned set of variables.
Dagitty.implied_conditional_independencies
— Functionimplied_conditional_independencies(dag)
From given DAG find all pair-wise conditional independencies of nodes. Returns vector of ConditionalIndependence
structures.
Examples
julia> using Dagitty
julia> g = DAG(:A => :C, :C => :B)
DAG: {3, 2} directed simple Int64 graph with labels [:A, :B, :C])
julia> implied_conditional_independencies(g)
1-element Vector{ConditionalIndependence}:
ConditionalIndependence(:A, :B, [:C])
Dagitty.implied_conditional_independencies_min
— Functionimplied_conditional_independencies_min
From given DAG return all pair-wise conditional independencies of nodes with minimal condition set.
Examples
julia> using Dagitty
julia> plant_dag = Dagitty.DAG(:H_0 => :H_1, :F => :H_1, :T => :F)
DAG: {4, 3} directed simple Int64 graph with labels [:F, :H_0, :H_1, :T])
julia> implied_conditional_independencies_min(plant_dag)
3-element Vector{ConditionalIndependence}:
ConditionalIndependence(:F, :H_0, Symbol[])
ConditionalIndependence(:H_0, :T, Symbol[])
ConditionalIndependence(:H_1, :T, [:F])
Benchmark of D-separation
I've done simple benchmark on "asia graph" (taken from NetworkX test suite). Code is in bench/t1.{py,jl}
. Results:
Python:
test1: 82.38 us
test2: 81.57 us
Julia:
test1: 7.998 μs (191 allocations: 16.58 KiB)
test2: 9.079 μs (225 allocations: 19.30 KiB)