採用類似連通域的兩遍遍曆法,聚合mark
使用方法:
1、初始化聚合池
2、不停往聚合池中新增兩兩匹配關係
3、輸出聚合結果
# -- coding: utf-8 --
import os
import glob
import sys
import cv2
import shutil
import numpy as np
import random
class
aggregatepool
(object):
def__init__
(self)
: self.markid2pmarkid =
self.pmarkid2markid =
self.group_id =
0 self.group_id_pairs =
def(self, qmarkid, bmarkid, aggregate):if
not aggregate:
# 不可差
if qmarkid not
in self.markid2pmarkid:
self.markid2pmarkid[qmarkid]
= self.group_id
self.group_id +=
1if bmarkid not
in self.markid2pmarkid:
self.markid2pmarkid[bmarkid]
= self.group_id
self.group_id +=
1else
:# 可差
if qmarkid in self.markid2pmarkid and bmarkid in self.markid2pmarkid:
(min
(self.markid2pmarkid[qmarkid]
, self.markid2pmarkid[bmarkid]),
max(self.markid2pmarkid[qmarkid]
, self.markid2pmarkid[bmarkid]))
)if qmarkid in self.markid2pmarkid and bmarkid not
in self.markid2pmarkid:
self.markid2pmarkid[bmarkid]
= self.markid2pmarkid[qmarkid]
if qmarkid not
in self.markid2pmarkid and bmarkid in self.markid2pmarkid:
self.markid2pmarkid[qmarkid]
= self.markid2pmarkid[bmarkid]
if qmarkid not
in self.markid2pmarkid and bmarkid not
in self.markid2pmarkid:
self.markid2pmarkid[qmarkid]
= self.group_id
self.markid2pmarkid[bmarkid]
= self.group_id
self.group_id +=
1def
aggregate
(self)
: set_list =
for id1, id2 in self.group_id_pairs:
exist =
false
for s in set_list:
if id1 in s or id2 in s:
s.add(id1)
s.add(id2)
exist =
true
ifnot exist:
news =
idmap =
for s in set_list:
mins =
min(s)
forid
in s:
idmap[id]
= mins
# 重新整理group-id
for markid in self.markid2pmarkid:
oldid = self.markid2pmarkid[markid]
newid = idmap[oldid]
self.markid2pmarkid[markid]
= newid
# 聚類
for markid in self.markid2pmarkid:
gid = self.markid2pmarkid[markid]
if gid not
in self.pmarkid2markid:
self.pmarkid2markid[gid]=[
] self.pmarkid2markid[gid]
# 視覺化
for gid in self.pmarkid2markid:
print
(gid,
"********************"
)for mark in self.pmarkid2markid[gid]
:print
(mark)
if __name__ ==
'__main__'
: all_marks =
# 創造100個待聚合的例項
for i in
range
(100):
singleid = random.randint(
10000
,99999
) gid = random.randint(50,
55)s =
str(singleid)
+"."
+str
(gid)
agg = aggregatepool(
)# 初始化聚合池
for i, qm in
enumerate
(all_marks)
:for j, bm in
enumerate
(all_marks)
:if i == j:
continue
else
:if qm.split(
".")[-
1]== bm.split(
".")[-
1]:# 判斷兩兩是否可聚
true
)# 新增聚合關係
else
: false
)# 新增聚合關係
agg.aggregate(
)# 輸出聚合結果
第乙個SpringBoot聚合專案
從開始構建專案各種難題,找了大佬幫忙解決 其中最難受的便是各種依賴以及mybatis 直接通過spring initializr 建立乙個主專案 不選直接下一步 接下來新增專案依賴以及在主pom中進行版本管理 注意一定要新增子專案包的module ok下一步 開始建立子專案 同樣按照上面建立主專案的...
乙個裝飾器裝飾乙個函式
2 如果鍵不存在,則新增到字典中。請使用裝飾器來實現,順便複習下 args和 kwargs的用法 a defselect func def inner args,kwargs if len args 0 if kwargs key in kwargs data print 鍵存在 else func...
乙個觸發器
設計乙個觸發器,當刪除employees中的某個雇員時,刪除orders表中的與這個雇員 相關的一切記錄。第一步 建立儲存過程 drop trigger employees delete gocreate trigger employees delete on employees instead o...