<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Machine Learning | Mahyar's world 🌏</title><link>https://mahyar-osn.github.io/tag/machine-learning/</link><atom:link href="https://mahyar-osn.github.io/tag/machine-learning/index.xml" rel="self" type="application/rss+xml"/><description>Machine Learning</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Tue, 22 Apr 2025 00:00:00 +0000</lastBuildDate><image><url>https://mahyar-osn.github.io/media/icon_hu35e4e9c9135f02752aab27d124db531b_75212_512x512_fill_lanczos_center_3.png</url><title>Machine Learning</title><link>https://mahyar-osn.github.io/tag/machine-learning/</link></image><item><title>The Limitations of Machine Learning in Replacing Physical Laws: Expanding the Critique</title><link>https://mahyar-osn.github.io/post/fallacy-ml-physics/</link><pubDate>Tue, 22 Apr 2025 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/post/fallacy-ml-physics/</guid><description>&lt;p>Before diving into my analysis, I want to acknowledge the insightful &lt;a href="https://science-memo.blogspot.com/2021/04/on-fallacy-of-replacing-physical-laws.html" target="_blank" rel="noopener">blog by Mehmet Süzen&lt;/a>
that inspired this post, which eloquently discusses the fallacy of replacing physical laws with machine-learned inference
systems. Having read it, I felt compelled to share my own perspective and expand on these critical arguments with
additional examples from recent literature and research.&lt;/p>
&lt;h2 id="the-fundamental-problem-of-circular-reasoning">The Fundamental Problem of Circular Reasoning&lt;/h2>
&lt;p>The original blog brilliantly identifies the circular reasoning inherent in claiming that machine learning systems can
discover or replace physical laws. This point deserves further emphasis: when a neural network is trained on data
generated by known physical principles, it cannot be said to &amp;ldquo;discover&amp;rdquo; those same principles through inference.&lt;/p>
&lt;p>Consider recent work in fluid dynamics, where physics-informed neural networks (PINNs) have gained popularity.
The paper &amp;ldquo;&lt;a href="https://www.frontiersin.org/journals/artificial-intelligence/articles/10.3389/frai.2020.00025/full" target="_blank" rel="noopener">Discovery of Physics From Data: Universal Laws and Discrepancies&lt;/a>&amp;rdquo;
highlights that &amp;ldquo;the naive application of ML/AI will generally be insufficient to infer universal physical laws without
further modification&amp;rdquo;.
The authors demonstrate this by examining falling objects, showing that measurement noise and secondary mechanisms
(like fluid drag) obscure the underlying law of gravitation, leading to erroneous models that might suggest an
Aristotelian theory where objects fall at speeds related to their mass, rather than identifying the true universal
gravitational constant.&lt;/p>
&lt;p>This illustrates perfectly how ML systems trained on physical data will incorporate all the complexities and noise
present in that data, rather than abstracting to the elegant, universal laws that human scientists have carefully
identified through theoretical reasoning and controlled experimentation.&lt;/p>
&lt;h2 id="beyond-narrow-applications-the-generalization-problem">Beyond Narrow Applications: The Generalization Problem&lt;/h2>
&lt;p>The original blog correctly identifies the problem of faulty generalization. Machine learning algorithms excel at
computational acceleration within narrowly defined parameter spaces, but struggle with broader generalization.&lt;/p>
&lt;p>A fascinating discussion on &lt;a href="https://www.reddit.com/r/MachineLearning/comments/lvwt3l/d_some_interesting_observations_about_machine/" target="_blank" rel="noopener">Reddit&lt;/a>
highlights this limitation: &amp;ldquo;In addition, the &amp;lsquo;marginally-better SOTA&amp;rsquo;-esque papers with no novel methods or aspects
besides some parameter tuning or adding extra layers to the DNN are also tiring to read. The wall of math then
exists only to provide a sense of rigor and novelty, obscuring the iterative nature lacking novelty&amp;rdquo;.
This reflects how ML approaches in physics often claim breakthroughs that are actually just incremental improvements
in limited domains.&lt;/p>
&lt;p>Another illustrative example comes from the field of symbolic regression.
While the &lt;a href="https://journals.aps.org/prd/abstract/10.1103/PhysRevD.111.015022" target="_blank" rel="noopener">AbdusSalam et al. paper&lt;/a>
in Physical Review D demonstrates how symbolic regression can help derive analytical expressions for physics beyond the
Standard Model, the authors position it as a tool to assist numerical studies, not as a replacement for physical theory.
The expressions derived still rely on the underlying physics-based model (the constrained minimal supersymmetric
Standard Model) and serve primarily to accelerate computation, not to discover new physical laws.&lt;/p>
&lt;h2 id="the-irreplaceable-role-of-scientists-in-establishing-causality">The Irreplaceable Role of Scientists in Establishing Causality&lt;/h2>
&lt;p>Perhaps the most important point from the original blog is that causality still requires scientists. Machine learning
excels at finding correlations but struggles with identifying true causal relationships.&lt;/p>
&lt;p>The Amazon Science blog on physics-constrained machine learning notes that &amp;ldquo;the predictions of deep-learning models
trained on physical data typically ignore fundamental physical principles. Such models might, for instance, violate
system conservation laws&amp;rdquo; (see &lt;a href="https://www.amazon.science/blog/physics-constrained-machine-learning-for-scientific-computing" target="_blank" rel="noopener">here&lt;/a>).
This highlights why human scientists remain essential - they understand that physical laws must adhere to conservation principles,
symmetries, and other fundamental constraints that ML systems don&amp;rsquo;t inherently respect.&lt;/p>
&lt;p>A conversation on &lt;a href="https://www.reddit.com/r/MachineLearning/comments/18mnl9f/d_i_dont_understand_why_physics_informed_neural/" target="_blank" rel="noopener">Reddit&lt;/a> about Physics Informed Neural Networks (PINNs) further illuminates this issue.
One commenter precisely notes: &amp;ldquo;The point of including a physical loss function, in addition to a data-driven loss,
is to impose inductive bias into the training process&amp;rdquo;. This human-guided approach to incorporating physics into ML
demonstrates that we&amp;rsquo;re not replacing physics with ML, but rather using our understanding of physics to guide
ML - the exact opposite of what some overenthusiastic claims suggest.&lt;/p>
&lt;h2 id="the-scientific-machine-learning-fallacy-a-deeper-look">The Scientific Machine Learning Fallacy: A Deeper Look&lt;/h2>
&lt;p>The term &amp;ldquo;Scientific Machine Learning Fallacy&amp;rdquo; coined in the original blog deserves broader recognition.
Claims of &amp;ldquo;machine scientists&amp;rdquo; or &amp;ldquo;automated scientific discovery&amp;rdquo; fundamentally misunderstand the nature of
scientific inquiry.&lt;/p>
&lt;p>A recent &lt;a href="https://arxiv.org/abs/2403.02913" target="_blank" rel="noopener">paper&lt;/a> on &amp;ldquo;Scientific machine learning for closure models in multiscale problems&amp;rdquo; acknowledges that
&amp;ldquo;the generalizability and interpretability of learned models is a major issue that needs to be addressed further&amp;rdquo;.
This admission from researchers in the field underscores the gap between current ML capabilities and true scientific
discovery.&lt;/p>
&lt;p>The Conversation &lt;a href="https://theconversation.com/a-new-ai-scientist-can-write-science-papers-without-any-human-input-heres-why-thats-a-problem-237029" target="_blank" rel="noopener">article&lt;/a> about an &amp;ldquo;AI scientist&amp;rdquo; further reveals the limits of these approaches.
While Sakana AI Labs claims their system can &amp;ldquo;make scientific discoveries in the area of machine learning in a
fully automated way,&amp;rdquo; the article questions whether such a system can produce truly &amp;ldquo;interesting&amp;rdquo; scientific papers,
noting that &amp;ldquo;good science requires novelty&amp;rdquo;. The ability to generate papers that look like scientific literature
doesn&amp;rsquo;t equate to generating novel scientific insights or laws.&lt;/p>
&lt;h2 id="the-automl-misnomer-and-meta-scientific-work">The AutoML Misnomer and Meta-Scientific Work&lt;/h2>
&lt;p>I strongly agree with the original blog that &amp;ldquo;AutoML&amp;rdquo; is a misnomer in scientific contexts.
These systems don&amp;rsquo;t replace scientists but rather change the nature of scientific work.&lt;/p>
&lt;p>The &lt;a href="https://www.semanticscholar.org/paper/Combining-physical-modeling-and-machine-learning-of-Brus/41e8a7335a0541ac1cd41333c97b347b51220070" target="_blank" rel="noopener">paper&lt;/a> on &amp;ldquo;Combining physical modeling and machine learning for micro-scale modeling of a fuel cell electrode&amp;rdquo;
demonstrates this well. It describes a &amp;ldquo;comprehensive transition from white-box models, characterized by their
reliance on physical laws, to black-box models exemplified by neural networks&amp;rdquo;. Yet the core contribution isn&amp;rsquo;t
replacing physics but creating a &amp;ldquo;synergistic integration&amp;rdquo; where neural networks complement physical modeling.&lt;/p>
&lt;p>This represents what the original blog aptly calls &amp;ldquo;MetaML&amp;rdquo; - a transformation of scientific workflows rather than
a replacement of scientific thinking.&lt;/p>
&lt;h2 id="the-proper-role-augmentation-not-replacement">The Proper Role: Augmentation, Not Replacement&lt;/h2>
&lt;p>To conclude, I believe the most productive path forward is viewing machine learning as an augmentation to physical
sciences, not a replacement. The &lt;a href="https://www.semanticscholar.org/paper/Learning-physical-laws%3A-the-case-of-micron-size-in-Matei-Zhenirovskyy/02fad00443cb7f13834f19b69c225478f00602b1" target="_blank" rel="noopener">paper&lt;/a>
on &amp;ldquo;Learning physical laws: the case of micron size particles in dielectric fluid&amp;rdquo;
demonstrates this approach well, noting that &amp;ldquo;representation structure is key in learning generalizable models&amp;rdquo;.
The authors use &amp;ldquo;the port-Hamiltonian formalism as a high level model structure&amp;rdquo; that is
&amp;ldquo;continuously refined based on our understanding of the physical process.&amp;rdquo;
This integration of physics understanding with machine learning represents the right approach.&lt;/p>
&lt;p>Similarly, the &lt;a href="https://arxiv.org/abs/2402.16517" target="_blank" rel="noopener">work&lt;/a> on &amp;ldquo;Discovering Artificial Viscosity Models for Discontinuous Galerkin Approximation of
Conservation Laws&amp;rdquo; shows how physics-informed machine learning can automate the discovery of models - but within
a physics-informed framework, not replacing it&lt;/p>
&lt;p>In summary, while machine learning offers powerful tools for scientific research, the fallacy of replacing physical
laws with learned models deserves continued critical attention. True scientific progress will come from the thoughtful
integration of machine learning with physical understanding, not from claims that ML can autonomously discover or
replace the fundamental laws of nature. The original blog&amp;rsquo;s warning about circular reasoning, faulty generalization,
and the continued need for human scientists remains prescient and worthy of expansion as these technologies continue
to develop.&lt;/p>
&lt;h2 id="human-thinking-not-machine-imitation">Human Thinking, Not Machine Imitation&lt;/h2>
&lt;p>This philosophical depth reminds us that true scientific thinking involves not just pattern recognition and prediction,
but deep conceptual understanding that may not be reducible to computational processes. When we forget this,
we risk confusing the map (our mathematical models and computational simulations) with the territory
(physical reality itself).&lt;/p></description></item><item><title>Temporal Predictive Coding</title><link>https://mahyar-osn.github.io/projects/temporal-predictive-coding/</link><pubDate>Sun, 15 Dec 2024 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/projects/temporal-predictive-coding/</guid><description>&lt;p>&lt;strong>Authors&lt;/strong>: Beren Millidge, Mufeng Tang, Mahyar Osanlouy, Nicol S. Harper, Rafal Bogacz&lt;br>
&lt;strong>Publication&lt;/strong>: PLOS Computational Biology (April 2024)&lt;br>
&lt;strong>Code&lt;/strong>: &lt;a href="https://github.com/C16MItang/temporal-predictive-coding" target="_blank" rel="noopener">GitHub Repository&lt;/a>&lt;br>
&lt;strong>Read the paper&lt;/strong>: &lt;a href="https://doi.org/10.1371/journal.pcbi.1011183" target="_blank" rel="noopener">PLOS Computational Biology&lt;/a>&lt;/p>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>How does the brain process dynamic sensory inputs; like tracking a moving object or predicting the next note in a melody?
In this work, we propose &lt;strong>temporal predictive coding (tPC)&lt;/strong>, a biologically plausible neural framework that extends
classical predictive coding to handle time-varying stimuli. By unifying Bayesian inference, neural dynamics,
and synaptic plasticity, tPC explains how cortical circuits might learn to predict and adapt to continuously
changing environments.&lt;/p>
&lt;hr>
&lt;h2 id="key-contributions">Key Contributions&lt;/h2>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>A unified model for temporal prediction&lt;/strong>:
tPC bridges predictive coding (for static inputs) and Kalman filtering (for dynamic systems), enabling online inference and learning without complex matrix operations.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Biologically plausible implementation&lt;/strong>:
The model uses only &lt;strong>local computations&lt;/strong> and &lt;strong>Hebbian plasticity&lt;/strong>, aligning with known cortical microcircuit architecture.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Motion-sensitive receptive fields&lt;/strong>:
When trained on natural movies, tPC neurons develop Gabor-like, direction-selective receptive fields—matching properties of early visual cortex neurons.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Nonlinear generalization&lt;/strong>:
The framework extends to nonlinear systems (e.g., pendulum dynamics), outperforming linear models in complex tasks.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="methodology">Methodology&lt;/h2>
&lt;h3 id="core-principles">Core Principles&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Generative model&lt;/strong>: Hidden states evolve via a Markov process, with observations generated from hidden states.&lt;/li>
&lt;/ul>
&lt;p>$$
x_k = A f(x_{k-1}) + B u_k + \omega_x
$$&lt;/p>
&lt;p>$$
y_k = C f(x_k) + \omega_y
$$&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Free energy minimization&lt;/strong>:
Neurons minimize prediction errors at two levels:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Sensory errors&lt;/strong>: Mismatch between predicted and actual observations.&lt;/li>
&lt;li>&lt;strong>Temporal errors&lt;/strong>: Mismatch between predicted and inferred hidden states.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Neural implementation&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Explicit prediction error neurons or dendritic computations.&lt;/li>
&lt;li>Synaptic updates follow local Hebbian rules (e.g., ΔA ∝ prediction error × presynaptic activity).&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="comparison-to-kalman-filtering">Comparison to Kalman Filtering&lt;/h3>
&lt;ul>
&lt;li>tPC approximates Kalman filtering but avoids tracking posterior uncertainty.&lt;/li>
&lt;li>Achieves similar accuracy in linear tracking tasks with simpler computations.&lt;/li>
&lt;/ul>
&lt;p>$$
\hat{x}_k^- = A \hat{x}_{k-1} + B u_k
$$&lt;/p>
&lt;p>$$
\hat{x}_k = \hat{x}_k^- + K(y_k - C\hat{x}_k^-)
$$&lt;/p>
&lt;p>$$
K = \Sigma_x C^T \left[C \Sigma_x C^T + \Sigma_y \right]^{-1}
$$&lt;/p>
&lt;hr>
&lt;h2 id="results">Results&lt;/h2>
&lt;h3 id="1-robust-tracking-of-dynamic-states">1. Robust Tracking of Dynamic States&lt;/h3>
&lt;ul>
&lt;li>tPC accurately infers position, velocity, and acceleration from noisy observations, even with scrambled sensory inputs.&lt;/li>
&lt;li>Matches Kalman filter performance with 5 inference steps (MSE difference &amp;lt; 1%).&lt;/li>
&lt;/ul>
&lt;h3 id="2-learning-synaptic-weights">2. Learning Synaptic Weights&lt;/h3>
&lt;ul>
&lt;li>Hebbian plasticity enables online learning of dynamics (&lt;strong>A&lt;/strong>, &lt;strong>B&lt;/strong>) and observation (&lt;strong>C&lt;/strong>) matrices.&lt;/li>
&lt;li>Learns to predict observations even with random initial weights.&lt;/li>
&lt;/ul>
&lt;h3 id="3-biological-receptive-fields">3. Biological Receptive Fields&lt;/h3>
&lt;ul>
&lt;li>Trained on natural movies, tPC develops:
&lt;ul>
&lt;li>&lt;strong>Spatiotemporal receptive fields&lt;/strong> with motion direction selectivity.&lt;/li>
&lt;li>Gabor-like filters resembling V1 simple cells.
&lt;img src="journal.pcbi.1011183.g006.PNG" alt="Receptive fields" width="600">
&lt;em>Representations developed by the model when trained with patches from movies of dynamic natural scenes.
A: First 10 frames of 2 example training movies used in our experiments. Patches extracted from movies obtained
at websites pexels.com, pixabay.com and commons.wikimedia.org (for wikimedia attributions
see &lt;a href="https://github.com/C16Mftang/temporal-predictive-coding%29" target="_blank" rel="noopener">https://github.com/C16Mftang/temporal-predictive-coding)&lt;/a>. B: The projective fields C developed Gabor-like
filters after training. C: Space-time receptive fields developed by hidden neurons of the tPC model.
&lt;a href="https://doi.org/10.1371/journal.pcbi.1011183.g006" target="_blank" rel="noopener">https://doi.org/10.1371/journal.pcbi.1011183.g006&lt;/a>&lt;/em>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="4-nonlinear-dynamics">4. Nonlinear Dynamics&lt;/h3>
&lt;ul>
&lt;li>Outperforms linear models in predicting pendulum motion (20% lower MSE).&lt;/li>
&lt;li>Captures nonlinearities where linear approximations fail (e.g., large-angle oscillations).
&lt;img src="journal.pcbi.1011183.g007.PNG" alt="Receptive fields" width="800">
&lt;em>&lt;strong>Simulations of the pendulum&lt;/strong>. &lt;strong>A:&lt;/strong> A free-body diagram of a simple pendulum that has a mass m attached to a string
with length $L$. Also shown are the forces applied to the mass. The restoring force $-mg sin \theta$ is a net force toward
the equilibrium position. &lt;strong>B:&lt;/strong> A phase portrait of the pendulum simulation showing the result of our linear versus
nonlinear models prediction for the ground-truth data. The vector field (i.e. set of small arrows) was
created by computing the derivatives of $\frac{d\theta_1}{dt}$ and $\frac{d\theta_2}{dt}$ at $t = 0$ a grid of 30
points over the range of $-\pi$ to $\pi$ and -4 to +4 for $\theta_1$ and $\theta_2$ respectively. &lt;strong>C:&lt;/strong> The barplot
shows the difference between the mean prediction errors of the linear model versus the nonlinear model from 100
simulations with varying noise profiles. The mean errors are significantly different $(p \ll 0.001)$
&lt;a href="https://doi.org/10.1371/journal.pcbi.1011183.g007" target="_blank" rel="noopener">https://doi.org/10.1371/journal.pcbi.1011183.g007&lt;/a>&lt;/em>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="implications">Implications&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Theoretical&lt;/strong>: Provides a unified account of static and dynamic sensory processing under predictive coding.&lt;/li>
&lt;li>&lt;strong>Experimental&lt;/strong>: Predicts neural responses to time-varying stimuli and receptive field properties.&lt;/li>
&lt;li>&lt;strong>Translational&lt;/strong>: Framework for neuromorphic hardware and efficient machine learning models.&lt;/li>
&lt;/ul>
&lt;hr></description></item><item><title>The Hitchhiker’s Guide to Rebranding Machine Learning (And a Shoutout to Geoff Hinton!)</title><link>https://mahyar-osn.github.io/post/ml-physics-nobel/</link><pubDate>Thu, 12 Dec 2024 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/post/ml-physics-nobel/</guid><description>&lt;p>There’s a funny thing that happens when you spend long enough inside the vocabulary of machine learning.
Words begin to feel like worn shoes. &lt;em>Loss&lt;/em>, &lt;em>gradient&lt;/em>, &lt;em>training&lt;/em>, &lt;em>inference&lt;/em>. After a while you stop
hearing them. And then one day a physicist wanders into the room and starts describing the very same things
you do for a living, only the words coming out of their mouth sound like they belong on a chalkboard in a
faculty lounge somewhere in Göttingen, circa 1925.&lt;/p>
&lt;p>It’s the same machinery, of course. Just rotated by ninety degrees, so the light hits it differently.&lt;/p>
&lt;h3 id="a-small-guide-to-rebranding-machine-learning">A small guide to rebranding machine learning&lt;/h3>
&lt;p>I’ve been keeping a little Rosetta stone of these translations for a while, partly as a joke and partly
because I think they genuinely help. Every time you reach for the physics word instead of the engineering
one, some quiet door opens in your head and a hallway of intuitions you didn’t know you had comes spilling
out. So here it is, the same dictionary I keep in the back of my own head, set out plainly so you can take
what you like from it.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>What an engineer says&lt;/th>
&lt;th>What a physicist would have said&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Machine learning&lt;/td>
&lt;td>Statistical mechanics&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Loss function&lt;/td>
&lt;td>Energy functional&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Optimizing the model&lt;/td>
&lt;td>Minimizing free energy&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Trained model&lt;/td>
&lt;td>Equilibrium distribution&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>KL divergence&lt;/td>
&lt;td>Free energy difference&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Gaussian noise&lt;/td>
&lt;td>Thermal fluctuations&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Random step&lt;/td>
&lt;td>Brownian motion&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>SGD&lt;/td>
&lt;td>Directed Brownian motion&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GPU&lt;/td>
&lt;td>Simulated particle accelerator&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Diffusion models&lt;/td>
&lt;td>Langevin dynamics&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>LLMs&lt;/td>
&lt;td>High-order discrete Markov chains&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>NLP&lt;/td>
&lt;td>String theory (the strings being, well, strings)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Reinforcement learning&lt;/td>
&lt;td>Control theory&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Robotics&lt;/td>
&lt;td>Physical computation&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Audio learning&lt;/td>
&lt;td>1D signal processing&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Image learning&lt;/td>
&lt;td>2D signal processing&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Video learning&lt;/td>
&lt;td>3D signal processing&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Multimodal models&lt;/td>
&lt;td>n-dimensional signal processing&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>There’s a real point hiding inside the silliness here, which is that the borders between fields are mostly
historical accidents. Two communities looked at the same elephant from opposite sides of the room and gave it
two different names. Noticing that is, I think, one of the small pleasures of being alive at a moment when
the disciplines are quietly merging back into each other.&lt;/p>
&lt;h3 id="and-while-were-here-a-word-about-geoff-hinton">And while we’re here, a word about Geoff Hinton&lt;/h3>
&lt;p>I can’t talk about any of this without pausing for a moment of genuine awe at Geoff Hinton. As of this year
he’s the second person ever to hold both a Turing Award and a Nobel Prize. The first was Herbert A. Simon,
who picked up his Nobel in Economics. Two people, in the entire history of these prizes, have crossed that
particular bridge. Both of them were thinking about minds, and about what it means for a physical system to
have one. I find that detail quietly beautiful.&lt;/p>
&lt;p>So the next time someone at a dinner party asks what it is you actually do, you have my permission to look
them dead in the eye and tell them, in your most serious voice, that you spend your days &lt;strong>minimizing free
energy in high-order discrete Markov chains using simulated particle accelerators&lt;/strong>. It happens to be true.
It also happens to be the kind of sentence that makes the universe sound a little more like itself.&lt;/p></description></item><item><title>Kalman Filtering in the Age of PyTorch: State Estimation, Differentiability, and the Philosophy of Uncertainty</title><link>https://mahyar-osn.github.io/post/kalman-filter/</link><pubDate>Wed, 08 May 2024 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/post/kalman-filter/</guid><description>&lt;h2 id="introduction">Introduction&lt;/h2>
&lt;p>The Kalman filter, a paragon of recursive estimation, has long stood at the intersection of mathematics, engineering, and epistemology.
Conceived in the 1960s to address the challenges of navigation and control in aerospace, its recursive structure and optimality
under Gaussian assumptions have made it indispensable across robotics, signal processing, finance, and beyond.
Yet, as machine learning frameworks like PyTorch have redefined the computational landscape, the Kalman filter
finds itself in a new context—one where differentiability, GPU acceleration, and integration with deep neural architectures
are not just desirable, but essential.&lt;/p>
&lt;p>In this blog post I want to embark on a dual journey. On one hand, I want to delve into the technicalities of
implementing Kalman filters in PyTorch, leveraging its tensor operations and automatic differentiation to enable
new research and applications.
On the other, I want to reflect on the philosophical questions about the nature of uncertainty, the meaning of optimality,
and the evolving relationship between model-based and data-driven approaches. By weaving together rigorous mathematics,
practical coding insights, and reflective inquiry, we aim to illuminate both the power and the limitations of state estimation
in the age of neural computation.&lt;/p>
&lt;h2 id="the-mathematical-foundations-of-kalman-filtering">The Mathematical Foundations of Kalman Filtering&lt;/h2>
&lt;h3 id="the-state-space-model-dynamics-and-observations">The State-Space Model: Dynamics and Observations&lt;/h3>
&lt;p>At the heart of the Kalman filter lies the state-space model, a mathematical abstraction that describes the evolution of a
system&amp;rsquo;s hidden state over time and its relationship to noisy observations. Formally, the discrete-time linear state-space model is given by:&lt;/p>
&lt;p>$$
\begin{aligned}
x_{k} &amp;amp;= F_{k} x_{k-1} + B_{k} u_{k} + w_{k} \\
z_{k} &amp;amp;= H_{k} x_{k} + v_{k}
\end{aligned}
$$&lt;/p>
&lt;p>Where:&lt;/p>
&lt;ul>
&lt;li>$x_{k}$: State vector at time $k$&lt;/li>
&lt;li>$F_{k}$: State transition matrix&lt;/li>
&lt;li>$B_{k}$: Control input matrix&lt;/li>
&lt;li>$u_{k}$: Control vector&lt;/li>
&lt;li>$w_{k}$: Process noise $\sim \mathcal{N}(0,Q_{k})$&lt;/li>
&lt;li>$z_{k}$: Observation vector&lt;/li>
&lt;li>$H_{k}$: Observation matrix&lt;/li>
&lt;li>$v_{k}$: Observation noise $\sim \mathcal{N}(0,R_{k})$&lt;/li>
&lt;/ul>
&lt;p>This model encodes two key assumptions: linearity and Gaussianity. The linearity allows for closed-form recursive updates,
while the Gaussianity ensures that all conditional distributions remain Gaussian, making the mean and covariance sufficient statistics
for the state estimate.&lt;/p>
&lt;h3 id="recursive-estimation-prediction-and-update">Recursive Estimation: Prediction and Update&lt;/h3>
&lt;p>The Kalman filter operates in two alternating steps: prediction (time update) and correction (measurement update).
In the prediction step, the filter projects the current state estimate forward in time, using the system dynamics:&lt;/p>
&lt;p>$$
\begin{aligned}
\hat{x}_{k|k-1} = F_{k} \hat{x}_{k-1|k-1} + B_{k} u_{k} \\
P_{k|k-1} = F_{k} P_{k-1|k-1} F_{k}^{T} + Q_{k}
\end{aligned}
$$&lt;/p>
&lt;p>Here $\hat{x}_{k|k-1}$
is the predicted state mean,
and $P_{k|k-1}$
is the predicted state covariance.&lt;/p>
&lt;p>In the update step, the filter incorporates the new measurement $z_{k}$ to refine the state estimate:&lt;/p>
&lt;p>$$
\begin{aligned}
K_{k} &amp;amp;= P_{k|k-1} H_{k}^{T} \left( H_{k} P_{k|k-1} H_{k}^{T} + R_{k} \right)^{-1} \\
\hat{x}_{k|k} &amp;amp;= \hat{x}_{k|k-1} + K_{k} \left( z_{k} - H_{k} \hat{x}_{k|k-1} \right) \\
P_{k|k} &amp;amp;= \left( I - K_{k} H_{k} \right) P_{k|k-1}
\end{aligned}
$$&lt;/p>
&lt;p>Where $K_{k}$ is the Kalman gain, which determines how much the measurement should be trusted relative to the prediction.
Its derivation is rooted in the minimization of the mean squared error of the state estimate, balancing the uncertainty in the prediction and the measurement&lt;/p>
&lt;h3 id="the-geometry-of-uncertainty-covariance-propagation">The Geometry of Uncertainty: Covariance Propagation&lt;/h3>
&lt;p>A subtle yet profound aspect of the Kalman filter is its treatment of uncertainty. The covariance matrices $P_{k|k-1}$ and $P_{k|k}$
encode not just the spread of possible states, but also the correlations between different state variables.
The propagation of covariance through the system dynamics involves the transformation:&lt;/p>
&lt;p>$$
P_{k|k-1} = F_{k} P_{k-1|k-1} F_{k}^{T} + Q_{k}
$$&lt;/p>
&lt;p>This operation reflects how uncertainty &amp;ldquo;flows&amp;rdquo; through the linear transformation $F_{k}$, and how process noise $Q_{k}$
injects additional uncertainty. The measurement update, in turn, reduces uncertainty by incorporating
information from the observation, as modulated by the Kalman gain.&lt;/p>
&lt;p>Understanding the covariance as a bilinear form, rather than just a matrix, reveals the deep connection between
the algebra of estimation and the geometry of probability distributions. This perspective is crucial for appreciating
the filter&amp;rsquo;s optimality and for extending it to more complex, nonlinear, or high-dimensional settings.&lt;/p>
&lt;h2 id="kalman-filtering-meets-pytorch-implementation-and-differentiability">Kalman Filtering Meets PyTorch: Implementation and Differentiability&lt;/h2>
&lt;h3 id="why-pytorch-beyond-deep-learning">Why PyTorch? Beyond Deep Learning&lt;/h3>
&lt;p>PyTorch, originally designed for deep learning, offers a flexible tensor computation library with automatic
differentiation and seamless GPU acceleration. While its primary use case has been neural networks,
its capabilities make it an attractive platform for implementing classical algorithms like the Kalman filter.
The motivations are manifold:&lt;/p>
&lt;p>First, PyTorch&amp;rsquo;s tensor operations enable efficient batch processing, which is invaluable when filtering multiple signals
or running ensembles of filters in parallel. Second, the autograd engine allows for differentiable programming, making
it possible to optimize filter parameters or integrate the filter as a module within a larger neural architecture.
Third, PyTorch&amp;rsquo;s ecosystem encourages modularity, extensibility, and integration with probabilistic programming frameworks such as Pyro.&lt;/p>
&lt;h3 id="coding-the-classical-kalman-filter-in-pytorch">Coding the Classical Kalman Filter in PyTorch&lt;/h3>
&lt;p>Implementing the Kalman filter in PyTorch involves translating the recursive equations into tensor operations.
Consider the following minimal implementation for a batch of signals:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4">&lt;code class="language-python" data-lang="python">&lt;span style="color:#f92672">import&lt;/span> torch
&lt;span style="color:#f92672">from&lt;/span> torch &lt;span style="color:#f92672">import&lt;/span> nn
&lt;span style="color:#f92672">from&lt;/span> torch.linalg &lt;span style="color:#f92672">import&lt;/span> inv
&lt;span style="color:#66d9ef">class&lt;/span> &lt;span style="color:#a6e22e">KalmanFilter&lt;/span>(nn&lt;span style="color:#f92672">.&lt;/span>Module):
&lt;span style="color:#e6db74">&amp;#34;&amp;#34;&amp;#34;Kalman Filter implementation for state estimation in linear dynamic systems.
&lt;/span>&lt;span style="color:#e6db74">
&lt;/span>&lt;span style="color:#e6db74"> Attributes:
&lt;/span>&lt;span style="color:#e6db74"> F (Tensor): State transition matrix.
&lt;/span>&lt;span style="color:#e6db74"> B (Tensor): Control input matrix.
&lt;/span>&lt;span style="color:#e6db74"> H (Tensor): Observation matrix.
&lt;/span>&lt;span style="color:#e6db74"> Q (Tensor): Process noise covariance.
&lt;/span>&lt;span style="color:#e6db74"> R (Tensor): Observation noise covariance.
&lt;/span>&lt;span style="color:#e6db74"> state_dim (int): Dimensionality of the state.
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;span style="color:#66d9ef">def&lt;/span> __init__(self, F, B, H, Q, R, state_dim):
super()&lt;span style="color:#f92672">.&lt;/span>__init__()
self&lt;span style="color:#f92672">.&lt;/span>F &lt;span style="color:#f92672">=&lt;/span> F&lt;span style="color:#f92672">.&lt;/span>clone()
self&lt;span style="color:#f92672">.&lt;/span>B &lt;span style="color:#f92672">=&lt;/span> B&lt;span style="color:#f92672">.&lt;/span>clone()
self&lt;span style="color:#f92672">.&lt;/span>H &lt;span style="color:#f92672">=&lt;/span> H&lt;span style="color:#f92672">.&lt;/span>clone()
self&lt;span style="color:#f92672">.&lt;/span>Q &lt;span style="color:#f92672">=&lt;/span> Q
self&lt;span style="color:#f92672">.&lt;/span>R &lt;span style="color:#f92672">=&lt;/span> R
self&lt;span style="color:#f92672">.&lt;/span>state_dim &lt;span style="color:#f92672">=&lt;/span> state_dim
&lt;span style="color:#75715e"># placeholders for the current state, covariance, observation and control&lt;/span>
self&lt;span style="color:#f92672">.&lt;/span>x &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">None&lt;/span> &lt;span style="color:#75715e"># [state_dim, 1]&lt;/span>
self&lt;span style="color:#f92672">.&lt;/span>P &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">None&lt;/span> &lt;span style="color:#75715e"># [state_dim, state_dim]&lt;/span>
self&lt;span style="color:#f92672">.&lt;/span>zs &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">None&lt;/span> &lt;span style="color:#75715e"># [obs_dim, 1]&lt;/span>
self&lt;span style="color:#f92672">.&lt;/span>us &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#66d9ef">None&lt;/span> &lt;span style="color:#75715e"># [control_dim, 1]&lt;/span>
&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">project&lt;/span>(self):
&lt;span style="color:#e6db74">&amp;#34;&amp;#34;&amp;#34;Projects the state and covariance forward.&amp;#34;&amp;#34;&amp;#34;&lt;/span>
x_pred &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(self&lt;span style="color:#f92672">.&lt;/span>F, self&lt;span style="color:#f92672">.&lt;/span>x) &lt;span style="color:#f92672">+&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(self&lt;span style="color:#f92672">.&lt;/span>B, self&lt;span style="color:#f92672">.&lt;/span>us)
P_pred &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(self&lt;span style="color:#f92672">.&lt;/span>F, torch&lt;span style="color:#f92672">.&lt;/span>matmul(self&lt;span style="color:#f92672">.&lt;/span>P, self&lt;span style="color:#f92672">.&lt;/span>F&lt;span style="color:#f92672">.&lt;/span>T)) &lt;span style="color:#f92672">+&lt;/span> self&lt;span style="color:#f92672">.&lt;/span>Q
&lt;span style="color:#66d9ef">return&lt;/span> x_pred, P_pred
&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">correct&lt;/span>(self, x_pred, P_pred):
&lt;span style="color:#e6db74">&amp;#34;&amp;#34;&amp;#34;Corrects the state estimate with the current observation.&amp;#34;&amp;#34;&amp;#34;&lt;/span>
S &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(self&lt;span style="color:#f92672">.&lt;/span>H, torch&lt;span style="color:#f92672">.&lt;/span>matmul(P_pred, self&lt;span style="color:#f92672">.&lt;/span>H&lt;span style="color:#f92672">.&lt;/span>T)) &lt;span style="color:#f92672">+&lt;/span> self&lt;span style="color:#f92672">.&lt;/span>R
K &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(P_pred, self&lt;span style="color:#f92672">.&lt;/span>H&lt;span style="color:#f92672">.&lt;/span>T) &lt;span style="color:#f92672">@&lt;/span> inv(S)
&lt;span style="color:#75715e"># state update&lt;/span>
self&lt;span style="color:#f92672">.&lt;/span>x &lt;span style="color:#f92672">=&lt;/span> x_pred &lt;span style="color:#f92672">+&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(K, (self&lt;span style="color:#f92672">.&lt;/span>zs &lt;span style="color:#f92672">-&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(self&lt;span style="color:#f92672">.&lt;/span>H, x_pred)))
&lt;span style="color:#75715e"># covariance update&lt;/span>
I &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>eye(self&lt;span style="color:#f92672">.&lt;/span>state_dim, device&lt;span style="color:#f92672">=&lt;/span>P_pred&lt;span style="color:#f92672">.&lt;/span>device)
self&lt;span style="color:#f92672">.&lt;/span>P &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul((I &lt;span style="color:#f92672">-&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(K, self&lt;span style="color:#f92672">.&lt;/span>H)), P_pred)
&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">forward&lt;/span>(self, zs, us):
&lt;span style="color:#e6db74">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;span style="color:#e6db74"> Processes a batch of observation/control sequences.
&lt;/span>&lt;span style="color:#e6db74">
&lt;/span>&lt;span style="color:#e6db74"> Args:
&lt;/span>&lt;span style="color:#e6db74"> zs: [timesteps, batch, obs_dim] sequence of observations
&lt;/span>&lt;span style="color:#e6db74"> us: [timesteps, batch, control_dim] sequence of control inputs
&lt;/span>&lt;span style="color:#e6db74"> Returns:
&lt;/span>&lt;span style="color:#e6db74"> xs: [batch, state_dim, timesteps] filtered state estimates
&lt;/span>&lt;span style="color:#e6db74"> pred_obs: [batch, obs_dim, timesteps] one-step predictions of observations
&lt;/span>&lt;span style="color:#e6db74"> residuals: [batch, obs_dim, timesteps] observation residuals
&lt;/span>&lt;span style="color:#e6db74"> &amp;#34;&amp;#34;&amp;#34;&lt;/span>
xs &lt;span style="color:#f92672">=&lt;/span> []
pred_obs &lt;span style="color:#f92672">=&lt;/span> []
residuals &lt;span style="color:#f92672">=&lt;/span> []
&lt;span style="color:#75715e"># initial state &amp;amp; covariance&lt;/span>
self&lt;span style="color:#f92672">.&lt;/span>x &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>zeros((self&lt;span style="color:#f92672">.&lt;/span>state_dim, &lt;span style="color:#ae81ff">1&lt;/span>), device&lt;span style="color:#f92672">=&lt;/span>zs&lt;span style="color:#f92672">.&lt;/span>device)
self&lt;span style="color:#f92672">.&lt;/span>P &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>eye(self&lt;span style="color:#f92672">.&lt;/span>state_dim, device&lt;span style="color:#f92672">=&lt;/span>zs&lt;span style="color:#f92672">.&lt;/span>device)
&lt;span style="color:#75715e"># iterate over time&lt;/span>
&lt;span style="color:#66d9ef">for&lt;/span> z_t, u_t &lt;span style="color:#f92672">in&lt;/span> zip(zs&lt;span style="color:#f92672">.&lt;/span>transpose(&lt;span style="color:#ae81ff">0&lt;/span>, &lt;span style="color:#ae81ff">1&lt;/span>), us&lt;span style="color:#f92672">.&lt;/span>transpose(&lt;span style="color:#ae81ff">0&lt;/span>, &lt;span style="color:#ae81ff">1&lt;/span>)):
self&lt;span style="color:#f92672">.&lt;/span>zs &lt;span style="color:#f92672">=&lt;/span> z_t&lt;span style="color:#f92672">.&lt;/span>unsqueeze(&lt;span style="color:#ae81ff">1&lt;/span>)
self&lt;span style="color:#f92672">.&lt;/span>us &lt;span style="color:#f92672">=&lt;/span> u_t&lt;span style="color:#f92672">.&lt;/span>unsqueeze(&lt;span style="color:#ae81ff">1&lt;/span>)
x_pred, P_pred &lt;span style="color:#f92672">=&lt;/span> self&lt;span style="color:#f92672">.&lt;/span>project()
self&lt;span style="color:#f92672">.&lt;/span>correct(x_pred, P_pred)
xs&lt;span style="color:#f92672">.&lt;/span>append(self&lt;span style="color:#f92672">.&lt;/span>x&lt;span style="color:#f92672">.&lt;/span>detach()&lt;span style="color:#f92672">.&lt;/span>clone())
y_pred &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>matmul(self&lt;span style="color:#f92672">.&lt;/span>H, x_pred)
pred_obs&lt;span style="color:#f92672">.&lt;/span>append(y_pred)
residuals&lt;span style="color:#f92672">.&lt;/span>append(self&lt;span style="color:#f92672">.&lt;/span>zs &lt;span style="color:#f92672">-&lt;/span> y_pred)
xs &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>cat(xs, dim&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>)
pred_obs &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>cat(pred_obs, dim&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>)
residuals &lt;span style="color:#f92672">=&lt;/span> torch&lt;span style="color:#f92672">.&lt;/span>cat(residuals, dim&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#ae81ff">1&lt;/span>)
&lt;span style="color:#66d9ef">return&lt;/span> xs, pred_obs, residuals
&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="differentiable-kalman-filters-learning-and-optimization">Differentiable Kalman Filters: Learning and Optimization&lt;/h2>
&lt;p>One of the most transformative aspects of implementing the Kalman filter in PyTorch is the ability to make the entire
filtering process differentiable. By treating the system matrices ($F$, $H$, $Q$, $R$) as learnable parameters,
one can optimize them using gradient-based methods, either to fit data or to tune the filter for specific tasks.
This approach blurs the line between classical estimation and machine learning, enabling hybrid models that combine
the structure of state-space models with the flexibility of data-driven learning.&lt;/p>
&lt;p>Recent research has focused on improving the efficiency of backpropagation through the Kalman filter.
While PyTorch&amp;rsquo;s automatic differentiation can compute gradients, it may incur significant computational overhead,
especially for large-scale problems. Novel closed-form expressions for the derivatives of the filter&amp;rsquo;s outputs with
respect to its parameters have been developed, offering substantial speed-ups (up to 38 times faster than PyTorch&amp;rsquo;s
autograd in some cases). These advances make it feasible to embed Kalman filters within deep learning pipelines,
trainable end-to-end, and responsive to the demands of modern applications.&lt;/p>
&lt;h2 id="pytorch-libraries-for-kalman-filtering">PyTorch Libraries for Kalman Filtering&lt;/h2>
&lt;p>Several open-source libraries have emerged to facilitate Kalman filtering in PyTorch:&lt;/p>
&lt;ul>
&lt;li>torch-kf: A fast implementation supporting batch filtering and smoothing, capable of running on both CPU and GPU. It is particularly efficient when filtering large batches of signals, leveraging PyTorch&amp;rsquo;s parallelism.&lt;/li>
&lt;li>DeepKalmanFilter: Implements deep variants of the Kalman filter, where neural networks parameterize parts of the state-space model. This enables modeling of nonlinear dynamics and observations, bridging the gap between classical filtering and deep generative models.&lt;/li>
&lt;li>Pyro: A probabilistic programming framework that supports differentiable Kalman filters and extended Kalman filters, with learnable parameters and integration with variational inference.&lt;/li>
&lt;li>torchfilter: Provides advanced filters such as the square-root unscented Kalman filter, supporting both state and parameter estimation in nonlinear systems.&lt;/li>
&lt;/ul>
&lt;h2 id="extensions-and-hybrid-models-beyond-the-classical-filter">Extensions and Hybrid Models: Beyond the Classical Filter&lt;/h2>
&lt;h3 id="nonlinear-and-non-gaussian-filtering">Nonlinear and Non-Gaussian Filtering&lt;/h3>
&lt;p>While the classical Kalman filter assumes linear dynamics and Gaussian noise, many real-world systems violate
these assumptions. Extensions such as the Extended Kalman Filter (EKF) and Unscented Kalman Filter (UKF) address
nonlinearities by linearizing the dynamics or propagating sigma points, respectively. Particle filters, in turn,
approximate arbitrary distributions via Monte Carlo sampling.&lt;/p>
&lt;p>Implementing these advanced filters in PyTorch follows the same principles: tensorized operations,
differentiability, and integration with neural modules. For example, the EKF can be implemented by computing
Jacobians using PyTorch&amp;rsquo;s autograd, while the UKF can leverage batched sigma point propagation for efficient parallelism.&lt;/p>
&lt;h3 id="deep-kalman-filters-and-latent-dynamics">Deep Kalman Filters and Latent Dynamics&lt;/h3>
&lt;p>The fusion of Kalman filtering with deep learning has given rise to deep Kalman filters, where neural networks
parameterize the transition and observation functions. This approach enables modeling of complex, nonlinear,
and high-dimensional systems, such as video sequences or sensor fusion in robotics. The deep Kalman filter retains
the probabilistic structure of the classical filter but augments it with the representational power of neural networks.&lt;/p>
&lt;p>In PyTorch, this is achieved by defining neural modules for the transition and observation models,
and using the filtering equations to propagate means and covariances through time. The entire model
can be trained end-to-end using stochastic gradient descent, with the Kalman filter acting as a differentiable
layer within the network.&lt;/p>
&lt;h3 id="hybrid-estimators-neural-networks-and-kalman-filters">Hybrid Estimators: Neural Networks and Kalman Filters&lt;/h3>
&lt;p>Hybrid models that combine neural networks and Kalman filters have demonstrated superior performance in
state estimation tasks, particularly in scenarios with complex dynamics or partial observability.
These models can be categorized into two main types:&lt;/p>
&lt;ul>
&lt;li>NN-KF: Neural networks learn the parameters or functions of the state-space model, which are then used by the Kalman filter for estimation.&lt;/li>
&lt;li>KF-NN: The Kalman filter provides state estimates or uncertainty measures that are used as inputs or features for a neural network.&lt;/li>
&lt;/ul>
&lt;p>Such hybridization leverages the strengths of both approaches: the interpretability and optimality of the Kalman filter,
and the flexibility and expressiveness of neural networks. In PyTorch, these models can be implemented as composite
modules, trained jointly or sequentially, and deployed in a wide range of applications from battery state-of-charge
estimation to autonomous navigation.&lt;/p>
&lt;h2 id="philosophical-reflections-uncertainty-knowledge-and-learning">Philosophical Reflections: Uncertainty, Knowledge, and Learning&lt;/h2>
&lt;h3 id="the-epistemology-of-state-estimation">The Epistemology of State Estimation&lt;/h3>
&lt;p>At a deeper level, the Kalman filter embodies a philosophy of knowledge under uncertainty. It formalizes the process of
updating beliefs in the face of incomplete and noisy information, balancing prior expectations (the model) with new
evidence (the measurements). The recursive structure mirrors the Bayesian paradigm, where beliefs are continuously
revised as new data arrives.&lt;/p>
&lt;p>Yet, the filter&amp;rsquo;s optimality is contingent on its assumptions: linearity, Gaussianity, and known noise covariances.
When these assumptions are violated, as is often the case in complex systems, the filter&amp;rsquo;s estimates may become biased
or inconsistent. This raises fundamental questions: What does it mean to &amp;ldquo;know&amp;rdquo; the state of a system? How do we quantify
and manage uncertainty? Can we trust our models, or must we adapt them in light of new evidence?&lt;/p>
&lt;h3 id="the-fusion-of-model-based-and-data-driven-approaches">The Fusion of Model-Based and Data-Driven Approaches&lt;/h3>
&lt;p>The integration of Kalman filtering with PyTorch and neural networks reflects a broader trend in computational science:
the synthesis of model-based and data-driven approaches. Classical estimation theory offers structure, interpretability,
and guarantees of optimality. Machine learning provides flexibility, scalability, and the ability to discover patterns
from data.&lt;/p>
&lt;p>Hybrid models, differentiable filters, and end-to-end learning challenge the traditional dichotomy between &amp;ldquo;hard-coded&amp;rdquo;
models and &amp;ldquo;black-box&amp;rdquo; learning. They invite us to reconsider the boundaries between theory and data, deduction and
induction, certainty and doubt. In this sense, the Kalman filter is not just an algorithm, but a lens through which to
explore the nature of inference, prediction, and adaptation.&lt;/p>
&lt;h3 id="the-philosophy-of-differentiable-programming">The Philosophy of Differentiable Programming&lt;/h3>
&lt;p>The advent of differentiable programming—where algorithms are designed to be composed, differentiated,
and optimized—raises new philosophical questions. When we make the Kalman filter differentiable, we enable it to
learn from data, to adapt its parameters, and to participate in the broader ecosystem of neural computation.
But we also introduce new forms of uncertainty: about the correctness of gradients, the stability of optimization,
and the interpretability of learned models.&lt;/p>
&lt;p>Is the differentiable Kalman filter still a Kalman filter, or has it become something new? What are the implications of
treating classical algorithms as modules within a deep learning pipeline? How do we balance the desire for optimality
with the need for flexibility? These questions invite ongoing reflection and experimentation.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>The Kalman filter, once a symbol of control theory and aerospace engineering, has found new life in the era of PyTorch
and machine learning. Its recursive structure, principled handling of uncertainty, and optimality under Gaussian
assumptions remain as compelling as ever. Yet, its implementation and interpretation are evolving, shaped by the
demands of differentiability, scalability, and integration with neural computation.&lt;/p>
&lt;p>By exploring the mathematical foundations, practical coding strategies, extensions to nonlinear and hybrid models,
and the deeper philosophical questions that arise, we have sought to illuminate both the enduring relevance and
the transformative potential of Kalman filtering in the age of PyTorch. As we continue to blur the boundaries between
model-based and data-driven approaches, the filter serves as a bridge—not just between past and future, but between
certainty and doubt, theory and practice, knowledge and learning.&lt;/p>
&lt;p>The journey of the Kalman filter is far from over. Its recursive dance of prediction and correction, its geometry
of uncertainty, and its adaptability to new computational paradigms ensure that it will remain a central figure in the
ongoing dialogue between mathematics, engineering, and philosophy. Whether as a standalone estimator, a differentiable
module, or a component of a deep generative model, the Kalman filter challenges us to rethink what it means to know,
to predict, and to learn.&lt;/p>
&lt;h2 id="further-reading-and-resources">Further Reading and Resources&lt;/h2>
&lt;p>For those interested in diving deeper, consider exploring the following resources:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="https://github.com/raphaelreme/torch-kf" target="_blank" rel="noopener">torch-kf&lt;/a>: Fast PyTorch implementation of Kalman filters, supporting batch processing and GPU acceleration.&lt;/li>
&lt;li>&lt;a href="https://github.com/morim3/DeepKalmanFilter" target="_blank" rel="noopener">DeepKalmanFilter&lt;/a>: PyTorch implementation of deep Kalman filters, integrating neural networks with probabilistic state-space models.&lt;/li>
&lt;li>[Pyro Tutorials](&lt;a href="https://pyro.ai/examples/ekf.html" target="_blank" rel="noopener">https://pyro.ai/examples/ekf.html&lt;/a>: Differentiable Kalman and extended Kalman filters with learnable parameters.&lt;/li>
&lt;li>&lt;a href="https://stanford-iprl-lab.github.io/torchfilter/_modules/torchfilter/filters/_square_root_unscented_kalman_filter/" target="_blank" rel="noopener">torchfilter&lt;/a>: Advanced filters including square-root unscented Kalman filter for nonlinear systems.&lt;/li>
&lt;li>Recent Research: &lt;a href="https://stanford-iprl-lab.github.io/torchfilter/_modules/torchfilter/filters/_square_root_unscented_kalman_filter/" target="_blank" rel="noopener">Closed-form gradients for efficient differentiable filtering&lt;/a>,
&lt;a href="https://www.semanticscholar.org/paper/A-review%3A-state-estimation-based-on-hybrid-models-Feng-Li/1f9d96407167c1bb894c4dec60a64bd31c00d1e8" target="_blank" rel="noopener">hybrid models for state estimation&lt;/a>,
and &lt;a href="https://arxiv.org/abs/2010.08196" target="_blank" rel="noopener">practical applications in robotics and sensor fusion&lt;/a>.&lt;/li>
&lt;/ul></description></item><item><title>3D Reconstruction of Human Olfactory Projection</title><link>https://mahyar-osn.github.io/projects/olfactory/</link><pubDate>Fri, 10 Nov 2023 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/projects/olfactory/</guid><description>&lt;p>&lt;strong>Authors&lt;/strong>: Victoria F Low, Chinchien Lin, Shan Su, Mahyar Osanlouy, Mona Khan, Soroush Safaei, Gonzalo Maso Talou, Maurice A Curtis, Peter Mombaerts&lt;br>
&lt;strong>Publication&lt;/strong>: &lt;em>Communications Biology&lt;/em> (November 2024)&lt;br>
&lt;strong>Code&lt;/strong>: &lt;a href="https://zenodo.org/records/7865523" target="_blank" rel="noopener">Zenodo Repository&lt;/a>&lt;br>
&lt;strong>Interactive 3D Model&lt;/strong>: &lt;a href="https://mip.datavisualiser.cloud.edu.au/neuroglancer/A1147/it13" target="_blank" rel="noopener">Neuroglancer Platform&lt;/a>&lt;/p>
&lt;hr>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>This study presents a computational pipeline to reconstruct the 3D microanatomy of the human olfactory system, from the
nasal cavity to the olfactory bulb—using fluorescence histology, deep learning, and high-performance computing (HPC).
The workflow addresses challenges in processing terabyte-scale datasets and provides new insights into olfactory sensory
neuron (OSN) distribution and axon trajectories.&lt;/p>
&lt;hr>
&lt;h2 id="key-computational-contributions">Key Computational Contributions&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>First end-to-end pipeline&lt;/strong> for large-scale 3D reconstruction of human olfactory tissues (~7.45 cm³ specimen, 1234
sections).&lt;/li>
&lt;li>&lt;strong>CNN-based segmentation&lt;/strong> achieving Dice scores &amp;gt;0.85 for critical structures (OSNs, glomeruli, vasculature).&lt;/li>
&lt;li>&lt;strong>HPC-optimized registration&lt;/strong> reducing banana-effect artifacts via multi-resolution deformable alignment.&lt;/li>
&lt;li>&lt;strong>Public 3D dataset&lt;/strong> enabling interactive exploration of olfactory projection via Neuroglancer.&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="methodology">Methodology&lt;/h2>
&lt;h3 id="computational-pipeline">Computational Pipeline&lt;/h3>
&lt;img src="2025-04-13_22-28.png" alt="Receptive fields" width="400">
&lt;p>&lt;em>From fluorescence histology to 3D visualization – click to expand&lt;/em>&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Fluorescence Histology&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Quadruple staining: Hoechst (nuclei), UEA1 (OSNs), OMP (mature OSNs), VGLUT2 (axon terminals).&lt;/li>
&lt;li>Whole-slide scanning: 1.097 µm/pixel resolution, ~2.9 TB raw data.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>CNN Segmentation&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Architecture: Modified 2D U-Net with 4 input channels (Hoechst + 3 markers).&lt;/li>
&lt;li>Training: Bootstrap approach with iterative ground truth expansion (20-45 sections/structure).&lt;/li>
&lt;li>Key layers:
&lt;pre tabindex="0">&lt;code># Simplified U-Net structure
encoder = [Conv2D(8→16→32), MaxPooling2D]
bottleneck = Conv2D(64) + Upsampling2D
decoder = [Conv2D(32→16→8), Concatenate(skip connections)]
&lt;/code>&lt;/pre>&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>HPC Registration&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Intra-block&lt;/strong>: Parallel registration of 247 blocks (5 sections each) using SimpleElastix.&lt;/li>
&lt;li>&lt;strong>Inter-block&lt;/strong>: Banana-effect correction via affine + B-spline transformations between blocks.&lt;/li>
&lt;li>Metrics: Mutual information for intensity alignment, DSC for structural consistency.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="results">Results&lt;/h2>
&lt;h3 id="segmentation-performance">Segmentation Performance&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Structure&lt;/th>
&lt;th>Dice Score&lt;/th>
&lt;th>Binary Cross-Entropy&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Vasculature&lt;/td>
&lt;td>0.808&lt;/td>
&lt;td>0.0148&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>OSNs&lt;/td>
&lt;td>0.760&lt;/td>
&lt;td>0.0173&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Glomeruli&lt;/td>
&lt;td>0.779&lt;/td>
&lt;td>0.0017&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;em>OSN segmentation achieved single-cell resolution in sparse regions but grouped cells in dense zones.&lt;/em>&lt;/p>
&lt;h3 id="registration-efficiency">Registration Efficiency&lt;/h3>
&lt;ul>
&lt;li>1082 CPU hours on 96 Intel Xeon Gold 6136 cores&lt;/li>
&lt;li>16% error reduction vs. sequential registration&lt;/li>
&lt;li>Tolerance: ±80 µm axial drift corrected&lt;/li>
&lt;/ul>
&lt;h3 id="key-findings">Key Findings&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>OSN Count&lt;/strong>: ~2.7 million OSNs calculated via morphometric extrapolation (90% CI: 2.4–2.9M).&lt;/li>
&lt;li>&lt;strong>Fila Olfactoria&lt;/strong>: 34 foramina identified in cribriform plate (17/side).&lt;/li>
&lt;li>&lt;strong>Non-uniform Distribution&lt;/strong>: Olfactory epithelium showed serrated borders and posterior-anterior density gradient.&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="implications">Implications&lt;/h2>
&lt;h3 id="technical-advancements">Technical Advancements&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Scalable ML&lt;/strong>: Method enables processing of whole-brain datasets (~100x mouse brain volume).&lt;/li>
&lt;li>&lt;strong>Clinical Potential&lt;/strong>: Pipeline adaptable for Parkinson’s/Alzheimer’s studies via α-synuclein/tau staining.&lt;/li>
&lt;li>&lt;strong>Open Science&lt;/strong>: First public 3D olfactory dataset with ~5.8 GB/channel resolution.&lt;/li>
&lt;/ul>
&lt;h3 id="biological-insights">Biological Insights&lt;/h3>
&lt;ul>
&lt;li>Challenges mouse-to-human extrapolation: ~10x fewer OSNs/glomerulus vs. mice.&lt;/li>
&lt;li>Provides baseline for studying SARS-CoV-2 olfactory dysfunction.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="computational-tools-used">Computational Tools Used&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Segmentation&lt;/strong>: TensorFlow U-Net, Fiji for ground truth&lt;/li>
&lt;li>&lt;strong>Registration&lt;/strong>: SimpleElastix, ITK&lt;/li>
&lt;li>&lt;strong>Visualization&lt;/strong>: ParaView, Neuroglancer&lt;/li>
&lt;li>&lt;strong>HPC&lt;/strong>: New Zealand eScience Infrastructure (NeSI)&lt;/li>
&lt;/ul>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img alt="Neuroglancer screenshot placeholder" srcset="
/projects/olfactory/2025-04-13_22-30_hu0a3d9e68d0bcba58dbfed67f020b6e7c_1016129_378c0bcc687f8925b56e8df10b0a25fa.webp 400w,
/projects/olfactory/2025-04-13_22-30_hu0a3d9e68d0bcba58dbfed67f020b6e7c_1016129_c29f28f27c7b3ae1fc51e30bdf455294.webp 760w,
/projects/olfactory/2025-04-13_22-30_hu0a3d9e68d0bcba58dbfed67f020b6e7c_1016129_1200x1200_fit_q75_h2_lanczos_3.webp 1200w"
src="https://mahyar-osn.github.io/projects/olfactory/2025-04-13_22-30_hu0a3d9e68d0bcba58dbfed67f020b6e7c_1016129_378c0bcc687f8925b56e8df10b0a25fa.webp"
width="760"
height="564"
loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;em>Interactive 3D exploration&lt;/em>&lt;/p>
&lt;hr></description></item><item><title>Spatiotemporal patterns in the embryonic heart</title><link>https://mahyar-osn.github.io/projects/embryo/</link><pubDate>Mon, 25 Sep 2023 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/projects/embryo/</guid><description>&lt;p>&lt;strong>Authors&lt;/strong>: Nazanin Ebrahimi, Mahyar Osanlouy, Chris Bradley, Fabiana Kubke, Dane Gerneke, Peter Hunter &lt;br>
&lt;strong>Publication&lt;/strong>: &lt;em>iScience.&lt;/em> (July 2022)&lt;br>
&lt;strong>Dataset&lt;/strong>: &lt;a href="https://doi.org/10.17632/jwj6m5yxct.1" target="_blank" rel="noopener">Mendeley Data&lt;/a>&lt;/p>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>This study presents an innovative hybrid experimental-computational pipeline to investigate the &lt;strong>spatiotemporal growth patterns&lt;/strong> underlying cardiac C-looping in embryonic chick hearts. C-looping is a critical phase in heart development where the straight heart tube transforms into a C-shaped structure, setting the stage for proper chamber formation. Abnormalities during this process are linked to congenital heart defects. The work combines &lt;strong>multi-scale imaging&lt;/strong>, &lt;strong>deep learning-based cell segmentation&lt;/strong>, and &lt;strong>biomechanical modeling&lt;/strong> to bridge cellular dynamics with tissue-level deformations, offering new insights into the mechanisms driving heart morphogenesis.&lt;/p>
&lt;hr>
&lt;h2 id="key-contributions">Key Contributions&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>First 3D multi-scale dataset&lt;/strong> of C-looping hearts, integrating cell-to-organism level data from confocal microscopy and micro-CT.&lt;/li>
&lt;li>&lt;strong>Fully automated 3D myocardial cell segmentation&lt;/strong> using a custom convolutional neural network (CNN), achieving a Dice coefficient of 0.91 ± 0.1.&lt;/li>
&lt;li>&lt;strong>Finite Element (FE) biomechanical models&lt;/strong> capturing spatiotemporal heart geometry changes across four developmental timepoints.&lt;/li>
&lt;li>&lt;strong>Variance-driven analysis&lt;/strong> revealing how inter-cellular space (ICS) and cellular heterogeneity contribute to tissue growth.&lt;/li>
&lt;li>&lt;strong>Open-source pipeline&lt;/strong> for integrating cellular features with tissue-level kinematics, enabling future studies on cardiac morphogenesis.&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="methodology">Methodology&lt;/h2>
&lt;h3 id="experimental-workflow">Experimental Workflow&lt;/h3>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Multi-modal imaging&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Confocal microscopy&lt;/strong>: Whole-mount staining (WGA, NCAM-1, DAPI) provided 3D cell-resolution images of myocardial cells.&lt;/li>
&lt;li>&lt;strong>Micro-CT scanning&lt;/strong>: Sub-micron resolution imaging contextualized heart geometry within the entire embryo.&lt;/li>
&lt;li>&lt;strong>Optical clearing&lt;/strong>: Enabled high-resolution imaging while preserving 3D architecture.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Temporal staging&lt;/strong>: Embryos were ordered developmentally using anatomical landmarks and dorsal detachment metrics.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;img src="workflow.jpg" alt="drc-worfklow" width="800">
&lt;h3 id="computational-workflow">Computational Workflow&lt;/h3>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>3D Deep Learning for Cell Segmentation&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>A &lt;strong>3D U-Net architecture&lt;/strong> was trained to segment individual myocardial cells from confocal stacks.&lt;/li>
&lt;li>Achieved 91% Dice similarity compared to manual segmentation, reducing processing time from &lt;strong>8 hours to seconds&lt;/strong> per 100 cells.&lt;/li>
&lt;li>Addressed memory constraints via a traceable slicing-merging algorithm for large-scale image processing.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Finite Element Modeling&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Anatomically accurate FE meshes were fitted to heart geometries using OpenCMISS.&lt;/li>
&lt;li>RMS fitting error &amp;lt; 3 μm enabled precise representation of tissue deformation.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Spatiotemporal Analysis&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Cellular features (volume, anisotropy, orientation) were mapped onto FE meshes.&lt;/li>
&lt;li>&lt;strong>General Linear Model (GLM)&lt;/strong> linked tissue growth to cellular dynamics (cell number, ICS volume, anisotropy).&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;img src="segmentation.png" alt="drc-worfklow" width="800">
&lt;hr>
&lt;h2 id="results">Results&lt;/h2>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Differential Growth Patterns&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Ventral regions showed ~2x higher tissue growth than dorsal regions, driven by increased cell proliferation and ICS expansion.&lt;/li>
&lt;li>Outer curvature cells exhibited circumferential alignment, while inner curvature cells remained isotropic.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Role of Inter-Cellular Space (ICS)&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>ICS accounted for 30–45% of tissue volume changes, highlighting its role in accommodating growth.&lt;/li>
&lt;li>Ventral ICS volume increased by 62% during bending phases.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Variance as a Developmental Signal&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Ring-shaped variance patterns&lt;/strong> in cell volume/anisotropy emerged around the outer curvature, suggesting mechanical feedback loops.&lt;/li>
&lt;li>High-variance regions correlated with zones of rapid tissue remodeling.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Tissue-Cell Dynamics&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>GLM analysis explained 70% of tissue growth variance, with cell number (β = 0.48, p &amp;lt; 0.001) and ICS (β = 0.32, p &amp;lt; 0.01) as key predictors.&lt;/li>
&lt;li>Cell orientation aligned with tissue deformation vectors during rotation (r &amp;gt; 0.8) but not bending phases.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="implications">Implications&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Mechanistic Insights&lt;/strong>: Challenges the &amp;ldquo;differential growth hypothesis&amp;rdquo; by showing ICS and cellular heterogeneity are equally critical to looping.&lt;/li>
&lt;li>&lt;strong>Toolkit for Developmental Biology&lt;/strong>: The pipeline is extensible to other organs/species, enabling studies on how cellular noise shapes tissue patterning.&lt;/li>
&lt;li>&lt;strong>Clinical Relevance&lt;/strong>: Provides a framework to explore how genetic mutations disrupt growth coordination, informing congenital heart defect research.&lt;/li>
&lt;li>&lt;strong>AI/ML Impact&lt;/strong>: Demonstrates the power of deep learning in automating large-scale 3D biological image analysis.&lt;/li>
&lt;/ul>
&lt;img src="deformation.jpg" alt="drc-worfklow" width="800"></description></item><item><title>SFEAL</title><link>https://mahyar-osn.github.io/projects/sfeal/</link><pubDate>Fri, 22 Sep 2023 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/projects/sfeal/</guid><description>&lt;p>&lt;strong>Authors&lt;/strong>: Mahyar Osanlouy, Alys R. Clark, Haribalan Kumar, Clair King, Margaret L. Wilsher, David G. Milne, Ken Whyte, Eric A. Hoffman &amp;amp; Merryn H. Tawhai
&lt;strong>Publication&lt;/strong>: &lt;em>Nature Scientific Reports.&lt;/em> (September 2020)&lt;br>
&lt;strong>Code&lt;/strong>: &lt;a href="https://github.com/mahyar-osn/SFEAL" target="_blank" rel="noopener">Mendeley Data&lt;/a>&lt;/p>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>This project presents a quantitative investigation into age‐related variations in lung and fissure shape among healthy adults (aged 20–90 years). By integrating advanced finite element mesh fitting techniques with statistical shape modeling and principal component analysis (PCA), the study establishes a robust framework for capturing and quantifying subtle geometric changes in lung morphology. Such a mathematical framework provides a normative baseline against which pathological alterations may be compared.&lt;/p>
&lt;h2 id="key-contributions">Key Contributions&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Integration of Finite Element Modeling and PCA:&lt;/strong>&lt;br>
• Developed a high-order finite element (FE) mesh fitted to segmented lung surfaces, incorporating curvature and smoothness constraints.&lt;br>
• Applied PCA to reduce dimensionality, isolating principal modes of shape variation.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Mathematical Modeling of Shape Deformations:&lt;/strong>&lt;br>
• Formulated an energy minimization problem that couples data fidelity with smoothness constraints.&lt;br>
• Expressed lung shape variations as weighted perturbations from a mean model in a high-dimensional space.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Clinical Insights:&lt;/strong>&lt;br>
• Revealed strong associations between lung geometry, age, and BMI.&lt;br>
• Enabled detection of subtle fissure shifts and volumetric changes, likely reflecting underlying tissue elasticity.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="methodology">Methodology&lt;/h2>
&lt;h3 id="finite-element-mesh-construction">Finite Element Mesh Construction&lt;/h3>
&lt;p>Each lung is represented by a finite element mesh with a fixed topology (225 nodes in this study). To ensure an accurate and smooth representation, the mesh is fitted to imaging data by minimizing an energy functional that balances data fidelity against surface smoothness.&lt;/p>
&lt;h4 id="energy-model-formulation">Energy Model Formulation&lt;/h4>
&lt;p>The energy function is defined as:&lt;/p>
&lt;p>$$
T(u) = \sum_{i=1}^{N} \gamma_i \left| z(\xi_i) - z_d \right|^2 + \int_{\Omega} g(u(\xi)), d\xi,
$$&lt;/p>
&lt;p>where:&lt;/p>
&lt;ul>
&lt;li>$u$ is the vector of shape (or nodal displacement) parameters.&lt;/li>
&lt;li>$z(\xi_i)$ represents the geometric position of a node in local parametric coordinates $\xi_i$.&lt;/li>
&lt;li>$z_d$ is the target data point from the segmented lung surface.&lt;/li>
&lt;li>$\gamma_i$ is a weight factor controlling data matching for each node.&lt;/li>
&lt;li>$g(u(\xi))$ is the smoothness (regularization) term that penalizes rapid or non-physical deformations.&lt;/li>
&lt;li>$\Omega$ denotes the domain over which the mesh is defined.&lt;/li>
&lt;/ul>
&lt;p>This formulation ensures that the FE mesh adapts to the lung&amp;rsquo;s surface while preserving a biologically plausible smooth geometry.&lt;/p>
&lt;h4 id="pseudo-code-for-mesh-fitting">Pseudo-code for Mesh Fitting&lt;/h4>
&lt;pre>&lt;code>for each subject:
// Step 1: Initialize template mesh
Initialize template_mesh with 225 nodes
// Step 2: Define anatomical landmarks
Define landmarks:
- Apices
- Diaphragm
- Lung base edges
- Anterior segments
// Step 3: Optimize node positions using energy minimization
Optimize node positions by minimizing the energy function T(u):
T(u) = Σγ ||z(ξ₁, ξ₂) - z_d||² + ∫ g(u(ξ)) dξ
// where:
// z = nodal coordinates (x, y, z)
// g = smoothness constraint (curvature regularization)
// γ = data matching weight factor
&lt;/code>&lt;/pre>
&lt;p>&lt;em>Mean fitting error: 5.2 ± 2.3 mm&lt;/em>&lt;/p>
&lt;h3 id="data-alignment-and-statistical-shape-modeling">Data Alignment and Statistical Shape Modeling&lt;/h3>
&lt;p>Prior to PCA, lung shapes are aligned using General Procrustes Analysis (GPA) to eradicate variations due to
translation, rotation, and, in the case of the size-exclusive model, scaling.&lt;/p>
&lt;h4 id="alignment-equation">Alignment Equation&lt;/h4>
&lt;p>The alignment is expressed as:&lt;/p>
&lt;p>$$
\bar{S} = \alpha R S + T,
$$&lt;/p>
&lt;p>where:&lt;/p>
&lt;ul>
&lt;li>$S$ is the original shape vector,&lt;/li>
&lt;li>$R$ is the rotation matrix,&lt;/li>
&lt;li>$T$ is the translation vector,&lt;/li>
&lt;li>$\alpha$ is the scaling factor (applied only in size-inclusive models).&lt;/li>
&lt;/ul>
&lt;h3 id="principal-component-analysis-pca">Principal Component Analysis (PCA)&lt;/h3>
&lt;p>PCA is employed to reduce the high-dimensional shape vector into principal modes that capture the primary sources of variance.&lt;/p>
&lt;h4 id="pca-decomposition-via-svd">PCA Decomposition via SVD&lt;/h4>
&lt;p>The shape matrix $\mathbf{S}$ is decomposed using singular value decomposition (SVD):&lt;/p>
&lt;p>$$
\mathbf{S} = \mathbf{U} {\Sigma} \mathbf{V}^{T},
$$&lt;/p>
&lt;p>where:&lt;/p>
&lt;ul>
&lt;li>$\mathbf{U}$ contains the eigenvectors of $\mathbf{S} \mathbf{S}^{T}$,&lt;/li>
&lt;li>${\Sigma}$ is the diagonal matrix of singular values $\sigma_i$ (with $\lambda_i = \sigma_i^2$ being
the eigenvalues),&lt;/li>
&lt;li>$\mathbf{V}^{T}$ holds the principal directions in the data space.&lt;/li>
&lt;/ul>
&lt;p>Each lung shape is reconstructed as:&lt;/p>
&lt;p>$$
M_{l}(w) = \bar{S}_0 + w, u_{l},
$$&lt;/p>
&lt;p>with:&lt;/p>
&lt;ul>
&lt;li>$\bar{S}_0$ being the mean shape,&lt;/li>
&lt;li>$u_l$ the $l$th principal component,&lt;/li>
&lt;li>$w$ the corresponding weight factor.&lt;/li>
&lt;/ul>
&lt;p>The variance explained by each mode is:&lt;/p>
&lt;p>$$
\text{Variance Explained} = \frac{\sigma_l^2}{\sum_{i} \sigma_i^2} \times 100%.
$$&lt;/p>
&lt;h2 id="results">Results&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Correlation with Age:&lt;/strong>&lt;br>
Specific principal shape modes display strong correlations with age (e.g., $R = -0.75, ; p &amp;lt; 0.001$),&lt;/p>
&lt;/li>
&lt;li>
&lt;p>indicating that lung geometries become more “pyramidal” as age increases.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Sex and BMI Associations:&lt;/strong>&lt;br>
Differences in shape related to lung size manifest in the size-inclusive model, highlighting sex-related volumetric differences. In contrast, the size-exclusive model emphasizes purely geometric deformations, with moderate correlations observed for BMI.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;img src="pca-lung.png" alt="drc-worfklow" width="800">
&lt;img src="pca-plot.png" alt="drc-worfklow" width="800">
&lt;h2 id="implications">Implications&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Clinical Applications:&lt;/strong>&lt;br>
The detailed mathematical framework enables lung shape to be employed as a biomarker for aging and disease. Deviations from the normative PCA model may assist in early detection or staging of conditions like COPD and IPF.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Technical Advancements:&lt;/strong>&lt;br>
The fusion of finite element modeling with PCA offers a versatile and robust method for analyzing complex organ shapes. This approach can be adapted to other anatomical structures requiring similar quantitative assessments.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Future Directions:&lt;/strong>&lt;br>
Enhancing the energy model and incorporating dynamic imaging (e.g., covering breathing cycles) could further refine shape analysis. Additionally, exploring non-linear dimensionality reduction techniques may uncover further subtleties in lung morphology.&lt;/p>
&lt;/li>
&lt;/ul></description></item><item><title>AI-Driven Radiomics for Precision Prostate Cancer Therapy</title><link>https://mahyar-osn.github.io/projects/prostate/</link><pubDate>Sun, 20 Aug 2023 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/projects/prostate/</guid><description>&lt;h1 id="ai-driven-radiomics-for-precision-prostate-cancer-therapy">AI-Driven Radiomics for Precision Prostate Cancer Therapy&lt;/h1>
&lt;p>&lt;strong>Authors&lt;/strong>: Tsz Him Chan, Annette Haworth, Alan Wang, Mahyar Osanlouy et al.&lt;br>
&lt;strong>Publication&lt;/strong>: &lt;em>EJNMMI Research&lt;/em> (2023)&lt;br>
&lt;strong>Code&lt;/strong>: &lt;a href="mailto:Hayley.Reynolds@auckland.ac.nz">Available on Request&lt;/a>&lt;/p>
&lt;hr>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>This pioneering study developed an AI-powered radiomics pipeline to optimize biologically targeted radiation therapy
(BiRT) for prostate cancer. By integrating PSMA PET/CT with multiparametric MRI (mpMRI),
we created voxel-level predictions of tumor location and grade through advanced image registration and machine learning
techniques.&lt;/p>
&lt;hr>
&lt;h2 id="key-innovations">Key Innovations&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>Multi-modal fusion&lt;/strong>: First study combining PSMA PET radiomics with DCE MRI perfusion parameters&lt;/li>
&lt;li>&lt;strong>Voxel-wise prediction&lt;/strong>: Achieved 0.89 AUC for tumor detection using 3D radiomic features&lt;/li>
&lt;li>&lt;strong>Grade differentiation&lt;/strong>: Developed two-stage RFC model separating high/low-grade disease (Accuracy: 0.67-0.99)&lt;/li>
&lt;li>&lt;strong>HPC-optimized registration&lt;/strong>: Reduced spatial uncertainty to 3.3mm using deformable histology alignment&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="computational-pipeline">Computational Pipeline&lt;/h2>
&lt;h3 id="1-multi-modal-image-registration">1. Multi-modal Image Registration&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Data Integration&lt;/strong>: Co-registered PSMA PET/CT (5 scanners), mpMRI (2x Siemens 3T), and whole-mount histology&lt;/li>
&lt;li>&lt;strong>Key Steps&lt;/strong>:&lt;/li>
&lt;/ul>
&lt;pre tabindex="0">&lt;code class="language-Pseudo-code" data-lang="Pseudo-code">align_pet_ct() → rigid_registration(mpMRI) →
deformable_registration(ex_vivo_MRI) →
histology_annotation_propagation()
&lt;/code>&lt;/pre>&lt;ul>
&lt;li>&lt;strong>Challenges Solved&lt;/strong>:&lt;/li>
&lt;li>Bladder filling artifacts in PET&lt;/li>
&lt;li>Partial volume effects in 3.27mm PET slices&lt;/li>
&lt;li>Non-linear prostate deformation post-resection&lt;/li>
&lt;/ul>
&lt;h3 id="2-radiomic-feature-engineering">2. Radiomic Feature Engineering&lt;/h3>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Modality&lt;/th>
&lt;th>Features Extracted&lt;/th>
&lt;th>Key Parameters&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>PSMA PET&lt;/td>
&lt;td>3D LoG, LBP, GLCM textures&lt;/td>
&lt;td>SUVmax, metabolic tumor volume&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DCE MRI&lt;/td>
&lt;td>Ktrans, iAUGC60, TTP perfusion maps&lt;/td>
&lt;td>Pharmacokinetic modeling&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ADC Maps&lt;/td>
&lt;td>NGTDM coarseness, percentile values&lt;/td>
&lt;td>b=1200 s/mm² diffusion restriction&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;strong>Feature Selection&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>ANOVA filtering → Gini impurity ranking&lt;/li>
&lt;li>Final feature set: 50 most discriminative parameters&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="machine-learning-architecture">Machine Learning Architecture&lt;/h2>
&lt;h3 id="tumor-detection-model">Tumor Detection Model&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>Two-stage RFC Framework&lt;/strong>:&lt;/li>
&lt;/ul>
&lt;ol>
&lt;li>&lt;strong>Location Detection&lt;/strong>: 842 sensitivity/804 specificity&lt;/li>
&lt;li>&lt;strong>Grade Classification&lt;/strong>: Low vs High Grade (ISUP ≥3)&lt;/li>
&lt;/ol>
&lt;ul>
&lt;li>&lt;strong>Performance Comparison&lt;/strong>:&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Model&lt;/th>
&lt;th>AUC&lt;/th>
&lt;th>Sensitivity&lt;/th>
&lt;th>Specificity&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>PET Alone&lt;/td>
&lt;td>0.865&lt;/td>
&lt;td>0.781&lt;/td>
&lt;td>0.799&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>mpMRI Alone&lt;/td>
&lt;td>0.882&lt;/td>
&lt;td>0.802&lt;/td>
&lt;td>0.801&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Combined&lt;/strong>&lt;/td>
&lt;td>&lt;strong>0.890&lt;/strong>&lt;/td>
&lt;td>&lt;strong>0.842&lt;/strong>&lt;/td>
&lt;td>&lt;strong>0.804&lt;/strong>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;img src="roc.png" alt="Receptive fields" width="400">
&lt;p>&lt;em>Receiver operating characteristics for different models&lt;/em>&lt;/p>
&lt;h3 id="key-radiomic-predictors">Key Radiomic Predictors&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>PET&lt;/strong>: 3D LoG(σ=3mm) minimum&lt;/li>
&lt;li>&lt;strong>ADC&lt;/strong>: NGTDM Coarseness&lt;/li>
&lt;li>&lt;strong>DCE MRI&lt;/strong>: Ktrans 90th percentile&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="clinical-implications">Clinical Implications&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Personalized Radiotherapy&lt;/strong>: Enables voxel-level dose painting based on metabolic/perfusion features&lt;/li>
&lt;li>&lt;strong>Early Recurrence Prediction&lt;/strong>: High-grade lesions showed 2.8× higher PSMA uptake (p&amp;lt;0.01)&lt;/li>
&lt;li>&lt;strong>Technical Impact&lt;/strong>:&lt;/li>
&lt;li>Solved partial volume effects in PET-guided planning&lt;/li>
&lt;li>Demonstrated perfusion &amp;gt; diffusion for grade prediction&lt;/li>
&lt;li>Open-source registration framework [3D Slicer Plugin]&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="future-directions">Future Directions&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Multi-institutional validation&lt;/strong> across PET/MRI scanners&lt;/li>
&lt;li>&lt;strong>DL Enhancement&lt;/strong>: Replace handcrafted features with 3D CNNs&lt;/li>
&lt;li>&lt;strong>Real-time Adaptation&lt;/strong>: Integrate with MR-Linac systems&lt;/li>
&lt;/ul>
&lt;hr>
&lt;p>&lt;em>This project received funding from Prostate Cancer Foundation of Australia and Health Research Council of New Zealand.&lt;/em>&lt;/p></description></item><item><title>Why Normalizing Flows (and Tensorizing Flows) deserve more attention</title><link>https://mahyar-osn.github.io/post/tensorizing-flows/</link><pubDate>Fri, 04 Aug 2023 00:00:00 +0000</pubDate><guid>https://mahyar-osn.github.io/post/tensorizing-flows/</guid><description>&lt;p>Other generative models like diffusion models and autoregressive LLMs tend to steal the spotlight, since they&amp;rsquo;re great
at producing stunning images or generating text. Normalizing Flows, on the other hand, aren&amp;rsquo;t the first choice for
those headline-grabbing tasks. But if you focus only on sample quality, you might overlook what makes Normalizing Flows
truly valuable.&lt;/p>
&lt;h2 id="why-normalizing-flows-deserve-more-attention">Why Normalizing Flows Deserve More Attention&lt;/h2>
&lt;p>Most generative models are black boxes. GANs, for example, can create high-quality samples, but you can&amp;rsquo;t compute the
likelihood of a given data point. Energy-based models often only give you unnormalized densities, so you can compare
samples but not get an actual probability.&lt;/p>
&lt;p>Normalizing Flows are different. They let you map a simple base distribution (like a Gaussian) through a sequence of
invertible transformations to model complex data. The kicker? You always have access to the exact, normalized probability
density for any sample. This is a huge deal for applications where you need to know the likelihood, not just generate
data.&lt;/p>
&lt;h2 id="the-real-world-use-case-variational-inference">The Real-World Use Case: Variational Inference&lt;/h2>
&lt;p>One area where this property is crucial is Variational Inference (VI). Here, you want to approximate a complex target
distribution with a flexible, normalized family so you can do things like Bayesian inference efficiently.
NFs are a natural fit because you can both sample from them and compute exact densities—something most other models
can&amp;rsquo;t offer.&lt;/p>
&lt;h2 id="but-theres-a-catch">But There&amp;rsquo;s a Catch&amp;hellip;&lt;/h2>
&lt;p>Traditional NFs use a Gaussian as their base distribution. This works fine for unimodal targets, but if your true
distribution is multimodal (think: multiple peaks), NFs tend to &amp;ldquo;collapse&amp;rdquo; to just one mode. This limits their
expressiveness in VI, especially for challenging scientific or physics problems where multimodality is the norm.&lt;/p>
&lt;h2 id="enter-tensorizing-flows">Enter Tensorizing Flows&lt;/h2>
&lt;p>The paper &amp;ldquo;Tensorizing Flows: A Tool for Variational Inference&amp;rdquo; introduces a clever fix: replace the Gaussian base
with a tensor-train (TT) distribution, built using tools from tensor networks. This TT base can already capture much
of the structure (including multimodality) of the target distribution, so the flow only needs to handle the
&amp;ldquo;fine details.&amp;rdquo; The result is a model that&amp;rsquo;s both more expressive and easier to train for high-dimensional,
multimodal problems.&lt;/p>
&lt;h2 id="resources">Resources&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://arxiv.org/pdf/2305.02460" target="_blank" rel="noopener">Article&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/VincentStimper/normalizing-flows" target="_blank" rel="noopener">NormFlow&lt;/a>&lt;/li>
&lt;/ul></description></item></channel></rss>