AI Wiki中文/EN

Maximum entropy: choose a distribution under explicit constraints

最大熵原理

Derive exponential weights, certify a finite maximum with KL and test moment matching against exact probabilities.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

A mean does not determine a distribution

A small device can emit 0,1 or 2 pulses. Suppose the only supplied constraint is a mean of 10/7 pulses. Many distributions fit: (0,4/7,3/7), (1/7,2/7,4/7) and (2/7,0,5/7) all do. Maximum entropy chooses the distribution with the largest Shannon entropy among the ones that satisfy the stated information.

The word “maximum” applies to this feasible set, not to all imaginable models. Choosing the possible outcomes and deciding which averages to preserve are substantive assumptions. Read entropy, Lagrange multipliers and KL divergence first.

Constrain what is known, optimize what remains

For a fixed finite alphabet with feature values fᵢ and a feasible mean μ, using natural logarithms gives entropy in nats:

max⁡pi≥0 H(p)=−∑ipiln⁡pisubject to∑ipi=1,∑ipifi=μ.\max_{p_i\ge0}\ H(p)=-\sum_i p_i\ln p_i \quad\text{subject to}\quad \sum_i p_i=1,\qquad\sum_i p_i f_i=\mu.

Define 0 ln 0=0 by continuity. The feasible set is closed, bounded and convex. Entropy is continuous and strictly concave on the probability simplex, so a nonempty feasible set has a unique maximizing distribution. Constraint multipliers need not themselves be unique if features are redundant.

For an interior solution, use L=H(p)+a(Σpᵢ−1)+λ(Σpᵢfᵢ−μ). Setting derivatives to zero gives −ln pᵢ−1+a+λfᵢ=0. Normalization removes a:

pλ(i)=eλfiZ(λ),Z(λ)=∑ieλfi,dln⁡Zdλ=Eλ[f],d2ln⁡Zdλ2=Var⁡λ(f).p_\lambda(i)=\frac{e^{\lambda f_i}}{Z(\lambda)},\qquad Z(\lambda)=\sum_i e^{\lambda f_i},\qquad \frac{d\ln Z}{d\lambda}=\mathbb E_\lambda[f],\quad \frac{d^2\ln Z}{d\lambda^2}=\operatorname{Var}_\lambda(f).

The sign of λ reflects our Lagrangian convention; choosing the opposite sign changes the parameter notation, not the distribution family. Jaynes’s 1957 paper, Section 2, printed pages 622–623, develops constrained entropy, exponential weights and the partition function. This chapter’s finite pulse example is original.

For f=(0,1,2), λ=ln 2 gives weights 1,2,4 and Z=7, hence the exact candidate q=(1,2,4)/7. Its mean is 10/7 and its feature variance is 26/49, which is positive. Thus the mean increases strictly with λ for finite λ. Bisection can solve an interior mean constraint; at μ=0 or 2, the maximizing distributions are endpoint point masses and finite λ does not suffice.

Certify the maximum, not just a stationary point

If a positive candidate q has exponential form and satisfies the constraints, every feasible p has the same expectation of ln q. Therefore:

DKL(p∥q)=∑ipiln⁡pi−∑ipiln⁡qi=H(q)−H(p)≥0.D_{\mathrm{KL}}(p\Vert q) =\sum_i p_i\ln p_i-\sum_i p_i\ln q_i =H(q)-H(p)\ge0.

KL nonnegativity, as developed in MIT’s information-measures notes, proves global optimality; equality requires p=q. This argument also covers feasible p with zero components because q is positive. In our example, writing p₂=t gives p₁=10/7−2t and p₀=t−3/7, with 3/7≤t≤5/7. It makes the entire feasible line segment visible.

Recover the exact candidate numerically

This complete Python 3.12 program solves only the three-state problem. It accepts rational endpoint means 0 and 2, or interior means in[1/1024,2047/1024]. Means outside that numerical interior band are deliberately rejected rather than silently returning a bad endpoint approximation. The mathematical maximum-entropy problem still has a solution there.

from fractions import Fraction as F
from math import exp, fsum, log


def distribution(lam):
    logits = [0.0,lam,2*lam]
    shift = max(logits)
    weights = [exp(v-shift) for v in logits]
    total = fsum(weights)
    return [w/total for w in weights]


def maxent_three(mu):
    if type(mu) not in (int,F) or not 0 <= mu <= 2:
        raise ValueError('rational mean in [0,2] required')
    if mu == 0: return [1.0,0.0,0.0],None
    if mu == 2: return [0.0,0.0,1.0],None
    if not F(1,1024) <= mu <= 2-F(1,1024):
        raise ValueError('interior numerical domain is [1/1024,2047/1024]')
    target = float(mu); lo,hi = -16.0,16.0
    for _ in range(80):
        mid = (lo+hi)/2
        if mid == lo or mid == hi: break
        p = distribution(mid)
        if p[1]+2*p[2] < target: lo=mid
        else: hi=mid
    lam=(lo+hi)/2; p=distribution(lam)
    if abs(p[1]+2*p[2]-target)>1e-12:
        raise ArithmeticError('mean residual exceeds tolerance')
    return p,lam


def entropy(p):
    return -fsum(float(x)*log(float(x)) for x in p if x)


if __name__ == '__main__':
    q=[F(1,7),F(2,7),F(4,7)]
    fitted,lam=maxent_three(F(10,7))
    print('fitted probabilities:',*[f'{x:.9f}' for x in fitted])
    print('lambda:',f'{lam:.9f}','reference log(2):',f'{log(2):.9f}')
    for name,p in [('optimum',q),('left endpoint',[F(0),F(4,7),F(3,7)]),
                   ('right endpoint',[F(2,7),F(0),F(5,7)])]:
        divergence=fsum(float(x)*log(float(x/y)) for x,y in zip(p,q) if x)
        print(name,'entropy:',f'{entropy(p):.9f}',
              'entropy gap:',f'{entropy(q)-entropy(p):.9f}',
              'KL:',f'{divergence:.9f}')

Output:

fitted probabilities: 0.142857143 0.285714286 0.571428571
lambda: 0.693147181 reference log(2): 0.693147181
optimum entropy: 0.955699891 entropy gap: 0.000000000 KL: 0.000000000
left endpoint entropy: 0.682908105 entropy gap: 0.272791786 KL: 0.272791786
right endpoint entropy: 0.598269589 entropy gap: 0.357430303 KL: 0.357430303

The exponentials use a common maximum-logit subtraction before normalization. Bracket[−16,16] covers the supported interior means. The loop stops on floating-point stagnation or after 80 iterations, and checks the actual mean residual against 10⁻¹². It does not claim an exact floating-point bracket width after stagnation. The rational q and endpoint distributions supply reference values independent of the solver.

For k states and B iterations, this one-parameter approach costs O(Bk) arithmetic operations and O(k) storage. Here k=3 and B≤80. More constraints lead to a vector-valued moment-matching problem whose curvature is a feature covariance matrix; this program does not implement that general solver.

The constraints carry the assumptions

Uniformity follows when the finite alphabet is fixed and normalization is the only constraint. It does not mean all descriptions of the world should be assigned equal probability. Splitting one category into ten labels changes the alphabet and can change the result. With a nonuniform reference measure, minimizing KL to that reference is a different, explicit choice.

On infinite or continuous supports, existence, integrability and the reference measure need separate analysis. Differential entropy changes with coordinates; copying the finite argument without those qualifications is unsafe. A noisy empirical average is also not the same as an exact known population constraint. Measurement uncertainty may warrant intervals, regularization or a likelihood model.

Jaynes argued for maximum entropy as inference from partial knowledge. That interpretive claim is not a theorem that the chosen constraints describe reality, nor does it replace held-out predictive evaluation. It is distinct from maximum likelihood, which optimizes the fit of a parameterized model to observed data.

Check feasibility before entropy

  1. Why is the uniform distribution not feasible for mean 10/7 on 0,1,2?

Answer 1: Its mean is 1, not 10/7.

  1. What are the exponential weights at λ=ln 2?

Answer 2: 1,2,4; after normalization they give(1,2,4)/7.

  1. How can an endpoint with a zero component be compared using KL to q?

Answer 3: q is positive, and the zero p component contributes 0. The identity H(q)−H(p)=KL(p||q) remains valid.

  1. Does a numerical-domain rejection at μ=1/100000 imply no mathematical maximum exists?

Answer 4: No. It lies outside this small solver’s contract; the finite feasible set still has a unique maximizer.

From moment constraints to probabilistic models

Exponential-family models connect moment matching, partition functions and convex optimization. Maximum-entropy models with interaction features can also lead to Markov random fields, where normalization may become the expensive part.

Project: add a second-moment constraint on this three-state alphabet. Determine whether the constraints uniquely specify the distribution, are inconsistent, or leave freedom, before running any optimizer. Then compare exact constraints with a tolerance interval to see how modeling choices alter the feasible set.

Make a prediction, then check

Does maximum entropy remove the need to choose a support and constraints?

Choose one answer

Learning objectives

  • Derive finite exponential weights and their moment constraints.
  • Prove global optimality and separate solver limits from mathematical existence.

Prerequisites & connections

Explore related knowledge →

References

  1. Information Theory and Statistical Mechanics
    E. T. Jaynes · 1957
  2. MIT 6.441 — Course Notes, Chapters2–3
    Yury Polyanskiy; Yihong Wu · 2016

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-06 · Codex single-agent authored technical review: cited primary-source locations, mathematical assumptions, original examples, exact/literal and numerical checks, and bilingual review; not independent human or second-agent review.

  • Single-agent authored technical review: primary-source locations, explicit assumptions and limits, mathematical derivations, literal/exact reference probabilities, bilingual equations and four matching exercises. Not independent human or second-agent review.
  • Four focused CPython3.12.4 tests passed per chapter; strict bilingual MDX/KaTeX rendering gives three display equations, six anchors and four answers. Exact rational inference is separated from floating-point maximum-entropy solving; test scopes and repository results are recorded separately.
  • Promoted the full prose, equations, code and exercises. Tests read formal MDX only; removed temporary fallbacks/draft skips and updated review assertion to checked. Algorithm and independent references are unchanged; final record binds both locale hashes.
  • Publication navigation points published topics to complete articles and removes corresponding pending wording, retaining directory entries for unwritten targets. Principles, equations, programs and exercises are unchanged; final article SHA values rebound.
  • Final English copy edit separates words from adjacent numerals outside code, equations and link destinations; formulas/programs unchanged, final SHA rebound.

Source locations checked:

  • Information Theory and Statistical Mechanics · Original scan visually read: title/date on printed620; Section2 printed622–623, constraints, entropy, exponential weights and partition derivatives. Receipt1956 not confused with publication1957.
  • MIT 6.441 — Course Notes, Chapters2–3 · 2016 course notes divergence nonnegativity and information measures; used for the independently derived entropy-gap certificate, not a claim of copying a maxent solver.

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.