This repository is the official implementation to reproduce the experiments described in "Causal Discovery for time series from multiple datasets with latent contexts" by W. Günther, U. Ninad, and J. Runge (accepted at UAI 2023).
To install the requirements run:
pip install -r requirements.txt
In this section, we describe how to run the whole experimental pipeline (data generation, method evaluation, metric calculation, plotting) to generate the results and plots presented in the paper.
In the config.py file you can specify the paths in which the output of these experiments should be stored.
To run the main experiments, execute this command:
python run_experiments.py --experiment 0
This generates toy-data from the SCM
where
It then computes the output of the J-PCMCI+, PCMCI+ with observed context variables, PCMCI+ with dummy variables and original PCMCI+ on system variables.
Using the ground truth graphs and output graphs of these methods, it calculates the metrics which are described in more detail in the paper, and plots the results.
To run a simpler (and quicker) linear version of the experiments, run this command:
python run_experiments.py --experiment 1
This generates toy-data from a simplified version of the SCM above, namel 7225 y from
And then proceeds as described above.
The results of this experimental setup are
To run a nonlinear variant of the simplified experiments, run this command:
python run_experiments.py --experiment 2
This generates toy-data from the following SCM
And then proceeds as described above.
The results of this experimental setup are
You can also only generate data for specific parameter settings and compare the algorithms on these. This is done by running this command:
python compute.py --experiment 1
Using the parameters you can specify:
-
cfloat, dependence factor between$X$ and$Y$ -
affected_varslist[str], list of the affected nodes, default is['x', 'y'] -
hs_typeslist[str], functional form and dependence of heteroskedasticity, either'linear_z','periodic_z', or'quadratic_z'or'linear_time','periodic_time', or'quadratic_time', default is['linear_time'] -
strengthfloat, the strength of heteroskedasticity, default is5. -
sample_sizeint, sample size -
random_seedint or None, random seed to be used for the experiment
-e -ss <sample_size> -d <nb_domains> -n <nb_nodes> -l <nb_links> -kt <k_time> "
"-ks <k_space> -o <frac_observed> -f <functional_form> -t <ci_test> -a <pc_alpha> -tm <tau_max> "
"-nr <nb_realisations>
To calculate the metrics on pre-computed outputs of the methods, run:
python methods.py --experiment 0
Using the parameters you can specify:
experiment{0, 1, 2}, experiment type
python plot.py --experiment 0
Again, using the parameters you can specify:
experiment{0, 1, 2}, experiment type
You can redistribute and/or modify the code under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.