关于「文风溯源:字二元组余弦、Burrows Delta 与朴素贝叶斯」,《扶乩意动与乩文溯源》给出的定量结论是什么?

结论:第五章在自拟语料上演示字二元组余弦、伯罗斯 Delta 与朴素贝叶斯三种文风溯源方法,六篇乩文全部归属正确,而朴素贝叶斯的对数优势比 8.92 到 21.37 系统性偏大。

数据口径:立项蓝图把三层都写成既定事实;核对原始文献后,本书把后两层修正为有模型、待检验的假说,并说明法拉第 1853 年检验的是转桌而不是乩笔。 书中参数为示意,乩文语料全部为自拟合成示范;全部计算由书中程序生成。

English version

对照数据表

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

log-likelihood relative to the best medium (natural log)
texttrueABCnamedlog10 oddsper 100
S1A0.0-34.1-31.2A13.555.57
S2A0.0-20.5-33.8A8.923.50
S3B-67.80.0-34.4B14.936.17
S4B-77.40.0-48.6B21.118.72
S5B-64.60.0-33.8B14.686.09
S6C-90.1-49.20.0C21.378.58
查看完整验算程序
# Chapter 5. p53: naive Bayes on the shared syllables, Mosteller-Wallace
# style. Same seeded demonstration corpus as p51. Only the 40 shared
# syllables are features (topic words of either register are dropped,
# as Mosteller and Wallace kept to function words). Each medium gets a
# multinomial with add-one smoothing; a seance text's log-likelihood
# under each medium gives log10 odds against the runner-up and, with
# equal priors, a posterior. Independence between syllables is false
# in this corpus (habit successors), so the odds are overconfident by
# construction; the program also shows the odds per 100 syllables.
# 模型:朴素贝叶斯与对数优势比;语料全部为自拟合成示范。
import bisect
import math
import random
from collections import Counter

SYL = ("zhi hu zhe ye yi er qi suo wei yu ze nai ru ruo gu fu bu wu"
       " you ren xin tian di shan shui yue ri feng yun hua men jia lu"
       " chun qiu he jiang shi wen ming").split()
OWN = {"A": "cha jiu qin shu", "B": "mai dou can sang",
       "C": "chuan hai qiao zhou"}
DEITY = "shen xian fo sheng dan jing tan luan".split()
SEEDS = {"A": 11, "B": 22, "C": 33}


def profile(name):
    # an author's habits: a locally shuffled Zipf order of the shared
    # syllables and one favourite successor for each syllable
    rng = random.Random(SEEDS[name])
    order = list(range(len(SYL)))
    for _ in range(30):
        i = rng.randrange(len(SYL) - 1)
        j = min(len(SYL) - 1, i + 1 + rng.randrange(6))
        order[i], order[j] = order[j], order[i]
    weight = [0] * len(SYL)
    for rank, idx in enumerate(order):
        weight[idx] = 600 // (rank + 2)
    habit = [rng.randrange(len(SYL)) for _ in SYL]
    return weight, habit


def write(name, length, deity, rng):
    # deity register: a shared ritual vocabulary at rate 0.2 and a
    # doubled taste for the four sentence particles
    weight, habit = profile(name)
    if deity:
        weight = [w * 2 if i < 4 else w for i, w in enumerate(weight)]
        topic, rate = DEITY, 0.20
    else:
        topic, rate = OWN[name].split(), 0.10
    cum, tot = [], 0
    for w in weight:
        tot += w
        cum.append(tot)
    out, prev = [], None
    for _ in range(length):
        u = rng.random()
        if u < rate:
            tok = topic[rng.randrange(len(topic))]
            prev = None
        elif prev is not None and u < rate + 0.12:
            prev = habit[prev]
            tok = SYL[prev]
        else:
            prev = bisect.bisect_right(cum, rng.randrange(tot))
            tok = SYL[prev]
        out.append(tok)
    return out


def corpus(rng):
    own = {m: [write(m, 400, False, rng) for _ in range(5)]
           for m in "ABC"}
    truth = "AABBBC"
    revealed = [write(m, 300, True, rng) for m in truth]
    return own, revealed, truth


def model(essays):
    c = Counter(t for e in essays for t in e if t in SYL)
    n = math.fsum(c[s] for s in SYL)
    return {s: math.log((c[s] + 1) / (n + len(SYL))) for s in SYL}


def loglik(text, lp):
    return math.fsum(lp[t] for t in text if t in lp)


if __name__ == "__main__":
    rng = random.Random(20261112)
    own, revealed, truth = corpus(rng)
    lps = {m: model(own[m]) for m in "ABC"}
    print("log-likelihood relative to the best medium (natural log)")
    print("  text  true      A        B        C    named  log10 odds"
          "  per 100")
    for i, text in enumerate(revealed):
        ll = [loglik(text, lps[m]) for m in "ABC"]
        top = max(ll)
        best = ll.index(top)
        second = sorted(ll)[-2]
        lo10 = (top - second) / math.log(10.0)
        used = len([t for t in text if t in lps["A"]])
        print("  S{}     {}   {:7.1f}  {:7.1f}  {:7.1f}    {}    {:6.2f}"
              "    {:5.2f}".format(i + 1, truth[i], ll[0] - top,
                                   ll[1] - top, ll[2] - top, "ABC"[best],
                                   lo10, 100.0 * lo10 / used))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《扶乩意动效应微肌电、乩笔轨迹随机游走与乩文语言模型溯源母典》第 5 章「文风溯源:字二元组余弦、Burrows Delta 与朴素贝叶斯」(版本 1.0.0). 5D Library. DOI 待发布

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

BibTeX
@book{fan2026226,
  author    = {Fan, Yafu},
  title     = {Ideomotor Micro-Movements in Spirit Writing, Random-Walk Stylus Trajectories and Stylometric Attribution of Revealed Texts},
  year      = {2026},
  publisher = {5D Library},
  edition   = {1.0.0},
  note      = {DOI pending}
}

本书其他章节结论