WHY MATHEMATICS?
Why Mathematics? | SEDR for Spatial Embeddings: Masked Autoencoders, Variational Graph Learning, KL Divergence and Deep Clustering
How SEDR compresses gene expression, reconstructs deliberately masked spots and uses a variational graph autoencoder to learn spatial embeddings for clustering, denoising and imputation.
Why mathematics is important becomes easier to see when a real decision depends on it. This guide follows the mechanism from definitions and dimensions to a worked calculation, validation, practical learning and responsible use. It keeps factual evidence separate from interpretation and treats every illustrative scenario as an example rather than a promise of results.
Choose a reading route
- Create a masked self-supervised reconstruction task
- Encode the spatial neighbourhood graph with a variational autoencoder
- Balance reconstruction evidence and KL regularization
- Cluster joint embeddings while testing seed and graph stability
Chapter map
- 1. Input expression X
- 2. Deep encoder
- 3. Decoder reconstruction
- 4. Random spot mask
- 5. Masked self-supervised loss
- 6. Spatial adjacency
- 7. Graph convolution encoder
- 8. Posterior mean
- 9. Posterior log variance
- 10. Reparameterization trick
- 11. Graph decoder
- 12. KL regularizer
- 13. Joint embedding
- 14. Iterative deep clustering
- 15. Worked six-node example
- 16. Governance and learning
Visit the How Mathematics Works hub for the wider series and its connections to education, reasoning, science, computing, design and careers.
1. Input expression X
This is where modelling choices begin to affect evidence. Each node has an m-gene vector after declared normalization and selection.
A concrete situation
Two thousand spots each contain 2,500 selected genes.
What the mathematics does not license
Transformations affect reconstruction loss. That distinction matters because a correct formula can still answer the wrong operational question.
Try it, check it, transfer it
Version every preprocessing step. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
2. Deep encoder
The central mathematical idea is concrete. Several nonlinear layers compress high-dimensional expression into a smaller latent vector.
A concrete situation
A 2,500-gene vector becomes 64 numbers.
What the mathematics does not license
Compression can discard rare programs. The habit of checking assumptions is one of the practical benefits of learning mathematics.
Try it, check it, transfer it
Check reconstruction by gene class. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
3. Decoder reconstruction
Here the geometry becomes operational. A decoder maps the latent vector back toward the original expression dimension.
A concrete situation
The network predicts the 2,500-gene profile.
What the mathematics does not license
Low average error may hide rare-gene failure. The same reasoning helps students move from an exercise to a real dataset.
Try it, check it, transfer it
Stratify errors. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
4. Random spot mask
This step deserves a careful pause. A sampled subset of spots has its expression replaced by a learned mask vector.
A concrete situation
Fifteen per cent of spots are hidden in one epoch.
What the mathematics does not license
Mask rate changes difficulty. That distinction matters because a correct formula can still answer the wrong operational question.
Try it, check it, transfer it
Run a mask-rate grid. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
Did You Know? In this chapter, the most important number is useful only together with its construction rule. Changing scaling, sample membership or validation design can change the numerical answer without changing the arithmetic.
5. Masked self-supervised loss
The useful question is not only how to calculate, but what the calculation assumes. Reconstruction error on hidden and visible examples teaches context-aware features without labels.
A concrete situation
A masked cortical spot is reconstructed from learned structure.
What the mathematics does not license
Neighbour leakage can make tests too easy. The habit of checking assumptions is one of the practical benefits of learning mathematics.
Try it, check it, transfer it
Hold out complete regions. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
6. Spatial adjacency
A small example makes the mechanism visible. Coordinates define a binary or weighted graph connecting nearby spots.
A concrete situation
Each interior Visium node connects to six neighbours.
What the mathematics does not license
A radius can bridge a tissue gap. The same reasoning helps students move from an exercise to a real dataset.
Try it, check it, transfer it
Overlay edges. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
7. Graph convolution encoder
This is where modelling choices begin to affect evidence. Node features aggregate along adjacency to produce spatially informed hidden states.
A concrete situation
A boundary node combines its own code with nearby codes.
What the mathematics does not license
Repeated aggregation over-smooths. That distinction matters because a correct formula can still answer the wrong operational question.
Try it, check it, transfer it
Compare layer depth. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
8. Posterior mean
The central mathematical idea is concrete. One graph network outputs the centre of each node latent distribution.
A concrete situation
Node i has a 10-dimensional mean vector.
What the mathematics does not license
A mean alone hides uncertainty. The habit of checking assumptions is one of the practical benefits of learning mathematics.
Try it, check it, transfer it
Keep variance outputs. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
Did You Know? In this chapter, the most important number is useful only together with its construction rule. Changing scaling, sample membership or validation design can change the numerical answer without changing the arithmetic.
9. Posterior log variance
Here the geometry becomes operational. A second output controls uncertainty in every latent dimension.
A concrete situation
Sparse context produces a larger variance.
What the mathematics does not license
Neural variance need not be calibrated. The same reasoning helps students move from an exercise to a real dataset.
Try it, check it, transfer it
Use coverage tests. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
10. Reparameterization trick
This step deserves a careful pause. z equals mean plus standard deviation times normal noise, allowing gradients through sampling.
A concrete situation
One epsilon draw produces a differentiable latent sample.
What the mathematics does not license
Monte Carlo noise affects training. That distinction matters because a correct formula can still answer the wrong operational question.
Try it, check it, transfer it
Set and vary seeds. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
11. Graph decoder
The useful question is not only how to calculate, but what the calculation assumes. Latent inner products or another decoder reconstruct the probability of graph edges.
A concrete situation
Nearby compatible nodes receive a high link probability.
What the mathematics does not license
Reconstructing input adjacency can repeat a bad graph. The habit of checking assumptions is one of the practical benefits of learning mathematics.
Try it, check it, transfer it
Challenge graph construction. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
12. KL regularizer
A small example makes the mechanism visible. The approximate posterior is compared with a standard normal prior.
A concrete situation
Large means and tiny variances pay a larger KL cost.
What the mathematics does not license
Too much KL can collapse information. The same reasoning helps students move from an exercise to a real dataset.
Try it, check it, transfer it
Plot loss components. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
Did You Know? In this chapter, the most important number is useful only together with its construction rule. Changing scaling, sample membership or validation design can change the numerical answer without changing the arithmetic.
13. Joint embedding
This is where modelling choices begin to affect evidence. Expression and spatial latent representations are concatenated or combined for downstream analysis.
A concrete situation
A 64-dimensional expression code joins a 10-dimensional graph code.
What the mathematics does not license
Scale imbalance lets one view dominate. That distinction matters because a correct formula can still answer the wrong operational question.
Try it, check it, transfer it
Standardize and ablate. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
14. Iterative deep clustering
The central mathematical idea is concrete. Embeddings and cluster assignments are refined together using pseudo-label structure.
A concrete situation
Centres move as confident nodes tighten their groups.
What the mathematics does not license
Pseudo-labels can reinforce errors. The habit of checking assumptions is one of the practical benefits of learning mathematics.
Try it, check it, transfer it
Repeat starts and compare stability. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
15. Worked six-node example
Here the geometry becomes operational. Mask one profile, calculate one normalized graph update and one KL term.
A concrete situation
The hidden node borrows from two neighbours while retaining uncertainty.
What the mathematics does not license
A toy graph is perfectly registered. The same reasoning helps students move from an exercise to a real dataset.
Try it, check it, transfer it
Add a false edge. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
16. Governance and learning
This step deserves a careful pause. Version masks, graph, architecture, loss weights, seeds and clustering.
A concrete situation
A student separates reconstruction, prior and graph evidence.
What the mathematics does not license
A latent cluster is not anatomy by itself. That distinction matters because a correct formula can still answer the wrong operational question.
Try it, check it, transfer it
Write an embedding model card. Then explain the result to someone who has not seen the formula. If the explanation needs a hidden assumption, add that assumption to the model record.
Did You Know? In this chapter, the most important number is useful only together with its construction rule. Changing scaling, sample membership or validation design can change the numerical answer without changing the arithmetic.
A seven-day practice lab
- Day 1: define the decision, observation unit, X variables and Y or reference condition.
- Day 2: reproduce the smallest worked example and check every dimension, unit and sign.
- Day 3: build a transparent baseline and write what it assumes.
- Day 4: fit the main method inside a training-only pipeline; record every parameter.
- Day 5: challenge one assumption with a deliberately difficult dataset or operating regime.
- Day 6: compare validation metrics with the practical workload created by errors.
- Day 7: present one supported conclusion, one unresolved uncertainty and one safe next experiment.
Questions for a student, parent or mentor
- Which part of the model is a mathematical definition, and which part is a choice?
- What small calculation would catch a sign, scale or dimension error?
- What evidence comes from training, validation and the untouched test?
- What benign condition could look like a fault or prediction failure?
- How would the answer change for another response, asset, school project or time period?
- What should a human review before acting on the score?
A method-specific audit before deployment
SEDR learns two connected representations. A deep autoencoder compresses gene expression, while masked self-supervision asks the network to reconstruct deliberately hidden spot profiles. A variational graph autoencoder uses the spatial adjacency graph to learn a probability distribution over spatial embeddings. The two representations are joined before deep clustering.
This design brings together linear algebra, neural networks, probability and graph theory. Reconstruction loss preserves expression information; the mask creates a prediction task without manual labels; graph convolution aggregates neighbours; Kullback–Leibler divergence regularises the variational posterior; and iterative clustering alternates between embeddings and pseudo-labels.
Validation should hide spots and genes before tuning, vary graph construction and masking rates, run several random seeds and compare with PCA, ordinary autoencoders and spatial baselines. A clean latent map is not proof of a biological compartment. Denoised or imputed values are conditional predictions and should be compared with measured holdouts and independent tissue evidence.
Frequently asked questions
What is SEDR?
SEDR is an unsupervised deep-learning method that combines a masked gene-expression autoencoder with a variational graph autoencoder to produce a low-dimensional spatial embedding.
Why mask spots during training?
Deliberately replacing selected spot profiles with a learnable mask creates a self-supervised task: the model must infer the hidden profile from learned expression structure and graph context.
What is a variational graph autoencoder?
It encodes each graph node as a probability distribution with a mean and variance, samples a latent vector by reparameterization and reconstructs graph relationships while regularizing the posterior.
Why use KL divergence?
KL divergence penalizes departure of the approximate latent posterior from a simple prior, encouraging a smoother and reusable probability space.
How are spatial domains formed?
A deep clustering module iteratively updates embeddings and pseudo-labels or cluster centres, after which conventional clustering and biological interpretation are applied.
Are imputed genes measured values?
No. They are model reconstructions based on the training data, masks and graph. They require measured holdouts and external validation.
Primary source and fact-check note
Hang Xu, Yahui Long, Kok Siong Ang et al., “Unsupervised spatially embedded deep representation of spatial transcriptomics,” Genome Medicine 16, 12 (2024), DOI 10.1186/s13073-024-01283-x. Definitions and core claims in this article were checked against this primary publication. Calculations shown here were independently recomputed. Examples are educational illustrations; they are not reported industrial performance results.
Useful next reading
Keep the options open. Mathematics education supports clearer questions, transferable problem-solving skills and informed choices across science, engineering, computing, AI, statistics, design and many other careers. It does not guarantee intelligence, income, admission or employment; those outcomes depend on far more than one subject or model.
Extended laboratory: topic-specific validation and responsible use
Mask audit
Freeze held-out spots, genes and regions.
Graph audit
Compare radius, k and false-edge challenges.
Loss audit
Plot reconstruction, graph and KL terms.
Posterior audit
Check latent variance and coverage.
Did You Know? A sophisticated adjustment can be algebraically correct and still answer the wrong scientific question when samples, labels, batches or validation boundaries are wrong.
Seed audit
Repeat network initialization and clustering.
Ablation audit
Remove masking or graph components.
Imputation audit
Compare against untouched measurements.
Final claim
A denoised map is a conditional prediction.
Did You Know? A sophisticated adjustment can be algebraically correct and still answer the wrong scientific question when samples, labels, batches or validation boundaries are wrong.
Mechanism workshop: calculate, challenge and transfer
Workshop 1: Input expression X
Begin with this mechanism: Each node has an m-gene vector after declared normalization and selection. Work through the concrete case: Two thousand spots each contain 2,500 selected genes. Make the limitation visible: Transformations affect reconstruction loss. Complete the evidence step: Version every preprocessing step. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 2: Deep encoder
Begin with this mechanism: Several nonlinear layers compress high-dimensional expression into a smaller latent vector. Work through the concrete case: A 2,500-gene vector becomes 64 numbers. Make the limitation visible: Compression can discard rare programs. Complete the evidence step: Check reconstruction by gene class. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 3: Decoder reconstruction
Begin with this mechanism: A decoder maps the latent vector back toward the original expression dimension. Work through the concrete case: The network predicts the 2,500-gene profile. Make the limitation visible: Low average error may hide rare-gene failure. Complete the evidence step: Stratify errors. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 4: Random spot mask
Begin with this mechanism: A sampled subset of spots has its expression replaced by a learned mask vector. Work through the concrete case: Fifteen per cent of spots are hidden in one epoch. Make the limitation visible: Mask rate changes difficulty. Complete the evidence step: Run a mask-rate grid. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Did You Know? A sophisticated adjustment can be algebraically correct and still answer the wrong scientific question when samples, labels, batches or validation boundaries are wrong.
Workshop 5: Masked self-supervised loss
Begin with this mechanism: Reconstruction error on hidden and visible examples teaches context-aware features without labels. Work through the concrete case: A masked cortical spot is reconstructed from learned structure. Make the limitation visible: Neighbour leakage can make tests too easy. Complete the evidence step: Hold out complete regions. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 6: Spatial adjacency
Begin with this mechanism: Coordinates define a binary or weighted graph connecting nearby spots. Work through the concrete case: Each interior Visium node connects to six neighbours. Make the limitation visible: A radius can bridge a tissue gap. Complete the evidence step: Overlay edges. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 7: Graph convolution encoder
Begin with this mechanism: Node features aggregate along adjacency to produce spatially informed hidden states. Work through the concrete case: A boundary node combines its own code with nearby codes. Make the limitation visible: Repeated aggregation over-smooths. Complete the evidence step: Compare layer depth. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 8: Posterior mean
Begin with this mechanism: One graph network outputs the centre of each node latent distribution. Work through the concrete case: Node i has a 10-dimensional mean vector. Make the limitation visible: A mean alone hides uncertainty. Complete the evidence step: Keep variance outputs. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Did You Know? A sophisticated adjustment can be algebraically correct and still answer the wrong scientific question when samples, labels, batches or validation boundaries are wrong.
Workshop 9: Posterior log variance
Begin with this mechanism: A second output controls uncertainty in every latent dimension. Work through the concrete case: Sparse context produces a larger variance. Make the limitation visible: Neural variance need not be calibrated. Complete the evidence step: Use coverage tests. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 10: Reparameterization trick
Begin with this mechanism: z equals mean plus standard deviation times normal noise, allowing gradients through sampling. Work through the concrete case: One epsilon draw produces a differentiable latent sample. Make the limitation visible: Monte Carlo noise affects training. Complete the evidence step: Set and vary seeds. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 11: Graph decoder
Begin with this mechanism: Latent inner products or another decoder reconstruct the probability of graph edges. Work through the concrete case: Nearby compatible nodes receive a high link probability. Make the limitation visible: Reconstructing input adjacency can repeat a bad graph. Complete the evidence step: Challenge graph construction. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 12: KL regularizer
Begin with this mechanism: The approximate posterior is compared with a standard normal prior. Work through the concrete case: Large means and tiny variances pay a larger KL cost. Make the limitation visible: Too much KL can collapse information. Complete the evidence step: Plot loss components. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Did You Know? A sophisticated adjustment can be algebraically correct and still answer the wrong scientific question when samples, labels, batches or validation boundaries are wrong.
Workshop 13: Joint embedding
Begin with this mechanism: Expression and spatial latent representations are concatenated or combined for downstream analysis. Work through the concrete case: A 64-dimensional expression code joins a 10-dimensional graph code. Make the limitation visible: Scale imbalance lets one view dominate. Complete the evidence step: Standardize and ablate. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 14: Iterative deep clustering
Begin with this mechanism: Embeddings and cluster assignments are refined together using pseudo-label structure. Work through the concrete case: Centres move as confident nodes tighten their groups. Make the limitation visible: Pseudo-labels can reinforce errors. Complete the evidence step: Repeat starts and compare stability. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 15: Worked six-node example
Begin with this mechanism: Mask one profile, calculate one normalized graph update and one KL term. Work through the concrete case: The hidden node borrows from two neighbours while retaining uncertainty. Make the limitation visible: A toy graph is perfectly registered. Complete the evidence step: Add a false edge. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.
Workshop 16: Governance and learning
Begin with this mechanism: Version masks, graph, architecture, loss weights, seeds and clustering. Work through the concrete case: A student separates reconstruction, prior and graph evidence. Make the limitation visible: A latent cluster is not anatomy by itself. Complete the evidence step: Write an embedding model card. Write the matrices, graph, similarity, probability distribution, loss term or permutation rule with named dimensions and units. Calculate one small example by hand, then change one assumption and explain which output moves and why. Use complete donors, tissue sections, spatial regions, image batches or gene sets outside tuning when testing transfer. Keep measurement, fitted representation, statistical evidence, biological interpretation and decision on separate notebook lines so a student, parent or reviewer can audit the mathematics.