A Spatial Hidden Markov Model (SHMM) is a statistical framework that partitions a tissue into discrete, unobserved functional regions by assuming that the measured gene expression at each spatial location is an emission generated by an underlying, hidden state. Unlike standard clustering, the model enforces a Markov property on the latent states, meaning the state assignment at one location is probabilistically dependent on the states of its immediate spatial neighbors, thereby penalizing erratic, non-contiguous domain assignments.
Glossary
Spatial Hidden Markov Model

What is a Spatial Hidden Markov Model?
A Spatial Hidden Markov Model (SHMM) is a probabilistic graphical model that infers unobserved spatial domains within tissue by modeling observed gene expression as emissions from a latent state sequence with explicitly encoded spatial dependencies.
Inference in an SHMM typically involves the Expectation-Maximization (EM) algorithm or variational methods to estimate transition probabilities between adjacent spatial coordinates and emission parameters for each hidden state. This architecture is particularly effective for spatial domain detection in tissues like the brain or tumor microenvironments, where it smooths technical noise while preserving sharp boundaries between biologically distinct anatomical or functional zones.
Key Features of Spatial HMMs
Spatial Hidden Markov Models (HMMs) extend classical HMMs by incorporating spatial dependencies between hidden states, enabling the identification of coherent tissue domains from noisy spatial transcriptomics data.
Hidden State Inference
The model assumes each spatial location (spot or cell) belongs to an unobserved discrete state representing a functional tissue domain. The observed gene expression vector at a location is treated as a multivariate emission conditioned on this hidden state. The goal is to infer the most probable sequence of hidden states across the entire tissue by balancing the likelihood of the observed expression data with the spatial coherence of the state assignments.
Markov Random Field Prior
Unlike temporal HMMs, spatial HMMs enforce state consistency through a Potts model or Markov Random Field (MRF) prior on the hidden states. This prior penalizes neighboring locations that are assigned to different states, encouraging spatially smooth domain boundaries. The strength of this penalty is controlled by an interaction parameter that determines how much weight is given to spatial coherence versus the gene expression likelihood.
Expectation-Maximization Training
Parameter estimation is typically performed via the Expectation-Maximization (EM) algorithm. In the E-step, the model computes the posterior probability of each hidden state at every location given the current parameter estimates. In the M-step, the emission distribution parameters and spatial interaction parameters are updated to maximize the expected complete-data log-likelihood. This iterative process converges to a local optimum that defines the spatial domains.
Gaussian Emission Distributions
The gene expression data for each hidden state is commonly modeled as a multivariate Gaussian distribution. This captures the mean expression profile and the gene-gene covariance structure within each domain. For count-based data, alternatives include Poisson or Negative Binomial emissions. The choice of emission distribution directly impacts the model's ability to accurately represent the technical noise characteristics of the spatial transcriptomics platform.
Spatial Domain Detection
The primary application is unsupervised tissue segmentation. By applying a spatial HMM to a spatial transcriptomics dataset, the inferred hidden states directly correspond to anatomically meaningful regions. This reveals functional tissue architecture without requiring prior histological annotations. The resulting domains can be visualized as a spatial map of state assignments, highlighting cortical layers in the brain, tumor microenvironments, or developmental zones.
Scalable Variational Approximation
Exact inference in spatial HMMs is computationally intractable due to the complex dependencies in the MRF prior. Practical implementations rely on variational Bayes or mean-field approximations to make inference scalable to datasets with tens of thousands of spatial locations. These methods decouple the dependencies by assuming a factorized posterior distribution, enabling efficient iterative updates that scale linearly with the number of spatial locations.
Frequently Asked Questions
Explore the core concepts behind Spatial Hidden Markov Models, a foundational probabilistic framework for identifying coherent tissue domains by modeling spatial dependencies in gene expression data.
A Spatial Hidden Markov Model (SHMM) is a probabilistic graphical model that infers unobserved spatial domains by assuming that the observed gene expression at each tissue location depends on a hidden state with explicit spatial dependencies. Unlike standard Hidden Markov Models that assume a linear chain, SHMMs operate on a spatial neighborhood graph where each node represents a cell or spot, and edges connect spatial neighbors. The model posits that the hidden state (e.g., a tissue region or cell type) at one location influences the states of its immediate neighbors through a Markov random field prior. The generative process involves two layers: a hidden layer of discrete spatial states that evolve according to a spatial Potts model, and an observed layer where gene expression counts are emitted from state-specific distributions, typically negative binomial or Gaussian. Inference is performed via Expectation-Maximization or variational Bayes to estimate the posterior probability of each location belonging to each hidden state, effectively segmenting the tissue into functionally coherent domains without requiring prior annotation.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Key computational concepts that extend or complement Spatial Hidden Markov Models for analyzing tissue architecture and gene expression patterns.
Spatial Domain Detection
The unsupervised identification of tissue regions with coherent gene expression profiles and histology. While Spatial HMMs infer domains through latent state transitions, other approaches use graph-based clustering or non-negative matrix factorization. The goal is partitioning a tissue into anatomically meaningful zones—such as cortical layers in the brain or tumor microenvironments—without prior annotation.
Spatial Autocorrelation
A statistical measure of the degree to which a variable's values at nearby locations are more similar than expected by random chance. This is the foundational assumption behind Spatial HMMs: that neighboring spots share hidden states. Key metrics include:
- Moran's I: Quantifies overall clustering of expression patterns
- Geary's C: More sensitive to local differences
- Spatial HMMs explicitly model this dependency through transition probabilities between adjacent locations
Spatial Neighborhood Graph
A data structure where each spatial location is a node, and edges connect neighboring locations based on a distance threshold or k-nearest neighbors. This graph serves as the structural backbone for Spatial HMMs, defining which locations can influence each other's hidden state transitions. Construction methods include:
- Delaunay triangulation on cell centroids
- Fixed-radius neighbor graphs for regular grids
- k-NN graphs with k typically set to 6-8 for 2D tissues
Spatial Deconvolution
A computational process that estimates the proportions of different cell types within each spatial transcriptomics spot by separating the mixed gene expression signal. While Spatial HMMs identify tissue domains, deconvolution reveals the cellular composition within those domains. Common methods include:
- Reference-based: Uses single-cell RNA-seq signatures to estimate proportions
- Reference-free: Blind source separation via NMF or Bayesian models
- Integration with HMM-derived domains enables spatial niche analysis
Spatial Trajectory Inference
A computational method that orders cells based on their spatial coordinates and gene expression profiles to reconstruct dynamic biological processes in situ. Unlike Spatial HMMs which partition space into discrete domains, trajectory inference models continuous gradients of change. Applications include:
- Mapping developmental lineages within embryos
- Reconstructing tumor invasion fronts
- Identifying differentiation gradients in adult tissues
- Often combined with RNA velocity for directional information
Spatial Registration
The computational alignment of multiple tissue images or spatial datasets into a common coordinate system to enable integrative cross-modality analysis. Spatial HMMs applied to registered data can identify domains conserved across:
- Serial tissue sections from the same sample
- Multi-modal data (e.g., transcriptomics + proteomics)
- Biological replicates for robust domain calling
- Atlas-level integration against reference tissue maps
Key techniques include landmark-based, intensity-based, and deep learning approaches.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us