---
title: 'DoFlow: Causal Flows for Time-Series'
url: https://www.emergentmind.com/topics/doflow
type: topic
---

# DoFlow: Causal Flows for Time-Series

DoFlow refers to "DoFlow: Causal Generative Flows for Interventional and Counterfactual Time-Series Prediction" [2511.02137], a framework uniting continuous normalizing flows (CNFs), structural causal modeling (SCM), and neural ODEs for time-series forecasting under both observational and causal queries on systems structured by a known directed acyclic graph (DAG). DoFlow is designed to answer not just observational (“what will happen?”) forecasts, but also interventional (“what if we do $X$?”) and counterfactual (“what would have happened if we did $X'$ instead?”) queries, with explicit likelihoods for proper statistical inference and anomaly detection.

## 1. Problem Formulation and Causal Setting

The DoFlow framework considers a multivariate time series $\{X_t\}_{t=1}^T$, where $X_t \in \mathbb{R}^K$, and leverages a DAG $\mathcal{G}$ over nodes $1,\ldots,K$ to encode instantaneous causal dependencies: if $j\in\mathrm{pa}(i)$, then $X_{j,t} \rightarrow X_{i,t}$ (with $\mathrm{pa}(i)$ denoting the parent set). Each node $i$ evolves according to a (possibly nonlinear) structural equation:
\[
X_{i,t} = f_i(X_{i,t-}, X_{\mathrm{pa}(i),t-}, U_{i,t}),
\]
where $X_{i,t-}$ and $X_{\mathrm{pa}(i), t-}$ denote the past values, and $U_{i,t}$ are independent exogenous (noise) variables.

Forecasting tasks in this setting are divided as:
- **Observational forecasting**: Estimate $p(X_{\tau+1:T} | X_{1:\tau})$.
- **Interventional forecasting**: For an intervention schedule $\mathcal{I} \subset \{(i, t)\}$, with values $\gamma_{i,t}$, estimate $p(X_{\tau+1:T} \mid X_{1:\tau}, do(X_\mathcal{I} := \gamma_\mathcal{I}))$.
- **Counterfactual forecasting**: Given realized $X_{1:T}^F$ (the factual trajectory) and counterfactual interventions, infer $X_{\tau+1:T}^{CF}$ with the same $U$ that generated the factual path.

## 2. Architecture: Continuous Normalizing Flows on a Causal DAG

DoFlow employs a per-node, per-timestep continuous normalizing flow:
- For each node $i$ and forecast step $t$, a neural ODE parameterizes the bijection between Gaussian noise $z_{i,t} \sim \mathcal{N}(0,1)$ and $X_{i,t}$, conditioned on recurrent states $H_{i,t-1}$ summarizing its and its parents' past.
- For each $i,t$, consider the path $x_{i,t}(s)$, $s \in [0,1]$, governed by
  \[
  \frac{dx_{i,t}(s)}{ds} = v_i(x_{i,t}(s), s; H_{i,t-1}),
  \]
  with $x_{i,t}(0) = z_{i,t}$ and $x_{i,t}(1) = X_{i,t}$.
- The forward (“encoding”) direction maps base noise to data; the reverse allows likelihood computation and inference.

The joint density over the forecast window is autoregressive:
\[
\log p_\theta(X_{\tau+1:T} | H_\tau) = \sum_{t=\tau+1}^{T} \left[
\log q(z_t) - \int_0^1 \mathrm{Tr}\left( \frac{\partial v}{\partial x} \right) \, ds
\right],
\]
where $q(z_t) = \mathcal{N}(z_t; 0,1)$.

## 3. Learning via Conditional Flow Matching

The flow vector fields $v_i$ are trained using a conditional flow matching (CFM) criterion:
- For each training triple $(x_{i,t}, s, z)$, linearly interpolate $\phi(s) = (1-s)x_{i,t} + s z$,
- The loss is
  \[
  \mathbb{E}_{\text{data},\, s \sim U[0,1],\, z \sim \mathcal{N}(0,1)} \left\|
  v_i(\phi(s), s; H_{i,t-1}) - (z - x_{i,t})
  \right\|^2.
  \]
This loss aligns the learned velocity field $v_i$ along interpolants between data and base noise, facilitating stable and expressive conditional flows adapted to the marginal dynamics of each node conditional on its Markov blanket.

## 4. Causal Interventions, Counterfactuals, and Theoretical Guarantees

### Interventional Forecasting

At inference, the system proceeds stepwise in DAG topological order:
- For each node $i$ at time $t$:
  - If $(i,t) \in \mathcal{I}$: set $\hat{y}_{i,t} = \gamma_{i,t}$ (explicit intervention).
  - Else: sample $z_{i,t} \sim \mathcal{N}(0,1)$ and decode $\hat{y}_{i,t} = \Phi_\theta^{-1}(z_{i,t}; \hat{H}_{i,t-1})$.
- Recurrent hidden states for $i$ and its children are then updated and the process continues for subsequent times and nodes.

### Counterfactual Forecasting

DoFlow implements the abduction-action-prediction paradigm for counterfactuals:
1. **Abduction:** Encode the factual trajectory $X^F_{\tau+1:T}$ one step at a time to obtain latent codes $Z^F_{i,t}$.
2. **Action:** For intervention points, set $X^{CF}_{i,t} = \gamma_{i,t}$; for others, reuse $Z^F_{i,t}$.
3. **Prediction:** Decode each latent using the counterfactual history $\hat{H}^{CF}_{i,t-1}$:
   \[
   \hat{Y}_{i,t}^{CF} = \Phi_\theta^{-1}(Z^F_{i,t}; \hat{H}^{CF}_{i,t-1})
   \]
   producing a deterministic trajectory that is consistent with the original $U$.

### Counterfactual Recovery Theorem

Under assumptions:
- (A1) $U_t$ is independent of all previous variables.
- (A2) $f_i(\cdot, U)$ is strictly monotone in $U$.
- (A3) In the infinite-data limit, $Z_t$ is standard normal and independent of $H_{t-1}$.

It follows:
- The flow encoder maps $X_t$ to a $Z_t$ that depends only on $U_t$ (not $H_{t-1}$).
- Decoding $Z_t$ under counterfactual parent trajectories recovers $X^{CF}_t$ as under the true SCM.
- This theoretical guarantee ensures that the encode–do–decode mechanism implemented in DoFlow is *sound* in the limit for univariate, monotonic SCMs, and suggests wider applicability in practice given similar regularities in the learned flows.

## 5. Applications: Likelihood-based Anomaly Detection and Empirical Results

DoFlow is evaluated on both synthetic and real-world time-series data in settings requiring causal forecasting:

### Synthetic DAG-structured Systems

- Supports various causal graph structures: Chain, Tree, Diamond, Fully-Connected-Layer, with both additive and non-additive (nonlinear) SCMs.
- Metrics:
  - RMSE for point predictions under observational, interventional, and counterfactual regimes.
  - Maximum Mean Discrepancy (MMD) for matching forecast distributions.
- Empirical findings:
  - DoFlow outperforms GRU, TFT, TiDE, TSMixer, DeepVAR, and MQF2 on observational and interventional RMSE/MMD.
  - It is the only method with nontrivial counterfactual RMSE, i.e., capable of explicit, data-consistent what-if predictions.

### Hydropower System (Real Data)

- 8-node DAG: turbine vibrations, generator signals, transformer outputs, and control units.
- Experiments:
  - Interventional forecasting is validated by simulating turbine failures (power-outages).
  - Early anomaly detection is demonstrated: log-likelihood dips identify emerging faults 10–20 minutes before actual outages.
  - Interventional RMSE is substantially lower than adapted black-box baselines.

### Cancer Treatment Time-Series

- Nodes: four treatments (chemo/radiotherapy, with dose schedules) as parents of tumor volume $Y_t$ in single-step DAG.
- Experimental protocol:
  - First 55 days observed per patient; days 56–62 rolled out for 10 hypothetical treatment regimens.
  - RMSE measured against ground-truth generated by adversarially-balanced SCMs.
- DoFlow reduces normalized RMSE by approximately 50% compared to CRN, RMSN, and MSM baselines for treatment effect estimation.

### Likelihood-based Anomaly Detection

- Every generated trajectory has an explicit log-likelihood.
- Anomalous events are detected by thresholding $-\log p_\theta(\hat{Y}_{\tau+1:T}|\hat{H}_\tau)$.
- In hydropower and synthetic domains, this enables principled, model-aware diagnosis of rare system behaviors.

## 6. Framework Significance, Trade-offs, and Broader Implications

DoFlow synthesizes causal SCMs, normalizing flows, temporal recurrence, and neural ODE machinery to operationalize the full spectrum of time-series causal inference:

| Capability                     | DoFlow Implementation                            |
|---------------------------------|--------------------------------------------------|
| Observational forecasting       | CNF roll-out, recurrent, explicit density        |
| Interventional (do-operator)    | Intervention per node/time, DAG topological pass |
| Counterfactual ("encode-do-decode") | Abduct latent, intervene, conditionally decode |
| Anomaly detection               | Likelihood thresholding along roll-outs         |

Resource requirements are mainly determined by neural ODE integration per node per time step, with recurrence for history; scalability tracks that of modern CNF ODE solutions and RNNs.

Salient trade-offs:
- **Expressivity vs. computational cost:** Per-node flows avoid the curse of dimensionality but require parallel ODE solves.
- **Theoretical identifiability:** Guarantees hinge on monotonicity and independence assumptions; complex SCMs with unobserved confounding may violate these, but practical benefit has been observed in heterogeneous domains.
- **Interpretability:** The DAG-structured flows maintain explicit causal semantics, facilitating interventional science and policy queries, unlike black-box sequence models.

DoFlow thus advances unification of generative modeling and causal inference in dynamical systems, opening principled paths for "what-if" reasoning and risk assessment in domains such as industrial process control, medicine, and physical system modeling.

Source: https://www.emergentmind.com/topics/doflow