关于「东西方原典考辨:《孙子·用间》的先知与香农的采样计数」,《稀疏探针与暗折重构》给出的定量结论是什么?

结论:第七章考辨《孙子·用间》「先知必取于人」与香农的采样计数:示意账目中类推损失 59400 元、全盘抽样 57600 元、稀疏探针 12960 元;商品每多十倍,稀疏计数只多 17.3 次。

数据口径:只要暗折是稀疏的,把商品随机组合成购物车、只读结算总额,所需报价次数大致与暗折数乘以商品数对暗折数之比的对数成正比,远少于商品数;在非负约束下极小化一范数,无噪声时得到的是精确的表。 书中商品、金额、成本与竞品均为示意;全部计算由书中程序生成;本书是非个人化经营参考,不是法律意见。

English version

对照数据表

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

n = 120, 24 months, sparse plan m = 24 + 3 hold-outs
policyquotesquote costmissed item-monthslosstotal
analogy00995940059400
census2880576000057600
sparse648129600012960
months where a hold-out forced extra quotes: 0
查看完整验算程序
# Chapter 7. p71: "grudging a hundred pieces of gold" as arithmetic.
# Model (illustrative): a store prices n = 120 items against one
# competitor. Each month every hidden discount survives with chance
# 0.6 and new ones appear so that about k = 5 are live (Poisson
# arrivals, mean 2). An item whose hidden discount we do not know
# costs 600 yuan of margin that month; one basket quote costs 20 yuan
# of staff time. Three policies over 24 months (seed 20261171):
#   analogy - keep the month-0 census table (Sunzi: "by analogy");
#   census  - quote every item alone each month (n quotes);
#   sparse  - m = ceil(1.5 k ln(n/k)) basket quotes plus 3 hold-out
#             quotes; if a hold-out fails, add 8 quotes and refit,
#             and after two failures fall back to a census.
import math
import random
from fractions import Fraction as Fr

def esum(v):
    s = Fr(0)
    for t in v:
        s += t
    return s


def lp_min(A, b, c, exact=False):
    # min c.x subject to A x = b, x >= 0: two-phase tableau simplex.
    # b is nudged to b + A d (d_j > 0, tiny, distinct) so that no
    # pivot is degenerate; the final basis is re-applied to the true
    # b through B^-1. Exact mode uses fractions and Bland's rule.
    m, n = len(A), len(A[0])
    cv = Fr if exact else float
    add = esum if exact else math.fsum
    tol = 0 if exact else 1e-9
    big = 1 + max(abs(v) for v in b)
    d = [Fr(1, 2 ** (30 + j)) if exact else
         1e-7 * big * (0.5 + (0.6180339887 * (j + 1)) % 1.0)
         for j in range(n)]
    T, sg = [], []
    for i in range(m):
        s = -1 if b[i] < 0 else 1
        row = [cv(s * v) for v in A[i]] + [cv(0)] * (m + 1)
        row[n + i] = cv(1)
        row[-1] = cv(abs(b[i])) + s * add([A[i][j] * d[j]
                                           for j in range(n)])
        T.append(row)
        sg.append(s)
    basis = [n + i for i in range(m)]
    W = n + m

    def pivot(r, q, z):
        pv = T[r][q]
        T[r] = [v / pv for v in T[r]]
        pr = T[r]
        nz = [j for j in range(W + 1) if pr[j] != 0]
        for row in T + [z]:
            f = row[q]
            if row is not pr and f != 0:
                for j in nz:
                    row[j] -= f * pr[j]
        basis[r] = q

    def run(z, stop):
        piv = 0
        while not (stop and -z[W] <= tol):
            q, best = -1, -1e-7
            for j in range(n):
                if exact and z[j] < 0:
                    q = j
                    break
                if not exact and z[j] < best:
                    q, best = j, z[j]
            if q < 0:
                return piv
            r, rt = -1, None
            for i in range(m):
                if T[i][q] > tol:
                    t = T[i][W] / T[i][q]
                    if rt is None or t < rt:
                        r, rt = i, t
            pivot(r, q, z)
            piv += 1
        return piv

    z = [cv(0)] * (W + 1)
    for j in list(range(n)) + [W]:
        z[j] = -add([T[i][j] for i in range(m)])
    piv = run(z, True)
    if -z[W] > (0 if exact else 1e-6 * big):
        return None, None, piv
    z = [cv(v) for v in c] + [cv(0)] * (m + 1)
    for i in range(m):
        if basis[i] < n and z[basis[i]] != 0:
            f = z[basis[i]]
            z = [z[j] - f * T[i][j] for j in range(W + 1)]
    piv += run(z, False)
    x = [cv(0)] * n
    for i in range(m):
        if basis[i] < n:
            x[basis[i]] = add([T[i][n + j] * abs(b[j])
                               for j in range(m)])
    lam = [-sg[j] * z[n + j] for j in range(m)]
    return x, lam, piv


def poisson(rng, lam):
    # Knuth: multiply uniforms until the product drops below e^-lam
    t, k, p = math.exp(-lam), 0, rng.random()
    while p > t:
        p *= rng.random()
        k += 1
    return k


def sparse_month(rng, n, x, m):
    A = [[1 if rng.random() < 0.5 else 0 for _ in range(n)]
         for _ in range(m + 3)]
    used = m + 3
    for _ in range(3):
        y = [int(math.fsum(A[i][j] * x[j] for j in range(n)))
             for i in range(len(A))]
        fit = len(A) - 3
        xh, _, _ = lp_min(A[:fit], y[:fit], [1] * n)
        xr = [round(v) for v in xh]
        if all(round(math.fsum(A[i][j] * xr[j] for j in range(n)))
               == y[i] for i in range(fit, len(A))):
            return xr, used
        extra = [[1 if rng.random() < 0.5 else 0 for _ in range(n)]
                 for _ in range(8)]
        A = A[:fit] + extra + A[fit:]
        used += 8
    return list(x), used + n


rng = random.Random(20261171)
n, months, cq, loss = 120, 24, 20, 600
m = math.ceil(1.5 * 5 * math.log(n / 5))
x = [0] * n
for j in rng.sample(range(n), 5):
    x[j] = rng.randint(5, 60)
known = list(x)
tally = {"analogy": [0, 0], "census": [0, 0], "sparse": [0, 0]}
fails = 0
for t in range(months):
    x = [v if v and rng.random() < 0.6 else 0 for v in x]
    for j in rng.sample(range(n), poisson(rng, 2.0)):
        x[j] = rng.randint(5, 60)
    tally["analogy"][1] += len([j for j in range(n)
                                if x[j] and known[j] != x[j]])
    tally["census"][0] += n
    xr, used = sparse_month(rng, n, x, m)
    fails += used > m + 3
    tally["sparse"][0] += used
    tally["sparse"][1] += len([j for j in range(n) if xr[j] != x[j]])
print("n = %d, %d months, sparse plan m = %d + 3 hold-outs"
      % (n, months, m))
print("policy    quotes   quote cost   missed item-months   loss"
      "    total")
for p in ("analogy", "census", "sparse"):
    q, miss = tally[p]
    print("%-8s %7d  %11d  %19d  %6d  %7d"
          % (p, q, q * cq, miss, miss * loss, q * cq + miss * loss))
print("months where a hold-out forced extra quotes: %d" % fails)

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《压缩感知一范数极小化、神秘访客稀疏探针与竞品暗折矩阵精确重构母典》第 7 章「东西方原典考辨:《孙子·用间》的先知与香农的采样计数」(版本 1.0.0). 5D Library. DOI 待发布

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

BibTeX
@book{fan2026242,
  author    = {Fan, Yafu},
  title     = {Compressed Sensing and L1 Minimisation: Sparse Mystery-Shopper Probes and the Exact Recovery of Competitors' Hidden-Discount Matrices},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论