关于「正态与均匀两条捷径的代价:分位数、对数损失与极小极大」,《最大熵需求重建》给出的定量结论是什么?

结论:第三章以三把尺子比较三种做法:在四个示意真相下,最大熵的对数损失恒为 7.080 比特,最坏情形最小;第 90 百分位的最坏误差却是正态捷径更小,18.8 对 23.5 元。

数据口径:本书推翻这一常识:正态捷径私加了对称形状与标准差,示意参数下均值 80、下限 30 时它把 0.133 的概率放在不可能的区间,均值 40 时升到 0.412;均匀捷径隐含均值在区间中点,直接违背已知均值。 只承认上下限与均值时,杰恩斯 1957 年提出的最大熵原则给出截断指数分布,示意甜品店的第 90 百分位客单为 146.0 元。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 18.8, 23.5, 90

truth max-ent b(2,8.8) b(1.2,5.28) two-hump
true P5065.4 74.7 71.1 60.9
true P90146.0 122.5 134.9 156.5
abs error of P50
max-ent0.0 9.3 5.7 4.5 worst 9.3
normal14.6 5.3 8.9 19.1 worst 19.1
uniform99.6 90.3 93.9 104.1 worst 104.1
abs error of P90
max-ent0.0 23.5 11.2 10.5 worst 23.5
normal8.4 15.1 2.8 18.8 worst 18.8
uniform127.0 150.5 138.1 116.5 worst 150.5
查看完整验算程序
# Chapter 3. p33: quantile errors of each forecast under each truth.
# Model: the four illustrative truths of p32 (all on [30, 300], mean
# 80). For each forecast we compare its P50 and P90 with the true ones;
# true quantiles come from bisection on a Simpson-rule distribution
# function (math.fsum). We report the worst absolute error across the
# four truths, the figure an owner who does not know the shape faces.
import math
from statistics import NormalDist

A, B, M = 30.0, 300.0, 80.0
L = B - A
FR = (M - A) / L


def simpson(f, lo, hi, n=2000):
    h = (hi - lo) / n
    terms = [f(lo), f(hi)]
    terms += [4.0 * f(lo + i * h) for i in range(1, n, 2)]
    terms += [2.0 * f(lo + i * h) for i in range(2, n, 2)]
    return math.fsum(terms) * h / 3.0


def integ(f, n=2000, hi=B):
    # x = A + v * v removes the kink of densities that start at A
    g = lambda v: f(A + v * v) * 2.0 * v
    return simpson(g, 0.0, math.sqrt(hi - A), n)


def te_mean(lam):
    u = lam * L
    if abs(u) < 1e-8:
        return A + L / 2.0
    return A + 1.0 / lam - L / math.expm1(u)


def solve(m):
    lo, hi = -2.0, 2.0
    for _ in range(80):
        mid = (lo + hi) / 2.0
        if te_mean(mid) > m:
            lo = mid
        else:
            hi = mid
    return (lo + hi) / 2.0


def te_pdf(lam):
    return lambda x: lam * math.exp(-lam * (x - A)) / -math.expm1(-lam * L)


def te_q(lam, p):
    return A - math.log1p(p * math.expm1(-lam * L)) / lam


def beta_pdf(u, al, be):
    if u <= 0.0 or u >= 1.0:
        return 0.0
    lg = math.lgamma(al + be) - math.lgamma(al) - math.lgamma(be)
    return math.exp(lg + (al - 1) * math.log(u) + (be - 1) * math.log1p(-u))


def beta_x(al, be):
    return lambda x: beta_pdf((x - A) / L, al, be) / L


F2 = (FR - 0.75 * 0.1) / 0.25
MIX = ((0.75, 4.0, 36.0), (0.25, 8.0, 8.0 * (1 - F2) / F2))


def mix_pdf(x):
    return math.fsum(w * beta_x(a, b)(x) for w, a, b in MIX)


def truths():
    lam = solve(M)
    return [("max-ent", te_pdf(lam)),
            ("b(2,8.8)", beta_x(2.0, 8.8)),
            ("b(1.2,5.28)", beta_x(1.2, 5.28)),
            ("two-hump", mix_pdf)]


def quantile(f, p):
    lo, hi = A, B
    for _ in range(40):
        mid = (lo + hi) / 2.0
        if integ(f, 400, mid) < p:
            lo = mid
        else:
            hi = mid
    return (lo + hi) / 2.0


if __name__ == "__main__":
    lam = solve(M)
    nd = NormalDist(M, L / 6.0)
    ts = truths()
    tq = {p: [quantile(t, p) for _, t in ts] for p in (0.5, 0.9)}
    print("  truth    " + "".join("{:>12}".format(n) for n, _ in ts))
    for p in (0.5, 0.9):
        print("  true P{:<2.0f} ".format(100 * p)
              + "".join("{:>12.1f}".format(v) for v in tq[p]))
    fc = [("max-ent", lambda p: te_q(lam, p)),
          ("normal", nd.inv_cdf),
          ("uniform", lambda p: A + p * L)]
    for p in (0.5, 0.9):
        print("abs error of P{:.0f}".format(100 * p))
        for name, q in fc:
            err = [abs(q(p) - v) for v in tq[p]]
            print("  {:<9}".format(name)
                  + "".join("{:>12.1f}".format(e) for e in err)
                  + "  worst {:>5.1f}".format(max(err)))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《最大熵原理与缺数据需求重建、仅知均价与上下限时最不偏的客单分布推断母典》第 3 章「正态与均匀两条捷径的代价:分位数、对数损失与极小极大」(版本 1.0.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-301 · v1.0.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026301,
  author    = {Fan, Yafu},
  title     = {The Maximum-Entropy Principle and Demand Reconstruction from Missing Data: the Least-Biased Order-Value Distribution Given Only a Mean and Bounds},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论