Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Entropy and Margin Measures of Annotation Uncertainty

Cell-Type Annotation and Its Uncertainty · Tutorial 334 of 700

Entropy and Margin Measures of Annotation Uncertainty

You will calculate entropy and top-two margins for hypothetical cells and learn why they capture different aspects of an uncertain cell-type prediction.

Intermediate 12 min read

What You'll Learn

  • Define predictive entropy and the top-two probability margin for a cell’s candidate labels.
  • Calculate entropy in nats and interpret its range.
  • Calculate the difference between the two largest label probabilities.
  • Compare what entropy and margin reveal about the full probability distribution.
  • Identify assumptions, numerical pitfalls, and limits on interpretation.

Why Summarize a Cell’s Label Probabilities?

A cell-type classifier can assign probabilities to several candidate labels, rather than returning only one label. For example, a cell might receive probabilities 0.45 for one type and 0.44 for another. Reporting only the most probable label hides how close the alternatives are. Two useful summaries are predictive entropy, which reflects the spread of probability across all candidate labels, and the top-two probability margin, which measures the lead of the most probable label over the runner-up.

These measures describe the classifier’s probability distribution for a cell. They do not, by themselves, establish whether the probabilities are accurate or whether the cell has a biologically ambiguous identity. In particular, interpreting a classifier’s probabilities requires care: a probability is a model output, and its empirical reliability is a separate question.

Definition: For a cell \(i\) with \(K\) mutually exclusive candidate labels, let \(p_{ik}\) be the predicted probability of label \(k\), where \(p_{ik}\geq 0\) and \(\sum_{k=1}^{K}p_{ik}=1\). Sort these probabilities in descending order as \(p_{i(1)}\geq p_{i(2)}\geq\cdots\geq p_{i(K)}\). The predictive entropy is \(H_i=-\sum_{k=1}^{K}p_{ik}\ln(p_{ik})\), using the convention \(0\ln(0)=0\). The top-two probability margin is \(M_i=p_{i(1)}-p_{i(2)}\). Entropy is measured in nats when the natural logarithm is used; the margin is a probability difference and has no physical units.

The probabilities must refer to the same candidate-label set and sum to one. If a classifier provides unnormalized scores, those scores cannot be used directly in these formulas; first obtain a probability distribution using the model’s specified procedure. The class-imbalance adjustment in the earlier material may change the probabilities, so calculate the summaries from the probabilities that are actually intended to guide the annotation.

What the Two Measures Capture

Entropy uses every label probability. It is low when most probability is concentrated on one label, and higher when probability is spread across several labels. For a fixed set of \(K\) labels, its minimum is 0, attained when one label has probability 1, and its maximum is \(\ln(K)\), attained when all labels have probability \(1/K\). Thus, entropy values depend in part on the number of candidate labels. A normalized version, \(H_i/\ln(K)\), ranges from 0 to 1 for \(K>1\), but it should be compared only when the label sets and their meanings are appropriately aligned.

The margin uses only the two largest probabilities. A large margin means the leading label is well ahead of the runner-up; a small margin means those two candidates are close. Its value lies between 0 and 1. A margin of 0 indicates a tie at the top, not necessarily maximum entropy: substantial probability might still be concentrated on the tied labels, or might be spread across many labels.

A large top probability alone is not the same as a large margin. If the leading probability is 0.60, a runner-up of 0.59 cannot occur in a normalized distribution, but a runner-up of 0.39 gives a margin of 0.21. Conversely, knowing the margin does not reveal whether the probability left over after the top two is concentrated on one label or dispersed among many. Entropy and margin are complementary summaries, not substitutes.

Worked Example: A Close Decision Between Two Leading Labels

Suppose a hypothetical cell has probabilities 0.45, 0.44, and 0.11 for three candidate labels. They are valid probabilities because they are nonnegative and sum to 1.00. The leading label is the one with probability 0.45.

The top-two margin is \(M_i=0.45-0.44=0.01\). The leading label is therefore only 0.01 probability points ahead of the runner-up, so the ranking between these two predictions is close.

Using natural logarithms, the entropy contributions are \(-0.45\ln(0.45)\approx0.3593\), \(-0.44\ln(0.44)\approx0.3612\), and \(-0.11\ln(0.11)\approx0.2428\). Hence \(H_i\approx0.3593+0.3612+0.2428=0.9634\) nats. The small margin describes the near-tie at the top, while the entropy also accounts for the remaining 0.11 assigned to the third label.

The classifier’s most probable label is still the label with probability 0.45. Neither summary changes the label-ranking rule; they make aspects of the probability distribution visible.

Why Entropy Has These Bounds

The bounds explain how to interpret an entropy value for a specified number of labels. Because every probability lies in \([0,1]\), each term \(-p_{ik}\ln(p_{ik})\) is nonnegative, with the zero-probability term defined by its limit as 0. Thus \(H_i\geq0\). If one probability is 1 and all the others are 0, every contribution is zero, so the minimum is attained.

For the upper bound, compare the distribution \(p_{ik}\) with the uniform probabilities \(u_k=1/K\). For every positive \(p_{ik}\), the inequality \(\ln(x)\leq x-1\), applied to \(x=u_k/p_{ik}\), gives \(p_{ik}\ln(u_k/p_{ik})\leq u_k-p_{ik}\). Summing over positive probabilities (with zero terms handled by a limit) yields \(\sum_k p_{ik}\ln(u_k/p_{ik})\leq0\), since \(\sum_k u_k=\sum_k p_{ik}=1\). Rearranging gives the entropy bound:

$$ \begin{aligned} \sum_{k=1}^{K}p_{ik}\ln\left(\frac{p_{ik}}{u_k}\right)&\geq 0\\ \sum_{k=1}^{K}p_{ik}\ln(p_{ik})+\ln(K)&\geq 0\\ H_i&\leq \ln(K). \end{aligned} $$

Equality in the upper bound requires the probabilities to be uniform across the \(K\) labels. For example, when there are four candidate labels, the maximum entropy is \(\ln(4)\approx1.386\) nats. An entropy of 1.0 nats means something different when there are two candidate labels than when there are ten; the range and label set provide essential context.

Worked Comparisons

Worked Example: Same Margin, Different Probability Spread

Consider two hypothetical cells, each with four candidate labels. Cell A has probabilities 0.60, 0.30, 0.10, and 0.00. Cell B has probabilities 0.60, 0.30, 0.05, and 0.05. For both cells the two largest probabilities are 0.60 and 0.30, so \(M=0.60-0.30=0.30\).

For Cell A, \(H_A=-(0.60\ln(0.60)+0.30\ln(0.30)+0.10\ln(0.10))\approx0.3065+0.3612+0.2303=0.8979\) nats. The zero-probability term contributes 0.

For Cell B, \(H_B=-(0.60\ln(0.60)+0.30\ln(0.30)+0.05\ln(0.05)+0.05\ln(0.05))\approx0.3065+0.3612+0.1498+0.1498=0.9673\) nats. The top two predictions and their gap are identical, but Cell B has more entropy because its remaining probability is distributed across two labels rather than concentrated in one. The margin alone cannot show this difference.

Worked Example: A Zero Margin Is Not Maximum Entropy

Suppose a hypothetical cell has probabilities 0.40, 0.40, and 0.20. The margin is \(M=0.40-0.40=0\), because the two leading labels are tied.

Its entropy is \(H=-(0.40\ln(0.40)+0.40\ln(0.40)+0.20\ln(0.20))\approx0.3665+0.3665+0.3219=1.0549\) nats. With three candidate labels, the maximum possible entropy is \(\ln(3)\approx1.0986\) nats. Thus, this distribution has zero margin but is not uniform and does not attain maximum entropy. The tie tells us that the first and second labels are equally likely according to the classifier; entropy describes the spread across all three.

Calculating and Checking the Measures

For each cell, the calculation can be organized as a short sequence. Keep enough precision during the calculation to avoid changing rankings or summary values through premature rounding.

1
Check the probability vector.
Confirm that the entries are nonnegative and sum to 1, allowing only small discrepancies attributable to rounding.
2
Sort the probabilities.
Identify the largest and second-largest entries. These determine the margin, including when there are ties.
3
Compute the margin and entropy.
Subtract the second-largest probability from the largest, and sum \(-p\ln(p)\) over every candidate label.
4
Interpret against the label set.
Describe the leading-label gap and the probability spread, and state how many candidate labels were considered.

Common warning signs include probabilities that do not sum to approximately 1, negative entries, or an entropy outside the bounds 0 to \(\ln(K)\). These often signal a calculation error, a failure to normalize scores, or an inconsistent label set. Rounding can make probabilities appear to sum to 0.99 or 1.01; where possible, calculate from unrounded values. Define \(0\ln(0)\) as 0 rather than attempting to evaluate \(\ln(0)\).

Comparison, Interpretation, and Limitations

SummaryUsesWhat it emphasizesWhat it leaves out
Predictive entropyAll candidate-label probabilitiesHow probability is spread across the full label setWhich specific two labels are closest at the top
Top-two marginThe two largest probabilitiesThe lead of the most probable label over its nearest competitorHow probability is distributed among all other labels
Maximum probabilityThe largest probability onlyThe probability assigned to the selected top labelThe runner-up gap and the full probability spread

A practical summary can report the predicted label, its probability, the margin, and entropy. This is more informative than presenting any one number without context. For example, low entropy and a large margin both suggest concentration on a leading prediction, while a small margin highlights a close competition among the top two. A high entropy with a moderate margin can occur when the remaining probability is broadly distributed.

These summaries have important limits. They do not prove that a prediction is correct, quantify the frequency of errors, or establish that a cell is biologically intermediate between types. Entropy and margin are functions of the supplied probability vector: if the model’s probabilities are poorly matched to observed outcomes, these measures may still be computed correctly but may not correspond well to actual prediction reliability. Likewise, comparisons across classifiers or datasets require attention to the candidate labels and probability-generation procedures. A larger entropy can reflect a genuinely broader model distribution, a different number of labels, or differences in the model outputs; the number alone does not identify the cause.

Common Mistakes

  • Using only the predicted label. The top label suppresses information about competing labels. Report its probability or a complementary uncertainty summary when the probability distribution is relevant.
  • Calling a small margin high entropy. A small margin indicates that the top two probabilities are close. It says nothing by itself about how the remaining probability is distributed.
  • Calling zero margin maximum uncertainty. It means the top two probabilities tie. The distribution may still be far from uniform, as the worked example shows.
  • Comparing entropy without checking \(K\). The maximum possible entropy is \(\ln(K)\), so values from different candidate-label sets need careful interpretation.
  • Interpreting model uncertainty as biological ambiguity. The summaries describe the model’s probability vector, not a direct measurement of cell identity or a guarantee of prediction accuracy.
Key takeaway: Predictive entropy summarizes probability spread across all candidate labels; the top-two margin summarizes the gap between the leading two. Calculate both from a valid probability vector, interpret them relative to the label set, and do not treat either as a direct guarantee of biological ambiguity or prediction accuracy.

Check Your Understanding

Try each question, then check the solutions below.

  1. A cell has probabilities 0.80, 0.15, and 0.05. What is its top-two margin?
  2. For probabilities 0.50, 0.25, 0.25, calculate entropy in nats to three significant figures.
  3. Two cells have the same top-two margin. Give one reason their entropies could differ.
  4. What does a margin of zero establish, and what does it not establish?
  5. Why should entropy values be interpreted with the number of candidate labels in mind?

Solutions. (1) \(M=0.80-0.15=0.65\). (2) \(H=-(0.50\ln(0.50)+0.25\ln(0.25)+0.25\ln(0.25))\approx0.3466+0.3466+0.3466=1.040\) nats. (3) The probabilities below the top two may be allocated differently across labels; entropy uses all probabilities, while margin does not. (4) It establishes that the largest and second-largest probabilities are tied. It does not establish that all labels are equally probable or that entropy is maximal. (5) The maximum entropy is \(\ln(K)\), so the possible range changes with the number of candidate labels.

Clinical Biostats