---
title: 'GeneFlow: Discrete Eulerian and Rectified-Flow Models'
url: https://www.emergentmind.com/topics/geneflow
type: topic
---

# GeneFlow: Discrete Eulerian and Rectified-Flow Models

GeneFlow is a name used in two distinct arXiv contexts. In population genetics and fluid dynamics, it denotes a discrete Eulerian algorithm for stochastic competition, diffusion, and advection on a lattice, introduced in “Discrete Eulerian model for population genetics and dynamics under flow,” where the focus is weakly compressible flow, FKPP-type dynamics, and fixation under sources and sinks [1907.09377]. In spatial transcriptomics and computational pathology, GeneFlow denotes a framework that maps single-cell gene expression to paired histopathological images via rectified flow, combining an attention-based RNA encoder, a conditional U-Net, and high-order ODE integration to generate \(256\times256\) cellular image tiles with modalities such as H\&E and DAPI [2511.00119].

## 1. Terminological scope and disambiguation

A common source of confusion is terminological rather than methodological: the same name refers to unrelated research programs in different domains. One concerns stochastic population genetics under advection, logistic competition, and demographic noise; the other concerns conditional generative modeling from transcriptomics to imaging phenotypes. A plausible implication is that use of the name alone is insufficient for identification, and the arXiv id is the decisive disambiguator [1907.09377] [2511.00119].

| Usage of “GeneFlow” | Domain | Core object |
|---|---|---|
| Discrete Eulerian model | Population genetics under flow | Lattice algorithm for \(p_A\), \(p_B\), fixation, and advection |
| Rectified-flow framework | Spatial transcriptomics and histopathology | Mapping from gene-expression matrices to image tiles |

The population-genetic usage is organized around continuum PDEs and a mesh-based stochastic simulation procedure. The histopathology usage is organized around representation learning for RNA, conditional image generation, and deterministic transport in latent-image space. The shared name therefore does not indicate a shared formalism.

## 2. Continuum formulation in population genetics under flow

In the fluid-mechanical setting, GeneFlow considers two competing genotypes, \(A\) and \(B\), with local densities \(p_A(x,t)\) and \(p_B(x,t)\) in a \(d\)-dimensional domain. Both are advected by a prescribed velocity field \(v(x,t)\), diffuse, reproduce and die with logistic competition, and experience a selective advantage \(s\) for \(A\). In the nondimensional form that measures time in units of the birth rate \(\mu^{-1}\) and space in units of \(\sqrt{D/\mu}\), the governing equations are [1907.09377]:
$$
\partial_t p_A + \nabla\cdot(v\,p_A)
= D\,\nabla^2 p_A + \mu\,p_A(1-p_A-p_B) + s\,\mu\,p_Ap_B
+ \sqrt{\frac{2\mu\,p_A(1-p_A-p_B)}{N_0}}\,\eta_A(x,t),
$$
$$
\partial_t p_B + \nabla\cdot(v\,p_B)
= D\,\nabla^2 p_B + \mu\,p_B(1-p_A-p_B) - s\,\mu\,p_Ap_B
+ \sqrt{\frac{2\mu\,p_B(1-p_A-p_B)}{N_0}}\,\eta_B(x,t).
$$

Here \(v(x,t)\) is the prescribed advecting field, \(D\) is the diffusion coefficient, \(\mu\) is the intrinsic birth rate, \(s\) is the selective advantage of \(A\), \(N_0\) is the carrying-capacity per mesh cell, and \(\eta_{A,B}(x,t)\) are independent space-time white noises with \(\langle \eta(x,t)\eta(x',t')\rangle=\delta(x-x')\delta(t-t')\). Under the assumption \(p_A+p_B\approx 1\), it is convenient to work with the fraction \(f(x,t)=p_A/(p_A+p_B)\), which yields the stochastic FKPP equation under advection:
$$
\partial_t f + v\cdot\nabla f
= D\,\nabla^2 f + s\,f(1-f)
+ \sqrt{\frac{2f(1-f)}{N_0}}\,\eta(x,t).
$$

Within this reduced equation, \(v\cdot\nabla f\) advects allele frequency, \(D\nabla^2 f\) smooths spatial heterogeneity, \(s\,f(1-f)\) captures selection, and the square-root noise term represents genetic drift. This formulation is the analytical backbone of the method and of its interpretation under weak compressibility.

## 3. Eulerian discretization, stochastic update scheme, and no-flow validation

The computational contribution in the population-genetic work is a fixed-grid algorithm with \(O(1)\) per-cell cost even for large \(N_0\). The domain is discretized into \(n_1\times\cdots\times n_d\) cells of volume \((\Delta x)^d\), and each cell \(j\) stores two integers, \(N_j^A\) and \(N_j^B\). Each time step \(t\to t+\Delta t\) is split into four sub-steps for \(\beta\in\{A,B\}\) [1907.09377].

- **Step 1 (Diffusion):** each of the \(N_j^\beta\) individuals in cell \(j\) is assigned a random subcell position \(x_a\) within a slightly enlarged box of size \((1+2p)\Delta x\) centered on \(j\), with \(p=D\Delta t/(\Delta x)^2\ll 1\). This is equivalent to a nearest-neighbor random hopping operator that converges to \(D\nabla^2\) in the limit \(p\to 0\).

- **Step 2 (Advection):** each virtual particle is moved by \(x_a\leftarrow x_a+v(x_a,t)\Delta t\).

- **Step 3 (Relabeling):** each advected particle is re-binned to its new cell index \(j'=\lfloor x_a/\Delta x\rfloor\), producing temporary counts \(\tilde N_{j'}^\beta\).

- **Step 4 (Birth–Death / Competition):** in each cell \(j\), stochastic birth and death are applied a total of \(\tilde N_j^\beta\) times, with birth rate \(r_b(\beta)=\mu\Delta t\) and death rate \(r_d(\beta)=\mu\Delta t[(\tilde N_j^\beta-1+\tilde N_j^{\mathrm{other}}(1\mp s))/N_0]\), where the minus sign is for \(A\) and the plus sign for \(B\). Births and deaths can be sampled using binomial or Poisson variates.

Validation without flow proceeds by setting \(v\equiv 0\), reducing the method to a stochastic reaction-diffusion algorithm. Three tests are reported. First, for the 1D Fisher equation \(\partial_t c = D\,\partial_{xx}c + \mu c(1-c)\), the measured front speed \(v(N_0)\) for \(\mu=10\) and \(D=10^{-3}\) exhibits a cross-over between strong-drift scaling \(v\sim D\mu N_0\) at low \(N_0\) and Brunet–Derrida cutoff behavior
$$
v \simeq 2\sqrt{D\mu}\left[1-\frac{\pi^2}{2\ln^2N_0}\right]
$$
at large \(N_0\). Second, heterozygosity decay \(H(t)=\langle f(x)[1-f(x)]\rangle\) follows \(H(t)\sim t^{-1/2}\) in 1D, with simulations at \(N_0=50\) following this power law, and \(H(t)\sim 1/\ln t\) in 2D, with simulations at \(N_0=20\) on a \(256^2\) grid producing \(1/H(t)\sim \ln t\). Third, for an initial fraction \(f_0\) of type \(A\) in total population \(N=N_0\times(\#\text{cells})\), the well-mixed Kimura formula
$$
P_{\mathrm{fix}}(s)=\frac{1-e^{-sNf_0}}{1-e^{-sN}}
$$
is recovered in 1D and 2D for \(s\) up to \(O(0.1)\).

## 4. Weakly compressible flows, source–sink structure, and fixation in marine contexts

The extension to weakly compressible flow is motivated by organisms such as phytoplankton living at a specific depth in the three-dimensional, incompressible ocean while experiencing upwelling and downwelling events. In 1D, the toy flow is
$$
u(x)=u_0\sin(x-\pi/2),
$$
for which \(\nabla\cdot u=u_0\cos(x-\pi/2)\) alternates sources and sinks. In 2D, the generalization is
$$
u_x=u_0\sin(x-\pi/2)\sin y,\qquad
u_y=-u_0\sin(x-\pi/2)\cos y,
$$
with two sources and two sinks per period. In the weak-compressibility regime, \(u_0\ll \sqrt{D\mu}\), the approximation \(p_A+p_B\approx 1\) is still used, and the effective compressibility parameter is \(\kappa\sim u_0/\sqrt{D\mu}\ll 1\) [1907.09377].

A new length scale emerges near each source,
$$
l_s=\sqrt{D/u_0},
$$
beyond which an organism is swept away into a sink and is unlikely to return. In this regime, the fixation probability for \(s\to 0\) remains Kimura-like but with an effective population size determined by the source region:
$$
N_{\mathrm{eff}}\simeq B_1\rho_0 l_s
= B_1\left(\frac{N_0}{\Delta x^d}\right)\sqrt{D/u_0},
$$
where \(\rho_0=N_0/\Delta x^d\) and \(B_1\) is an \(O(1)\) constant fixed by fitting, with \(B_1\approx 3\)–\(4\). For small \(s\),
$$
P_{\mathrm{fix}}(s)\simeq
\frac{1-e^{-sN_{\mathrm{eff}}f_0}}{1-e^{-sN_{\mathrm{eff}}}}.
$$

For larger \(s\), the limiting factor becomes the ability of a growing \(A\)-cluster to escape the source before advection removes it. Balancing advection with the Fisher-wave speed \(2\sqrt{D\mu s}\) defines
$$
u_0\delta \sim 2\sqrt{D\mu s}
\quad\Rightarrow\quad
\delta(s)\simeq \frac{2\sqrt{D\mu s}}{u_0},
$$
and hence a second effective population scale:
$$
\text{1D:}\quad N_g\simeq 2\,\delta(s)\,\rho_0,
\qquad
\text{2D:}\quad N_g\simeq 4\,\delta(s)^2\,\rho_0
=4\left[\frac{2\sqrt{D\mu s}}{u_0}\right]^2\rho_0.
$$
For larger \(s\), the fixation curve is fitted by replacing \(N\) with \(N_g\). Simulations on \(64\times64\) grids with \(u_0=0.05\), \(D=10^{-2}\), and \(N_0=2\)–\(10\) confirm that for \(sN_{\mathrm{eff}}\lesssim 1\), data collapse onto the small-\(s\) Kimura curve with \(N_{\mathrm{eff}}\), while for \(sN_g\gtrsim 1\), the large-\(s\) curve with \(N\to N_g\) captures the turnover.

The biological interpretation stated for marine settings is that upwelling sources act as evolutionary “hot spots,” whereas downwelling sinks are demographic “sieves” that purge diversity. The net effect of weak compressibility is therefore to reduce the effective population to organisms born within \(l_s\) of a source, amplifying genetic drift and reducing the role of selection in the bulk.

## 5. Transcriptome-to-image GeneFlow: RNA encoder, conditional U-Net, and rectified flow

In the spatial-transcriptomic setting, GeneFlow starts from a paired dataset \(\mathcal D=\{(X_i,I_i)\}_{i=1}^N\), where \(X_i\in\mathbb R^{C_i\times G}\) is a gene-expression matrix with up to \(C_{\max}\) cells and \(G\) genes, and \(I_i\in\mathbb R^{H\times W\times K}\) is the corresponding \(256\times256\) histology tile. The pipeline first compresses \(X_i\) into a latent vector \(z\in\mathbb R^D\), then combines \(z\) with a sinusoidal time embedding \(\gamma(t)\in\mathbb R^{4d}\) to condition a U-Net, which serves as the backbone of a rectified-flow image generator [2511.00119].

The attention-based RNA encoder contains three modules: low-rank gene relations, gene attention, and multi-head cell attention. For each flattened cell expression \(x_i\in\mathbb R^G\), two factors \(U_i\in\mathbb R^{G\times K}\) and \(V_i\in\mathbb R^{K\times G}\) are predicted via a small MLP, and the enriched representation is
$$
\tilde x_i=x_i+\alpha(x_iU_iV_i),\qquad \alpha=0.1,
$$
which introduces learned gene-gene interactions at rank \(K\ll G\). Global gene attention then applies learnable scores \(a\in\mathbb R^G\):
$$
x'_i=\tilde x_i\odot \mathrm{softmax}(a).
$$
Each \(x'_i\) is passed through two residual blocks to produce a 256-dimensional cell embedding \(h_i\), and multi-head cell attention aggregates the cell-level information. For head \(h\), one computes \(P_i^{(h)}=W^{(h)}e_i\in\mathbb R^D\), obtains logits \(a_i^{(h)}\), applies a mask \(m_i\in\{0,1\}\) for real cells, and forms
$$
\alpha_i^{(h)}=
\frac{\exp(a_i^{(h)})\,m_i}{\sum_{j=1}^C \exp(a_j^{(h)})\,m_j},
\qquad
z^{(h)}=\sum_{i=1}^C \alpha_i^{(h)}P_i^{(h)},
$$
followed by \(z_{\mathrm{agg}}=\frac{1}{H}\sum_{h=1}^H z^{(h)}\) and a gating layer yielding the RNA code \(z\in\mathbb R^D\).

The image generator is a conditional U-Net with skip connections, where every ResBlock is jointly conditioned on \(\gamma(t)\) and \(z\). Rectified flow is defined by the deterministic ODE
$$
\frac{dx(t)}{dt}=v_\theta\bigl(x(t),t,z\bigr),\qquad t\in[0,1],
$$
which transports Gaussian noise \(x(0)\sim\mathcal N(0,I)\) to \(x(1)\approx I\). During training, the method introduces the reference path
$$
x(t)=\sin\!\Bigl(\frac{\pi}{2}t\Bigr)x_1+
\Bigl[1-\sin\!\Bigl(\frac{\pi}{2}t\Bigr)\Bigr]x_0+\epsilon_t,
\qquad
\epsilon_t=(1-t)\sigma z,
$$
with target velocity
$$
v^*(x(t),t)=\frac{d}{dt}x(t)
=(x_1-x_0)\frac{\pi}{2}\cos\!\Bigl(\frac{\pi}{2}t\Bigr)
-\frac{d\epsilon_t}{dt}.
$$
The paper states that rectified flow with high-order ODE solvers creates a continuous, bijective mapping between transcriptomics and image manifolds, addressing the many-to-one relationship inherent in the problem.

## 6. Training objectives, evaluation regime, and reported implications in histopathology

The primary training criterion in the image-generation GeneFlow is the velocity-matching mean-squared error
$$
\mathcal L_{\mathrm{RF}}
=\mathbb E_{x_1,t,x_0}
\bigl\|v_\theta(x(t),t)-v^*(x(t),t)\bigr\|_2^2
+\lambda\|W_1\|_1,
$$
with \(\lambda=10^{-3}\) as a sparsity regularizer on the first encoder layer. An optional spatial regularization term gives
$$
\mathcal L_{\mathrm{total}}
=\mathcal L_{\mathrm{RF}}
+\lambda_s\,w(\mathrm{epoch})\,\mathcal L_{\mathrm{spatial}},
$$
where \(w(\cdot)\) is a warm-up schedule. Two variants of \(\mathcal L_{\mathrm{spatial}}\) are specified: a segmentation-based variant using nuclear morphology, neighbor distances, and density, and a gradient-based variant using Sobel gradients and local patch statistics. No adversarial or GAN loss is used. Inference integrates the ODE using a 5th-order Dormand–Prince (Runge–Kutta) method with adaptive step size, while the abstract also describes inference as solving the ODE with a 5th-order Runge–Kutta integrator [2511.00119].

The reported datasets are Xenium\(_{C1}\), Xenium\(_{C2}\), Xenium\(_{P1}\), and HEST-1k. Xenium\(_{C1}\) and Xenium\(_{C2}\) are 10× Genomics Xenium human skin panels with approximately 300 genes, Xenium\(_{P1}\) is a Xenium Prime panel with \(5\text{k}\) genes, and HEST-1k contains 59 human samples from 12 organs and 1.6M paired patches. Modalities include H\&E \((40\times)\) with or without DAPI/18S, and the preprocessing uses \(256\times256\) crops centered on cell centroids, log-normalization, and QC that removes the bottom \(5\%\) low-count cells. The metrics are FID, SSIM, and feature distance in Inception/v2 latent space.

| Setting | Method | Reported values |
|---|---|---|
| Single-cell, Xenium\(_{C1}\) | Rectified flow | FID \(=20.73\), SSIM \(=0.24\) |
| Single-cell, Xenium\(_{C1}\) | Diffusion-baseline | FID \(\approx 171.1\), SSIM \(=0.22\) |
| Cross-dataset transfer, \(C1\to P1\) | Single-cell | FID \(=67.00\), SSIM \(=0.20\) |

Human evaluation involved three board-certified pathologists, who rated similarity to ground truth with median \(\ge 6/10\) and preferred rectified flow versus diffusion in \(86\%\) of pairwise comparisons. Qualitatively, the generated H\&E and DAPI images are reported to faithfully reproduce nuclear shape, nucleoli, cell-cell juxtapositions, and melanoma-specific phenotypes. The method is also described as outperforming a diffusion-based baseline in all experiments.

The stated implications are biological and practical. By generating morphology from transcriptomes, the framework enables in silico exploration of how a cell would look if its gene expression were altered. Conditioning on multi-cell patches permits probing intercellular interactions. In cancer, the framework is proposed as a way to reveal dysregulated imaging patterns such as EMT features and nuclear pleomorphism associated with oncogenic pathways. Potential applications listed in the paper include minimally invasive transcriptome-guided biopsy imaging, augmentation of training data for AI-based histopathology, and virtual perturbation studies.

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