本文整理汇总了Python中networkx.find_cliques方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.find_cliques方法的具体用法?Python networkx.find_cliques怎么用?Python networkx.find_cliques使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.find_cliques方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: form_cliques
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def form_cliques(p_values, nnames):
"""
This method forms the cliques
"""
# first form the numpy matrix data
m = len(nnames)
g_data = np.zeros((m, m), dtype=np.int64)
for p in p_values:
if p[3] == False:
i = np.where(nnames == p[0])[0][0]
j = np.where(nnames == p[1])[0][0]
min_i = min(i, j)
max_j = max(i, j)
g_data[min_i, max_j] = 1
g = networkx.Graph(g_data)
return networkx.find_cliques(g)
示例2: __init__
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def __init__(self,
points,
epsilon,
labels=None,
distfcn=distance.euclidean):
self.pts = points
self.labels = (range(len(self.pts))
if labels is None or len(labels) != len(self.pts)
else labels)
self.epsilon = epsilon
self.distfcn = distfcn
self.network = self.construct_network(self.pts,
self.labels,
self.epsilon,
self.distfcn)
self.import_simplices(map(tuple, nx.find_cliques(self.network)))
示例3: find_biggest_clique
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def find_biggest_clique(self):
"""Finds the biggest clique of validators committed to target estimate."""
# Do not have safety if less than half have candidate_estimate.
if self.validator_set.weight(self.with_candidate) < self.validator_set.weight() / 2:
return set(), 0
edges = self._collect_edges()
graph = nx.Graph()
graph.add_edges_from(edges)
cliques = nx.find_cliques(graph)
max_clique = []
max_weight = 0
for clique in cliques:
test_weight = utils.get_weight(clique)
if test_weight > max_weight:
max_clique = clique
max_weight = test_weight
return set(max_clique), max_weight
示例4: __k_clique_communities
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def __k_clique_communities(g, cliques=None):
if cliques is None:
cliques = nx.find_cliques(g)
cliques = [frozenset(c) for c in cliques if len(c) >= 4]
# First index which nodes are in which cliques
membership_dict = defaultdict(list)
for clique in cliques:
for node in clique:
membership_dict[node].append(clique)
# For each clique, see which adjacent cliques percolate
perc_graph = nx.Graph()
perc_graph.add_nodes_from(cliques)
for clique in cliques:
for adj_clique in _get_adjacent_cliques(clique, membership_dict):
if len(clique.intersection(adj_clique)) >= 3:
perc_graph.add_edge(clique, adj_clique)
# Connected components of clique graph with perc edges
# are the percolated cliques
for component in nx.connected_components(perc_graph):
yield frozenset.union(*component)
示例5: cliques
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def cliques(self):
"""
Iterator over maximal cliques in the phase space. To get a list of
cliques, use list(PhaseSpace.cliques).
"""
if self._cliques is None:
self.find_cliques()
return self._cliques
示例6: find_cliques
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def find_cliques(self):
self._cliques = nx.find_cliques(self.graph)
return self._cliques
示例7: __or__
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def __or__(self, graph):
if (len(graph.nodes()) == 1) and len(self.nodes()) == 1:
return list([0])
cg = self.correspondence_graph(graph, 0.4)
cliques = list(nx.find_cliques(cg))
cliques.sort(key=len)
return cliques[-1]
示例8: setUp
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def setUp(self):
z = [3, 4, 3, 4, 2, 4, 2, 1, 1, 1, 1]
self.G = cnlti(nx.generators.havel_hakimi_graph(z), first_label=1)
self.cl = list(nx.find_cliques(self.G))
H = nx.complete_graph(6)
H = nx.relabel_nodes(H, dict([(i, i + 1) for i in range(6)]))
H.remove_edges_from([(2, 6), (2, 5), (2, 4), (1, 3), (5, 3)])
self.H = H
示例9: test_find_cliques1
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def test_find_cliques1(self):
cl = list(nx.find_cliques(self.G))
rcl = nx.find_cliques_recursive(self.G)
expected = [[2, 6, 1, 3], [2, 6, 4], [5, 4, 7], [8, 9], [10, 11]]
assert_equal(sorted(map(sorted, cl)), sorted(map(sorted, rcl)))
assert_equal(sorted(map(sorted, cl)), sorted(map(sorted, expected)))
示例10: test_selfloops
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def test_selfloops(self):
self.G.add_edge(1, 1)
cl = list(nx.find_cliques(self.G))
rcl = nx.find_cliques_recursive(self.G)
assert_equal(sorted(map(sorted, cl)), sorted(map(sorted, rcl)))
assert_equal(cl,
[[2, 6, 1, 3], [2, 6, 4], [5, 4, 7], [8, 9], [10, 11]])
示例11: test_find_cliques2
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def test_find_cliques2(self):
hcl = list(nx.find_cliques(self.H))
assert_equal(sorted(map(sorted, hcl)),
[[1, 2], [1, 4, 5, 6], [2, 3], [3, 4, 6]])
示例12: test_directed
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def test_directed(self):
cliques = nx.find_cliques(nx.DiGraph())
示例13: image_agreements
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def image_agreements(imarr, beamparams, metric_mtx, fracsteps, cutoff=0.95):
if 'networkx' not in sys.modules:
raise Exception("networkx not installed: cannot use image_agreements()!")
(min_psize, max_fov) = get_psize_fov(imarr)
im_cliques_fraclevels = []
cliques_fraclevels = []
for fracidx in range(len(fracsteps)):
# print(fracidx)
slice_metric_mtx = metric_mtx[:, :, fracidx]
cuttoffidx = np.where(slice_metric_mtx >= cutoff)
consistant = zip(*cuttoffidx)
# make graph
G = nx.Graph()
for i in range(len(consistant)):
G.add_edge(consistant[i][0], consistant[i][1])
# find all cliques
cliques = list(nx.find_cliques(G))
# print(cliques)
cliques_fraclevels.append(cliques)
im_clique = []
for c in range(len(cliques)):
clique = cliques[c]
im_avg = imarr[clique[0]].blur_gauss(beamparams, fracsteps[fracidx])
for n in range(1, len(clique)):
imcomp = imarr[clique[n]].blur_gauss(beamparams, fracsteps[fracidx])
(error, im_avg, im2_shift) = im_avg.compare_images(imcomp, metric=['xcorr'],
psize=min_psize,
target_fov=max_fov,
blur_frac=0.0,
beamparams=beamparams)
im_avg.imvec = (im_avg.imvec + im2_shift.imvec) / 2.0
im_clique.append(im_avg.copy())
im_cliques_fraclevels.append(im_clique)
return(cliques_fraclevels, im_cliques_fraclevels)
示例14: __cluster__
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import find_cliques [as 别名]
def __cluster__(self,markings,user_ids,tools,reduced_markings,dimensions,subject_id):
"""
main clustering algorithm - works on a single per-subject basis
for rectangles, doesn't make use of reduced_markings
:param markings:
:param user_ids:
:param tools:
:param reduced_markings:
:param dimensions:
:param subject_id:
:return:
"""
print(markings)
print(reduced_markings)
print(len(zip(*markings)))
print([np.median(axis) for axis in zip(*markings)])
print([np.median(axis,axis=0) for axis in zip(*markings)])
print([np.median(axis,axis=1) for axis in zip(*markings)])
assert False
# if empty markings, just return nothing
if markings == []:
return [],0
results = []
overlap_graph = self.__overlap_graph__(markings)
# each clique is a group of markings which all refer to the same region on the page
# go through each clique
for c in networkx.find_cliques(overlap_graph):
# ignore any clique with less than 3 markings in it
if len(c) < 0:
continue
# get the specific markings in this clique and their corresponding tools
clique = [markings[i] for i in c]
tools_in_clique = [tools[i] for i in c]
# create the new cluster based on this clique
new_cluster = dict()
new_cluster["center"] = self.__median_rectangles__(clique)
new_cluster["cluster members"] = clique
new_cluster["users"] = [user_ids[i] for i in c]
# the tools used by each person with a rectangle in this cluster
new_cluster["tools"] = tools_in_clique
new_cluster["image area"] = None
results.append(new_cluster)
return results,0