***
## 一、Louvain 算法核心原理
Louvain 算法通过最大化**模块度(Modularity)**
算法分两个交替执行的阶段 :[3]
– **阶段一(局部优化)**:每个节点尝试加入邻居所在社群,
– **阶段二(聚合压缩)**:将每个社群压缩为一个”超级节点”
这种层级迭代使 Louvain 特别擅长发现**嵌套式教义结构**——既能看到宏观主题群组,
***
## 二、针对倪李神学的参数配置
“`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-
maxLevels: 5,
relationshipWeightProperty: ‘weight’,
includeIntermediateCommunities
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’` | 让强语义关系(如”目标是”)比弱关系更影响聚类 |
| `
***
## 三、预期发现的倪李神学社群
根据倪李神学概念的内在语义密度,Louvain 预期识别以下社群 :[3][1]
**宏观社群(高层级)**
| 社群ID | 预期包含概念 | 神学范畴 |
|——–|————|——-
| 社群 A | 三一神、父神、子、圣灵、神圣经纶 | 神论/经纶论 |
| 社群 B | 神圣生命、人的灵、调和、变化形态 | 生命论/救赎论 |
| 社群 C | 召会建造、地方召会、肢体、得胜者 | 召会论/末世论 |
| 社群 D | 属灵人、正常基督徒生活、生命读经 | 著作聚类 |
**细粒度子群(低层级)**:社群 B 内部可能进一步分裂为”灵的功用子群”(灵、魂、体、三分说)
***
## 四、写回节点并可视化
“`cypher
// 将社群ID写回节点属性
CALL gds.louvain.write(‘nee-lee-
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 的一个已知缺陷(可能产生内部不连通的社群),
“`cypher
CALL gds.leiden.stream(‘nee-lee-
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://
G, _ = gds.graph.project(“nee-lee-
{“RELATED_TO”: {“orientation”: “UNDIRECTED”,
“properties”: “weight”}})
result = gds.louvain.stream(G, relationshipWeightProperty=”
includeIntermediateCommunities
result[“name”] = result[“nodeId”].apply(lambda x: gds.util.asNode(x)[“name”])
# 按社群分组,输出各社群概念列表
community_report = (result.groupby(“communityId”)
.apply(list).reset_index())
community_report.columns = [“社群ID”, “包含概念”]
community_report[“概念数量”] = community_report[“包含概念”].
community_report.to_csv(“
print(community_report.sort_
“`
输出的 `theology_communities.csv` 可直接用于课程模块设计——每个社群对应一个**教义单元**,
Sources
[1] Louvain Community Detection | GraphAcademy https://graphacademy.neo4j.
[2] Louvain method – Wikipedia https://en.wikipedia.org/wiki/
[3] What is the Louvain Method? – PuppyGraph https://www.puppygraph.com/
[4] Spectral Community Detection in Clinical Knowledge Graphs https://towardsdatascience.
[5] Louvain Algorithm explanation with example for … – YouTube https://www.youtube.com/watch?
[6] community_detection – Memgraph https://memgraph.com/docs/
[7] Louvain :: Graph Data Science Library – TigerGraph Documentation https://docs.tigergraph.com/
[8] Community Detection Algorithms #datascience #machinelearning https://www.youtube.com/watch?
[9] louvain_communities — NetworkX 3.6.1 documentation https://networkx.org/
[10] Louvain Community Detection | GraphAcademy https://graphacademy.neo4j.
[11] An Improved Louvain Algorithm for Community Detection – 2021 https://onlinelibrary.wiley.
[12] Louvain’s Algorithm for Community Detection in Python https://towardsdatascience.