关于「东西方原典考辨:《庄子·骈拇》的枝指与奥卡姆的「徒然以多为之」」,《规则库的奥卡姆剃刀》给出的定量结论是什么?
结论:「续凫胫」是把一条短规则换成更长的版本,即把真规则收窄。规则那一半只多了 2.0 个比特,可是被收窄掉的那些记录重新变成了例外,例外那一半多出 45.6 个比特,总长度多出 47.6 个比特,留出误差上升 0.0307。「断鹤胫」是把一条长规则截短,即去掉一个条件,把真规则放宽。规则那一半反而省了 5.3 个比特,可是放宽以后误判了大量本不该动作的记录,例外那一半多出 152.5 个比特,总长度多出 147.2 个比特,留出误差上升 0.1408。「截肢」是把一条真规则整条删掉,规则省了 10.5 个比特,例外多出 74.6 个比特,留出误差上升 0.0507。
数据口径:书中的决策记录全部合成、参数均为示意,全部计算由书中程序生成;本书是非个人化的经营分析,不构成经营建议。 第二章建立两部编码账本:一条准确率超过八成、却只净修正 7 条例外的窄规则挣不回自己的篇幅;在合成台账上,门槛从提议者的 12 条规则中只放进 3 条,第三条的余量仅 2.9 个比特。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 0.0307, 0.0507, 0.1408, 147.2, 152.5, 2.0
| base: L(H) 24.4, L(D|H) 407.6, hold-out 0.1973 | ||||
| edit | dL(H) | dL(D|H) | dtotal | d holdout |
| extra finger | 14.9 | 0.0 | 14.9 | +0.0000 |
| wart | 12.5 | 0.0 | 12.5 | +0.0000 |
| lengthen duck | 2.0 | 45.6 | 47.6 | +0.0307 |
| cut crane | -5.3 | 152.5 | 147.2 | +0.1408 |
| amputate | -10.5 | 74.6 | 64.2 | +0.0507 |
查看完整验算程序
# Chapter 7. p71: the webbed toe, the extra finger, the duck's leg and
# the crane's leg, written as edits to a rule base and priced in bits.
# Base: the two true rules on the seeded 600-record ledger of p23,
# 4000 hold-out records. Edits (our reading of the Zhuangzi images):
# extra finger add a narrower copy of a true rule (one condition more)
# wart add a verbatim second copy of a true rule
# lengthen duck replace a true rule by a narrower version
# cut crane replace a true rule by a broader version
# amputate delete a true rule
# Reported: change in L(H), in L(D|H), in the total, and in hold-out
# error. A positive total means the edit makes the base worse.
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)
def greedy_path(cov, pos, full, kmax=40):
unc, path = full, []
while len(path) < kmax:
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
path.append((bi, best))
unc &= ~cov[bi]
return path
def errors(rules, cov, pos, full):
act = 0
for i in rules:
act |= cov[i]
return (pos & ~act & full).bit_count() + (act & ~pos).bit_count()
def ledger(rules, cands, cov, pos, full, n):
e = errors([index_of(cands, r) for r in rules], cov, pos, full)
lh = math.fsum([float(gamma(len(rules) + 1))]
+ [rule_bits(r) for r in rules])
return lh, exc_bits(n, e)
def index_of(cands, r):
return cands.index(tuple(sorted(r)))
if __name__ == "__main__":
rng = random.Random(20261113)
tr, te = records(rng, 600), records(rng, 4000)
cands = candidates()
cov, pos, full = cover_masks(tr, cands)
tcov, tpos, tfull = cover_masks(te, cands)
r1, r2 = ((0, 0), (1, 3)), ((2, 2), (3, 1))
base = [r1, r2]
edits = [("extra finger", [r1, r2, ((0, 0), (1, 3), (4, 1))]),
("wart", [r1, r2, r2]),
("lengthen duck", [((0, 0), (1, 3), (4, 1)), r2]),
("cut crane", [r1, ((2, 2),)]),
("amputate", [r1])]
lh0, ld0 = ledger(base, cands, cov, pos, full, 600)
ids = lambda rs: [index_of(cands, r) for r in rs]
h0 = errors(ids(base), tcov, tpos, tfull) / 4000
print("base: L(H) {:.1f}, L(D|H) {:.1f}, hold-out {:.4f}".format(
lh0, ld0, h0))
print(" edit dL(H) dL(D|H) dtotal d holdout")
for name, rs in edits:
lh, ld = ledger(rs, cands, cov, pos, full, 600)
h = errors(ids(rs), tcov, tpos, tfull) / 4000
print(" {:<14} {:>6.1f} {:>7.1f} {:>6.1f} {:>+9.4f}".format(
name, lh - lh0, ld - ld0, lh + ld - lh0 - ld0, h - h0))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《最小描述长度原则与规则库奥卡姆剃刀、两部编码判定新规则值不值得入库母典》第 7 章「东西方原典考辨:《庄子·骈拇》的枝指与奥卡姆的「徒然以多为之」」(版本 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}
}