---
title: "Keep both answers when a redshift distribution has two peaks"
description: "Build a normalized multimodal redshift posterior, integrate a positive amplitude exactly and distinguish peak height from probability mass."
canonical_url: "https://sandboxphysics.com/stories/galaxy-colors/when-redshift-has-two-answers/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/galaxy-colors/when-redshift-has-two-answers/"
last_modified: "2026-10-28"
---

[Galaxy colors from photons to redshift distributions](https://sandboxphysics.com/stories/galaxy-colors/)

L3 · Galaxy photometry

# Keep both answers when a redshift distribution has two peaks

Sandbox Physics · 2026-10-28

A redshift posterior assigns weight to every trial redshift after accounting for uncertain stellar age, dust and brightness. Its two peaks are two surviving explanations of the measurements. To compare their probabilities, we must specify how those other explanations are weighted and integrate them, not keep only the best fit at each redshift.

## Before you begin

The two preceding chapters define the spectral model and filter means. A probability density assigns probability to intervals through its area. A Gaussian error model makes small standardized residuals more probable than large ones.

## Write the five measurements in linear flux

Let $f_b$ be the measured mean frequency density in band b, in nanomaggies, with known standard deviation $\sigma_b$. For a fixed redshift, age and dust, divide all predicted band means by the predicted observed r-band mean. The resulting shape $s_b$ has r component one. A positive amplitude A then has a concrete unit: the model observed r-band mean in nanomaggies.

Assume independent Gaussian errors in these fluxes. Keep negative measured values; the error model concerns a noisy estimate around a positive true prediction. Independence is a teaching approximation for real survey measurements, whose calibration errors may be correlated.

$$
\chi^2(A,z,t,E)=\sum_{b\in\mathrm{used}}\frac{(f_b-A s_b(z,t,E))^2}{\sigma_b^2},\qquad p(\boldsymbol f\mid A,z,t,E)\propto e^{-\chi^2/2}
$$

The omitted Gaussian normalization is common to every trial because these errors are held fixed. If a model changes the variance, that normalization must be retained too.

Reading: Brammer · SDSS DR17 imaging fluxes and flux calibration

## An amplitude prior needs a scale and a normalization

A free overall amplitude removes the unknown stellar mass and distance from the colors. Marginalizing an improper uniform amplitude prior would leave an arbitrary scale, especially if each template were normalized differently. We instead define the observed-r normalization first and choose a proper half-normal amplitude prior with fixed scale ten thousand nanomaggies.

The prior favors positive brightness and integrates to one. Its scale is intentionally much broader than the default one-hundred-nanomaggy signal. It remains a model choice: faint or weakly constrained sources can depend more strongly on it. Spectroscopic holdouts must not be used to tune that scale while claiming independent validation.

$$
p(A)=\sqrt{\frac{2}{\pi}}\frac{1}{\tau}\exp\!\left(-\frac{A^2}{2\tau^2}\right),\quad A\geq0,\quad \tau=10^4\,\mathrm{nMgy}
$$

The probability density carries inverse-flux units. Choosing an amplitude unit or renormalizing a template also requires transforming its prior.

Reading: Hogg et al. · Brammer

## Complete the square and do the amplitude integral

Expand the residual squares. The terms quadratic in amplitude combine with the prior precision; the linear term is a weighted data–shape overlap. Completing the square turns the positive-amplitude integral into the area of a displaced Gaussian above zero.

This integral differs from choosing the amplitude that minimizes the residual. The extra width factor rewards parameter regions that fit over a wider range of amplitudes. The Gaussian cumulative probability accounts for the positive boundary. Both terms matter when comparing different colors and low-signal measurements.

$$
S=\sum_b\frac{s_b^2}{\sigma_b^2}+\tau^{-2},\quad B=\sum_b\frac{f_bs_b}{\sigma_b^2},\quad C=\sum_b\frac{f_b^2}{\sigma_b^2}
$$

Only used bands enter these sums. S is the amplitude precision after the prior, B is the weighted overlap and C is the squared data term.

$$
I(z,t,E)=\frac{2\Phi(B/\sqrt S)}{\tau\sqrt S}\exp\!\left[-\frac12\left(C-\frac{B^2}{S}\right)\right]
$$

I is the amplitude-marginal likelihood up to the fixed measurement normalization. Phi is the standard normal cumulative distribution. The code evaluates its logarithm and checks this expression against independent numerical quadrature.

Reading: Brammer · Hogg et al.

## Sum nuisance models and normalize redshift area

A nuisance parameter is a quantity needed to predict the data even when it is not the final question. Here age and dust play that role. Assign equal discrete prior weight to the six dust nodes and to the allowed age nodes at each redshift. Ages older than the assumed universe are excluded; renormalizing the age weights at each redshift defines a conditional age prior.

The redshift prior has uniform density from zero to 1.2. Evaluate every redshift node separated by 0.005, sum the age and dust alternatives with their prior weights, then normalize the area with the trapezoidal rule. Small peaks and steps can reflect the finite template grid. These are discrete nuisance priors; changing the number or spacing of age nodes changes the model unless the weights are adjusted.

A curve made from the minimum chi-square at each redshift would be a profile likelihood. It answers which single fit works best at each position. The curve here is a posterior under the stated priors, including all allowed nuisance states and the analytic amplitude integral.

$$
p(z\mid\boldsymbol f)=\frac{p(z)\sum_{t,E}p(t,E\mid z)I(z,t,E)}{\int_0^{1.2}p(z')\sum_{t,E}p(t,E\mid z')I(z',t,E)\,dz'}
$$

The denominator is a probability normalization, not a best-fit adjustment. Numerical integration includes both endpoint half-weights. Every separated peak survives this operation.

Reading: Brammer · Bruzual & Charlot

## Work through the saved default observation

The source is generated at redshift 0.325, age 2.154 billion years and continuum color excess 0.1, with true r mean one hundred nanomaggies. Fixed Gaussian draws give the fluxes below. Errors combine the stated fractional errors with a half-nanomaggy floor. Regenerating the same parameter setting reuses these draws.

The highest peak lies at 0.320 and the central 68 percent interval runs from 0.268 to 0.427. A second local peak lies near 0.425; its basin between neighboring local minima contains about 36.7 percent of the total probability. Peak height and integrated probability are different quantities. A wide lower hill can contain more probability than a narrow high one.

Removing u from the fit moves the highest peak to 0.545 and widens the central interval to approximately 0.263–0.547. The actual generating redshift has not changed. The extra ambiguity comes from losing one color measurement. The white template markers show a conditional fit at the highest peak, not a posterior-average spectrum.

| Band | Synthetic flux | Standard deviation |
| --- | --- | --- |
| u | $3.087$ | $0.573$ |
| g | $24.187$ | $0.974$ |
| r | $99.453$ | $3.041$ |
| i | $174.991$ | $5.930$ |
| z | $230.349$ | $11.781$ |

Reading: Doi et al. · EzGal model distribution

## Try the observation

### [Track probability rather than a single answer](https://sandboxphysics.com/labs/galaxy-colors-photometric-redshift/)

1. Find the default highest and secondary peaks and compare them with the saved numbers.
2. Turn off u. Identify both surviving redshift regions before reading the highest-peak readout. Explain how a smaller conditional residual can accompany a broader redshift distribution.

## Exercises and explained answers

The posterior median falls in a valley between two peaks. Is this a numerical failure?

No. The median divides integrated probability into equal halves; it need not maximize probability density. Report the curve and mode locations. A central interval can also span a low-density valley, so its endpoints alone may hide a separated alternative.

You double the number of dust nodes near one favored value and keep equal weights. Have you only improved numerical resolution?

You changed the prior mass near that value. To approximate a continuous dust prior, use weights proportional to the cell widths times the prior density. This Lab deliberately specifies a finite discrete prior, so its nodes and weights are part of the model.

A new infrared band is available. Which band placement best separates two candidate redshifts?

Compare the competing predicted spectra after allowing their own age, dust and amplitude. Prefer a band where their predicted fluxes differ by more than the achievable measurement and model errors. A band where both spectra are nearly proportional mainly refines amplitude.

[Previous: Redshift stretches a spectrum and dust reshapes it](https://sandboxphysics.com/stories/galaxy-colors/dust-and-moving-spectra/) [Next: Reproduce redshift distributions for twenty-four real SDSS galaxies](https://sandboxphysics.com/stories/galaxy-colors/sdss-five-band-tutorial/)

## Sources and calculation scope

1. [Hogg et al., The K correction, astro-ph/0210394v1 (2002)](https://arxiv.org/abs/astro-ph/0210394v1)

   Equations (2)–(12): spectral densities, photon response, redshift factors and the AB K correction. We use luminosity distance and define wavelength densities per Angstrom.

2. [Doi et al., Photometric Response Functions of the SDSS Imager, arXiv:1002.3701v1 (2010)](https://arxiv.org/abs/1002.3701v1)

   Table 4 response curves as distributed by speclite at commit 8159ea61f1c8539136660b4c2e87fbbf94a70097. The sdss2010 quantum throughputs already include an atmosphere at airmass 1.3; source files and BSD notice are retained.

3. [Bruzual & Charlot, Stellar population synthesis at the resolution of 2003, astro-ph/0309134v1](https://arxiv.org/abs/astro-ph/0309134v1)

   Sections 2–3 describe the stellar-population model and its spectral evolution. The frozen solar-metallicity Salpeter SSP file is distributed by EzGal; this course fixes its model choices rather than inferring a general galaxy age.

4. [EzGal model distribution, commit 133c62b383fae964701b673e62517293161b41d5](https://github.com/cmancone/easyGalaxy/tree/133c62b383fae964701b673e62517293161b41d5)

   tests/data/bc03\_ssp\_z\_0.02\_salp.model, primary image and the vs/ages FITS tables. README acknowledgements explicitly describe the model authors’ redistribution permission; the repository MIT notice is retained. Spectra are converted from fnu at ten parsecs into relative shapes.

5. [SDSS DR17 imaging fluxes and flux calibration](https://www.sdss4.org/dr17/algorithms/fluxcal/)

   The AB-offset and physical-flux sections state the approximate u shift, tentative z shift and their uncertainties. The tutorial freezes TOP 24 clean primary GALAXY spectra with zWarning=0 ordered by specObjID, keeping linear modelFlux values and inverse variances.

6. [Brammer, van Dokkum & Coppi, EAZY: A Fast, Public Photometric Redshift Code, arXiv:0807.1533v1 (2008)](https://arxiv.org/abs/0807.1533v1)

   Sections 2.1–2.5: template combinations, template error, priors and output redshifts. Section 3.3 and section 4, especially Figures 8–11, connect the error model and priors to real validation. Our finite SSP posterior is a separate teaching calculation.
