5D Library › Multimodal Calendrical Tensor Fusion, Modulo-90 Harmonic Dials and Cross-System Resonance Diagnostics · 中文

Chapter 5. A Multimodal Tensor: How Much Do the Five Systems Share?

Five systems on one set of births

A “multi-system” report amounts to computing, for each birth, a five-dimensional “tensor”: the bone-weight total (BW), the Ziping balancing element (ZP), the palace on which the ming palace’s Zi Wei ji lands (ZW), the Qimen bureau (QM) and the Sun’s sector on the 90-degree dial (UR). Whether these five dimensions are five independent pieces of information depends on their joint distribution.

The program uses a simplified calendar: the Sun’s longitude is uniform; the lunar day is uniform (the moon’s phase); the lunar month equals the solar-term month or the one before, depending on whether the new moon fell before the solar month began; the day’s stem-branch, the double-hour and the year are uniform. Qimen bureaus follow the split-supplement rule (solar term and the yuan of the day’s leading stem). The amount of information two dimensions share is their mutual information (Cover and Thomas 2006); to remove the small-sample bias the program also computes the mutual information after shuffling one column and subtracts it.

Calculation

# 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.
Pairwise mutual information between the five systems (above the shuffled baseline, bits).

Qimen bureaus and the Sun’s dial sector share 0.585 bits: both read the Sun’s position on the ecliptic. Ziping shares 0.133 bits with Qimen, through the month branch. Bone weight shares 0.045 to 0.048 bits with both, through the lunar month. The Zi Wei ji of the ming palace rests on the lunar day and the hour and is almost independent of the solar systems (0.013 bits or less).

From mutual information to independent votes

A multi-system report usually does not report five variables but five “verdicts”: each system says yes or no. The program defines one binary verdict per system (bone weight of 3.4 liang or less, a balancing element of fire, a yin-dun Qimen bureau, for example), computes the phi correlations between verdicts and, in the equal-correlation approximation, the effective number of independent votes neff=K2/∑ijρijn_{\mathrm{eff}} = K^2 / \sum_{ij} \rho_{ij}.

Calculation

# 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.

For verdicts defined this way the five systems are almost uncorrelated, the strongest being the -0.151 between bone weight and yin-dun Qimen; the effective number of independent votes is 5.17, even slightly above 5 (negatively correlated verdicts offset each other). This does not contradict the previous section: mutual information counts any form of dependence, while a binary verdict keeps a single bit. The yin-dun verdict (yang dun runs from the winter solstice to the summer solstice) and “the Sun in the first 15 degrees of the dial” happen to cut in uncorrelated directions.

Hypothesis · not established

The author’s interpretation (not yet tested): the “independence” of the systems in a multi-system report is not a property of the systems but of the question asked: the same systems are independent witnesses for some questions and, for others (questions tied to the season, for instance), repetitions of one witness. What would show this wrong: if the correlation matrix of the verdicts most used in real reports (for example “is this a key year?”) shows an effective number of independent votes close to the number of systems however the question is defined, the information the systems share can be neglected in practice.

Summary

The information the five systems share lies along two axes: Qimen and the dial share the Sun’s position, and Ziping joins them through the month branch; Zi Wei is almost independent. How binary verdicts correlate depends on how they are defined: the five verdicts of this chapter are almost uncorrelated, with an effective number of independent votes of about 5.17, but a set of season-related verdicts would give a different answer. Independence must be measured, not assumed.

References

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).