Closed archanarw closed 3 years ago
mechanism
is a function I wrote to return the SCM at each node in CausalModel
. In "Causal Inference in Statistics: A Primer", the authors have called the functions mechanisms, so I used the same name.I'll merge then if no protest.
Some high level comments.
It shouldn't be the case that you have Omega random variables as the nodes of your causal graph, instead you should implement the interfaces of Omega. These are
m(\omega)
where M :: CausalModelsing CounterfactualFairness, Test
using Omega, Distributions
# U₁ = 1 ~ Normal(27, 5)
# U₂ = 2 ~ Normal(2, 4)
# U₃ = 3 ~ Normal(1, 2)
# X = U₁
# Ya(ω) = 4 * X(ω)
# Yb(ω) = Ya(ω) + U₂(ω)
# Z(ω) = X(ω) / U₃
g = CausalModel()
U₁ = add_exo_variable!(g, :U₁, 1 ~ Normal(27, 5))
U₂ = add_exo_variable!(g, :U₂, 2 ~ Normal(27, 5))
U₃ = add_exo_variable!(g, :U₃, 3 ~ Normal(27, 5))
X = add_endo_variable!(g, :X, identity, U₁)
Ya = add_endo_variable!(g, :Ya, *, 4, X)
Yb = add_endo_variable!(g, :Yb, +, Ya, U₂)
Z = add_endo_variable!(g, :Yb, /, X, U₃)
@test typeof(X) == CausalVar
output = apply_context(g, (U₁ = 1.23, U₂ = 15, U₃ = 1.451))
ω = defω()
output2 = g(ω)
@test typeof(output) == typeof(output2)
@test typeof(X(ω)) == Float64
@test X(ω) == output2.X
g = add_vertex(g, (:Temp, identity))
g = add_vertex(g, (:IceCreamSales, Y))
g = add_vertex(g, (:Crime, Z))
Z_intervene = intervene(Z. X => 12.30)
Z_intervene(ω)
@test Z_intervene != Z(ω)
Very nice, I could use some words taking me through this. 1.) The
mechanism
s inherited from Omega, can I think of them as Markov kernels? 2.) Differentiability with respect to which variables are you talking about?