Skill Tracer
Skills › Scientific Agent Skills › scvi-tools › theoretical-foundations.md

theoretical-foundations.md

92 lines · skills/scvi-tools/references/theoretical-foundations.md at 5f2bc03

Open on GitHub
1# Interpreting the probabilistic model
2
3Reviewed against scvi-tools 1.5.1. These are interpretation rules, not guarantees
4that a particular trained model is scientifically adequate.
5

Interpreting the probabilistic model

Reviewed against scvi-tools 1.5.1. These are interpretation rules, not guarantees that a particular trained model is scientifically adequate.

Raw lines 1 to 5
6## Likelihood and variational inference
7
8For latent state `z`, observed data `x` and technical covariates `s`, an encoder
9approximates `q(z | x, s)` and the decoder models `p(x | z, s)`. The simplified
10objective is
12```text
13ELBO = E_q[log p(x | z, s)] - KL(q(z | x, s) || p(z))
14```
16Additional latent variables and losses depend on the model. The neural-network
17weights are usually point estimates, so posterior draws do not capture every
18source of parameter, preprocessing, reference or sampling uncertainty. Optimizing
19this nonconvex objective does not guarantee a global optimum or calibrated biology.
21SCVI commonly uses negative binomial counts with `Var(x)=mu+mu^2/theta`, or a
22zero-inflated NB mixture. A zero-inflation parameter is a mixture probability;
23it cannot by itself identify technical dropout versus biological absence.
24High sparsity does not prove that ZINB is preferable to NB. Compare suitable
25likelihoods using held-out fit, posterior predictive checks and domain knowledge.
26AUTOZI tests evidence for additional zero inflation under its assumptions; it does
27not label every zero's biological origin.
29Do not generalize the count likelihood to all scvi-tools models. PeakVI uses
30Bernoulli accessibility; methylation models use methylated/coverage counts;
31SysVI and CytoVI operate on appropriately transformed continuous values; VeloVI
32uses preprocessed spliced/unspliced abundances and kinetic assumptions.

Likelihood and variational inference

For latent state z, observed data x and technical covariates s, an encoder approximates q(z | x, s) and the decoder models p(x | z, s). The simplified objective is

ELBO = E_q[log p(x | z, s)] - KL(q(z | x, s) || p(z))

Additional latent variables and losses depend on the model. The neural-network weights are usually point estimates, so posterior draws do not capture every source of parameter, preprocessing, reference or sampling uncertainty. Optimizing this nonconvex objective does not guarantee a global optimum or calibrated biology.

SCVI commonly uses negative binomial counts with Var(x)=mu+mu^2/theta, or a zero-inflated NB mixture. A zero-inflation parameter is a mixture probability; it cannot by itself identify technical dropout versus biological absence. High sparsity does not prove that ZINB is preferable to NB. Compare suitable likelihoods using held-out fit, posterior predictive checks and domain knowledge. AUTOZI tests evidence for additional zero inflation under its assumptions; it does not label every zero's biological origin.

Do not generalize the count likelihood to all scvi-tools models. PeakVI uses Bernoulli accessibility; methylation models use methylated/coverage counts; SysVI and CytoVI operate on appropriately transformed continuous values; VeloVI uses preprocessed spliced/unspliced abundances and kinetic assumptions.

Raw lines 6 to 33
34## Integration and identifiability
36Conditioning the decoder on batch encourages removal of nuisance variation from
37`z`; it does not mathematically force a batch-invariant latent space. Complete
38batch/condition confounding prevents identification of their separate effects.
39Validate both mixing among comparable cell states and preservation of cell-type,
40condition, donor and trajectory structure that should remain.
42Covariates are model inputs, not a list of everything available in `.obs`.
43Library-size handling is already part of RNA models. Additional depth, tissue,
44condition or donor covariates can change the estimand or remove wanted signal.
45Continuous covariates must have appropriate scale; registration does not promise
46automatic standardization.
48`transform_batch` decodes a fitted cell state under a different registered batch.
49This is model-based counterfactual decoding. It is not an identified causal
50intervention, nor evidence that the model predicts unobserved drug responses.

Integration and identifiability

Conditioning the decoder on batch encourages removal of nuisance variation from z; it does not mathematically force a batch-invariant latent space. Complete batch/condition confounding prevents identification of their separate effects. Validate both mixing among comparable cell states and preservation of cell-type, condition, donor and trajectory structure that should remain.

Covariates are model inputs, not a list of everything available in .obs. Library-size handling is already part of RNA models. Additional depth, tissue, condition or donor covariates can change the estimand or remove wanted signal. Continuous covariates must have appropriate scale; registration does not promise automatic standardization.

transform_batch decodes a fitted cell state under a different registered batch. This is model-based counterfactual decoding. It is not an identified causal intervention, nor evidence that the model predicts unobserved drug responses.

Raw lines 34 to 51
52## Transfer, samples and spatial structure
54scArches performs model-specific architectural surgery with selective parameter
55freezing; it is not simply "freeze the encoder, train the decoder." Use
56`prepare_query_anndata`/`load_query_data` and inspect their freeze options. Query
57feature order, count scale, covariates and reference coverage matter. A classifier
58can confidently mislabel a cell type missing from its reference; evaluate rejection
59and uncertainty with held-out biological samples.
61MRVI uses sample-unaware `u` and sample-aware `z` representations with learned
62sample-conditioned transformations. It is not defined by the generic additive
63formula `z_shared + z_sample` or a simple normal random-intercept hierarchy.
64Sample distances and multivariate comparisons depend on sample support and design.
66DestVI deconvolves spatial expression with a labeled CondSCVI reference and
67continuous within-type states. Spatial coordinates do not automatically imply a
68spatial autocorrelation prior; validate proportions against independent tissue
69information. Tangram mapping is an optimization over cell-to-location assignment
70weights, not proof of the physical location of an individual sequenced cell.

Transfer, samples and spatial structure

scArches performs model-specific architectural surgery with selective parameter freezing; it is not simply "freeze the encoder, train the decoder." Use prepare_query_anndata/load_query_data and inspect their freeze options. Query feature order, count scale, covariates and reference coverage matter. A classifier can confidently mislabel a cell type missing from its reference; evaluate rejection and uncertainty with held-out biological samples.

MRVI uses sample-unaware u and sample-aware z representations with learned sample-conditioned transformations. It is not defined by the generic additive formula z_shared + z_sample or a simple normal random-intercept hierarchy. Sample distances and multivariate comparisons depend on sample support and design.

DestVI deconvolves spatial expression with a labeled CondSCVI reference and continuous within-type states. Spatial coordinates do not automatically imply a spatial autocorrelation prior; validate proportions against independent tissue information. Tangram mapping is an optimization over cell-to-location assignment weights, not proof of the physical location of an individual sequenced cell.

Raw lines 52 to 71
72## Posterior contrasts
74For RNA change-mode DE, positive LFC means group1 over group2. The returned
75`bayes_factor` is on the natural-log posterior-odds scale. Posterior FDP selection
76is conditional on the fitted model and hypotheses; it is not a conversion to
77frequentist p-values. More posterior samples reduce simulation noise, not
78biological uncertainty from a small number of donors. See
79[differential-expression.md](differential-expression.md) for exact API choices.
81The logged `elbo_validation` training metric is a loss (lower is better), while
82`get_elbo()` returns an ELBO (higher is better). Compare the same metric on the
83same held-out cells/features; a training curve alone does not establish convergence,
84identifiability, generalization or successful integration.
86Sources: [variational inference](https://docs.scvi-tools.org/en/stable/user_guide/background/variational_inference.html),
87[SCVI](https://docs.scvi-tools.org/en/stable/user_guide/models/scvi.html),
88[AUTOZI](https://docs.scvi-tools.org/en/stable/user_guide/models/autozi.html),
89[SysVI assumptions](https://github.com/scverse/scvi-tools/blob/1.5.1/docs/user_guide/models/sysvi.md),
90[MrVI](https://docs.scvi-tools.org/en/stable/user_guide/models/mrvi.html),
91[DestVI](https://docs.scvi-tools.org/en/stable/user_guide/models/destvi.html),
92[transfer implementation](https://github.com/scverse/scvi-tools/blob/1.5.1/src/scvi/model/base/_archesmixin.py).

Posterior contrasts

For RNA change-mode DE, positive LFC means group1 over group2. The returned bayes_factor is on the natural-log posterior-odds scale. Posterior FDP selection is conditional on the fitted model and hypotheses; it is not a conversion to frequentist p-values. More posterior samples reduce simulation noise, not biological uncertainty from a small number of donors. See differential-expression.md for exact API choices.

The logged elbo_validation training metric is a loss (lower is better), while get_elbo() returns an ELBO (higher is better). Compare the same metric on the same held-out cells/features; a training curve alone does not establish convergence, identifiability, generalization or successful integration.

Sources: variational inference, SCVI, AUTOZI, SysVI assumptions, MrVI, DestVI, transfer implementation.

Raw lines 72 to 92