Why Library Size Is a Modeling Choice
A cell with more recorded molecules will often have larger counts for many genes, even if its relative expression profile resembles that of a cell with fewer molecules. A count VAE therefore needs to distinguish the overall scale of a cell’s counts from how that cell’s counts are allocated across genes. The distinction is consequential: it determines whether a cell’s total count is treated as fixed, as arising around a known exposure, or as a random quantity to infer.
Let \(x_{ig}\) be the observed count for gene \(g\) in cell \(i\), and let \(z_i\) be that cell’s biological latent representation. Write \(C_i=\sum_g x_{ig}\) for the observed total. Suppose the decoder maps \(z_i\) to gene proportions \(\rho_{ig}(z_i)\), where \(\rho_{ig}\geq 0\) and \(\sum_g\rho_{ig}=1\). The library-size component supplies the scale multiplying those proportions.
These approaches are not merely three notations for the same procedure. They differ in whether the total is modeled as random, whether it contributes information to the likelihood, and whether uncertainty about the scale is represented. The introductory material on generative latent-variable models and count VAE likelihoods provides the general setting; here the focus is how library size enters the decoder.
Three Ways to Represent the Scale
A common fixed-offset model uses a known positive scale \(O_i\) and assumes conditionally independent Poisson counts:
The conditional expected count is \(O_i\rho_{ig}(z_i)\), and the expected total is \(O_i\), because the proportions sum to one. The offset is treated as given, not estimated from the count likelihood. It may be based on a library-size measure or a chosen exposure. If the offset is expressed through a log link, \(\log O_i\) is added to the gene-specific decoder log mean. The Poisson assumption also implies conditional independence across genes and equality of each conditional variance and mean.
Alternatively, one can condition directly on the observed total. Under the same gene proportions, the conditional model is
Its expected count for gene \(g\), conditional on the observed total, is \(C_i\rho_{ig}(z_i)\). The total is fixed by construction; this likelihood models how the recorded molecules are allocated, not why the cell has \(C_i\) molecules. It therefore cannot use variation in totals to learn a cell-specific scale.
A latent-scale model instead uses a positive random variable \(L_i\):
The lognormal prior is one standard choice, not a requirement. A VAE can use an encoder distribution \(q_\phi(\log L_i\mid x_i)\) to approximate the posterior. Conditional on \(L_i\) and \(z_i\), the expected count is \(L_i\rho_{ig}(z_i)\). Marginally, if \(L_i\) and \(z_i\) are independent under the distribution being averaged, the expectation is \(E[L_i]E[\rho_{ig}(z_i)]\). If they are dependent, the expectation is \(E[L_i\rho_{ig}(z_i)]\), which need not factor into those two terms.
Worked Example: Two Cells With Different Fixed Offsets
Suppose a decoder assigns three genes proportions \((0.50,0.30,0.20)\) for each of two hypothetical cells. Use fixed offsets \(O_1=100\) and \(O_2=200\) count-scale units. Under the independent Poisson model, the conditional means are offset times gene proportion.
For cell 1, the expected counts are \(100(0.50)=50\), \(100(0.30)=30\), and \(100(0.20)=20\). The total expected count is \(50+30+20=100\).
For cell 2, the expected counts are \(200(0.50)=100\), \(200(0.30)=60\), and \(200(0.20)=40\). The total expected count is \(100+60+40=200\).
The proportions are identical, but doubling the fixed offset doubles every expected count. These are expected counts, not guarantees that the observed counts equal those values. For instance, under the model, the first gene’s count in cell 1 has a Poisson distribution with mean 50 and variance 50.
Why the Poisson and Multinomial Views Are Related
The connection between an offset model and a conditional-total model can be derived directly. Suppose counts are conditionally independent Poisson with means \(L_i\rho_{ig}\), and the proportions sum to one. For one cell, write \(C_i=\sum_g x_{ig}\). The joint probability of the gene counts is
The first bracket is the probability mass function of \(C_i\sim\operatorname{Poisson}(L_i)\). The second is the multinomial probability of the observed allocation given that total. Thus independent Poisson counts imply a Poisson total and a multinomial allocation conditional on the total. This factorization requires independent Poisson counts and proportions summing to one; it should not be assumed automatically for other count likelihoods.
This result clarifies the modeling distinction. Conditioning on \(C_i\) removes the Poisson-total factor. A fixed Poisson offset retains that factor, although if the chosen offset equals the observed total, its value is constant with respect to the decoder proportions. A latent \(L_i\) makes the total informative about the scale and combines that information with the prior and encoder approximation.
Worked Example: Checking a Conditional Multinomial Probability
For a hypothetical cell with total \(C=10\), suppose the decoder proportions for three genes are \(0.50\), \(0.30\), and \(0.20\). Calculate the conditional probability of observing counts \((5,3,2)\).
The multinomial probability is
The arithmetic uses \((0.50)^5=0.03125\). The result is the probability of this exact count vector conditional on a total of 10 and the specified proportions; it is not the probability that the proportions are correct.
If instead the counts are generated by independent Poisson distributions with means \((5,3,2)\), the total has a Poisson distribution with mean 10. The probability of observing this exact vector is the total probability multiplied by the conditional allocation probability:
The conditional probability and the joint probability answer different questions. The latter includes the probability of obtaining a total of 10 under the Poisson model.
Working With a Latent Library Size
A latent scale lets a model represent cell-to-cell differences in total count while propagating uncertainty in that scale. For example, with \(q_\phi(\log L_i\mid x_i)=N(m_i,v_i)\), the expected scale under this approximate posterior is \(\exp(m_i+v_i/2)\). This follows from the mean of a lognormal random variable; using \(\exp(m_i)\) instead gives the median, not the mean, unless \(v_i=0\).
The latent-scale contribution to a VAE objective is an expectation of the count log likelihood under the approximate posterior, together with a penalty for departing from the prior. In a model with both \(z_i\) and \(\log L_i\), the relevant terms have the form
Here \(D_{\mathrm{KL}}\) is the Kullback–Leibler divergence, which penalizes a variational distribution that differs from its prior. The exact decomposition of the divergence depends on the chosen prior and whether the latent variables are modeled independently. The important point for library size is that the count likelihood and prior both affect its inferred distribution; it is not simply replaced by the observed total.
Worked Example: Expected Counts Under a Latent Scale
Consider two hypothetical cells with the same decoder proportions \((0.50,0.30,0.20)\). Suppose their approximate posterior distributions for log library size are normal with means \(\log(80)\) and \(\log(160)\), respectively, and both have variance \(0.01\). For a normal variable \(Y\sim N(m,v)\), \(E[\exp(Y)]=\exp(m+v/2)\).
For cell 1, \(E[L_1]=\exp(\log(80)+0.01/2)=80\exp(0.005)\approx80.40\). Its posterior-mean expected gene counts, using the stated proportions, are approximately \(80.40(0.50)=40.20\), \(80.40(0.30)=24.12\), and \(80.40(0.20)=16.08\).
For cell 2, \(E[L_2]=\exp(\log(160)+0.005)=160\exp(0.005)\approx160.80\). Its corresponding expected counts are approximately \(80.40\), \(48.24\), and \(32.16\). The expected totals equal the posterior mean scales because the proportions sum to one.
These are averages over uncertainty in \(L_i\) with the proportions held fixed. If the posterior for \(L_i\) is dependent on \(z_i\), the expected gene count must be computed as \(E[L_i\rho_{ig}(z_i)]\) under joint posterior draws rather than by multiplying separate posterior means.
Choosing Among the Approaches
| Representation | What is conditioned on or inferred? | Information about totals | Useful when |
|---|---|---|---|
| Fixed offset \(O_i\) | Offset is given; counts follow the selected likelihood. | Total counts vary around the offset-implied mean under the Poisson model. | A reliable exposure or size factor is available and scale uncertainty is not the target. |
| Observed total \(C_i\) | Counts follow a multinomial distribution conditional on their sum. | The total is fixed and contributes no likelihood information about cell scale. | The target is relative allocation across genes, conditional on each recorded total. |
| Latent scale \(L_i\) | Scale has a prior and is inferred jointly or approximately with other latents. | The total informs the scale, with uncertainty moderated by the prior. | Cell-specific scale uncertainty should be represented rather than fixed in advance. |
The table assumes the same normalized gene-proportion decoder for clarity. Other parameterizations are possible, but a decoder that produces unnormalized rates must define how those rates and the library scale interact. If both can change freely in overall magnitude, the model may have difficulty distinguishing a larger library scale from uniformly larger gene rates. Constraining the proportions to sum to one makes the intended separation explicit.
A fixed offset is computationally simple, but conclusions can be sensitive to how that offset is constructed. Conditioning on the observed total avoids modeling total-count variation, but cannot explain systematic differences in totals. A latent scale is more flexible and expresses uncertainty, but introduces a prior and an additional inference problem. It does not automatically correct technical biases, and a poorly chosen prior can shrink unusual cells toward typical scales.
Diagnostics, Assumptions, and Common Pitfalls
The assumptions should be checked in relation to the scientific target. For the Poisson derivation, counts must be conditionally independent given the cell’s scale and decoder proportions, and the proportions must sum to one. The offset must be treated as fixed and appropriate for the role assigned to it. The multinomial alternative requires conditioning on a known total and interpreting the target as gene allocation. The latent model requires a defensible prior and an encoder capable of representing uncertainty in the scale.
Warning signs include observed totals that are systematically inconsistent with fixed offsets; latent posterior scales that are repeatedly pushed against the prior’s extreme tail; or cells whose large totals are explained only by implausible shifts in the gene proportions. Compare observed totals with the model-implied distribution of totals when totals are modeled. For a latent Poisson model with proportions summing to one, \(C_i\mid L_i\sim\operatorname{Poisson}(L_i)\); for an observed-total multinomial model, such a total check is not meaningful because the total is conditioned upon. Sensitivity to plausible offset definitions or prior scales is also informative.
A common mistake is to say, “The observed total is 200, so the Poisson model treats the total as fixed at 200.” That is not generally correct. Under independent Poisson counts with fixed offset \(O_i=200\), the total is random with distribution \(\operatorname{Poisson}(200)\); it has expectation 200, but can take other values. Under the multinomial model conditional on \(C_i=200\), the total is fixed. The correction is to state explicitly whether the likelihood models the total or conditions it away.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions below.
- With proportions \((0.60,0.25,0.15)\) and fixed offset \(O=80\), what are the three expected gene counts?
- Under an observed-total multinomial model with \(C=80\), what is the expected count for the gene with proportion \(0.25\)? Does this model assign a probability distribution to \(C\)?
- For independent Poisson counts with means \(L\rho_g\) and proportions summing to one, what is the distribution of their sum?
- If \(\log L\sim N(\log 50,0.04)\), calculate \(E[L]\) to three significant figures.
- Explain why a Poisson offset equal to the observed total and a multinomial conditional on that total are related but are not identical modeling statements.
Solutions. (1) Multiply each proportion by 80: \(48\), \(20\), and \(12\) expected counts. (2) The expected count is \(80(0.25)=20\). The conditional multinomial model does not assign a distribution to \(C\); it conditions on the observed value. (3) The sum is \(\operatorname{Poisson}(L)\), since the means sum to \(L\). (4) \(E[L]=\exp(\log 50+0.04/2)=50\exp(0.02)\approx51.0\). (5) The independent Poisson model retains a Poisson probability for the total, while the conditional multinomial removes that factor by conditioning on the total. When the fixed offset equals the observed total and the proportions sum to one, the Poisson-total factor is constant with respect to the proportions, but the generative statements remain different.