以下是 Louvain 算法原理及其在倪李神学关系网络中的完整应用指南:

***

## 一、Louvain 算法核心原理

Louvain 算法通过最大化**模块度(Modularity)**来发现社群,模块度衡量社群内部连接的密度与随机分布的偏差 。模块度值介于 -1 到 1 之间,**高于 0.4 表示存在有意义的社群结构** 。[1][2]

算法分两个交替执行的阶段 :[3]

– **阶段一(局部优化)**:每个节点尝试加入邻居所在社群,若模块度提升则移动,直到无节点移动能改善模块度
– **阶段二(聚合压缩)**:将每个社群压缩为一个”超级节点”,重复阶段一,形成层级结构

这种层级迭代使 Louvain 特别擅长发现**嵌套式教义结构**——既能看到宏观主题群组,也能看到细粒度的概念子社群 。[1]

***

## 二、针对倪李神学的参数配置

“`cypher
// 投影神学图谱(含关系权重)
CALL gds.graph.project(
‘nee-lee-theology’,
[‘Concept’, ‘Book’, ‘Theme’],
{
RELATED_TO: { orientation: ‘UNDIRECTED’, properties: ‘weight’ },
EXPOUNDS: { orientation: ‘UNDIRECTED’, properties: ‘weight’ },
BELONGS_TO: { orientation: ‘UNDIRECTED’ }
}
)

// 运行 Louvain(保留中间层级,便于多尺度分析)
CALL gds.louvain.stream(‘nee-lee-theology’, {
maxLevels: 5,
relationshipWeightProperty: ‘weight’,
includeIntermediateCommunities: true,
tolerance: 0.00001
})
YIELD nodeId, communityId, intermediateCommunityIds
RETURN
gds.util.asNode(nodeId).name AS concept,
communityId AS final_community,
intermediateCommunityIds AS hierarchy
ORDER BY final_community, concept
“`

**参数神学意义** :[1]

| 参数 | 建议值 | 神学意义 |
|——|——–|———|
| `maxLevels` | 3–5 | 层级太少则教义混合;太多则过度细分 |
| `tolerance` | `0.00001` | 精细收敛,适合概念密集的神学图谱 |
| `relationshipWeightProperty` | `’weight’` | 让强语义关系(如”目标是”)比弱关系更影响聚类 |
| `includeIntermediateCommunities` | `true` | 同时获得宏观主题群与细粒度子群 |

***

## 三、预期发现的倪李神学社群

根据倪李神学概念的内在语义密度,Louvain 预期识别以下社群 :[3][1]

**宏观社群(高层级)**

| 社群ID | 预期包含概念 | 神学范畴 |
|——–|————|——-–|
| 社群 A | 三一神、父神、子、圣灵、神圣经纶 | 神论/经纶论 |
| 社群 B | 神圣生命、人的灵、调和、变化形态 | 生命论/救赎论 |
| 社群 C | 召会建造、地方召会、肢体、得胜者 | 召会论/末世论 |
| 社群 D | 属灵人、正常基督徒生活、生命读经 | 著作聚类 |

**细粒度子群(低层级)**:社群 B 内部可能进一步分裂为”灵的功用子群”(灵、魂、体、三分说)与”经历子群”(重生、成圣、变化)。

***

## 四、写回节点并可视化

“`cypher
// 将社群ID写回节点属性
CALL gds.louvain.write(‘nee-lee-theology’, {
writeProperty: ‘community’,
relationshipWeightProperty: ‘weight’
})
YIELD communityCount, modularity
RETURN communityCount AS 发现社群数,
round(modularity, 4) AS 模块度

// 查看各社群的概念列表
MATCH (n:Concept)
RETURN n.community AS 社群,
collect(n.name) AS 概念列表,
count(*) AS 概念数量
ORDER BY 概念数量 DESC
“`

写回后,在 Neo4j Browser 右侧面板选择”按 `community` 属性着色”,即可立即看到颜色区分的社群可视化。

***

## 五、Leiden 算法:Louvain 的升级替代

对于倪李神学这类**概念紧密交织**的图谱,可考虑使用 **Leiden 算法** ——它修正了 Louvain 的一个已知缺陷(可能产生内部不连通的社群),确保每个社群内部都是连通的:[4]

“`cypher
CALL gds.leiden.stream(‘nee-lee-theology’, {
relationshipWeightProperty: ‘weight’,
gamma: 1.0 // 分辨率参数:>1 产生更多小社群;<1 产生更少大社群
})
YIELD nodeId, communityId
RETURN gds.util.asNode(nodeId).name AS concept, communityId
ORDER BY communityId
“`

**`gamma` 参数的神学调节意义**:设为 `0.5` 得到宏观教义板块(适合课程模块设计);设为 `1.5` 得到细粒度概念群(适合精细比较神学分析)。[4]

***

## 六、用 Python 输出社群分析报告

“`python
from graphdatascience import GraphDataScience
import pandas as pd

gds = GraphDataScience(“bolt://localhost:7687″, auth=(“neo4j”, “password”))
G, _ = gds.graph.project(“nee-lee-theology”, [“Concept”],
{“RELATED_TO”: {“orientation”: “UNDIRECTED”,
“properties”: “weight”}})

result = gds.louvain.stream(G, relationshipWeightProperty=”weight”,
includeIntermediateCommunities=True)

result[“name”] = result[“nodeId”].apply(lambda x: gds.util.asNode(x)[“name”])

# 按社群分组,输出各社群概念列表
community_report = (result.groupby(“communityId”)[“name”]
.apply(list).reset_index())
community_report.columns = [“社群ID”, “包含概念”]
community_report[“概念数量”] = community_report[“包含概念”].apply(len)
community_report.to_csv(“theology_communities.csv”, index=False, encoding=”utf-8-sig”)
print(community_report.sort_values(“概念数量”, ascending=False))
“`

输出的 `theology_communities.csv` 可直接用于课程模块设计——每个社群对应一个**教义单元**,社群间的跨界节点(Betweenness 高)即是单元间的**衔接概念**,适合作为教学过渡点。

Sources
[1] Louvain Community Detection | GraphAcademy https://graphacademy.neo4j.com/courses/workshop-gds/2-community-detection-fraud/2-louvain-deep-dive/
[2] Louvain method – Wikipedia https://en.wikipedia.org/wiki/Louvain_method
[3] What is the Louvain Method? – PuppyGraph https://www.puppygraph.com/blog/louvain
[4] Spectral Community Detection in Clinical Knowledge Graphs https://towardsdatascience.com/spectral-community-detection-in-clinical-knowledge-graphs/
[5] Louvain Algorithm explanation with example for … – YouTube https://www.youtube.com/watch?v=akfiGPBtCuM
[6] community_detection – Memgraph https://memgraph.com/docs/advanced-algorithms/available-algorithms/community_detection
[7] Louvain :: Graph Data Science Library – TigerGraph Documentation https://docs.tigergraph.com/graph-ml/3.10/community-algorithms/louvain
[8] Community Detection Algorithms #datascience #machinelearning https://www.youtube.com/watch?v=DM9Htgdxy7g
[9] louvain_communities — NetworkX 3.6.1 documentation https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.community.louvain.louvain_communities.html
[10] Louvain Community Detection | GraphAcademy https://graphacademy.neo4j.com/courses/workshop-gds-python-aga/1-python-client/8-louvain-on-citations/
[11] An Improved Louvain Algorithm for Community Detection – 2021 https://onlinelibrary.wiley.com/doi/10.1155/2021/1485592
[12] Louvain’s Algorithm for Community Detection in Python https://towardsdatascience.com/louvains-algorithm-for-community-detection-in-python-95ff7f675306/