This bundle contains the manuscript published at International Journal of Approximate Reasoning and entitled "A Divide and Conquer Approach for Causal Computation". The organisation is the following:
- examples: a toy example for running the method proposed in the paper.
- ctfzeros: python sources implementing the method.
- models: set of structural causal models in UAI format considered in the experimentation.
- requirements.txt: code dependencies.
First of all, check the Python version. This sources have been coded with the following Python version:
!python --versionPython 3.11.2
Then, install the dependencies in the requirement.txt file. The main dependency is the python packege bcause (https://github.com/PGM-Lab/bcause).
!pip install --upgrade pip setuptools wheel
!pip install -r ./requirements.txtIn this repository, we provide functionality for preprocessing the model and data so they could work we our inference algorithm:
from ctfzeros.prepro import load_and_preprocessfilepath = "./models/synthetic/simple_nparents2_nzr10_zdr05_13.uai"
datapath = "./models/synthetic/simple_nparents2_nzr10_zdr05_13.csv"
model, data, _, _ = load_and_preprocess(filepath, datapath)
model<StructuralCausalModel (Y:2,X2:2,X1:2|Uy:16,Ux1:2,Ux2:2), dag=[Uy][Y|Uy:X2:X1][X2|Ux2][X1|Ux1][Ux1][Ux2]>
model.draw()data.dataframe tbody tr th {
vertical-align: top;
}
.dataframe thead th {
text-align: right;
}
| X2 | X1 | Y | |
|---|---|---|---|
| 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 |
| 2 | 0 | 1 | 1 |
| 3 | 0 | 1 | 1 |
| 4 | 0 | 1 | 1 |
| ... | ... | ... | ... |
| 995 | 0 | 1 | 1 |
| 996 | 0 | 1 | 0 |
| 997 | 0 | 1 | 1 |
| 998 | 0 | 1 | 0 |
| 999 | 0 | 1 | 1 |
1000 rows × 3 columns
First, load corresponding modules for using DCCC and EMCC:
from ctfzeros.divideconquer import DCCC_inverted_tree
from bcause.inference.causal.multi import EMCCSet up the DCCC inference engine with a number of solutions
infDCCC = DCCC_inverted_tree(model, data, num_runs=20)
infDCCC.prob_sufficiency("X1", "Y")[0.22996883482457, 0.6933748869005733]
Alternatively, each individual query can be obtained as follows:
Similarly, with the state of the art method EMCC interating up to 100 iterations each EM run.
infEMCC = EMCC(model,data,num_runs=20, max_iter=100)
infEMCC.prob_sufficiency("X1","Y")