# 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`

— Function`is_d_separated(dag, x, y, cond)`

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.

**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
```

`Dagitty.ConditionalIndependence`

— Type`ConditionalIndependence`

Structure representing conditional independency between two variables given conditioned set of variables.

`Dagitty.implied_conditional_independencies`

— Function`implied_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])
```

## 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: 95.59 us
test2: 97.65 us
```

Julia:

```
test1: 10.191 μs (205 allocations: 17.78 KiB)
test2: 11.556 μs (236 allocations: 20.33 KiB)
```