A Significance Test for Distance Bias in Protein-Design VAEs

When biologists use a variational autoencoder — a generative model that compresses data into a small set of continuous latent coordinates and decodes samples back from them — to design new proteins, they face a ranking problem. The model assigns each candidate sequence a likelihood, and the lab synthesizes the sequences that score highest. But these scores carry a documented distortion: as a candidate gets more mutations away from the natural sequences the model was trained on, its likelihood sinks even when the protein would actually fold and function. The result is that a generative model trained to explore sequence space quietly refuses to leave the neighborhood it knows. Today, this "similarity bias" is either ignored, or patched with a heuristic percentile correction. Nobody can say, with controlled error rates, whether a given model's scores are statistically significantly biased across distances, or whether an observed drop is just sampling noise.

This is precisely the problem the fairness-auditing literature solved for demographic subgroups. There, the core insight was that observed performance gaps between groups can be chance artifacts, and that naive statistical tests explode when the groups differ in size or underlying variance. The same statistical machinery — adapted so that "distance strata" play the role of demographic groups, and so that the comparison happens inside the VAE's latent geometry — gives protein design something it currently lacks: an inferential certificate of whether a trained model scores distant variants unfairly, and a variance-calibrated replacement score with error control.

Core Claim

The proposal claims three things. First, the similarity bias documented in Removing bias in sequence models of protein fitness, which shows likelihood scores dropping monotonically with mutational distance from the wild type, can be turned from a descriptive observation into a formal hypothesis test. Second, that test must be a studentized one: naive permutation of distance-stratum labels is invalid here for exactly the reason Evaluating Fairness Using Permutation Tests identified — strata differ in underlying variance by construction, and unstudentized tests reached false-positive rates as high as 75% in that setting, while the studentized version held the nominal 5%. Third, the VAE's own latent space is the right place to define the strata and the background distribution, because it encodes functional similarity that raw mutation counting misses, as Generating functional protein variants with variational autoencoders showed when its MSA-trained VAE captured long-range epistatic constraints that local models could not.

The distance-strata framing also inherits a structural problem familiar from LiFT: A Scalable Framework for Measuring Fairness in ML Applications: near-strata are densely sampled (tiny gaps look significant) while far strata are sparsely sampled (large gaps look like noise). Any honest test must correct for this asymmetry, which is exactly what studentization does.

Research Program

We build an audit procedure for a trained protein VAE, treating its decoder log-likelihood $\ell_\theta(x)$ as the "model output" under audit. For each candidate sequence $x$, we simulate a background population of random variants matched to $x$ in latent distance — distance from the training family's latent centroid, computed in the VAE's own embedding — and convert the raw score into a background-calibrated statistic:

$$z(x) \;=\; \frac{\ell_\theta(x) \;-\; \mu_{d(x)}}{\sigma_{d(x)}}$$

where $d(x)$ is $x$'s latent distance, and $\mu_d$ and $\sigma_d$ are the mean and standard deviation of scores over the simulated random background at that latent distance. The z-score asks: relative to meaningless sequences at the same latent distance, is this candidate unusually likely?

The hypothesis test then compares mean z-scores across strata. The null hypothesis is the weak null: expected calibrated scores are equal across distance strata, even though the strata's underlying sequence distributions differ. Following Evaluating Fairness Using Permutation Tests, the test statistic is studentized,

$$T_n \;=\; \frac{\widehat{\Delta}}{\widehat{\sigma}_{\Delta}}, \qquad \widehat{\Delta} \;=\; \bar{z}_{\text{far}} - \bar{z}_{\text{near}},$$

where $\bar{z}_{\text{far}}$ and $\bar{z}_{\text{near}}$ are stratum means of $z$ over evaluated candidates and $\widehat{\sigma}_{\Delta}$ is a nested bootstrap estimate of the standard error, embedded inside the permutation loop because no closed-form variance exists for complex score functionals. A rejected null certifies that the model's scoring degrades with distance beyond what unequal stratum variance explains. The same calibration also yields the deliverable practitioners actually want: a distance-calibrated ranking score $z(x)$ with bootstrap confidence intervals, replacing raw likelihood in candidate selection.

The program has three work packages. The first builds the test on top of existing VAE architectures (the MSA VAE and autoregressive AR-VAE of Generating functional protein variants with variational autoencoders, and a RecGen-style conditional VAE as in Prediction of designer-recombinases for DNA editing with generative deep learning). The second establishes asymptotic validity of the studentized statistic under the weak null, importing the pivotal-quantity argument from Evaluating Fairness Using Permutation Tests; doing statistics in latent space is computationally realistic, since Conformal Reliability: A New Evaluation Metric for Conditional Generation showed that calibration inside a VAE latent space ran over 1900 times faster than grid-based approaches in the raw space. The third audits deployed practice, contrasting our inferential test with the point-estimate mitigation style of Counterfactual Fairness with Disentangled Causal Effect Variational Autoencoder, which enforces a fairness property during training but supplies no p-values or error control for certifying it afterward.

Baselines

The do-nothing reference point is raw VAE likelihood ranking, which is the deployed practice in Generating functional protein variants with variational autoencoders: those likelihoods were the best predictors of experimental luminescence, beating BLOSUM62 and Pfam profile HMM scores, and 9 of 11 sequences selected that way showed measurable enzymatic luminescence. Our method beats this baseline if the calibrated score $z(x)$ improves recovery of functional distant variants on held-out deep mutational scanning assays at high mutational depths without degrading recovery at low depths, on identical candidate pools.

The strongest existing competitor is the percentile recalibration of Removing bias in sequence models of protein fitness, which re-scores each variant against simulated random backgrounds at matched mutational distance. It will be run on the same trained VAEs, with the same background-simulation compute budget and the same tuning effort, so any difference is the method and not the resources. Beating it means two things jointly: equal or better recovery of top-performing distant variants, and a valid hypothesis test with controlled Type I error, which recalibration does not provide at all. We must be honest about the comparison: no reported result found on Lacuna for the exact numerical score improvement of percentile recalibration, so the head-to-head is genuinely open.

Two statistical ablations isolate the ingredients. First, the identical test pipeline with studentization switched off — the unstudentized permutation test that Evaluating Fairness Using Permutation Tests showed inflating false positives to 75% under unequal variances, with distance strata being a textbook unequal-variance case. Second, the same test but with strata and background matching defined by Hamming distance in sequence space instead of latent distance; this isolates whether the VAE geometry contributes anything. As a contextual reference point rather than a competitor, supervised methods sit outside our unsupervised regime: on ProteinGym, the supervised ProteinNPT achieved a Spearman correlation of 0.613, but it requires labeled fitness data, which de novo design and rare families lack.

Why not just…?

Why not just use the percentile recalibration that already exists? This is the most serious alternative, and we will run it head-to-head under matched compute. What it lacks is inference: recalibration is a descriptive correction with no null hypothesis, no p-values, no confidence intervals, and no control over how often it certifies a fair model as fair by chance. If recalibration matches our ranking recovery, the contribution honestly narrows to the certificate — a test with demonstrated 5% Type I error — which is precisely the element the literature lacks. The experiments are designed to settle which part survives.

Why not just use a supervised model like ProteinNPT? Supervised models top the ProteinGym leaderboard (Spearman 0.613) but need assay labels for the target family. Directed evolution toward genuinely novel targets — the setting where distance bias matters most, as in the RecGen recombinase design of Prediction of designer-recombinases for DNA editing with generative deep learning — has labels only for past targets, and we would additionally audit whether supervised scores inherit the same distance pathology in extrapolative regimes. Our audit applies to any trained generative scorer, supervised or not.

Why not just run t-tests per distance bin? The cross-validation-plus-t-test approach of A novel approach for assessing fairness in deployed machine learning algorithms works for tabular classification with Gaussian-ish fold statistics, but distance strata have wildly unequal variances and small distant-stratum sample counts, where normality assumptions break; and as that paper's own clinical results show, such tests flag or clear whole models without disentangling sampling noise from systematic drift. The permutation machinery we adopt is metric-agnostic and needs no fold distributional assumptions.

Why not just do the test in sequence space, without any VAE latent? A real threat. Hamming distance is free and alignment-free for substitutions, and a Hamming-stratified studentized test is a legitimate simpler method — which is why it is the ablation that isolates our key ingredient. Two pieces of evidence motivate the latent version: the MSA VAE of Generating functional protein variants with variational autoencoders captured long-range epistatic similarity that local and alignment-based models missed, and ProteinGym showed alignment-based methods fail outright on 300,000 indel mutations, where only unaligned latent models can define matched backgrounds. If the Hamming-stratified test matches the latent one on substitutions, we will report that plainly.

Proposed Experiments

The first experiment establishes calibration. We train VAEs on synthetic sequence families with planted, distance-independent fitness, so the null is true by construction, and verify empirically that our studentized test holds a 5% rejection rate while the unstudentized permutation and cross-validated t-tests inflate — the fairness literature predicts inflation as high as 75% for the unstudentized variant in unequal-variance settings.

The second measures power on real pathology. The 14 deep mutational scan datasets assembled by Removing bias in sequence models of protein fitness — including GFP (with the ppluGFP ortholog at only 18% sequence identity), PhoQ, GCN4, and AAV2 capsids — are the natural testbed, since the score-shift pathology is already documented there. We report rejection rates and p-values by mutational depth, and the same for the Hamming-stratified ablation.

The third is the benchmark comparison on ProteinGym: 217 substitution assays and 66 indel assays, scored by Spearman correlation, NDCG, and Top-1% recall, comparing raw likelihood, percentile recalibration, and our calibrated z-score, all on the same trained models. The indel assays are where latent and unaligned models can operate and alignment-based scoring cannot, making them the sharpest test of the latent ingredient.

The fourth is retrospective wet-lab grounding. Generating functional protein variants with variational autoencoders synthesized candidates ranked by raw likelihood: 9 of 11 MSA VAE designs were functional, versus 6 of 12 for the AR-VAE, and the most distant functional variant carried 35 differences from any training sequence. We re-rank their full candidate pool with the calibrated score and ask whether the distant functional variants would have been promoted and near-clones demoted — a counterfactual audit of a real selection decision.

The fifth extends the audit to conditional design: the RecGen pipeline of Prediction of designer-recombinases for DNA editing with generative deep learning (74 of 89 leave-one-out cases predicted, 8 of 14 novel-target designs active) also ranks candidates by generative scores, and its documented cross-reactivity on wild-type targets is a second bias axis the same testing machinery can address.

The decisive checks are three: the Type I error table (ours near 5%, unstudentized inflated); the recalibration head-to-head on ranking recovery at depth, which determines whether our contribution is the score, the test, or both; and the Hamming-versus-latent ablation, which determines whether the VAE geometry earns its place. Any of the three can force an honest redesign of the proposal, and the experiments are sized so each verdict is unambiguous.