Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
super(RBERVertexPartitionTest, self).setUp();
self.partition_type = leidenalg.RBERVertexPartition;
log_debug('Running leiden clustering...')
res = self.params['leiden_res']
seed = self.params['seed']
# construct the graph object
nn = set(self.snn_graph[self.snn_graph.columns[0]])
g = ig.Graph()
g.add_vertices(len(nn))
g.vs['name'] = list(range(1, len(nn)+1))
ll = []
for i in self.snn_graph.itertuples(index=False):
ll.append(tuple(i))
g.add_edges(ll)
if self.params == 'ModularityVertexPartition':
part = leidenalg.ModularityVertexPartition
else:
part = leidenalg.RBERVertexPartition
cl = leidenalg.find_partition(g,
part,
n_iterations=10,
resolution_parameter=res,
seed=seed)
self.leiden_cl = cl.membership
self.leiden_prep()
log_debug('Leiden has finished.')
self._sdm = SampleDistanceMatrix(x=x, d=d, metric=metric,
use_pdist=use_pdist,
sids=sids, fids=fids, nprocs=nprocs)
if graph is None:
knn_conn_mat = self._sdm.s_knn_connectivity_matrix(
k=k, use_pca=use_pca, use_hnsw=use_hnsw,
index_params=index_params, query_params=query_params,
verbose=verbose)
graph = SampleDistanceMatrix.knn_conn_mat_to_aff_graph(
knn_conn_mat, aff_scale=aff_scale)
if partition_method == "RBConfigurationVertexPartition":
la_part_cls = la.RBConfigurationVertexPartition
elif partition_method == "RBERVertexPartition":
la_part_cls = la.RBERVertexPartition
elif partition_method == "CPMVertexPartition":
la_part_cls = la.CPMVertexPartition
elif partition_method == "SignificanceVertexPartition":
la_part_cls = la.SignificanceVertexPartition
elif partition_method == "SurpriseVertexPartition":
la_part_cls = la.SurpriseVertexPartition
else:
raise ValueError(
"Unknown partition method: {}".format(partition_method))
la_res = la.find_partition(graph, la.RBConfigurationVertexPartition,
seed=random_state, weights='weight',
resolution_parameter=resolution)
# keep track of results and parameters
self._graph = graph
self._la_res = la_res