{"id":20723636,"url":"https://github.com/networks-learning/counterfactual-tpp","last_synced_at":"2025-04-23T17:27:31.466Z","repository":{"id":40792761,"uuid":"391908193","full_name":"Networks-Learning/counterfactual-tpp","owner":"Networks-Learning","description":"Code and real data for \"Counterfactual Temporal Point Processes\", NeurIPS 2022","archived":false,"fork":false,"pushed_at":"2022-09-26T09:10:07.000Z","size":7169,"stargazers_count":15,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T01:51:45.346Z","etag":null,"topics":["counterfactual","explainable-ai","explainable-ml","gumbel-max","point-process","structural-causal-model","temporal-point-process"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2111.07603","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Networks-Learning.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-02T10:37:35.000Z","updated_at":"2024-04-09T14:51:19.000Z","dependencies_parsed_at":"2023-01-18T09:49:16.178Z","dependency_job_id":null,"html_url":"https://github.com/Networks-Learning/counterfactual-tpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Networks-Learning%2Fcounterfactual-tpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Networks-Learning%2Fcounterfactual-tpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Networks-Learning%2Fcounterfactual-tpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Networks-Learning%2Fcounterfactual-tpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Networks-Learning","download_url":"https://codeload.github.com/Networks-Learning/counterfactual-tpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250479613,"owners_count":21437395,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["counterfactual","explainable-ai","explainable-ml","gumbel-max","point-process","structural-causal-model","temporal-point-process"],"created_at":"2024-11-17T04:09:17.465Z","updated_at":"2025-04-23T17:27:31.444Z","avatar_url":"https://github.com/Networks-Learning.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# counterfactual-tpp\nThis is a repository containing code and real data for the paper [Counterfactual Temporal Point Processes](https://arxiv.org/abs/2111.07603), published at NeurIPS 2022.\n## Pre-requisites\n\nThis code depends on the following packages:\n\n 1. [`networkx`](https://networkx.org/)\n 2. `numpy`\n 3. `pandas`\n 4. `matplotlib`\n \n \n to generate map plots:\n \n 5. [`GeoPandas`](https://geopandas.org/)\n 6. `geoplot`\n\nIn order to install the project dependencies you can run the following command:\n```bash\npip install -r requirements.txt\n```\n## Code structure\n\n - [src/counterfactual_tpp.py:](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/src/counterfactual_tpp.py) Contains the code to sample rejected events using the superposition property and the algorithm to calculate the counterfactuals.\n - [src/gumbel.py:](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/src/gumbel.py) Contains the utility functions for the Gumbel-Max SCM.\n - [src/sampling_utils.py:](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/src/sampling_utils.py) Contains the code for the Lewis' thinning algorithm (`thinning_T` function) and some other sampling utilities.\n - [src/hawkes/hawkes.py:](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/src/hawkes/hawkes.py) Contains the code for sampling from the hawkes process using the superposition property of tpps. It also includes the algorithm for sampling a counterfactual sequence of events given a sequence of observed events for a Hawkes process.\n - [src/hawkes/hawkes_example.ipynb:](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/src/hawkes/hawkes_example.ipynb) Contains an example of running algorithm 3 (in the paper) for both cases where we have (1) both observed and un-observed events, and (2) the case that we have only the observed events.\n - [ebola/graph_generation.py:](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/ebola/graph_generation.py) Contains code to build the Ebola network based on the network of connected\n    districts. This code is adopted from the [disease-control](https://github.com/Networks-Learning/disease-control) project. \n - [ebola/dynamics.py:](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/ebola/dynamics.py) Contains code for sampling counterfactual sequence of infections given a sequence of observed infections from the SIR porcess (the ` calculate_counterfactual` function). The rest of the code is adopted from the [disease-control](https://github.com/Networks-Learning/disease-control) project, which simulates continuous-time SIR epidemics with exponentially distributed\n    inter-event times.\n\nThe directory [ebola/data/ebola](https://github.com/Networks-Learning/counterfactual-tpp/tree/main/ebola/data/ebola) contains the information about the Ebola network adjanceny matrix and the cleaned ebola outbreak data adopted from the [disease-control](https://github.com/Networks-Learning/disease-control) project.\n\nThe directory [ebola/map/geojson](https://github.com/Networks-Learning/counterfactual-tpp/tree/main/ebola/map/geojson) contains the geographical information of the districts studied in the Ebola outbreak dataset. The geojson files are obtained from [Nominatim](https://nominatim.openstreetmap.org/ui/search.html).\n\nThe directory [ebola/map/overall_data](https://github.com/Networks-Learning/counterfactual-tpp/tree/main/ebola/map/overall_data) contains data for generating the geographical maps in the paper, and includs the overall number of infection under applying different interventions.\n\nThe directories [src/data_hawkes](https://github.com/Networks-Learning/counterfactual-tpp/tree/main/src/data_hawkes) and [src/data_inhomogeneous](https://github.com/Networks-Learning/counterfactual-tpp/tree/main/src/data_inhomogeneous) contain observational data used to generate Synthetic plots in the paper. You can use this data to re-generate paper's plots. Otherwise, you can simply generate new random samples by the code.\n\n## Experiments \n\n### Synthetic\n - [Inhomogeneous Poisson Processes](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/src/inhomogeneous_experiments.ipynb)\n - [Hawkes Processes](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/src/hawkes_experiments.ipynb)\n\n### Epidemiological\n- [Ebola Epidemic Simulation and Counterfactual Calculations](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/ebola/ebola_experiments.ipynb)\n- [Generate Geographical Distribution of infections](https://github.com/Networks-Learning/counterfactual-tpp/blob/main/ebola/map/generate_geopands_data.ipynb)\n\n## Citation\nIf you use parts of the code in this repository for your own research, please consider citing:\n\n```\n@inproceedings{noorbakhsh2022counterfactual,\n        title={Counterfactual Temporal Point Processes},\n        author={Noorbakhsh, Kimia and Gomez-Rodriguez, Manuel},\n        booktitle={Advances in Neural Information Processing Systems},\n        year={2022}\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworks-learning%2Fcounterfactual-tpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetworks-learning%2Fcounterfactual-tpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetworks-learning%2Fcounterfactual-tpp/lists"}