Giter VIP home page Giter VIP logo

causal_learning_unknown_interventions's Introduction

Learning Neural Causal Models from Unknown Interventions

This is a Pytorch implementation of the Learning Neural Causal Models from Unknown Interventions paper. Here we learn the causal model based on a meta-learning transfer objective from unknown intervention data. Please cite:

Nan Rosemary Ke*, Olexa Bilaniuk*, Anirudh Goyal, Stefan Bauer, Hugo Larochelle, Chris Pal, Yoshua Bengio

@article{ke2019learning,
    title={Learning Neural Causal Models from Unknown Interventions},
    author={Ke, Nan Rosemary and Bilaniuk, Olexa and Goyal, Anirudh and Bauer, Stefan and Larochelle, Hugo and Pal, Chris and Bengio, Yoshua},
    journal={arXiv preprint arXiv:1910.01075},
    year={2019}
}

Installation

  1. This code is based on Pytorch. The conda enviroment for running this code can be installed as follows,
conda env create -f environment.yml

pip install -e .

CPU features required: AVX2, FMA (Intel Haswell+)


  1. Training code
# chain3
python run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p chain3  

# fork3
python run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p fork3

# collider3
python run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p collider3

# confounder3
python run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p confounder3

--seed specifies the random seed

--mopt specifies the optimizer and learning rate used to train the functional parameters

--gopt specifies the optimizer and learning rate used to train the structural parameters

--predict specifies the number of samples used for predicting the intervened node. Specifying 0 for this argument uses the groundtruth intervention node.

--temperature specifies the temperature setting fot the softmax for the groundtruth structured causal model.

-N specifies the number of categories for the categorical distribution

-M specifies the number of discrete random variables

--graph allows one to specify via the command-line several causal DAG skeletons.

-p specifies, by name, one of several --graph presets for groundtruth causal graphs (e.g. chain3).

--train_functional specifies how many iterations to train the functional parameters.

--limit-samples specifies the number of samples used per intervention. Suggest to use 500 for graphs of size < 10 and 1000 for graphs size between 10 and 15.

By default, the models and log files are stored in the work directory.


  1. Extracting useful information from log files.

Strip all the SLURM output of interruptions:

scripts/strip_interrupts.py slurm-%j.out         > STRIPPED_LOGFILE.txt

Extract gamma CE timeseries

scripts/series_gammace.py   STRIPPED_LOGFILE.txt > gammace.txt

Compute AUROC-over-time

scripts/series_auc.py       STRIPPED_LOGFILE_1.txt STRIPPED_LOGFILE_2.txt STRIPPED_LOGFILE_3.txt STRIPPED_LOGFILE_4.txt STRIPPED_LOGFILE_5.txt > auc.txt

causal_learning_unknown_interventions's People

Contributors

nke001 avatar obilaniu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

causal_learning_unknown_interventions's Issues

AttributeError: module 'causal' has no attribute '_causal'

Hello @nke001 , I'm thrilled you put together this package and I just finished reading the corresponding paper. I seem to have a problem running this in my python 3.9.6 virtual environment. I'm able to install all of the requirements, but when I run the command python run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p confounder3 as listed in your README, I get the following error:

[2021-09-19 11:55:03.091 EDT ~~ INFO    ] *****************************************
[2021-09-19 11:55:03.091 EDT ~~ INFO    ] Command:             run.py train --seed 1 --train_functional 10000 --mopt adam:5e-2,0.9 --gopt adam:5e-3,0.1 -v 500 --lsparse 0.1 --bs 256 --ldag 0.5 --predict 100 --temperature 1 --limit-samples 500 -N 2 -p confounder3
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] CWD:                 /Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] Experiment Name:     1-cat-200-256-10-10000-100-None-None-3-2-2-20-10-100-10-1.0-1.0-1.0-['{0-2}->{0-2}']-[]-Namespace(lr=0.05, beta1=0.9, beta2=0.999, eps=1e-08, name='adam')-Namespace(lr=0.005, beta1=0.1, beta2=0.999, eps=1e-08, name='adam')-0.0-[Namespace(lr=0.1, name='const')]-0.5-0-500-0
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] Experiment UUID:     M3_N2_T1.0_predict100_BS256_seed1_lsparse[Namespace(lr=0.1, name='const')]__UUID-8fa3a767-0f7c-5922-eb09-ffcd53838ac4
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] Experiment Work Dir: /Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/work/CausalOptimization-40037046-a359-470b-b327-af9bbef3e532/by-uuid/M3_N2_T1.0_predict100_BS256_seed1_lsparse[Namespace(lr=0.1, name='const')]__UUID-8fa3a767-0f7c-5922-eb09-ffcd53838ac4
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] 
[2021-09-19 11:55:03.092 EDT ~~ INFO    ] 
Traceback (most recent call last):
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/run.py", line 206, in <module>
    sys.exit(main(sys.argv))
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/run.py", line 202, in main
    return a.__cls__.run(a)
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/run.py", line 174, in run
    return Experiment(a).rollback().run().exitcode
  File "/Users/roni_kobrosly/Desktop/Nauka/src/nauka/exp/experiment.py", line 155, in rollback
    else:                  return self.fromScratch()
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/causal/experiment.py", line 206, in fromScratch
    self.reseed(password="Seed: {} Init".format(self.a.seed))
  File "/Users/roni_kobrosly/Desktop/causal_learning_unknown_interventions/causal/experiment.py", line 65, in reseed
    causal._causal.seed(nauka.utils.pbkdf2int(64, password))
AttributeError: module 'causal' has no attribute '_causal'

So it seems I'm not able to read the _causal.c file in the package. I imagine this is because it's written in C. Could you help me understand what I'm doing wrong here?

About C code conversion to Python

Your work is very instructive, but the C part of the code can't be debugged.
I want to learn about the function :
causal._causal.sample_mlp(self._np_W0gt, self._np_B0gt,
self._np_W1gt, self._np_B1gt,
self.N, self.gammagt.numpy(),
out=s, alpha=0.1)
(located in line 384 under the models.py folder)

and another function :
causal._causal.logprob_mlp(self._np_W0slow,
self._np_B0slow,
self._np_W1slow,
self._np_B1slow,
self.N,
block,sample,config,logp,
alpha=0.1,temp=self.a.temperature)
(located in line 401 under the models.py folder).
Are these two functions implemented in Python? Or could you please describe the specific process of these two algorithms in detail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.