GM$GED#22
Merged
heatingma merged 3 commits intoThinklab-SJTU:mainfrom Mar 13, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GM 的K 是(n2,n1,n2,n1)
对于dummy非法点对的惩罚应该为0,只需要在求解后删除dummy点对的匹配就行。如果施加惩罚无法对应原本的cost,而且惩罚过大会造成rrwm等算法不稳定。所以不需要这一步 :
Ged 的K提供两种构建模式:is_compacted True对应只能用astar解, False可以使用rrwm,ipfp,sm求解
2. 求解器
根据论文《Graph Edit Distance as a Quadratic Program》 可以把K扩展成(n1+n2)来使用gm求解器解,但是这是非精确求解器,而且pygm求解器接口是以affinity的形似=式,需要把cost转化为affinity。具体而言操作如下:
在样例里,由于rrwm,sm,ipfp不是精确求解器,而且受temperature影响,不一定能达到最优。
数据

GM 做了同构图和子图样例(10~20点)和一个8点小同构图样例测试astar
GED 由于最优cost计算时间长,这里只提供8对8编辑样例
两张图均使用nx的几何图随机生成接口生成,我按照GED的K构建代价计算方式定义节点替换代价(几何图中两节点位置的曼哈顿距离>1e-5则视为替换) 使用nx.optimal_edit_paths获取最优编辑方式并把第1中视为ref_sol(可以有非常多的最优编辑方式),把GED的默认evaluate改为score模式。
else
计算md5时由于包含非numpy对象,GM&GED 会报错,对AffinityBuild QAPGraphBase重载__repr__