Search

Search papers and lessons

Integrated Positional Encoding

Level 4 · 13 min read

Integrated positional encoding replaces a point's sine and cosine features with their average over the region a pixel covers, which fades the frequencies too fine to resolve there.

On this page

  • Colour = topic mix
  • Linear algebra
  • Calculus
  • Probability
  • Discrete math
  • Electromagnetism
  • Electrical engineering
  • ReadReady to readNot yet

TL;DR

Integrated positional encoding (IPE) is a way to feed a 3D position into a neural network so that the network sees only the detail that the viewing footprint can resolve. Instead of encoding a single point with sine and cosine features at many frequencies, it encodes the region the pixel covers, modelled as a Gaussian, and returns the average of those features over the region. Each frequency is scaled down by a factor that falls as the frequency and the region size grow, so distant or zoomed-out views stop flickering.

Builds on: Positional Encoding, Multivariate Gaussian, Anti-Aliasing · Leads to: Mip-NeRF, the paper that introduced it, and multi-scale neural scene representations that render the same model at any distance.

Where it's used

Zooming through one scene. A neural radiance field of a city can be viewed from a street and from a plane. A standard NeRF samples single points along each ray, so a distant building covers many pixels with one thin sample per pixel. The result is shimmering, because the high-frequency features the network learned for close-up detail change from one frame to the next. Mip-NeRF, the paper that introduced IPE, uses it to make the same model stable across scales.

Anti-aliased novel views. When a camera moves, the pixel footprint on a surface changes size. IPE gives the network a feature that changes smoothly with that size, so the image does not jump between sharp and blurred detail as the camera passes a surface at a shallow angle.

Multi-scale training for 3D content. A single model trained on images at several resolutions can use one encoding for every scale, with the footprint setting how much fine detail reaches the network. This is useful for large scenes where detail is seen at very different distances.

How it works

Think of a pixel as looking through a small cone. The cone passes through a region of space, and the question is what the network should see for that region. A point encoding answers with the features of one point. IPE answers with the average of the features over the region, which is the same as a low-pass filter applied to the encoding.

flowchart LR
  C["Pixel cone for one interval"] --> G["Gaussian with mean and covariance"]
  G --> E["Expected sine and cosine per coordinate"]
  E --> D["Damping by footprint size and frequency"]
  D --> N["Encoding fed to the network"]
  1. Start with the region, not the point. For one interval along a ray, the cone's footprint is summarised by a Gaussian with a mean μ\boldsymbol\mu and a covariance Σ\boldsymbol\Sigma. Check: the mean is where the interval sits, and the covariance is how far it spreads across the cone.
  2. Recall the point encoding. NeRF's positional encoding gives a point xx the features sin⁡(2lx)\sin(2^l x) and cos⁡(2lx)\cos(2^l x) (the sine and cosine) for frequencies l=0,1,…,L−1l = 0, 1, \dots, L-1. Check: at l=0l = 0 the features vary slowly, and at l=L−1l = L-1 they vary fastest.
  3. Average each feature over the Gaussian. For a coordinate XX that is Gaussian with mean μ\mu and variance σ2\sigma^2, the average of sin⁡(ωX)\sin(\omega X) is sin⁡(ωμ)\sin(\omega\mu) times a damping factor. The same holds for cos⁡(ωX)\cos(\omega X). Check: with no spread, σ=0\sigma = 0, the damping factor is 1 and the point encoding is recovered.
  4. Apply the damping at each frequency. At frequency 2l2^l the damping factor is exp⁡(−124lσ2)\exp\big(-\tfrac12 4^l \sigma^2\big), where exp⁡\exp is the exponential and σ\sigma is the spread. A tiny instance: with σ=0.05\sigma = 0.05 and μ=0.1\mu = 0.1 at l=3l = 3, the frequency is ω=8\omega = 8. The phase is ωμ=0.8\omega\mu = 0.8, and the damping is exp⁡(−0.08)≈0.923\exp(-0.08) \approx 0.923. Check: the point encoding of sin⁡(0.8)\sin(0.8) is 0.7170.717, and the averaged one is about 0.6620.662, which is 0.9230.923 times the point value.
  5. Let fine frequencies disappear. Because the damping grows with the square of the frequency, a wide footprint removes the highest frequencies and keeps the coarse ones, so the encoding acts as a low-pass filter on position. Check: the damping factor is between 0 and 1, and it falls as ll rises.
  6. Feed the result to the network. The encoding of the interval, one entry per coordinate and frequency, replaces the point encoding. The network then renders the interval from its averaged features. Check: a far interval with a wide footprint gets few high-frequency entries, so it cannot depend on detail smaller than its footprint.

The plot shows the damping factor for two footprint sizes. A wider footprint, here σ=0.5\sigma = 0.5, drops below about 0.14 by frequency 4, while a narrow footprint, σ=0.05\sigma = 0.05, still keeps about 0.92 at frequency 8.

051015202530354000.20.40.60.81frequency omegadamping factor
  • sigma = 0.05
  • sigma = 0.5
The damping factor exp(-(1/2) omega^2 sigma^2) for two footprint sizes. The marked point is omega = 8 with sigma = 0.05, where the factor is about 0.923.

The math

Setting

The point encoding that NeRF uses for a coordinate xx is a list of sine and cosine pairs,

γ(x)=(sin⁡(20x),cos⁡(20x),…,sin⁡(2L−1x),cos⁡(2L−1x)).\gamma(x) = \big(\sin(2^0 x), \cos(2^0 x), \dots, \sin(2^{L-1} x), \cos(2^{L-1} x)\big).

NeRF multiplies the input by π\pi before the sines. That scaling only changes the units of the coordinate, so the derivation below drops it. Let ωl=2l\omega_l = 2^l be the frequency of level ll. The paper models the region of an interval with a multivariate Gaussian N(μ,Σ)\mathcal{N}(\boldsymbol\mu, \boldsymbol\Sigma), matched to the cone's mean and covariance. The approximation is the paper's choice, and the rest of this section takes it as given.

Step 1 in symbols: the expected value of one coordinate

Let XX be one coordinate of the region, a random variable with X∼N(μ,σ2)X \sim \mathcal{N}(\mu, \sigma^2). The average E[eiωX]\mathbb{E}[e^{i\omega X}] of a complex exponential is called the characteristic function of XX. Here ii is the imaginary unit (i2=−1i^2 = -1), and by Euler's formula eiθ=cos⁡θ+isin⁡θe^{i\theta} = \cos\theta + i\sin\theta, so the real part of the average is the average of the cosine and the imaginary part is the average of the sine. For a normal variable the characteristic function has a closed form,

E[eiωX]=eiωμ−12ω2σ2.\mathbb{E}\big[e^{i\omega X}\big] = e^{i\omega\mu - \tfrac12 \omega^2\sigma^2}.

Taking the real part gives E[cos⁡(ωX)]=cos⁡(ωμ) e−12ω2σ2\mathbb{E}[\cos(\omega X)] = \cos(\omega\mu)\, e^{-\frac12\omega^2\sigma^2}, and the imaginary part gives E[sin⁡(ωX)]=sin⁡(ωμ) e−12ω2σ2\mathbb{E}[\sin(\omega X)] = \sin(\omega\mu)\, e^{-\frac12\omega^2\sigma^2}. The factor e−12ω2σ2e^{-\frac12\omega^2\sigma^2} is the damping. It is the same for sine and cosine, and it depends only on the spread of the coordinate.

Step 2 in symbols: the integrated encoding

The encoding is applied to each coordinate separately, so each coordinate's expectation needs only its own marginal variance Σjj\Sigma_{jj}, which is the jj-th diagonal entry of Σ\boldsymbol\Sigma. The integrated encoding of a Gaussian region is therefore

IPE(μ,Σ)={ (sin⁡(2lμj) Λl,j, cos⁡(2lμj) Λl,j)}l=0,…,L−1, j=1,…,d,Λl,j=exp⁡(−12 4l Σjj).\mathrm{IPE}(\boldsymbol\mu, \boldsymbol\Sigma) = \Big\{\,\big(\sin(2^l\mu_j)\,\Lambda_{l,j},\ \cos(2^l\mu_j)\,\Lambda_{l,j}\big)\Big\}_{l=0,\dots,L-1,\ j=1,\dots,d},\qquad \Lambda_{l,j} = \exp\Big(-\tfrac12\, 4^{l}\,\Sigma_{jj}\Big).

Here dd is the number of coordinates, μj\mu_j is the jj-th entry of the mean, and Λl,j\Lambda_{l,j} is the damping at level ll for coordinate jj. Because Σjj\Sigma_{jj} is the variance of coordinate jj alone, the only approximation in this formula is the Gaussian itself.

Step 3 in symbols: the damping

Since 4l=(2l)24^l = (2^l)^2, the damping is

Λl=exp⁡(−12 4lσ2).\Lambda_l = \exp\big(-\tfrac12\, 4^{l}\sigma^2\big).

For a fixed footprint σ\sigma, Λl\Lambda_l falls as ll grows, and it falls faster for wider footprints. Two facts follow directly. Frequencies with 2lσ≪12^l\sigma \ll 1 pass almost unchanged, because the exponent is near zero. Frequencies with 2lσ≫12^l\sigma \gg 1 are wiped out, because the exponent is large and negative. The transition happens around 2lσ≈12^l\sigma \approx 1, which is where the spread is about 1/ω1/\omega of the coordinate, roughly a sixth of the wavelength 2π/ω2\pi/\omega of that frequency.

Worked examples

Example
1. One coordinate with no spread, then with spread
  1. Take a coordinate with mean μ=0\mu = 0 and frequency l=0l = 0, so ω=1\omega = 1.
  2. For a point, σ=0\sigma = 0. The damping is exp⁡(0)=1\exp(0) = 1, so the encoding is (sin⁡0,cos⁡0)=(0,1)(\sin 0, \cos 0) = (0, 1).
  3. Now let the coordinate spread with σ=1\sigma = 1. The damping is exp⁡(−12⋅1⋅1)=e−0.5≈0.607\exp(-\tfrac12 \cdot 1 \cdot 1) = e^{-0.5} \approx 0.607.
  4. The integrated cosine is cos⁡(0)⋅0.607=0.607\cos(0) \cdot 0.607 = 0.607, and the integrated sine is sin⁡(0)⋅0.607=0\sin(0) \cdot 0.607 = 0.
  5. Interpretation: the point encoding says the cosine is 1, but the average over the spread region is 0.607. Averaging pulls the feature toward zero, because the cosine is not linear in the coordinate.
Example
2. Standard: a mid-frequency feature
  1. Take a coordinate with mean μ=0.1\mu = 0.1, spread σ=0.05\sigma = 0.05, and level l=3l = 3, so ω=23=8\omega = 2^3 = 8.
  2. The phase is ωμ=8×0.1=0.8\omega\mu = 8 \times 0.1 = 0.8. The point features are sin⁡(0.8)≈0.7174\sin(0.8) \approx 0.7174 and cos⁡(0.8)≈0.6967\cos(0.8) \approx 0.6967.
  3. The damping exponent is 12ω2σ2=12⋅64⋅0.0025=0.08\tfrac12 \omega^2\sigma^2 = \tfrac12 \cdot 64 \cdot 0.0025 = 0.08, so the damping is e−0.08≈0.9231e^{-0.08} \approx 0.9231.
  4. The integrated sine is 0.7174×0.9231≈0.66220.7174 \times 0.9231 \approx 0.6622.
  5. The integrated cosine is 0.6967×0.9231≈0.64310.6967 \times 0.9231 \approx 0.6431.
  6. Interpretation: the spread is small, 0.05 in scene units, so the features change little, and the damping removes about 8 percent of each feature. The network sees a slightly weaker signal, not a different one.
Example
3. Realistic: a distant surface in a ten-level encoding

Suppose a NeRF uses L=10L = 10 levels, so l=0,…,9l = 0, \dots, 9, and a distant surface gives a footprint with σ=0.01\sigma = 0.01 in normalised scene units. These numbers are illustrative.

  1. At level l=7l = 7, ω=128\omega = 128 and 47=163844^7 = 16384. The exponent is 12⋅16384⋅0.0001=0.8192\tfrac12 \cdot 16384 \cdot 0.0001 = 0.8192, so the damping is e−0.8192≈0.441e^{-0.8192} \approx 0.441.
  2. At level l=8l = 8, 48=655364^8 = 65536. The exponent is 12⋅65536⋅0.0001=3.2768\tfrac12 \cdot 65536 \cdot 0.0001 = 3.2768, so the damping is e−3.2768≈0.038e^{-3.2768} \approx 0.038.
  3. At level l=9l = 9, 49=2621444^9 = 262144. The exponent is 12⋅262144⋅0.0001≈13.1\tfrac12 \cdot 262144 \cdot 0.0001 \approx 13.1, so the damping is about 2×10−62 \times 10^{-6}.
  4. Interpretation: the coarse levels still carry the surface's shape, while the finest two are close to zero. The network receives no usable signal from the finest detail, so it cannot learn to rely on it at that distance, and the flicker from that detail does not appear.

Try it: at level l=4l = 4 with σ=0.05\sigma = 0.05, what fraction of the point's feature survives? Answer: ω=16\omega = 16, so the exponent is 12⋅256⋅0.0025=0.32\tfrac12 \cdot 256 \cdot 0.0025 = 0.32, and the surviving fraction is e−0.32≈0.726e^{-0.32} \approx 0.726.

Common mistakes and tradeoffs

It is tempting to think the encoding of a region is the encoding of its centre. In fact the sine and cosine are not linear, so averaging them is not the same as encoding the average. A cosine at the centre of a region can be 1 while the average over the region is 0.607, as in the first example. The centre encoding overstates the detail the region can show.

It is tempting to think integrated encoding removes aliasing completely. In fact it only attenuates frequencies that a footprint cannot resolve, and the result is only as good as the Gaussian approximation of the footprint. A cone is not exactly a Gaussian, and the paper's claims rest on that approximation.

It is tempting to think integrated encoding is a blur applied to the output image. In fact the damping acts on the network's input, so the network learns from the features each footprint can resolve. The output stays sharp where the footprint is narrow, which is the point of making the encoding depend on scale.

SituationPoint encodingIntegrated encoding
One scale, close-up views onlySimple and fastUnnecessary cost, little gain
Views from near and far in one modelFlicker from fine detail at a distanceStable, because far footprints lose fine detail
Training on images at several resolutionsNeeds a separate model or manual filteringOne encoding covers every scale
Need the cheapest possible forward passOnly sines and cosinesAdds an exponential and a covariance per sample

Use integrated encoding when the same model must render at many scales, or when the camera moves through a scene so that footprints change size. Skip it when every view is at one scale, since the point encoding is simpler.

History

Neural scene models of the early 2020s used sine and cosine features to let a multilayer perceptron represent high-frequency detail. NeRF in 2020 used such features at fixed frequencies for each point along a ray, which gave sharp images at a single scale but no control over the scale of the detail. Mip-NeRF, by Barron and colleagues in 2021, observed that rendering a pixel should integrate over its footprint, not sample a point, and derived the integrated encoding in closed form for Gaussian regions. The signal-processing idea behind it is older: a sampled signal can only represent frequencies below half the sampling rate, and a low-pass filter that averages over a region removes the rest before sampling. The paper ties the two ideas together for neural fields.

Recap

  • A point encoding of position uses sines and cosines at frequencies 2l2^l, which lets a network represent fine detail but also makes distant views alias.
  • The integrated encoding averages those features over a Gaussian region, and for each coordinate the average is the point feature times a damping factor exp⁡(−124lσ2)\exp(-\tfrac12 4^l \sigma^2).
  • The damping is a low-pass filter. Wide footprints remove the fine frequencies, so the network sees only what the footprint can resolve.
  • The result is a single model that renders stably at many scales, at the cost of an exponential and a covariance for each sample.
  • Read next: NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis for the point encoding it replaces, and Mip-NeRF for the full method and its results.

Check yourself

QuestionRecall: what does integrated positional encoding average over, and what factor multiplies each sine and cosine feature?Show answer
It averages the sine and cosine features over the Gaussian region that the pixel's footprint covers, rather than evaluating them at one point. For a coordinate with spread sigma at frequency 2^l, each feature is multiplied by the damping factor exp(-(1/2) 4^l sigma^2), which is the average of the cosine or sine over that spread.
QuestionComputation: a coordinate has mean 0, spread sigma = 0.5, and frequency omega = 4 (level l = 2). What is the integrated cosine, and what is the integrated sine?Show answer
The damping exponent is (1/2) times omega squared times sigma squared, which is (1/2) times 16 times 0.25 = 2. The damping is e^(-2), about 0.135. The integrated cosine is cos(0) times 0.135, about 0.135, and the integrated sine is sin(0) times 0.135, which is 0.
QuestionWhy: why does a wider footprint remove fine frequencies more than coarse ones, and why is that useful for a distant view?Show answer
The damping exponent grows with omega squared times sigma squared, so a wide footprint pushes high-frequency factors toward zero while coarse frequencies stay near their point values. A distant pixel covers many scene units, so detail smaller than the footprint cannot affect its colour in a stable way. Removing that detail stops the model from producing features that change from frame to frame, which is the flicker that point encodings cause at a distance.
QuestionApplied: a NeRF with 12 levels renders a building well from close up, but its distant walls flicker as the camera moves. What would you change, and what would you check?Show answer
I would replace the point encoding with integrated encoding, so that each distant sample is encoded over its footprint and the finest levels are damped for wide footprints. I would check that the footprint covariance is computed from the pixel cone at each sample, since a wrong covariance would damp the wrong levels. I would then render held-out views at several distances and check that the flicker is gone and that close-up detail is still sharp. The Gaussian is an approximation of the cone, so I would look for artefacts at grazing angles, where it is least accurate.

Sources

  • Barron, J. T., Mildenhall, B., Tancik, M., Hedman, P., Martin-Brualla, R. and Srinivasan, P. P. (2021). Mip-NeRF: A Multiscale Representation for Anti-Aliasing Neural Radiance Fields. arXiv:2103.13415. https://arxiv.org/abs/2103.13415
  • Mildenhall, B., Srinivasan, P. P., Tancik, M., Barron, J. T., Ramamoorthi, R. and Ng, R. (2020). NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis. arXiv:2003.08934. https://arxiv.org/abs/2003.08934
  • Wikipedia, "Aliasing". https://en.wikipedia.org/wiki/Aliasing