Skip to content

Commit

Permalink
addd basic example / sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bradendubois committed Jan 18, 2022
1 parent 8817652 commit 274fa52
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/1-basic-backdoor/deconfound.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pathlib import Path

from do import API, Expression, Intervention, Outcome

api = API()

file = Path("pearl-3.4.yml")
model = api.instantiate_model(file)

xj = Outcome("Xj", "xj")
xi = Intervention("Xi", "xi")
e = Expression(xj, [xi])

# basic inference won't work!
try:
api.probability(e, model)
print("This cannot happen!")

except Exception:
e2 = Expression(xj)
result = api.treat(e2, [xi], model)
print(result)
116 changes: 116 additions & 0 deletions examples/1-basic-backdoor/pearl-3.4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: 'Pearl: Figure 3.4'
endogenous:
X1:
outcomes:
- x1
- ~x1
parents: []
table: [
[x1, 0.4],
[~x1, 0.6]
]
X2:
outcomes:
- x2
- ~x2
parents: []
table: [
[x2, 0.15],
[~x2, 0.85]
]
X3:
outcomes:
- x3
- ~x3
parents:
- X1
table: [
[x3, x1, 0.1],
[x3, ~x1, 0.3],
[~x3, x1, 0.9],
[~x3, ~x1, 0.7]
]
X4:
outcomes:
- x4
- ~x4
parents:
- X1
- X2
table: [
[x4, x1, x2, 0.7],
[x4, x1, ~x2, 0.9],
[x4, ~x1, x2, 0.55],
[x4, ~x1, ~x2, 0.15],
[~x4, x1, x2, 0.3],
[~x4, x1, ~x2, 0.1],
[~x4, ~x1, x2, 0.45],
[~x4, ~x1, ~x2, 0.85]
]
X5:
outcomes:
- x5
- ~x5
parents:
- X2
table: [
[x5, x2, 0.8],
[x5, ~x2, 0.25],
[~x5, x2, 0.2],
[~x5, ~x2, 0.75]
]
X6:
outcomes:
- x6
- ~x6
parents:
- Xi
table: [
[x6, xi, 0.9],
[x6, ~xi, 0.25],
[~x6, xi, 0.1],
[~x6, ~xi, 0.75]
]
Xi:
outcomes:
- xi
- ~xi
parents:
- X3
- X4
table: [
[xi, x3, x4, 0.5],
[xi, x3, ~x4, 0.65],
[xi, ~x3, x4, 0.1],
[xi, ~x3, ~x4, 0.25],
[~xi, x3, x4, 0.5],
[~xi, x3, ~x4, 0.35],
[~xi, ~x3, x4, 0.9],
[~xi, ~x3, ~x4, 0.75]
]
Xj:
outcomes:
- xj
- ~xj
parents:
- X6
- X4
- X5
table: [
[xj, x6, x4, x5, 0.0],
[xj, x6, x4, ~x5, 0.25],
[xj, x6, ~x4, x5, 0.7],
[xj, x6, ~x4, ~x5, 0.45],
[xj, ~x6, x4, x5, 0.15],
[xj, ~x6, x4, ~x5, 0.8],
[xj, ~x6, ~x4, x5, 0.95],
[xj, ~x6, ~x4, ~x5, 0.05],
[~xj, x6, x4, x5, 1.0],
[~xj, x6, x4, ~x5, 0.75],
[~xj, x6, ~x4, x5, 0.3],
[~xj, x6, ~x4, ~x5, 0.55],
[~xj, ~x6, x4, x5, 0.85],
[~xj, ~x6, x4, ~x5, 0.2],
[~xj, ~x6, ~x4, x5, 0.05],
[~xj, ~x6, ~x4, ~x5, 0.95]
]

0 comments on commit 274fa52

Please sign in to comment.