TTiti的学习笔记
首页 / 综合实践 / 08_资料库/RGCN_第一章完整教辅_复杂网络名词地图.md

第一章完整教辅:复杂网络名词地图、代码任务、作业答案

综合实践 · 08_资料库/RGCN_第一章完整教辅_复杂网络名词地图.md

第一章完整教辅:复杂网络名词地图、代码任务、作业答案

对应教材:

  • RGCN Volume I Chapter 1: Introduction
  • RGCN Volume II Chapter 1.1-1.4: Introduction and preliminaries

本章目标不是证明定理,而是建立“看懂后续章节”的最低词汇和方法基础。

核心主线:


真实网络现象 -> 图表示 -> 度数分布 -> 幂律尾部 -> 极端 hub -> 巨分量/小世界 -> 随机图模型


0. 本章你最终要会说什么

你应该能说出下面这段话:

复杂网络可以抽象为 graph,其中节点表示对象,边表示关系。真实网络通常不是每个节点都差不多,而是 degree distribution 高度不均匀:大多数节点度数较小,少数节点度数极大。若尾部分布近似满足 power law,则最大度数会随网络规模快速增长,形成 hub。hub 会影响网络的连通性、传播能力和 typical distance。Erdos-Renyi graph 是最简单的随机图基准模型,但在 sparse regime 下度数近似 Poisson,尾部较轻,因此不能充分解释真实复杂网络中的极端高度数节点。

1. Graph / 图

1.1 一句话定义

Graph 是由节点 vertex 和边 edge 组成的结构,用来表示对象之间的关系。

1.2 直觉解释

如果你只研究一个对象,比如“一个人有多少朋友”,那是普通数据分析。 如果你研究“人和人之间谁认识谁”,就需要 graph。

图的关键不是单个对象,而是对象之间的连接结构。

1.3 专业表达

一个无向图通常写作:


G = (V, E)

其中:

  • V 是 vertex set,节点集合;
  • E 是 edge set,边集合;
  • 如果 {u, v} in E,表示节点 uv 之间有连接。

1.4 典型场景

真实系统节点
社交网络好友关系
网页网络网页超链接
论文引用网络论文引用关系
交通网络城市/车站道路/线路
脑网络脑区/神经元功能连接/突触连接

1.5 交流时可以怎么说

I model the system as a graph, where vertices represent objects and edges represent relationships between objects.

中文:

我把这个系统建模成一个图,节点表示对象,边表示对象之间的关系。

2. Degree / 度数

2.1 一句话定义

Degree 是一个节点连接了多少条边。

2.2 直觉解释

在社交网络中,degree 就是一个人的好友数。 在网页网络中,in-degree 可以表示有多少网页链接到它。

2.3 专业表达

对无向图,节点 v 的度数写作:


d_v = number of edges incident to v

也可以写成:


d_v = |{u : {u, v} in E}|

意思是:和 v 相连的节点数量。

2.4 和极值的关系

最大度数:


D_max = max_v d_v

就是一个极值问题。

在复杂网络中,我们常常不只问“平均每个节点有多少连接”,还问:

  • 最大的节点有多大?
  • 它是不是远远超过平均水平?
  • 它是否会影响传播、连通性和网络距离?

3. Degree Distribution / 度数分布

3.1 一句话定义

Degree distribution 描述“随机选一个节点,它的度数是多少”的概率分布。

3.2 直觉解释

平均度只告诉你一个平均水平,但看不出差异。

两个网络可能平均度都等于 4:

  • 网络 A:每个节点度数都接近 4;
  • 网络 B:大多数节点度数为 1,少数节点度数为 100。

这两个网络的结构完全不同。degree distribution 就是用来描述这种差异的。

3.3 专业表达

如果网络有 n 个节点,度数为 k 的节点数是 N_k,则经验度数分布为:


p_k = N_k / n

其中:

  • k 是度数;
  • N_k 是 degree 等于 k 的节点数;
  • p_k 是随机选一个节点时 degree 等于 k 的概率。

3.4 交流时可以怎么说

Instead of only reporting the average degree, I examine the empirical degree distribution, especially its tail.

中文:

我不只报告平均度,还会看经验度数分布,特别是尾部。

4. Tail Distribution 和 CCDF

4.1 一句话定义

Tail distribution 是随机变量超过某个阈值的概率。

对 degree 来说:


P(D >= k)

表示随机选一个节点,它的度数至少为 k 的概率。

4.2 CCDF 是什么

CCDF 是 complementary cumulative distribution function,常写为:


P(D >= k)

或:


P(D > k)

4.3 为什么它重要

因为我们关心的是高 degree 节点有多少。 尾部越厚,高度数节点越多,最大度数越可能极端。

4.4 交流时可以怎么说

The CCDF is useful because it directly shows how many vertices have degree at least k.

中文:

CCDF 很有用,因为它直接显示 degree 至少为 k 的节点比例。

5. Power Law / 幂律

5.1 一句话定义

Power law 表示尾部概率按幂函数下降,例如:


P(D > x) approx x^{-alpha}

RGCN 中常用:


P(D > x) approx x^{-(tau-1)}

5.2 直觉解释

如果尾部下降很快,极端大值很少出现。 如果尾部下降很慢,极端大值更常见。

幂律尾部就是“下降很慢”的典型形式。

5.3 tau 怎么理解

在:


P(D > x) approx x^{-(tau-1)}

中:

  • D 是 degree;
  • x 是阈值;
  • tau 是 power-law exponent;
  • tau 越小,尾部越厚;
  • 尾部越厚,hub 越极端。

5.4 常见区间

复杂网络中经常关注:


tau in (2, 3)

直觉含义:

  • 平均 degree 可以是有限的;
  • 方差可能非常大或趋于无穷;
  • 网络中会出现明显 hub。

6. Maximum Degree / 最大度数

6.1 一句话定义

Maximum degree 是网络中度数最大的节点的度数。

6.2 核心推导

假设:


P(D > x) approx x^{-(tau-1)}

n 个节点。最大度数的量级可以用:


n P(D > x_n) approx 1

理解。

代入尾部公式:


n x_n^{-(tau-1)} approx 1

移项:


x_n^{tau-1} approx n

所以:


x_n approx n^{1/(tau-1)}

6.3 直觉解释

n P(D > x_n) approx 1 的意思是:

全网大约有 1 个节点超过这个阈值。

所以这个阈值就是最大度数的自然尺度。

6.4 交流时可以怎么说

The typical scale of the maximum degree can be estimated by solving n P(D > x_n) approx 1.

中文:

最大度数的典型量级可以通过令超过阈值的期望节点数约等于 1 来估计。

7. Hub / 枢纽节点

7.1 一句话定义

Hub 是 degree 远高于普通节点的高度数节点。

7.2 为什么重要

Hub 会影响:

  • 信息传播;
  • 疾病传播;
  • 搜索效率;
  • 网络脆弱性;
  • typical distance;
  • giant component。

7.3 直觉解释

Hub 像交通枢纽。 普通节点之间本来可能很远,但通过 hub 可以快速连接。

7.4 交流时可以怎么说

Hubs are not just outliers; in heavy-tailed networks, they are expected structural features.

中文:

Hub 不只是异常点;在重尾网络中,它们是自然出现的结构特征。

8. Scale-Free / 无标度

8.1 一句话定义

Scale-free 通常指网络的 degree distribution 没有典型尺度,常与 power-law tail 相关。

8.2 直觉解释

如果一个网络有典型尺度,那么大多数节点都围绕某个典型 degree 波动。 如果没有典型尺度,就可能出现从很小 degree 到极大 degree 的宽范围差异。

8.3 注意

不要轻易说“这个网络就是 scale-free”。更稳妥的表达是:

The degree distribution appears to be heavy-tailed or approximately power-law over a certain range.

中文:

该网络的度数分布在一定范围内表现出重尾或近似幂律特征。

9. Small-World / 小世界

9.1 一句话定义

Small-world 表示网络中随机两点之间的典型距离很短。

9.2 专业表达

如果网络大小为 n,typical distance 可能像:


log n

甚至在某些重尾网络中像:


log log n

9.3 和 scale-free 的区别

概念关注什么
scale-freedegree distribution 的尾部
small-world节点之间的 shortest path distance

9.4 和 hub 的关系

Hub 可以缩短路径。

一个普通节点可能先到达中等节点,再到达 hub,再从 hub 到另一个区域。 因此 hub 像捷径一样降低 typical distance。


10. Giant Component / 巨分量

10.1 一句话定义

Giant component 是包含正比例节点的连通分量。

10.2 专业表达

设最大连通分量大小为 |C_max|。如果:


|C_max| / n -> rho > 0

则称存在 giant component。

10.3 为什么重要

如果存在 giant component,说明网络中大量节点可以互相到达。

这对以下问题很重要:

  • 疾病是否能大规模传播;
  • 信息是否能扩散到大范围;
  • 网络是否整体连通;
  • 删除 hub 是否会导致网络碎裂。

11. Erdos-Renyi Graph / ER 随机图

11.1 一句话定义

ER 图是每条边独立地以同一概率出现的随机图。

11.2 专业表达

G(n, p) 中:

  • n 个节点;
  • 每一对节点独立连边;
  • 连边概率是 p

11.3 稀疏情形

复杂网络常关注 sparse regime:


p = lambda / n

此时平均度约为:


lambda

节点度数近似:


Bin(n-1, lambda/n) -> Poisson(lambda)

11.4 ER 图的作用

ER 图是基准模型。它可以帮助我们理解:

  • 随机连边会产生什么结构;
  • giant component 什么时候出现;
  • 真实网络和同质随机图有什么不同。

11.5 ER 图的局限

ER 图的节点是同质的,度数近似 Poisson。 Poisson 尾部很轻,因此很难解释真实复杂网络中的极端 hub。


12. 第一章代码任务:从小网络到幂律极值

这一节给出完整代码。每一行都有注释,便于你直接理解。

代码只用 Python 标准库,不需要安装额外包。


12.1 代码任务 A:手工构造一个小网络并计算 degree distribution

任务目标

用 5 个节点的小网络理解:

  • graph;
  • degree;
  • degree distribution;
  • maximum degree;
  • CCDF。

完整代码


# 导入 Counter,用来统计每个 degree 出现了多少次

from collections import Counter



# 用字典表示一个无向图

# 每个 key 是一个节点

# 每个 value 是这个节点的邻居集合

graph = {

    "A": {"B", "C", "D"},  # A 和 B、C、D 相连,所以 A 的 degree 是 3

    "B": {"A", "C"},       # B 和 A、C 相连,所以 B 的 degree 是 2

    "C": {"A", "B"},       # C 和 A、B 相连,所以 C 的 degree 是 2

    "D": {"A", "E"},       # D 和 A、E 相连,所以 D 的 degree 是 2

    "E": {"D"},            # E 只和 D 相连,所以 E 的 degree 是 1

}



# 计算每个节点的 degree

# len(neighbors) 表示邻居数量,也就是 degree

degrees = {node: len(neighbors) for node, neighbors in graph.items()}



# 打印每个节点的 degree

print("Degrees:")

for node, degree in degrees.items():

    print(node, degree)



# 统计 degree distribution

# Counter 会统计 degree=1、degree=2、degree=3 分别出现多少次

degree_counts = Counter(degrees.values())



# 节点总数

n = len(graph)



# 把节点数转换成比例

degree_distribution = {

    degree: count / n

    for degree, count in degree_counts.items()

}



# 打印度数分布

print("\nDegree distribution:")

for degree in sorted(degree_distribution):

    print(degree, degree_distribution[degree])



# 计算最大度数

max_degree = max(degrees.values())



# 找到所有达到最大度数的节点

hubs = [

    node

    for node, degree in degrees.items()

    if degree == max_degree

]



# 打印最大度数和 hub 节点

print("\nMaximum degree:", max_degree)

print("Hub node(s):", hubs)



# 计算 CCDF:P(D >= k)

print("\nCCDF:")

for k in sorted(degree_counts):

    fraction = sum(1 for degree in degrees.values() if degree >= k) / n

    print(f"P(D >= {k}) = {fraction}")

逐行解释


from collections import Counter

导入 Counter。它可以帮我们统计列表中每个值出现多少次。


graph = {...}

用字典表示图。每个节点对应一个邻居集合。


"A": {"B", "C", "D"}

表示 A 和 B、C、D 相连。


degrees = {node: len(neighbors) for node, neighbors in graph.items()}

遍历每个节点和它的邻居集合,用邻居数量作为 degree。


degree_counts = Counter(degrees.values())

统计不同 degree 出现次数。例如 degree=2 出现了 3 次。


n = len(graph)

计算节点总数。


degree_distribution = {degree: count / n for degree, count in degree_counts.items()}

把“节点数”除以总节点数,得到比例。


max_degree = max(degrees.values())

找最大 degree。


hubs = [node for node, degree in degrees.items() if degree == max_degree]

找出 degree 等于最大 degree 的节点。


fraction = sum(1 for degree in degrees.values() if degree >= k) / n

计算 degree 至少为 k 的节点比例,即 CCDF。

运行后你应该得到的结论

这个小图中:

  • A 的 degree 最大;
  • A 是这个小网络里的 hub;
  • degree distribution 显示大多数节点 degree 是 2;
  • CCDF 显示 degree 至少达到某个阈值的节点比例。

12.2 代码任务 B:模拟幂律尾部和最大值增长

任务目标

理解为什么幂律尾部会产生极端 hub。

完整代码


# 导入 random,用来生成随机数

import random



# 导入 mean 和 median,用来计算平均数和中位数

from statistics import mean, median



# 固定随机种子,保证每次运行结果大致可复现

random.seed(20260716)



# 定义一个函数,用来生成 Pareto 分布样本

# Pareto 分布是最常见的幂律尾部分布之一

def pareto_sample(alpha, size, xmin=1.0):

    # 创建空列表,用来存储样本

    values = []



    # 重复 size 次,生成 size 个随机数

    for _ in range(size):

        # random.random() 生成 0 到 1 之间的均匀随机数

        u = random.random()



        # 通过反函数法生成 Pareto 样本

        # alpha 越小,尾部越厚,极端值越容易出现

        x = xmin * (1 - u) ** (-1 / alpha)



        # 把生成的样本加入列表

        values.append(x)



    # 返回样本列表

    return values



# 定义一个函数,总结一组数的基本统计量

def summarize(values):

    # 先排序,方便取分位数和最大值

    values = sorted(values)



    # 样本数量

    n = len(values)



    # 返回一个字典,包含平均数、中位数、95% 分位数和最大值

    return {

        "n": n,

        "mean": round(mean(values), 3),

        "median": round(median(values), 3),

        "p95": round(values[int(0.95 * n)], 3),

        "max": round(values[-1], 3),

    }



# 设置 alpha

# 在 RGCN 常用记号中 alpha = tau - 1

alpha = 1.5



# 对不同网络规模 n 做模拟

for n in [100, 1000, 10000]:

    # 生成 n 个幂律尾部样本,可以理解为 n 个节点的潜在 degree

    sample = pareto_sample(alpha=alpha, size=n)



    # 理论最大值尺度约为 n^(1/alpha)

    theory_scale = n ** (1 / alpha)



    # 打印样本规模

    print("n =", n)



    # 打印样本统计

    print("summary =", summarize(sample))



    # 打印理论最大值尺度

    print("theory scale n^(1/alpha) =", round(theory_scale, 3))



    # 空行,让输出更清楚

    print()

逐行解释


import random

导入随机数模块。


from statistics import mean, median

导入平均数和中位数函数。


random.seed(20260716)

固定随机种子。这样每次运行结果不会完全乱变。


def pareto_sample(alpha, size, xmin=1.0):

定义函数,生成 Pareto 样本。Pareto 分布有幂律尾部。


values = []

准备一个空列表存样本。


for _ in range(size):

循环 size 次。


u = random.random()

生成一个 0 到 1 之间的随机数。


x = xmin * (1 - u) ** (-1 / alpha)

用反函数法生成 Pareto 随机变量。


values.append(x)

把生成的数加入列表。


return values

返回完整样本。


def summarize(values):

定义统计汇总函数。


values = sorted(values)

排序,方便取最大值和分位数。


n = len(values)

样本数量。


"mean": round(mean(values), 3)

计算平均值,保留三位小数。


"median": round(median(values), 3)

计算中位数。


"p95": round(values[int(0.95 * n)], 3)

计算约 95% 分位数。


"max": round(values[-1], 3)

排序后最后一个值就是最大值。


alpha = 1.5

设置尾部指数。alpha 越小,尾部越厚。


for n in [100, 1000, 10000]:

分别模拟 100、1000、10000 个节点。


sample = pareto_sample(alpha=alpha, size=n)

生成 n 个幂律尾部样本。


theory_scale = n ** (1 / alpha)

计算理论最大值尺度。

运行后你应该得到的结论

n 增大时:

  • 中位数变化不大;
  • 最大值增长明显;
  • 最大值大致和 n^(1/alpha) 同量级。

这说明:

幂律尾部下,网络规模越大,越容易出现极端 hub。

12.3 代码任务 C:模拟 ER 图并观察最大度数

任务目标

理解 ER 图为什么是基准模型,以及为什么它不容易产生极端 hub。

完整代码


# 导入 random,用于随机决定边是否出现

import random



# 导入 mean,用来计算平均度

from statistics import mean



# 固定随机种子,保证结果可复现

random.seed(20260716)



# 定义函数,生成 ER 图 G(n, p),这里使用 p = lambda / n

def er_graph(n, lam):

    # 计算连边概率 p

    p = lam / n



    # 用列表存储每个节点的邻居集合

    adj = [set() for _ in range(n)]



    # 遍历所有不同节点对 i, j

    for i in range(n):

        for j in range(i + 1, n):

            # 以概率 p 添加边

            if random.random() < p:

                # 无向图中,i 是 j 的邻居,j 也是 i 的邻居

                adj[i].add(j)

                adj[j].add(i)



    # 返回邻接表

    return adj



# 定义函数,总结图的 degree 信息

def degree_summary(adj):

    # 每个节点的 degree 等于邻居数量

    degrees = [len(neighbors) for neighbors in adj]



    # 返回平均度、最大度、节点数

    return {

        "n": len(adj),

        "average_degree": round(mean(degrees), 3),

        "maximum_degree": max(degrees),

    }



# 设置节点数

n = 1000



# 尝试不同 lambda

for lam in [1, 3, 6]:

    # 生成 ER 图

    adj = er_graph(n=n, lam=lam)



    # 打印 lambda 和 degree 统计

    print("lambda =", lam)

    print(degree_summary(adj))

    print()

逐行解释


def er_graph(n, lam):

定义生成 ER 图的函数。


p = lam / n

使用 sparse regime。平均度大约是 lambda


adj = [set() for _ in range(n)]

创建邻接表。每个节点对应一个邻居集合。


for i in range(n):

    for j in range(i + 1, n):

遍历每一对不同节点。ji+1 开始,避免重复。


if random.random() < p:

以概率 p 决定是否连边。


adj[i].add(j)

adj[j].add(i)

因为是无向图,所以双方都记录对方为邻居。


degrees = [len(neighbors) for neighbors in adj]

计算所有节点的 degree。


"average_degree": round(mean(degrees), 3)

计算平均度。


"maximum_degree": max(degrees)

计算最大度。

运行后你应该得到的结论

lambda 从 1 增加到 6:

  • 平均度会上升;
  • 最大度也会上升;
  • 但最大度通常不会像幂律尾部那样极端。

这说明:

ER 图适合作为基准模型,但它的 Poisson-like degree distribution 尾部较轻,不能充分解释真实复杂网络中的极端 hub。

13. 第一章课后作业和答案

作业 1:概念解释

题目:用自己的话解释 graph、degree、degree distribution。

参考答案

Graph 是由节点和边组成的结构,节点表示对象,边表示对象之间的关系。Degree 是一个节点连接了多少条边,反映该节点的局部连接规模。Degree distribution 描述随机选一个节点时,它的 degree 可能是多少,用来刻画整个网络中节点连接数的差异。


作业 2:手算小网络

题目:给定边:


A-B, A-C, B-C, C-D, D-E, D-F

请计算每个节点的 degree、degree distribution 和 maximum degree。

参考答案

节点度数:

节点degree
A2
B2
C3
D3
E1
F1

Degree distribution:

degree节点数比例
122/6
222/6
322/6

Maximum degree:


D_max = 3

Hub 节点:


C 和 D


作业 3:最大度数量级推导

题目:假设:


P(D > x) approx x^{-(tau-1)}

用:


n P(D > x_n) approx 1

推出最大度数量级。

参考答案

代入:


n x_n^{-(tau-1)} approx 1

移项:


x_n^{tau-1} approx n

开方:


x_n approx n^{1/(tau-1)}

解释:

最大度数的自然尺度来自“全网大约有一个节点超过该阈值”的平衡条件。

作业 4:比较 ER 图和幂律网络

题目:为什么 ER 图不能充分解释真实网络中的 hub?

参考答案

在 sparse regime 下,ER 图中每个节点的 degree 近似服从 Poisson 分布。Poisson 分布尾部下降很快,所以极端大 degree 出现概率很低。真实复杂网络中常见少数节点 degree 远高于平均水平,即 hub 现象,这更符合 heavy-tailed 或 power-law-like degree distribution。因此 ER 图适合作为基准模型,但不能充分解释真实网络中的极端 hub。


作业 5:scale-free 和 small-world 区别

题目:scale-free 和 small-world 是同一个概念吗?

参考答案

不是。Scale-free 主要描述 degree distribution 的尾部,通常和 power-law degree distribution 有关,强调节点连接数的高度不均匀。Small-world 主要描述网络中随机两点之间的 typical distance 很短,强调路径长度。二者可能有关联,因为 hub 会缩短路径,但它们不是同一个概念。


14. 本章自测题

14.1 快速问答

  1. Graph 的两个基本组成是什么?
  2. Degree 表示什么?
  3. 为什么 average degree 不够?
  4. Degree distribution 解决什么问题?
  5. CCDF 表示什么?
  6. Power law tail 为什么重要?
  7. 最大度数为什么是极值问题?
  8. Hub 会影响哪些网络性质?
  9. Scale-free 和 small-world 有什么区别?
  10. ER 图的 degree 为什么近似 Poisson?

14.2 答案

  1. 节点和边。
  2. 一个节点连接了多少条边。
  3. 平均度看不出节点之间的异质性和尾部极端值。
  4. 描述随机选一个节点时它的 degree 分布。
  5. P(D >= k)P(D > k),即超过某个阈值的概率。
  6. 它说明极端大 degree 更可能出现。
  7. 因为它是所有节点 degree 的最大值。
  8. 传播、连通性、typical distance、脆弱性。
  9. Scale-free 关注 degree tail;small-world 关注 shortest path distance。
  10. 因为 Bin(n-1, lambda/n)n 大时近似 Poisson(lambda)

15. 本章可以直接背的专业表达

15.1 中文表达

我关注复杂网络中的极端连接现象。首先把系统表示为 graph,节点表示对象,边表示关系。接着研究 degree distribution,尤其是尾部。如果 degree distribution 具有 heavy tail 或 power-law-like tail,那么最大度数会随网络规模快速增长,形成 hub。Hub 不只是异常点,它会影响巨分量、传播过程和 typical distance。ER 图是重要基准模型,但在稀疏情形下 degree 近似 Poisson,尾部较轻,因此不能充分解释真实网络中的极端 hub。

15.2 英文表达

I focus on extreme connectivity in complex networks. I first represent the system as a graph, where vertices are objects and edges are relationships. Then I examine the empirical degree distribution, especially its tail. If the degree distribution is heavy-tailed or approximately power-law, the maximum degree can grow rapidly with the network size, leading to hubs. Hubs are not merely outliers; they can affect giant components, spreading processes, and typical distances. The Erdos-Renyi graph is a useful baseline, but in the sparse regime its degree distribution is approximately Poisson, which is too light-tailed to explain extreme hubs in many real networks.

16. 给 AI 的本章提示词


我正在学习 RGCN 第一章:复杂网络名词地图。

请围绕 graph, degree, degree distribution, CCDF, power law, maximum degree, hub, scale-free, small-world, giant component, Erdos-Renyi graph 对我进行问答训练。

要求:

1. 每次只问一个问题;

2. 如果我答错,请先指出缺失点;

3. 再给一个跨专业硕士新生能懂的解释;

4. 最后给一个更专业的英文表达。