Integrals in Probability
For anything measured on a continuous scale, probability is area rather than height — which is why the chance of hitting an exact value is zero and why so many useful quantities have no formula.
Why Does This Exist?
Three tools you use constantly are integrals, and none makes sense without this page.
norm.cdf is an integral. Every p-value, confidence interval and z-score lookup is area under a bell curve up to some point. There is no algebraic formula for it, which is why that function is a numerical routine and why statistics tables existed for a century.
The denominator in Bayes theorem is an integral. For continuous parameters the evidence term needs integrating over every possible value. That integral is why Bayesian methods are hard and why sampling and variational methods exist. The discrete version and its priors live in probability distributions.
The VAE loss is a workaround for an integral. The data probability under the model needs integrating over the whole latent space. It cannot be done, so training optimises a lower bound instead. The integral is step one, the bound is step three.
Think of It Like This
Asking how much a single point on a map weighs
You hold a map shaded by population density, people per square kilometre. Dark cities, pale countryside.
Ask how many people live in this province and the map answers: multiply density by area and total it. Ask how many live at these exact coordinates and the answer is zero. A point has no area, so however dark the shading, it contains nobody.
That is not a defect. It is what a density means. The shading is people per unit area, not people, and you get people only by multiplying by an area. A very dark point says the region around it is crowded, nothing about the point itself.
A probability density works the same. Its height is probability per unit of , not probability. Multiply by a width and you get probability. That is why a density can exceed while a probability cannot.
How It Actually Works
For a discrete variable every rule is a sum. For a continuous one every sum becomes an integral. That is the whole translation.
Density to probability
A density meets two conditions:
Never negative, total area exactly one. Probability comes from intervals:
Two consequences surprise people. First, for any single , because zero width has zero area, so and are interchangeable here. Second, can exceed . A Gaussian with peaks near . Nothing is wrong, it is a rate and narrowness compensates.
The CDF is the integral of the density
The cumulative function accumulates area from the left:
The chance of landing at or below . It runs to and never falls. Differentiate it and you get the density back, so CDF and PDF are an antiderivative pair. That is the most useful fact here, and it is why practical work happens in CDF space: any interval is one subtraction , and every p-value is a CDF call.
Expectation becomes an integral
Discrete expectation sums times probability. Continuous version:
Each value weighted by density, totalled across the line. More generally , the form that appears everywhere because a loss is an expectation of per-example cost. Variance follows the same swap with inside.
The normalising constant, and where things go wrong
Often you can write a shape proportional to a density but not the density itself:
forces total area to . Discrete is a sum you can compute, exactly what a softmax denominator is. Continuous is an integral, and that is where tractability dies.
Bayes with parameters and data shows it:
Numerator is easy, both pieces chosen by you. Denominator integrates over every setting, hopeless for millions of parameters. Every practical method dodges it: conjugate priors make it solvable for a few families, MAP maximises the numerator and drops , MCMC samples without knowing , variational methods bound it.
Worked example
Uniform on . Width needs height for area .
Midpoint, as symmetry demands. Narrow it to and keeps area . The density is , above , yet every probability stays below because widths are small.
Gaussian case: standard normal , the familiar percent, and it is an area. No elementary formula exists for , which is why the diagram labels that region instead of deriving it.
Code
This snippet checks the uniform arithmetic and the Gaussian area with only numpy and the standard library.
import mathimport numpy as np
def uniform_pdf(x: np.ndarray, lo: float, hi: float) -> np.ndarray: return np.where((x >= lo) & (x <= hi), 1.0 / (hi - lo), 0.0)
grid = np.linspace(0, 2, 200001)pdf = uniform_pdf(grid, 0, 2)print(round(float(np.trapezoid(pdf, grid)), 4)) # -> 1.0print(round(float(np.trapezoid(grid * pdf, grid)), 4)) # -> 1.0print(float(uniform_pdf(np.array([0.25]), 0, 0.5)[0])) # -> 2.0print(round(0.5 * (1 + math.erf(1 / math.sqrt(2))), 4)) # -> 0.8413The first two prints confirm total area and mean . The third shows density is fine. The last is , so is .
Watch Out For
Comparing densities across different units or parameterisations
A density shifts under a change of variable by a Jacobian factor, because the widths you multiply by changed. Probabilities stay identical, density values do not. So log-likelihoods on different preprocessings can read versus for the same model on the same data.
Compare continuous likelihoods and bits-per-dimension only across identical preprocessing. A positive continuous log-likelihood is also fine, since density above has positive log.
Assuming a normalising constant can be computed
The common failure is writing an unnormalised density, getting a working loss, and never noticing was dropped. Dropping it is correct for ranking or MAP, where has no gradient. It fails the moment you need a real probability, a calibrated confidence, a likelihood comparison or an energy model.
Know whether your objective needs . If you quote a probability, name the approximation that produced it.
The Quick Version
- For continuous variables every probability rule becomes an integral instead of a sum.
- A density is probability per unit, not probability. It may exceed .
- always, because zero width has zero area.
- The CDF is the integral of the density, differentiating it returns the density.
- Expectation is , and covers every loss.
- The normalising constant forces total area to . Discrete is a sum, continuous is often intractable.
- Bayes denominator is that integral, which is why MAP, MCMC and variational methods exist.
- Densities shift under reparameterisation, so compare likelihoods only on identical preprocessing.