Why Causal Inference and Deep Learning Both Depend on What You Refuse to Update
Hatched by Nan Wang
Jul 15, 2026
10 min read
2 views
88%
The Hidden Common Problem: When Should a Model Trust Change?
What if the hardest part of intelligence is not learning, but deciding what not to rewrite?
That question sits beneath two worlds that often seem far apart. In one, you are trying to infer a causal effect from panel data when the world is incomplete, noisy, and full of missing entries. In the other, you are building a neural network in which tensors flow through operations, gradients accumulate, and a single careless in place update can silently change the meaning of your computation. At first glance, one is econometrics and the other is machine learning plumbing. But both are really about the same tension: how to extract signal from a system that is evolving without letting the system erase its own history.
This is not just a technical coincidence. It points to a deeper epistemic rule: good inference depends on controlled mutability. If you update everything, you lose structure. If you update nothing, you cannot adapt. The art is in knowing what must remain stable so that the rest can be learned.
That is the shared heart of causal panel methods and PyTorch practice. One gives us a way to estimate hidden counterfactual structure from partially observed trajectories. The other gives us a computational discipline for preserving and transforming information through a graph of operations. Together, they reveal a powerful lens: intelligence is not only about fitting data, but about preserving the right invariants while allowing the right degrees of freedom to move.
Missing Data Is Not Just a Data Problem, It Is a Memory Problem
Panel data is attractive because it gives repeated observations over time. But the real world rarely hands us a complete ledger. Firms disappear, policies shift, people move, and measurements fail. The result is a matrix with holes, and those holes matter because they do not simply remove information, they distort the story we think the data is telling.
Matrix completion approaches to causal panel data begin with a deceptively simple intuition: the observed outcomes may be only a partial view of a lower dimensional structure. If a matrix of outcomes can be approximated by a small number of latent factors, then the missing potential outcomes might be recoverable by exploiting that structure. In other words, the missing entries are not filled by imagination, but by constraints implied by the rest of the system.
That idea is much deeper than interpolation. Interpolation says, “guess between known points.” Matrix completion says, “infer the hidden architecture that makes the known points cohere.” The difference is the difference between drawing a line through dots and discovering the grammar behind a sentence.
This matters for causality because causal inference is not merely prediction. We do not just want a model that fits observed outcomes. We want a model that can answer the counterfactual question: what would have happened here if treatment had not occurred? That is a missing data problem of a special kind. The missingness is not accidental. It is structural, created by the very intervention we care about.
So causal panel methods force a hard epistemic discipline: you may only recover the unobserved counterfactual if the observed parts of the world are rich enough to pin down the latent structure. This is not a free lunch. It is an exchange: you give up arbitrary flexibility in return for a principled way to recover what cannot be seen directly.
The most important thing missing data teaches us is that absence still has shape.
That sentence also describes deep learning more accurately than many realize. The information you do not preserve during computation, the gradients you overwrite, the tensors you reshape without thinking, the batch dimension you forget to include, all of these are forms of epistemic amnesia. The model may still run, but its internal story becomes incoherent.
In PyTorch, the Enemy Is Not Complexity, It Is Untracked Change
PyTorch looks like a library for calculation, but it is really a library for controlled transformation. A tensor can be created, reshaped, moved to GPU, converted from NumPy, or passed through operations that build a computation graph. Autograd keeps track of how outputs arise from inputs, and backward computes gradients by traversing that graph. The whole system depends on one elegant principle: every meaningful change must be traceable.
That is why details like requires_grad, grad_fn, with torch.no_grad(), and in place operations matter so much. An underscore at the end of a method name signals an in place update, a direct mutation of the underlying tensor. In place updates can be useful, but they are also dangerous because they alter the object that may still be needed by the graph. Similarly, if gradients are allowed to accumulate without clearing them, then the current step is contaminated by the memory of previous steps.
This sounds like a coding detail, but it is actually a theory of knowledge. A learning system must know which quantities are state and which are transient computation. If it confuses the two, it cannot tell whether a new signal is evidence or merely residue.
The same logic appears in shape handling. unsqueeze(0) is not cosmetic. It adds a batch dimension, turning a lone example into something the rest of the model can interpret consistently. Neural networks in this framework expect their world to be structured: batch first, then channels, then spatial dimensions. Without that structure, the model does not merely become unhappy. It becomes ambiguous about what kind of object it is processing.
Even the relation between NumPy arrays and tensors teaches the same lesson. On CPU, many tensors can move back and forth between ecosystems. But the conversion preserves only what is compatible with the receiving system. Once on GPU, the rules change. Portability is never absolute. It is always conditioned on invariants.
The cleanest way to understand PyTorch, then, is not as a bag of functions but as a discipline for preventing accidental forgetting. Autograd preserves the chain of causation. Tensor shapes preserve the role of each axis. The no_grad context preserves the boundary between learning and inference. These are not conveniences. They are safeguards against epistemic collapse.
The Shared Thesis: Learning Works by Freezing the Right Things
Here is the bridge between causal matrix completion and PyTorch:
Both are systems for updating parameters under constraint, where success depends on separating what should change from what must stay fixed.
In causal panel data, the fixed part is the latent structure that explains the untreated world. Treatment creates deviations, but if you let the treated outcomes rewrite the entire structure, you destroy the very counterfactual you are trying to estimate. The model must therefore protect the baseline pattern while allowing treatment effects to be identified as departures from it.
In PyTorch, the fixed part is the computational graph and the declared architecture of the model. A forward pass transforms inputs, but it should not silently mutate the objects that future gradient calculations depend on. The training loop alternates between exploration, where gradients are computed, and correction, where parameters are updated. But the graph itself must remain legible long enough to support the update.
This suggests a useful mental model: learning is a negotiation between invariance and plasticity.
- Invariance gives you identity, comparability, and causal meaning.
- Plasticity gives you adaptation, fitting, and improvement.
Too much plasticity, and every observation rewrites the world from scratch. Too much invariance, and the model cannot respond to new evidence. Good modeling lives in the narrow corridor between those extremes.
We can make this even more concrete.
Imagine you are trying to estimate the effect of a new policy on regional employment. Some regions are treated, some are not, and over time the economy shifts in ways unrelated to the policy. A naive before and after comparison confuses treatment with trend. A matrix completion approach tries to infer the untreated path by borrowing strength from similar regions and time patterns. But that only works if the latent economic structure is stable enough to be reconstructed.
Now imagine implementing that estimator in PyTorch. You represent the latent factors as tensors, the observed outcomes as a matrix, and the fitting objective as a loss. If you accidentally mutate a tensor in place that autograd still needs, your gradients may become wrong or unavailable. If you forget to zero gradients, you mix historical update signals with current ones. If you forget batch structure, your model may technically execute but semantically misread the input.
In both cases, the failure mode is the same: the system loses track of what is evidence, what is state, and what is merely computation.
A Better Framework: Three Kinds of Stability
To combine these ideas in a practical way, it helps to distinguish three kinds of stability that every intelligent system needs.
1. Structural stability
This is the pattern that makes inference possible. In panel data, it is the low dimensional relationship across units and time. In neural networks, it is the architecture and the graph of operations. Structural stability is what lets one part of the system explain another part.
Without it, there is no generalization. You are just memorizing fragments.
2. Operational stability
This is the discipline that preserves the integrity of computation. In PyTorch, this means using in place operations carefully, respecting shape conventions, clearing gradients, and deciding when to disable gradient tracking with no_grad. In estimation, it means using algorithms that do not let nuisance variation leak into the target estimate.
Without operational stability, the model may still produce outputs, but those outputs will not be trustworthy.
3. Counterfactual stability
This is the hardest one. It is the idea that we can imagine an alternate world while holding enough of the actual world fixed to make the comparison meaningful. Causal inference depends on this. The counterfactual is not a fantasy; it is a disciplined reconstruction under assumptions.
Without counterfactual stability, there is no causal meaning, only association.
These three forms of stability correspond to three layers of intelligence. A system that has only structure but no operational discipline is elegant but brittle. A system that has operational rigor but no structural assumptions is precise but shallow. A system that can imagine counterfactuals without stability is imaginative but ungrounded.
The deepest form of learning is not adaptation without limits. It is adaptation with memory.
That is why the small details of tensor handling and the large ideas of causal inference belong in the same conversation. Both ask: how do we change a system while protecting the conditions that make the change interpretable?
Key Takeaways
-
Treat missing data as a structural clue, not just a nuisance. Ask what latent pattern could make the observed entries coherent, and whether that pattern is stable enough to support causal claims.
-
Separate state from computation. In PyTorch, be explicit about what should accumulate gradients, what should be detached, and when to use
no_grad. -
Guard invariants before optimizing flexibility. A model that changes too freely becomes uninterpretable. A model that is too rigid cannot learn. Aim for the smallest set of assumptions that still makes inference possible.
-
Respect shape as meaning. Dimensions are not bookkeeping. Batch size, channels, and time often encode the role each axis plays in the model. Misreading shape is misreading the problem.
-
Think of causal estimation as controlled reconstruction. You are not filling in blanks arbitrarily. You are reconstructing an unobserved world from patterns that remain invariant under treatment.
Conclusion: The Best Models Know What Not to Rewrite
The temptation in both statistics and machine learning is to believe that intelligence means ever more adaptation. More parameters. More flexibility. More updating. But the more carefully you look, the more that story breaks down. The systems we trust most are not the ones that change everything. They are the ones that preserve enough of their internal logic for change to mean something.
Causal panel methods teach that missingness can be overcome only when the underlying structure is disciplined enough to survive partial observation. PyTorch teaches that learning only works when computation is tracked, gradients are managed, and mutation is controlled. Together, they reveal a more general principle: the goal is not to make a system endlessly plastic, but to make it selectively self preserving.
That is a different definition of intelligence. Not the power to rewrite the world at every step, but the wisdom to know which parts of the world must remain fixed so that the rest can be discovered.
Sources
Hatch New Ideas with Glasp AI 🐣
Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)
Start Hatching 🐣