Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

The Flow Rate Paradox: Causal Inference in Fluid Mechanics

Overview

In industrial fluid systems, observational sensor data is often highly confounded. This project simulates a scenario where standard machine learning (Ordinary Least Squares regression) yields a physically impossible result due to an unobserved confounder (a Simpson's Paradox). We use Causal Inference (Inverse Probability Weighting) to recover the true laws of physics.

1. The Physical Ground Truth (Data Generation)

The synthetic data is generated using the Hagen-Poiseuille equation for steady, laminar flow of an incompressible Newtonian fluid through a cylindrical pipe:

$$\Delta P = \frac{8 \mu L Q}{\pi R^4}$$

To simplify the system, we define the geometric and fluid properties as a single term, Hydraulic Resistance ($R_h$):

$$R_h = \frac{8 \mu L}{\pi R^4}$$

Yielding the linear relationship:

$$\Delta P = R_h Q$$

System Setup: We simulate two pipes. Pipe A is narrow (high resistance). Pipe B is wide (low resistance).

2. The Confounder: Operator Bias

A hidden bias is introduced into the operational data. The system operator preferentially routes hot fluid (low viscosity) through the narrow Pipe A, and cold fluid (high viscosity) through the wide Pipe B.

Viscosity is modeled as a function of temperature ($T$) using an exponential decay:

$$\mu(T) = \mu_0 \exp(-k T)$$

The operator's pipe selection ($D=1$ for Pipe A, $D=0$ for Pipe B) is modeled as a logistic function of temperature:

$$P(D=1 \mid T) = \frac{1}{1 + \exp(-\alpha(T - T_0))}$$

Because temperature determines both the fluid viscosity (affecting pressure drop) and the pipe selection, $T$ acts as a hidden confounder.

3. The Statistical Failure (Naive Regression)

If an analyst ignores temperature and fits a standard regression model to find hydraulic resistance:

$$\mathbb{E}[\Delta P \mid Q, D] = \beta_0 + \beta_1 Q + \beta_2 D$$

The model fails. Because $D$ is endogenous (correlated with the error term via $T$), the coefficient $\hat{\beta}_2$ is biased. The model incorrectly concludes that the wider Pipe B has a higher resistance than Pipe A, violating the known geometric truth.

4. The Causal Resolution

To recover the true physics, we map the causal graph: $T \rightarrow D$ and $T \rightarrow \Delta P$, identifying $T$ as a "backdoor path." We apply Inverse Probability Weighting (IPW) to simulate an intervention where pipe choice is independent of temperature.

We calculate a weight ($W_i$) for every data point based on the propensity score $e(T_i) = P(D_i=1 \mid T_i)$:

$$W_i = \frac{D_i}{e(T_i)} + \frac{1 - D_i}{1 - e(T_i)}$$

Applying these weights in a Weighted Least Squares (WLS) regression successfully breaks the spurious correlation, allowing us to mathematically recover the true, physical Hagen-Poiseuille resistance.

Tech Stack

  • Python 3.x
  • NumPy / Pandas (Synthetic Data Generation)
  • Statsmodels (OLS and WLS Regression)
  • DoWhy / CausalML (Causal Graphing and Propensity Estimation)

References & Further Reading

Causal Inference & Simpson's Paradox

  • Understanding Simpson’s Paradox - Judea Pearl (2014). UCLA Cognitive Systems Laboratory. This paper provides the foundational theory explaining why Simpson's Paradox is a causal, rather than purely statistical, phenomenon.
  • Simpson's Paradox (Wikipedia) - A comprehensive overview of the paradox, its mathematical definition, and famous historical examples.

Mathematical Methodology

Software & Tooling

  • DoWhy: An End-to-End Library for Causal Inference - Amit Sharma, Emre Kiciman, et al. (2020). arXiv preprint. The academic foundation for the Microsoft DoWhy library, which was utilized to construct the causal Directed Acyclic Graph (DAG) and estimate the propensity scores.

Fluid Dynamics Ground Truth

  • Fluid Mechanics - Frank M. White. McGraw-Hill Education. Used as the theoretical physical basis for generating the steady, laminar, and incompressible Hagen-Poiseuille pipe flow data.

About

Resolving spurious correlations in fluid dynamics using causal inference.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors