Other
CCPFN
File size: 2,787 Bytes
9dda2fd
6a45c04
9dda2fd
c0cd322
9dda2fd
c0cd322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
library_name: ccpfn
license: apache-2.0
pipeline_tag: other
---

# CCPFN: Causal Foundation Models with Continuous Treatments

This repository contains the weights for **CCPFN** (Continuous Causal Prior-Fitted Network), the first causal foundation model for continuous treatment settings, as presented in the paper [Causal Foundation Models with Continuous Treatments](https://huggingface.co/papers/2605.15133).

By leveraging in-context learning, CCPFN estimates the *conditional expected potential outcome* (CEPO), defined as $𝔼[Y(t) \mid X = x]$, predicting causal effects across a wide variety of unseen tasks without any additional training or fine-tuning.

* **Repository (Inference):** [layer6ai-labs/CCPFN-inference](https://github.com/layer6ai-labs/CCPFN-inference)
* **Paper:** [Causal Foundation Models with Continuous Treatments](https://huggingface.co/papers/2605.15133)

## Installation

You can install the inference package via `pip`:

```bash
pip install ccpfn
```

## Quick Start

Here is a simple example demonstrating how to run CCPFN for CEPO estimation:

```python
import numpy as np
import torch
from ccpfn import CEPOEstimator

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

# Define true individual treatment-response function
def treatment_response(x, t): 
      return np.cos(x[..., 0]) + 2 * x[..., 1] * t

# Define treatment assignment function
def treatment(x):
      return 1 + np.sin(x[..., 2])

# Create synthetic data - covariates, treatment, outcome
rng = np.random.default_rng(seed=42)
n_samples, n_features = 2048, 3
X = rng.standard_normal((n_samples, n_features))
T = treatment(X)
Y = treatment_response(X, T) + 0.1 * rng.standard_normal((n_samples,))

# Context/query (train/test) split
test_ratio = 0.3
ctx_idx = rng.choice(n_samples, int((1 - test_ratio) * n_samples), replace=False)
qry_idx = np.setdiff1d(np.arange(n_samples), ctx_idx)
X_ctx, X_qry = X[ctx_idx], X[qry_idx]
T_ctx, Y_ctx = T[ctx_idx], Y[ctx_idx]
T_qry = rng.random((X_qry.shape[0],))  # Counterfactual treatments

# CEPO Estimation
estimator = CEPOEstimator(device=device)
estimator.fit(X_ctx, T_ctx, Y_ctx)
cepo_pred = estimator.estimate_cepo(X_qry, T_qry)

# Evaluation and results
cepo_true = treatment_response(X_qry, T_qry)
rmse = np.sqrt(np.mean((cepo_true - cepo_pred) ** 2))
print("Results:")
print(f"RMSE: {rmse:.4f}")
```

## Citation

```bibtex
@misc{stith2026causalfoundationmodelscontinuous,
      title={Causal Foundation Models with Continuous Treatments}, 
      author={Christopher Stith and Medha Barath and Vahid Balazadeh and Jesse C. Cresswell and Rahul G. Krishnan},
      year={2026},
      eprint={2605.15133},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2605.15133}, 
}
```