Package: graph-partition
Graph PartitioningGraph Partitioning is an age-old problem with applications in various domains, such as
routing vehicles for delivery and finding the right target for immunizations to control a
pandemic. Graph Partitioning involves partitioning a graph’s vertices into roughly
equal-sized subsets such that the total edge cost spanning the subsets is at most k.
In this package we have implemented three major algorithms -Authors@somsubhra88Graph Convolution Networks (GCN)Graph Convolution Networks use neural networks on structured graphs. Graph convolutions are
generalizations of convolutions and are easier to apply in the spectral domain. Graph
Convolutional Networks (GCN) which can use both - graph and node feature information. This
python implementation is mostly inspired from a paper wiritten by Thomas N. Kipf and
Max Welling.PaperSpectral ClusteringThe spectral clustering method is defined for general weighted graphs; it identifies K clusters
using the eigenvectors of a matrix.Constrained K-Means ClusteringK-means clustering implementation whereby a minimum and/or maximum size for each cluster
can be specified.This K-means implementation modifies the cluster assignment step (E in EM) by formulating
it as a Minimum Cost Flow (MCF) linear network optimisation problem. This is then solved
using a cost-scaling push-relabel algorithm and uses Google's Operations Research
tools' SimpleMinCostFlow which is a fast C++ implementation.InstallationYou can install the graph-partition from PyPI:pipinstallgraph-partitionHow to UsePrimarily there are three major algorithms are thereGraph Convolutional Neural NetworkSpectral ClusteringConstrained K-Means ClusteringUsing of Graph Convolutional Networkimporturllib.requestfromscipy.spatialimportdistance_matrixfromgraph_partitionimport*# Artificial test Dataurl="https://cs.joensuu.fi/sipu/datasets/s1.txt"data=urllib.request.urlopen(url)ds=[]forlineindata:ds.append([float(x)forxinline.strip().split()])# Calculating the Const Matrixcost_matrix=distance_matrix(ds[:50],ds[:50])# Defining the GCN Modelgcn_model=GraphConvolutionNetwork(cost_matrix=cost_matrix,num_class=2,hidden_layers=10)# GCN fit and predictgcn_model.fit()# Printing the cluster labelprint(gcn_model.cluster_label)# Printing the cluster evaluation metricsprint(gcn_model.evaluation_metric)Using of Spectral Clusteringimporturllib.requestfromscipy.spatialimportdistance_matrixfromgraph_partitionimport*# Artificial test Dataurl="https://cs.joensuu.fi/sipu/datasets/s1.txt"data=urllib.request.urlopen(url)ds=[]forlineindata:ds.append([float(x)forxinline.strip().split()])# Calculating the Const Matrixcost_matrix=distance_matrix(ds[:50],ds[:50])# Defining Spectral Clustering Modelsc_model=SpectralClustering(cost_matrix=cost_matrix,num_class=2)# Printing the cluster labels and evaluation metricsprint(sc_model.cluster_label)print(sc_model.evaluation_metric)Using of Constrained K-Means Clusteringimporturllib.requestfromgraph_partitionimport*# Artificial test Dataurl="https://cs.joensuu.fi/sipu/datasets/s1.txt"data=urllib.request.urlopen(url)ds=[]forlineindata:ds.append([float(x)forxinline.strip().split()])# Defining Spectral Clustering Modelk_means_model=ConstrainedKMeans(design_matrix=ds[:50],num_class=2,evaluate_metric=True)# Printing the cluster labels and evaluation metricsprint(k_means_model.cluster_label)print(k_means_model.evaluation_metric)SupportFor any queries please contact viaemail