关于「两部编码账本:一条规则要修正多少条例外才算挣回自己的篇幅」,《规则库的奥卡姆剃刀》给出的定量结论是什么?
结论:第二章建立两部编码账本:一条准确率超过八成、却只净修正 7 条例外的窄规则挣不回自己的篇幅;在合成台账上,门槛从提议者的 12 条规则中只放进 3 条,第三条的余量仅 2.9 个比特。
数据口径:书中的决策记录全部合成、参数均为示意,全部计算由书中程序生成;本书是非个人化的经营分析,不构成经营建议。 第二章建立两部编码账本:一条准确率超过八成、却只净修正 7 条例外的窄规则挣不回自己的篇幅;在合成台账上,门槛从提议者的 12 条规则中只放进 3 条,第三条的余量仅 2.9 个比特。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 12, 2.9
| 1347 candidates, N 600, exceptions with no rule 172 | |||||||
| k | proposed rule | new | net | save | cost | margin | gate |
| 1 | sg=2&ss=1 | 55 | 37 | 57.0 | 12.5 | 44.5 | ADMIT |
| 2 | ch=0&bd=3 | 37 | 31 | 64.2 | 10.9 | 53.3 | ADMIT |
| 3 | ss=3&rg=4 | 23 | 7 | 16.2 | 13.2 | 2.9 | ADMIT |
| 4 | ch=3&rg=4 | 19 | 3 | 7.2 | 11.2 | -4.0 | reject |
| 5 | sg=1&ss=2&rg=4 | 5 | 5 | 12.3 | 13.2 | -0.9 | reject |
| 6 | ch=1&bd=3&rg=4 | 8 | 2 | 5.1 | 13.6 | -8.6 | reject |
| 7 | bd=1&ss=0&rg=4 | 2 | 2 | 5.1 | 15.6 | -10.5 | reject |
| 8 | bd=0&sz=1&rg=1 | 6 | 2 | 5.2 | 13.2 | -8.0 | reject |
| 9 | bd=1&sz=0&rg=4 | 2 | 2 | 5.3 | 13.2 | -7.9 | reject |
| 10 | ss=2&sz=1&rg=1 | 4 | 2 | 5.4 | 13.2 | -7.8 | reject |
| 11 | ch=0&sz=2&rg=2 | 3 | 1 | 2.7 | 13.2 | -10.5 | reject |
| 12 | bd=3&sz=0&rg=4 | 1 | 1 | 2.7 | 13.2 | -10.5 | reject |
| proposer offered 12, gate admitted 3 |
查看完整验算程序
# Chapter 2. p23: the MDL admission gate on synthetic decision records.
# Records (seeded, illustrative): six attributes ch bd sg ss sz rg with
# V = (4, 4, 3, 4, 3, 5) values; act = 1 with probability 0.85 if
# ch=0 and bd=3, 0.80 if sg=2 and ss=1, 0.45 if rg=4, else 0.12.
# Candidates: every conjunction of 1 to 3 conditions, THEN act.
# A greedy proposer offers, step by step, the candidate that removes the
# most training exceptions; the gate admits while margin > 0 (p21 code).
import itertools
import math
import random
V = (4, 4, 3, 4, 3, 5)
A = len(V)
NAMES = ("ch", "bd", "sg", "ss", "sz", "rg")
def truth(x):
if x[0] == 0 and x[1] == 3:
return 0.85
if x[2] == 2 and x[3] == 1:
return 0.80
return 0.45 if x[5] == 4 else 0.12
def records(rng, n):
out = []
for _ in range(n):
x = tuple(rng.randrange(v) for v in V)
out.append((x, 1 if rng.random() < truth(x) else 0))
return out
def gamma(n):
return 2 * (n.bit_length() - 1) + 1
def rule_bits(r):
m = len(r)
t = [float(gamma(m)), math.log2(math.comb(A, m))]
t += [math.log2(V[a]) for a, _ in r]
return math.fsum(t)
def exc_bits(n, e):
return gamma(e + 1) + math.log2(math.comb(n, e))
def candidates():
out = []
for m in (1, 2, 3):
for at in itertools.combinations(range(A), m):
for vs in itertools.product(*[range(V[a]) for a in at]):
out.append(tuple(zip(at, vs)))
return out
def cover_masks(data, cands):
am, pos = {}, 0
for i, (x, y) in enumerate(data):
for a in range(A):
am[(a, x[a])] = am.get((a, x[a]), 0) | (1 << i)
pos |= y << i
full = (1 << len(data)) - 1
cov = []
for r in cands:
c = full
for cond in r:
c &= am.get(cond, 0)
cov.append(c)
return cov, pos, full
def show(r):
return "&".join("{}={}".format(NAMES[a], v) for a, v in r)
if __name__ == "__main__":
rng = random.Random(20261113)
tr = records(rng, 600)
cands = candidates()
cov, pos, full = cover_masks(tr, cands)
n, unc, k = len(tr), full, 0
e = (pos & full).bit_count()
print("{} candidates, N {}, exceptions with no rule {}".format(
len(cands), n, e))
print(" k proposed rule new net save cost margin gate")
admitted = 0
while True:
best, bi = 0, -1
for i, c in enumerate(cov):
nw = c & unc
g = (nw & pos).bit_count() - (nw & ~pos).bit_count()
if g > best:
best, bi = g, i
if bi < 0:
break
nw = cov[bi] & unc
save = exc_bits(n, e) - exc_bits(n, e - best)
cost = rule_bits(cands[bi]) + gamma(k + 2) - gamma(k + 1)
ok = save > cost and admitted == k
admitted += 1 if ok else 0
k, e, unc = k + 1, e - best, unc & ~cov[bi]
print(" {:>2} {:<17} {:>4} {:>4} {:>5.1f} {:>6.1f} {:>7.1f} {}"
.format(k, show(cands[bi]), nw.bit_count(), best, save,
cost, save - cost, "ADMIT" if ok else "reject"))
print("proposer offered {}, gate admitted {}".format(k, admitted))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《最小描述长度原则与规则库奥卡姆剃刀、两部编码判定新规则值不值得入库母典》第 2 章「两部编码账本:一条规则要修正多少条例外才算挣回自己的篇幅」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-311 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026311,
author = {Fan, Yafu},
title = {The Minimum Description Length Principle and Ockham's Razor for Rule Bases: Two-Part Codes that Decide Whether a New Rule Earns Its Place},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}