{"id":30703277,"url":"https://github.com/vdblm/causalpfn","last_synced_at":"2025-09-02T16:58:32.675Z","repository":{"id":298140991,"uuid":"999002254","full_name":"vdblm/CausalPFN","owner":"vdblm","description":"CausalPFN: Amortized Causal Effect Estimation via In-Context Learning","archived":false,"fork":false,"pushed_at":"2025-08-10T18:33:30.000Z","size":46552,"stargazers_count":47,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-10T20:34:08.040Z","etag":null,"topics":["causal-inference","causalpfn","foundation-models","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vdblm.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-09T15:30:33.000Z","updated_at":"2025-08-03T17:21:29.000Z","dependencies_parsed_at":"2025-07-28T03:20:47.518Z","dependency_job_id":null,"html_url":"https://github.com/vdblm/CausalPFN","commit_stats":null,"previous_names":["vdblm/causalpfn"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vdblm/CausalPFN","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdblm%2FCausalPFN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdblm%2FCausalPFN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdblm%2FCausalPFN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdblm%2FCausalPFN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vdblm","download_url":"https://codeload.github.com/vdblm/CausalPFN/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdblm%2FCausalPFN/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273317757,"owners_count":25084037,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["causal-inference","causalpfn","foundation-models","machine-learning"],"created_at":"2025-09-02T16:58:27.090Z","updated_at":"2025-09-02T16:58:32.666Z","avatar_url":"https://github.com/vdblm.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CausalPFN \u003cspan style=\"font-size:70%\"\u003e(Amortized Causal Effect Estimation via In-Context Learning)\u003c/span\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://web.cs.toronto.edu/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/vdblm/causalpfn/main/assets/uoft_logo.jpg\" alt=\"Logo 1\" height=\"60\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://layer6.ai/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/vdblm/causalpfn/main/assets/layer6.png\" alt=\"Logo 2\" height=\"60\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://vectorinstitute.ai/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/vdblm/causalpfn/main/assets/vector_institute.jpg\" alt=\"Logo 3\" height=\"60\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Python](https://img.shields.io/badge/Python-3.10%2B-blue?style=for-the-badge\u0026logo=python\u0026logoColor=white)](https://www.python.org/)\n[![PyTorch](https://img.shields.io/badge/PyTorch-2.3%2B-red?style=for-the-badge\u0026logo=pytorch\u0026logoColor=white)](https://pytorch.org/)\n[![License](https://img.shields.io/badge/License-Apache_2.0-green?style=for-the-badge)](LICENSE)\n[![arXiv](https://img.shields.io/badge/arXiv-2506.07918-b31b1b.svg?style=for-the-badge\u0026logo=arxiv\u0026logoColor=white)](https://arxiv.org/abs/2506.07918)\n[![PyPI](https://img.shields.io/badge/PyPI-CausalPFN-blue?style=for-the-badge\u0026logo=pypi\u0026logoColor=white)](https://pypi.org/project/causalpfn/)\n\n**An easy-to-use library for causal effect estimation using transformer-based in-context learning**\n\n[🛠️ Installation](#installation) • [🚀 Quick Start](#quick-start) • [📊 Examples](#examples) • [🔬 Reproducibility](#reproducibility)\n\n\u003c/div\u003e\n\n---\n\nThis library is is used to produce the results in our paper [CausalPFN: Amortized Causal Effect Estimation via In-Context Learning](https://arxiv.org/abs/2506.07918).\n\n\n\n## 🌟 Overview\n\nCausalPFN leverages the power of transformer architectures for amortized causal effect estimation, enabling fast and accurate inference across diverse causal scenarios without the need for retraining. Our approach combines the flexibility of in-context learning with the rigor of causal inference.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/vdblm/causalpfn/main/assets/main_figure.jpg\" alt=\"CausalPFN Results\" width=\"90%\"\u003e\n\u003c/p\u003e\n\n### ✨ Key Features\n\n- **🚀 Fast Inference**: Amortized learning enables rapid causal effect estimation without retraining\n- **🧮 Uncertainty Quantification**: Built-in calibration and confidence estimation\n- **⚡ GPU Accelerated**: Optimized for modern hardware with CUDA support\n- **📈 Benchmarked**: Competitive performance against state-of-the-art causal inference methods\n- **📊 Uplift-Modelling**: Supports treatment effect estimation for personalized decision-making in real-world applications\n\n## Installation\n\n### Via PyPI\n```bash\npip install causalpfn\n```\n\n### Requirements\n- Python 3.10+\n- PyTorch 2.3+\n- NumPy\n- scikit-learn\n- tqdm\n- faiss-cpu\n- huggingface_hub\n\n## Quick Start\n\nHere's a complete example demonstrating CausalPFN for causal effect estimation:\n\n```python\nimport numpy as np\nimport torch\nimport time\nfrom causalpfn import CATEEstimator, ATEEstimator\n\ndevice = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n\n# 1. Generate synthetic data\nnp.random.seed(42)\nn, d = 20000, 5\nX = np.random.normal(1, 1, size=(n, d)).astype(np.float32)\n\n# Define true causal effects\ndef true_cate(x):\n    return np.sin(x[:, 0]) + 0.5 * x[:, 1]\n\ndef true_ate():\n    return np.mean(true_cate(X))\n\n# Generate treatment and outcomes\ntau = true_cate(X).astype(np.float32)\nT = np.random.binomial(1, p=0.5, size=n).astype(np.float32)\nY0 = X[:, 0] - X[:, 1] + np.random.normal(0, 0.1, size=n).astype(np.float32)\nY1 = Y0 + tau\nY = Y0 * (1 - T) + Y1 * T\n\n# 2. Train/test split\ntrain_idx = np.random.choice(n, size=int(0.7 * n), replace=False)\ntest_idx = np.setdiff1d(np.arange(n), train_idx)\nX_train, X_test = X[train_idx], X[test_idx]\nT_train, Y_train = T[train_idx], Y[train_idx]\ntau_test = tau[test_idx]\n\n# 3. CATE Estimation\nstart_time = time.time()\ncausalpfn_cate = CATEEstimator(\n    device=device,\n    verbose=True,\n)\ncausalpfn_cate.fit(X_train, T_train, Y_train)\ncate_hat = causalpfn_cate.estimate_cate(X_test)\ncate_time = time.time() - start_time\n\n# 4. ATE Estimation\ncausalpfn_ate = ATEEstimator(\n    device=device,\n    verbose=True,\n)\ncausalpfn_ate.fit(X, T, Y)\nate_hat = causalpfn_ate.estimate_ate()\n\n# 5. Evaluation\npehe = np.sqrt(np.mean((cate_hat - tau_test) ** 2))\nate_rel_error = np.abs((ate_hat - true_ate()) / true_ate())\n\nprint(f\"Results:\")\nprint(f\"ATE Relative Error: {ate_rel_error:.4f}\")\nprint(f\"PEHE: {pehe:.4f}\")\nprint(f\"CATE estimation time per 1000 samples: {cate_time / (len(X) / 1000):.4f}s\")\n```\n\n## Examples\n\nExplore our notebook collection below. Before running the notebooks, make sure to install the additional dependencies via `pip install .[dev]`.\n\n| Notebook | Description | Features |\n|----------|-------------|----------|\n| [Causal Effect Estimation](https://github.com/vdblm/CausalPFN/blob/main/notebooks/causal_effect.ipynb) | Compare CausalPFN with baseline methods | CATE/ATE estimation, benchmarking |\n| [Hillstrom Marketing](https://github.com/vdblm/CausalPFN/blob/main/notebooks/hillstrom_marketing.ipynb) | Uplift modeling case study | Real-world marketing application |\n| [Calibration Analysis](https://github.com/vdblm/CausalPFN/blob/main/notebooks/calibration.ipynb) | Uncertainty quantification demo | Confidence intervals, calibration |\n\n## Performance Benchmark\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/vdblm/causalpfn/main/assets/rank_vs_time.png\" alt=\"CausalPFN Results\" width=\"50%\"\u003e\n\u003c/p\u003e\n\n*Time vs. Performance. Comparison across 130 causal inference tasks from IHDP, ACIC, and Lalonde. CausalPFN achieves the best average rank (by precision in estimation of heterogeneous effect) while being much faster than other baselines.*\n\n## Reproducibility\n\nTo fully reproduce the [paper](https://arxiv.org/abs/2506.07918) results, see the [REPRODUCE](https://github.com/vdblm/CausalPFN/blob/main/REPRODUCE.md) file.\n\n## Citation\n\nIf you use CausalPFN in your research, please cite our paper:\n\n```bibtex\n@misc{balazadeh2025causalpfn,\n      title={CausalPFN: Amortized Causal Effect Estimation via In-Context Learning}, \n      author={Vahid Balazadeh and Hamidreza Kamkari and Valentin Thomas and Benson Li and Junwei Ma and Jesse C. Cresswell and Rahul G. Krishnan},\n      year={2025},\n      eprint={2506.07918},\n      archivePrefix={arXiv},\n      primaryClass={cs.LG},\n      url={https://arxiv.org/abs/2506.07918}, \n}\n```\n\n## Contributing\n\nWe welcome contributions! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## License\n\nThis project is licensed under the Apache-2.0 License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\n**[⭐ Star us on GitHub](https://github.com/vdblm/causalpfn)** • **[🐛 Report Bug](https://github.com/vdblm/causalpfn/issues)** • **[💡 Request Feature](https://github.com/vdblm/causalpfn/issues)**\n\nMade with ❤️ for better causal inference\n\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvdblm%2Fcausalpfn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvdblm%2Fcausalpfn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvdblm%2Fcausalpfn/lists"}