5D Library › 多模态历法张量融合、模九十谐波拨盘与跨系统共振诊断 · English

第五章 多模态张量:五套系统共享多少信息

把五套系统放在同一批出生上

一份「多系统合盘」报告,相当于对每一位出生者计算一个五维的「张量」:称骨总重(BW)、子平调候之神(ZP)、紫微命宫之忌所落的宫位(ZW)、奇门局数(QM),以及太阳在 90 度拨盘上的扇区(UR)。要知道这五个维度是不是五份独立的信息,就要看它们的联合分布。

程序使用一个简化的历法:太阳黄经均匀;农历日均匀(月相);农历月等于节气月或前一个月,取决于新月是否早于节气月的开始;日干支、时辰与年份均匀。奇门局数用拆补法(节气与日的符头所在之元)。衡量两维之间共享信息的量是互信息 (Cover and Thomas 2006);为了扣除小样本偏差,程序同时计算把其中一列打乱后的互信息,并把它减去。

推导

# Chapter 5. [p09] Five systems on one birth: how much do they share?
# A simplified calendar: solar longitude uniform; lunar day uniform
# 1..30 (moon phase); lunar month = solar month (yin month = month 1)
# or the one before, depending on whether the new moon fell before the
# solar month began; day sexagenary index and double-hour uniform; year
# index uniform. Features: BW bone-weight total (p01 tables); ZP
# corrective element (p03 model, 70/30); ZW role that receives the ming
# palace's flying ji (p05 model); QM Qimen bureau (split-supplement
# rule: solar term and the yuan of the day); UR the Sun's sector on
# the 90-degree dial (six sectors of 15 degrees). 60,000 births (seed
# 70); pairwise mutual information in bits, minus the value for the same
# columns after shuffling one of them (the small-sample bias).
import math
import random
from collections import Counter

YEAR = (12, 9, 6, 7, 12, 5, 9, 8, 7, 8, 15, 9, 16, 8, 8, 19, 12, 6,
        8, 7, 5, 15, 6, 16, 15, 7, 9, 12, 10, 7, 15, 6, 5, 14, 14, 9,
        7, 7, 9, 12, 8, 7, 13, 5, 14, 5, 9, 17, 5, 7, 12, 8, 8, 6,
        19, 6, 8, 16, 10, 7)
MONTH = (6, 7, 18, 9, 5, 16, 9, 15, 18, 8, 9, 5)
DAY = (5, 10, 8, 15, 16, 15, 8, 16, 8, 16, 9, 17, 8, 17, 10, 8, 9,
       18, 5, 15, 10, 9, 8, 9, 15, 18, 7, 8, 16, 6)
HOUR = (16, 6, 7, 10, 9, 16, 10, 8, 8, 9, 6, 6)
STEM_V = ((0.2, 0.3), (0.1, 0.4), (0.9, -0.3), (0.7, -0.2), (0.3, -0.6),
          (0.0, 0.5), (-0.3, -0.4), (-0.4, -0.2), (-0.6, 0.7), (-0.5, 0.8))
ELEM = {"mu": (0.2, 0.4), "huo": (1.0, -0.4), "tu": (0.1, -0.2),
        "jin": (-0.4, -0.3), "shui": (-0.7, 0.8)}
NAYIN = ("jin", "huo", "mu", "tu", "jin", "huo", "shui", "tu", "jin",
         "mu", "shui", "tu", "huo", "mu", "shui", "jin", "huo", "mu", "tu",
         "jin", "huo", "shui", "tu", "jin", "mu", "shui", "tu", "huo", "mu",
         "shui")
BUREAU = {"shui": 2, "mu": 3, "jin": 4, "tu": 5, "huo": 6}
JI = ("taiyang", "taiyin", "lianzhen", "jumen", "tianji", "wenqu",
      "tiantong", "wenchang", "wuqu", "tanlang")
# bureau (upper, middle, lower yuan) for the 24 terms from dongzhi;
# yang dun for the first 12, yin dun for the rest
TERMS = ((1, 7, 4), (2, 8, 5), (3, 9, 6), (8, 5, 2), (9, 6, 3), (1, 7, 4),
         (3, 9, 6), (4, 1, 7), (5, 2, 8), (4, 1, 7), (5, 2, 8), (6, 3, 9),
         (9, 3, 6), (8, 2, 5), (7, 1, 4), (2, 5, 8), (1, 4, 7), (9, 3, 6),
         (7, 1, 4), (6, 9, 3), (5, 8, 2), (6, 9, 3), (5, 8, 2), (4, 7, 1))

def stem_of(ys, b):
    return (2 * (ys % 5) + 2 + (b - 2) % 12) % 10

def zw_role(ys, m, d, h):
    ming = (2 + m - 1 - h) % 12
    s = stem_of(ys, ming)
    idx = next(i for i in range(60) if i % 10 == s and i % 12 == ming)
    n = BUREAU[NAYIN[idx // 2]]
    k = next(k for k in range(n) if (d + k) % n == 0)
    z = (2 + (d + k) // n - 1 + (-k if k % 2 else k)) % 12
    f = (4 - z) % 12
    pos = {"taiyang": z - 3, "wuqu": z - 4, "tiantong": z - 5,
           "lianzhen": z - 8, "tianji": z - 1, "taiyin": f + 1,
           "tanlang": f + 2, "jumen": f + 3, "wenchang": 10 - h,
           "wenqu": 4 + h}
    return (ming - pos[JI[s]] % 12) % 12

def zp_elem(stem, branch):
    b = (-math.cos(2 * math.pi * branch / 12),
         math.cos(2 * math.pi * (branch - 1) / 12))
    v = [0.7 * b[i] + 0.3 * STEM_V[stem][i] for i in range(2)]
    return min(ELEM, key=lambda e: ELEM[e][0] * v[0] + ELEM[e][1] * v[1])

def birth(rng):
    lam = rng.uniform(0, 360)
    sm = ((lam - 315) % 360) / 30            # solar months since lichun
    ms, frac = int(sm), sm - int(sm)
    d = rng.randrange(1, 31)
    m = ms + 1 if (d - 1) / 29.53 <= frac else ms
    m = 12 if m == 0 else m
    y, day, h = rng.randrange(60), rng.randrange(60), rng.randrange(12)
    branch = (ms + 2) % 12
    term = int(((lam - 270) % 360) // 15)    # 0 = dongzhi
    yuan = (day // 5) % 3
    q = (term, TERMS[term][yuan])
    bw = YEAR[y] + MONTH[m - 1] + DAY[d - 1] + HOUR[h]
    return {"BW": bw, "ZP": zp_elem(day % 10, branch),
            "ZW": zw_role(y % 10, m, d, h),
            "QM": (q[0] < 12, q[1]), "UR": int((lam % 90) // 15)}

def mi(xs, ys):
    n = len(xs)
    cx, cy, cxy = Counter(xs), Counter(ys), Counter(zip(xs, ys))
    return sum(c / n * math.log2(c * n / (cx[a] * cy[b]))
               for (a, b), c in cxy.items())

if __name__ == "__main__":
    rng = random.Random(70)
    data = [birth(rng) for _ in range(60000)]
    keys = ("BW", "ZP", "ZW", "QM", "UR")
    cols = {k: [r[k] for r in data] for k in keys}
    print("   entropy (bits): " + "  ".join(
        "{} {:.3f}".format(k, mi(cols[k], cols[k])) for k in keys))
    shuf = {}
    for k in keys:
        c = cols[k][:]
        rng.shuffle(c)
        shuf[k] = c
    print("   mutual information above the shuffled baseline (bits)")
    print("         " + "".join("{:>8s}".format(k) for k in keys))
    for a in keys:
        print("   {:5s} ".format(a) + "".join(
            "{:8.3f}".format(mi(cols[a], cols[b]) - mi(cols[a], shuf[b]))
            if a != b else "{:>8s}".format("-") for b in keys))
    print("\nReading: the systems are not independent witnesses. Qimen and")
    print("the Sun's dial sector both read the solar year and share most;")
    print("Ziping shares with them through the month branch; bone weight")
    print("a little, through the lunar month. Zi Wei, built on the lunar")
    print("day and hour, is close to independent of the solar systems.")
#    entropy (bits): BW 5.026  ZP 1.349  ZW 3.585  QM 4.170  UR 2.585
#    mutual information above the shuffled baseline (bits)
#                BW      ZP      ZW      QM      UR
#    BW           -   0.013   0.008   0.047   0.046
#    ZP       0.012       -   0.007   0.133   0.056
#    ZW       0.009   0.007       -   0.013   0.006
#    QM       0.048   0.133   0.013       -   0.585
#    UR       0.045   0.056   0.006   0.585       -
#
# Reading: the systems are not independent witnesses. Qimen and
# the Sun's dial sector both read the solar year and share most;
# Ziping shares with them through the month branch; bone weight
# a little, through the lunar month. Zi Wei, built on the lunar
# day and hour, is close to independent of the solar systems.
五套系统两两之间的互信息(已扣除打乱基线,比特)。

奇门局数与太阳的拨盘扇区共享 0.585 比特:两者读的都是太阳在黄道上的位置。子平与奇门共享 0.133 比特,经由月支。称骨与两者共享 0.045 到 0.048 比特,经由农历月。紫微命宫之忌建立在农历日与时辰之上,与太阳系的几套系统几乎独立(0.013 比特以下)。

从互信息到独立票数

多系统报告通常不是报告五个变量,而是报告五个「判断」:每套系统给出一个是或否。程序为每套系统定义一个二元判断(例如称骨 3.4 两及以下、调候取火、奇门阴遁),计算判断之间的 phi 相关系数,以及等相关近似下的有效独立票数 neff=K2/∑ijρijn_{\mathrm{eff}} = K^2 / \sum_{ij} \rho_{ij}。

推导

# Chapter 5. [p10] From five systems to the number of independent votes.
# The births and features of p09. Each system raises a binary flag:
# BW: bone weight 3.4 liang or less; ZP: corrective element huo;
# ZW: the ming palace's ji lands on ming, wealth, health or career;
# QM: a yin-dun bureau; UR: the Sun in the first 15 degrees of the dial.
# Pairwise phi correlations of the flags, and the effective number of
# independent votes n_eff = K^2 / (sum of all entries of the
# correlation matrix), K = 5. 60,000 births (seed 70).
import math
import random
from collections import Counter

YEAR = (12, 9, 6, 7, 12, 5, 9, 8, 7, 8, 15, 9, 16, 8, 8, 19, 12, 6,
        8, 7, 5, 15, 6, 16, 15, 7, 9, 12, 10, 7, 15, 6, 5, 14, 14, 9,
        7, 7, 9, 12, 8, 7, 13, 5, 14, 5, 9, 17, 5, 7, 12, 8, 8, 6,
        19, 6, 8, 16, 10, 7)
MONTH = (6, 7, 18, 9, 5, 16, 9, 15, 18, 8, 9, 5)
DAY = (5, 10, 8, 15, 16, 15, 8, 16, 8, 16, 9, 17, 8, 17, 10, 8, 9,
       18, 5, 15, 10, 9, 8, 9, 15, 18, 7, 8, 16, 6)
HOUR = (16, 6, 7, 10, 9, 16, 10, 8, 8, 9, 6, 6)
STEM_V = ((0.2, 0.3), (0.1, 0.4), (0.9, -0.3), (0.7, -0.2), (0.3, -0.6),
          (0.0, 0.5), (-0.3, -0.4), (-0.4, -0.2), (-0.6, 0.7), (-0.5, 0.8))
ELEM = {"mu": (0.2, 0.4), "huo": (1.0, -0.4), "tu": (0.1, -0.2),
        "jin": (-0.4, -0.3), "shui": (-0.7, 0.8)}
NAYIN = ("jin", "huo", "mu", "tu", "jin", "huo", "shui", "tu", "jin",
         "mu", "shui", "tu", "huo", "mu", "shui", "jin", "huo", "mu", "tu",
         "jin", "huo", "shui", "tu", "jin", "mu", "shui", "tu", "huo", "mu",
         "shui")
BUREAU = {"shui": 2, "mu": 3, "jin": 4, "tu": 5, "huo": 6}
JI = ("taiyang", "taiyin", "lianzhen", "jumen", "tianji", "wenqu",
      "tiantong", "wenchang", "wuqu", "tanlang")
# bureau (upper, middle, lower yuan) for the 24 terms from dongzhi;
# yang dun for the first 12, yin dun for the rest
TERMS = ((1, 7, 4), (2, 8, 5), (3, 9, 6), (8, 5, 2), (9, 6, 3), (1, 7, 4),
         (3, 9, 6), (4, 1, 7), (5, 2, 8), (4, 1, 7), (5, 2, 8), (6, 3, 9),
         (9, 3, 6), (8, 2, 5), (7, 1, 4), (2, 5, 8), (1, 4, 7), (9, 3, 6),
         (7, 1, 4), (6, 9, 3), (5, 8, 2), (6, 9, 3), (5, 8, 2), (4, 7, 1))

def stem_of(ys, b):
    return (2 * (ys % 5) + 2 + (b - 2) % 12) % 10

def zw_role(ys, m, d, h):
    ming = (2 + m - 1 - h) % 12
    s = stem_of(ys, ming)
    idx = next(i for i in range(60) if i % 10 == s and i % 12 == ming)
    n = BUREAU[NAYIN[idx // 2]]
    k = next(k for k in range(n) if (d + k) % n == 0)
    z = (2 + (d + k) // n - 1 + (-k if k % 2 else k)) % 12
    f = (4 - z) % 12
    pos = {"taiyang": z - 3, "wuqu": z - 4, "tiantong": z - 5,
           "lianzhen": z - 8, "tianji": z - 1, "taiyin": f + 1,
           "tanlang": f + 2, "jumen": f + 3, "wenchang": 10 - h,
           "wenqu": 4 + h}
    return (ming - pos[JI[s]] % 12) % 12

def zp_elem(stem, branch):
    b = (-math.cos(2 * math.pi * branch / 12),
         math.cos(2 * math.pi * (branch - 1) / 12))
    v = [0.7 * b[i] + 0.3 * STEM_V[stem][i] for i in range(2)]
    return min(ELEM, key=lambda e: ELEM[e][0] * v[0] + ELEM[e][1] * v[1])

def birth(rng):
    lam = rng.uniform(0, 360)
    sm = ((lam - 315) % 360) / 30            # solar months since lichun
    ms, frac = int(sm), sm - int(sm)
    d = rng.randrange(1, 31)
    m = ms + 1 if (d - 1) / 29.53 <= frac else ms
    m = 12 if m == 0 else m
    y, day, h = rng.randrange(60), rng.randrange(60), rng.randrange(12)
    branch = (ms + 2) % 12
    term = int(((lam - 270) % 360) // 15)    # 0 = dongzhi
    yuan = (day // 5) % 3
    q = (term, TERMS[term][yuan])
    bw = YEAR[y] + MONTH[m - 1] + DAY[d - 1] + HOUR[h]
    return {"BW": bw, "ZP": zp_elem(day % 10, branch),
            "ZW": zw_role(y % 10, m, d, h),
            "QM": (q[0] < 12, q[1]), "UR": int((lam % 90) // 15)}

FLAGS = {"BW": lambda r: r["BW"] <= 34, "ZP": lambda r: r["ZP"] == "huo",
         "ZW": lambda r: r["ZW"] in (0, 4, 5, 8),
         "QM": lambda r: not r["QM"][0], "UR": lambda r: r["UR"] == 0}

def phi(a, b):
    n = len(a)
    pa, pb = sum(a) / n, sum(b) / n
    pab = sum(x and y for x, y in zip(a, b)) / n
    return (pab - pa * pb) / math.sqrt(pa * (1 - pa) * pb * (1 - pb))

if __name__ == "__main__":
    rng = random.Random(70)
    data = [birth(rng) for _ in range(60000)]
    keys = tuple(FLAGS)
    f = {k: [FLAGS[k](r) for r in data] for k in keys}
    print("   base rates: " + "  ".join(
        "{} {:.3f}".format(k, sum(f[k]) / len(data)) for k in keys))
    print("   phi correlations")
    print("         " + "".join("{:>8s}".format(k) for k in keys))
    total = 0.0
    for a in keys:
        row = []
        for b in keys:
            r = 1.0 if a == b else phi(f[a], f[b])
            total += r
            row.append("{:8.3f}".format(r) if a != b else
                       "{:>8s}".format("-"))
        print("   {:5s} ".format(a) + "".join(row))
    print("   effective number of independent votes: {:.2f} of 5".format(
        25 / total))
    print("\nReading: with these flags the five verdicts are almost")
    print("uncorrelated, although p09 found shared information: mutual")
    print("information counts any dependence, a flag keeps one bit of it.")
    print("Independence of verdicts depends on the question asked, and")
    print("must be measured, not assumed.")
#    base rates: BW 0.241  ZP 0.471  ZW 0.330  QM 0.502  UR 0.170
#    phi correlations
#                BW      ZP      ZW      QM      UR
#    BW           -   0.067   0.017  -0.151   0.053
#    ZP       0.067       -   0.018  -0.084  -0.019
#    ZW       0.017   0.018       -   0.003   0.012
#    QM      -0.151  -0.084   0.003       -   0.002
#    UR       0.053  -0.019   0.012   0.002       -
#    effective number of independent votes: 5.17 of 5
#
# Reading: with these flags the five verdicts are almost
# uncorrelated, although p09 found shared information: mutual
# information counts any dependence, a flag keeps one bit of it.
# Independence of verdicts depends on the question asked, and
# must be measured, not assumed.

按这样定义的判断,五套系统几乎不相关,最强的是称骨与奇门阴遁的 -0.151;有效独立票数是 5.17,甚至略多于 5(负相关的判断彼此抵消)。这与上一节并不矛盾:互信息计算任何形式的依赖,而一个二元判断只保留了一个比特。奇门阴遁(冬至到夏至前为阳遁)与「太阳在拨盘第一个 15 度」这两个判断,恰好切在了互不相关的方向上。

假说 · 尚未验证

作者的诠释(尚未验证): 多系统报告中各系统的「独立性」不是系统本身的性质,而是所提问题的性质:同一组系统,对某些问题是独立的证人,对另一些问题(例如与季节有关的问题)则是同一个证人的几次重复。什么会证明这一判断错:若对真实报告中最常用的判断(例如「本年是否为关键年」)计算相关矩阵,发现无论问题如何定义,有效独立票数都接近系统的个数,那么系统间的共享信息在实践中可以忽略。

小结

五套系统共享的信息集中在两条轴上:奇门与拨盘共享太阳的位置,子平经由月支与它们相连;紫微几乎独立。二元判断之间的相关取决于判断的定义:本章定义的五个判断几乎不相关,有效独立票数约为 5.17,但换一组与季节有关的判断,结论就会不同。独立性必须测量,不能假定。

参考文献

Cover, Thomas M., and Joy A. Thomas. 2006. Elements of Information Theory. 2nd ed. Wiley.

Fan, Y. (2026). Multimodal Calendrical Tensor Fusion, Modulo-90 Harmonic Dials and Cross-System Resonance Diagnostics: Climate-Balance Vectors, Flying-Transformation Matrices and Solar-Arc Midpoint Trees [多模态历法张量融合、模九十谐波拨盘与跨系统共振诊断] (Version 1.0.0). 5D Library. https://doi.org/10.5281/zenodo.24090189 · Licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).