├── .gitattributes ├── LICENSE ├── Networkx Network Analyze.ipynb ├── README.md ├── UtilitiesNetwork.py ├── facebookNet_analyze.py ├── fbNet_community.png ├── fbNet_ego.py ├── fbNet_layout.png ├── graphs ├── ego_0_net.png ├── ego_0_net_betweenness.png ├── ego_0_net_communities.png ├── ego_0_net_degree.png ├── ego_107_net.png ├── ego_107_net_betweenness.png ├── ego_107_net_communities.png ├── ego_107_net_degree.png ├── ego_1684_net.png ├── ego_1684_net_betweenness.png ├── ego_1684_net_communities.png ├── ego_1684_net_degree.png ├── ego_1912_net.png ├── ego_1912_net_betweenness.png ├── ego_1912_net_communities.png ├── ego_1912_net_degree.png ├── ego_3437_net.png ├── ego_3437_net_betweenness.png ├── ego_3437_net_communities.png ├── ego_3437_net_degree.png ├── ego_348_net.png ├── ego_348_net_betweenness.png ├── ego_348_net_communities.png ├── ego_348_net_degree.png ├── ego_3980_net.png ├── ego_3980_net_betweenness.png ├── ego_3980_net_communities.png ├── ego_3980_net_degree.png ├── ego_414_net.png ├── ego_414_net_betweenness.png ├── ego_414_net_communities.png ├── ego_414_net_degree.png ├── ego_686_net.png ├── ego_686_net_betweenness.png ├── ego_686_net_communities.png ├── ego_686_net_degree.png ├── ego_698_net.png ├── ego_698_net_betweenness.png ├── ego_698_net_communities.png ├── ego_698_net_degree.png ├── fbNet_Degree.png ├── fbNet__net.png ├── fbnet__net_betweenness.png ├── fbnet__net_communities.png └── fbnet__net_degree.png └── scale_free ├── __pycache__ └── networkAOT.cpython-36.pyc ├── main.py └── networkAOT.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Anıl Osman Tur 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ComplexNetworksProjects 2 | 3 | Facebook ego network dataset used for network analysis project 4 | - [link to dataset website](https://snap.stanford.edu/data/ego-Facebook.html) 5 | 6 | - Networkx Network Analysis notebook contains: Networkx analysis demo for class presentaion. 7 | 8 | - Utilities Network file contains graph visiualizaion functions that used in other files as un abrivation. 9 | 10 | - Scale free directory has netwrok class to create scale free network writen from scratch to understand better the scale free networks. 11 | 12 | - Graphs folder contains drawn graphs from facebook-ego net dataset 13 | 14 | - Networks analysis with neworkx [notebook](Networkx%20Network%20Analyze.ipynb) 15 | 16 | ## The Resulted Graph Examples 17 | 1. 18 | ![](fbNet_community.png) 19 | 2. 20 | ![](fbNet_layout.png) 21 | 3. 22 | ![](graphs/ego_0_net_degree.png) 23 | 24 | ## Refrances 25 | 26 | - J. McAuley and J. Leskovec. Learning to Discover Social Circles in Ego Networks. NIPS, 2012. 27 | 28 | - Aric A. Hagberg, Daniel A. Schult and Pieter J. Swart, “Exploring network structure, dynamics, and function using NetworkX”, in Proceedings of the 7th Python in Science Conference (SciPy2008), Gäel Varoquaux, Travis Vaught, and Jarrod Millman (Eds), (Pasadena, CA USA), pp. 11–15, Aug 2008 29 | -------------------------------------------------------------------------------- /UtilitiesNetwork.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Sun Dec 3 00:51:30 2017 5 | 6 | @author: anilosmantur 7 | 8 | Visiualization functions 9 | """ 10 | 11 | import networkx as nx 12 | import matplotlib.pyplot as plt 13 | 14 | def drawCommunityGraph(G, pos, part, fgSize, nodeSize=35): 15 | size = float(len(set(part.values()))) 16 | print ('Found community count: ', size) 17 | count = 0. 18 | plt.figure(figsize=(fgSize, fgSize)) 19 | plt.axis('off') 20 | plt.margins(tight=True) 21 | for com in set(part.values()) : 22 | count = count + 1. 23 | list_nodes = [nodes for nodes in part.keys() if part[nodes] == com] 24 | values = [ (count / size) for nodes in list_nodes] 25 | nodes = nx.draw_networkx_nodes(G, 26 | pos, 27 | list_nodes, 28 | cmap=plt.get_cmap('jet'), 29 | with_labels=False, 30 | node_size = nodeSize, 31 | node_color = values, 32 | vmin=0.0, vmax=1.0 ) # color map magma 33 | nodes.set_edgecolor('black') 34 | nodes.set_linewidth(1.0) 35 | 36 | 37 | edges = nx.draw_networkx_edges(G, pos, alpha=0.5) 38 | edges.set_linewidth(0.5) 39 | plt.show() 40 | print('Printing community layout finished') 41 | 42 | def drawCommunityGraphSave(G, pos, part, fgSize, name): 43 | size = float(len(set(part.values()))) 44 | print ('Found community count: ', size) 45 | count = 0. 46 | plt.figure(figsize=(fgSize, fgSize)) 47 | plt.axis('off') 48 | plt.margins(tight=True) 49 | for com in set(part.values()) : 50 | count = count + 1. 51 | list_nodes = [nodes for nodes in part.keys() if part[nodes] == com] 52 | values = [ (count / size) for nodes in list_nodes] 53 | nodes = nx.draw_networkx_nodes(G, 54 | pos, 55 | list_nodes, 56 | cmap=plt.get_cmap('jet'), 57 | with_labels=False, 58 | node_size = 35, 59 | node_color = values, 60 | vmin=0.0, vmax=1.0 ) # color map magma 61 | nodes.set_edgecolor('black') 62 | nodes.set_linewidth(1.0) 63 | 64 | 65 | edges = nx.draw_networkx_edges(G, pos, alpha=0.5) 66 | edges.set_linewidth(0.5) 67 | 68 | plt.savefig('graphs/' + name +'_net_communities.png') 69 | print('Printing community layout finished') 70 | 71 | def drawCentralityGraph(G, pos, cent, fgSize, nodeSize=35): 72 | count = 0. 73 | plt.figure(figsize=(fgSize, fgSize)) 74 | plt.axis('off') 75 | plt.margins(tight=True) 76 | for com in set(cent.values()) : 77 | count = count + 1. 78 | list_nodes = [nodes for nodes in cent.keys() if cent[nodes] == com] 79 | values = [ (400 * com) for nodes in list_nodes] 80 | nodes = nx.draw_networkx_nodes(G, 81 | pos, 82 | list_nodes, 83 | cmap=plt.get_cmap('jet'), 84 | with_labels=False, 85 | node_size = values, 86 | node_color = values, 87 | vmin=0.0, vmax=1.0 ) # color map magma 88 | nodes.set_edgecolor('black') 89 | nodes.set_linewidth(1.0) 90 | 91 | 92 | edges = nx.draw_networkx_edges(G, pos, alpha=0.5) 93 | edges.set_linewidth(0.5) 94 | plt.show() 95 | print('Printing centrality layout finished') 96 | 97 | def drawCentralityGraphSave(G, pos, cent, fgSize, name='', c_type=''): 98 | count = 0. 99 | plt.figure(figsize=(fgSize, fgSize)) 100 | plt.axis('off') 101 | plt.margins(tight=True) 102 | for com in set(cent.values()) : 103 | count = count + 1. 104 | list_nodes = [nodes for nodes in cent.keys() if cent[nodes] == com] 105 | values = [ (400 * com) for nodes in list_nodes] 106 | nodes = nx.draw_networkx_nodes(G, 107 | pos, 108 | list_nodes, 109 | cmap=plt.get_cmap('jet'), 110 | with_labels=False, 111 | node_size = values, 112 | node_color = values, 113 | vmin=0.0, vmax=1.0 ) # color map magma 114 | nodes.set_edgecolor('black') 115 | nodes.set_linewidth(1.0) 116 | 117 | 118 | edges = nx.draw_networkx_edges(G, pos, alpha=0.5) 119 | edges.set_linewidth(0.5) 120 | plt.savefig('graphs/' + name +'_net_'+ c_type + '.png') 121 | print('Printing centrality layout finished') 122 | 123 | def nxDrawCommunityGraph(G, pos, coms, fgSize, nodeSize=35): 124 | size = len(coms) 125 | print ('community count: ', size) 126 | count = 0. 127 | plt.figure(figsize=(fgSize, fgSize)) 128 | plt.axis('off') 129 | plt.margins(tight=True) 130 | for com in coms : 131 | count = count + 1. 132 | list_nodes = [nodes for nodes in com] 133 | values = [ (count / size) for nodes in list_nodes] 134 | nodes = nx.draw_networkx_nodes(G, 135 | pos, 136 | list_nodes, 137 | cmap=plt.get_cmap('jet'), 138 | with_labels=False, 139 | node_size = nodeSize, 140 | node_color = values, 141 | vmin=0.0, vmax=1.0 ) # color map magma 142 | nodes.set_edgecolor('black') 143 | nodes.set_linewidth(1.0) 144 | 145 | 146 | edges = nx.draw_networkx_edges(G, pos, alpha=0.5) 147 | edges.set_linewidth(0.5) 148 | plt.show() 149 | print('Printing community layout finished') 150 | 151 | 152 | def drawGraph(G, pos, fgSize, nodeSize=35): 153 | plt.figure(figsize=(fgSize, fgSize)) 154 | plt.axis('off') 155 | plt.margins(tight=True) 156 | nodes = nx.draw_networkx_nodes(G, pos, node_size=nodeSize, node_color='red') 157 | nodes.set_edgecolor('black') 158 | nodes.set_linewidth(1.0) 159 | edges = nx.draw_networkx_edges(G, pos, edge_color='blue') 160 | edges.set_linewidth(0.5) 161 | plt.show() 162 | print('Printing layout finished') 163 | 164 | def drawGraphSave(G, pos, fgSize, name=''): 165 | plt.figure(figsize=(fgSize, fgSize)) 166 | plt.axis('off') 167 | plt.margins(tight=True) 168 | nodes = nx.draw_networkx_nodes(G, pos, node_size=35, node_color='red') 169 | nodes.set_edgecolor('black') 170 | nodes.set_linewidth(1.0) 171 | edges = nx.draw_networkx_edges(G, pos, edge_color='blue') 172 | edges.set_linewidth(0.5) 173 | plt.savefig('graphs/' + name +'_net.png') 174 | print('Printing layout finished') 175 | 176 | def drawEgoGraph(G, pos, egoNode, fgSize): 177 | plt.figure(figsize=(fgSize, fgSize)) 178 | plt.axis('off') 179 | plt.margins(tight=True) 180 | nodes = nx.draw_networkx_nodes(G, pos, node_size=35, node_color='green') 181 | nodes.set_edgecolor('black') 182 | nodes.set_linewidth(1.0) 183 | edges = nx.draw_networkx_edges(G, pos, edge_color='blue') 184 | edges.set_linewidth(0.5) 185 | plt.show() 186 | print('Printing Ego layout finished') 187 | 188 | def centralityPlot(cent, fgSize): 189 | plt.figure(figsize=(fgSize, fgSize)) 190 | plt.margins(tight=True) 191 | cent = sorted(cent.items()) 192 | values = [ c for (node, c) in cent] 193 | nodes = [ node for (node, c) in cent] 194 | plt.plot(nodes, values) 195 | plt.show() 196 | print('Printing Centrality Plot Finished') 197 | 198 | def centralityPlotSave(cent, fgSize, name='', c_type=''): 199 | plt.figure(figsize=(fgSize, fgSize)) 200 | plt.margins(tight=True) 201 | cent = sorted(cent.items()) 202 | values = [ c for (node, c) in cent] 203 | nodes = [ node for (node, c) in cent] 204 | plt.plot(nodes, values) 205 | plt.savefig('graphs/' + name +'_net_plot_'+ c_type + '.png') 206 | print('Printing Centrality Plot Finished') 207 | -------------------------------------------------------------------------------- /facebookNet_analyze.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Sat Dec 2 22:46:44 2017 5 | 6 | @author: anilosmantur 7 | """ 8 | 9 | import community 10 | import networkx as nx 11 | from networkx.algorithms import community as nx_com 12 | from networkx.algorithms import approximation as nx_approx 13 | import matplotlib.pyplot as plt 14 | import UtilitiesNetwork as un 15 | print('library imports done') 16 | 17 | FILE_NAME = '/home/anilosmantur/**/complex_networks/project/ego_facebook/facebook_combined.txt' 18 | 19 | edges = [] 20 | with open(FILE_NAME) as netfile: 21 | print('file opened') 22 | for i, line in enumerate(netfile): 23 | words = line.split() 24 | edges.append((int(words[0]), int(words[1]))) 25 | print('Reading edges finished') 26 | 27 | 28 | fb_net = nx.Graph(edges) 29 | info = nx.info(fb_net) + '\n' 30 | 31 | avgCluster_coef = nx.average_clustering(fb_net) 32 | Cl_co = 'Estimation of avgerage clusternig coefficient:'+str(avgCluster_coef) + '\n' 33 | 34 | dens = nx.density(fb_net) 35 | dens = 'Density of network: ' + str(dens) + '\n' 36 | 37 | #max_clique = nx_approx.max_clique(fb_net) 38 | #print(max_clique) 39 | 40 | # drawing the graph 41 | pos = nx.spring_layout(fb_net) 42 | un.drawGraphSave(fb_net, pos, 8, 'fbNet_') 43 | plt.close() 44 | 45 | part = community.best_partition(fb_net) 46 | size = float(len(set(part.values()))) 47 | com = 'Found community count: ' + str(size) + '\n' 48 | mode = community.modularity(part, fb_net) 49 | mode = 'Modularity: ' + str(mode) + '\n' 50 | un.drawCommunityGraphSave(fb_net, pos, part, 8, 'fbnet_') 51 | del part 52 | plt.close() 53 | 54 | 55 | centb = nx.centrality.betweenness_centrality(fb_net) 56 | un.centralityPlotSave(centb, 5, 'fbnet_', 'betweenness') 57 | un.drawCentralityGraphSave(fb_net, pos, centb, 8, 'fbnet_', 'betweenness') 58 | del centb 59 | plt.close() 60 | 61 | centd = nx.centrality.degree_centrality(fb_net) 62 | un.centralityPlotSave(centd, 5, 'fbnet_', 'degree') 63 | un.drawCentralityGraphSave(fb_net, pos, centd, 8, 'fbnet_', 'degree') 64 | del centd 65 | plt.close() 66 | 67 | with open('sums/fbnet_sum.txt', 'w') as sumfile: 68 | sumfile.write(info) 69 | sumfile.write(Cl_co) 70 | sumfile.write(com) 71 | sumfile.write(mode) 72 | sumfile.write(dens) 73 | 74 | # analyze the network 75 | hist = nx.degree_histogram(fb_net) 76 | plt.figure(figsize=(10, 10)) 77 | plt.plot(hist, linestyle=':') 78 | plt.title('Degree Historam') 79 | plt.savefig('fbNet_Degree.png') 80 | plt.close() 81 | print('Degree Historam finished') 82 | 83 | lap_spec = nx.laplacian_spectrum(fb_net) 84 | plt.plot(lap_spec) 85 | plt.title('Eigenvalues of the Laplacian') 86 | plt.savefig('fbNet_LapSpec.png') 87 | plt.close() 88 | print('Eigenvalues of the Laplacian') 89 | 90 | adj_spec = nx.adjacency_spectrum(fb_net) 91 | plt.plot(adj_spec) 92 | plt.title('Eigenvalues of the Adjaceny') 93 | plt.savefig('fbNet_AdjSpec.png') 94 | plt.close() 95 | print('Eigenvalues of the Adjaceny') 96 | 97 | spec_ordering = nx.spectral_ordering(fb_net) 98 | plt.plot(spec_ordering) 99 | plt.title('Spectral Ordering') 100 | plt.savefig('fbNet_SpecOrder.png') 101 | plt.close() 102 | print('Spectral Ordering') -------------------------------------------------------------------------------- /fbNet_community.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/fbNet_community.png -------------------------------------------------------------------------------- /fbNet_ego.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Sun Dec 3 00:33:22 2017 5 | 6 | @author: anilosmantur 7 | """ 8 | 9 | import os 10 | import community 11 | import networkx as nx 12 | from networkx.algorithms import community as nx_com 13 | from networkx.algorithms import approximation as nx_approx 14 | import matplotlib.pyplot as plt 15 | import UtilitiesNetwork as un 16 | 17 | print('library imports done') 18 | 19 | FILE_NAME = '/home/anilosmantur/***/complex_networks/project/ego_facebook/facebook/' 20 | 21 | edgeFiles = [file for file in os.listdir(FILE_NAME) if 'edges' in file] 22 | 23 | egoNodes = [int(ego[:-6]) for ego in edgeFiles ] 24 | egoNodes.sort() 25 | 26 | del edgeFiles 27 | 28 | for egoNode in egoNodes: 29 | edges = [] 30 | with open(FILE_NAME+ str(egoNode) + '.edges') as netfile: 31 | print('file opened') 32 | for i, line in enumerate(netfile): 33 | words = line.split() 34 | edges.append((egoNode, (int(words[0])))) 35 | edges.append((egoNode, (int(words[1])))) 36 | edges.append((int(words[0]), int(words[1]))) 37 | print('Reading edges finished') 38 | 39 | G = nx.Graph(edges) 40 | 41 | info = nx.info(G) + '\n' 42 | # drawing the graph 43 | pos = nx.spring_layout(G) 44 | un.drawGraphSave(G, pos, 8, 'ego_'+str(egoNode)) 45 | plt.close() 46 | 47 | part = community.best_partition(G) 48 | size = float(len(set(part.values()))) 49 | com = 'Found community count: ' + str(size) + '\n' 50 | mode = community.modularity(part, G) 51 | mode = 'Modularity: ' + str(mode) + '\n' 52 | un.drawCommunityGraphSave(G, pos, part, 8, 'ego_'+str(egoNode)) 53 | plt.close() 54 | #part2 = nx_com.girvan_newman(G) 55 | ##perf = nx_com.performance(G, part2) 56 | ##print('Performance girvan_newman : ', perf) 57 | #coms = list(sorted(c) for c in next(part2)) 58 | #un.nxDrawCommunityGraphSave(G, pos, coms, 8, gi) 59 | 60 | centb = nx.centrality.betweenness_centrality(G) 61 | un.centralityPlotSave(centb, 5, 'ego_'+str(egoNode), 'betweenness') 62 | un.drawCentralityGraphSave(G, pos, centb, 8, 'ego_'+str(egoNode), 'betweenness') 63 | plt.close() 64 | 65 | centd = nx.centrality.degree_centrality(G) 66 | un.centralityPlotSave(centd, 5, 'ego_'+str(egoNode), 'degree') 67 | un.drawCentralityGraphSave(G, pos, centd, 8, 'ego_'+str(egoNode), 'degree') 68 | plt.close() 69 | 70 | with open('sums/egoNet_' + str(egoNode) + 'sum.txt', 'w') as sumfile: 71 | sumfile.write(info) 72 | sumfile.write(com) 73 | sumfile.write(mode) -------------------------------------------------------------------------------- /fbNet_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/fbNet_layout.png -------------------------------------------------------------------------------- /graphs/ego_0_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_0_net.png -------------------------------------------------------------------------------- /graphs/ego_0_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_0_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_0_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_0_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_0_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_0_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_107_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_107_net.png -------------------------------------------------------------------------------- /graphs/ego_107_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_107_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_107_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_107_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_107_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_107_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_1684_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1684_net.png -------------------------------------------------------------------------------- /graphs/ego_1684_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1684_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_1684_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1684_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_1684_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1684_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_1912_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1912_net.png -------------------------------------------------------------------------------- /graphs/ego_1912_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1912_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_1912_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1912_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_1912_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_1912_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_3437_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3437_net.png -------------------------------------------------------------------------------- /graphs/ego_3437_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3437_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_3437_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3437_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_3437_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3437_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_348_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_348_net.png -------------------------------------------------------------------------------- /graphs/ego_348_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_348_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_348_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_348_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_348_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_348_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_3980_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3980_net.png -------------------------------------------------------------------------------- /graphs/ego_3980_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3980_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_3980_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3980_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_3980_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_3980_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_414_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_414_net.png -------------------------------------------------------------------------------- /graphs/ego_414_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_414_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_414_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_414_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_414_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_414_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_686_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_686_net.png -------------------------------------------------------------------------------- /graphs/ego_686_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_686_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_686_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_686_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_686_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_686_net_degree.png -------------------------------------------------------------------------------- /graphs/ego_698_net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_698_net.png -------------------------------------------------------------------------------- /graphs/ego_698_net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_698_net_betweenness.png -------------------------------------------------------------------------------- /graphs/ego_698_net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_698_net_communities.png -------------------------------------------------------------------------------- /graphs/ego_698_net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/ego_698_net_degree.png -------------------------------------------------------------------------------- /graphs/fbNet_Degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/fbNet_Degree.png -------------------------------------------------------------------------------- /graphs/fbNet__net.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/fbNet__net.png -------------------------------------------------------------------------------- /graphs/fbnet__net_betweenness.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/fbnet__net_betweenness.png -------------------------------------------------------------------------------- /graphs/fbnet__net_communities.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/fbnet__net_communities.png -------------------------------------------------------------------------------- /graphs/fbnet__net_degree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/graphs/fbnet__net_degree.png -------------------------------------------------------------------------------- /scale_free/__pycache__/networkAOT.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnilOsmanTur/ComplexNetworksProjects/3cbd3f3034ad6ee3d85b37ed267bb1c1a10df6b5/scale_free/__pycache__/networkAOT.cpython-36.pyc -------------------------------------------------------------------------------- /scale_free/main.py: -------------------------------------------------------------------------------- 1 | from networkAOT import Network 2 | 3 | 4 | def main(): 5 | # net = Network(10) 6 | 7 | # net.createScaleFree(1000, 3, 5) # n of nodes, link limit, core size 8 | # net.printDegrees() 9 | # net.plotDegreeDist() 10 | 11 | net = Network() 12 | net.createRandomNet(1000, 3, 100) # n of nodes, probability threshold 13 | net.printDegrees() 14 | net.plotDegreeDist() 15 | 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /scale_free/networkAOT.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import random 3 | import matplotlib.pyplot as plt 4 | 5 | class Node: 6 | def __init__(self, name): 7 | self.name = name 8 | self.adj = [] 9 | self.degree = 0 10 | 11 | def addAdjecent(self, x): 12 | if x not in self.adj: 13 | self.adj.append(x) 14 | self.degree += 1 15 | return x 16 | else: 17 | print(str(x) + " item is already a neighbor") 18 | return -1 19 | 20 | def delAdjecent(self, x): 21 | self.adj.remove(x) 22 | self.degree -= 1 23 | 24 | 25 | class Network: 26 | def __init__(self, randomSeed=None): 27 | self.net = [] 28 | self.netPrefList = [] 29 | self.prefSize = 0 30 | self.random = random.Random() 31 | self.random.seed( randomSeed ) # if its none system time will be used 32 | 33 | def addPref(self, x): 34 | self.netPrefList.append(x) 35 | self.prefSize += 1 36 | 37 | def createScaleFree(self, n_node, l_link, n_core): # n node for network l link for each node n core 38 | self.createCoreNodes(n_core) 39 | 40 | for i in range(n_core, (n_node + 1 - n_core)): 41 | node = Node(i) 42 | 43 | self.random.shuffle(self.netPrefList) 44 | for j in range(l_link): 45 | rand = self.random.randint(0, self.prefSize-1) 46 | pref = self.netPrefList[rand] 47 | connected = node.addAdjecent(pref) 48 | if connected != -1: 49 | self.net[connected].addAdjecent(i) 50 | self.addPref(connected) 51 | 52 | self.net.append(node) 53 | self.addPref(i) 54 | 55 | 56 | 57 | def createCoreNodes(self, n_core): 58 | 59 | for i in range(n_core): 60 | self.net.append(Node(i)) 61 | self.addPref(i) 62 | 63 | for i in range(n_core): 64 | node = self.net[i] 65 | for j in range(n_core): 66 | if j != i: 67 | node.addAdjecent(j) 68 | 69 | def degreeDistribution(self): 70 | degrees = [] 71 | n_degrees = [] 72 | for i in range(len(self.net)): 73 | node = self.net[i] 74 | degrees.append(node.degree) 75 | if node.degree not in n_degrees: 76 | n_degrees.append(node.degree) 77 | degrees.sort() 78 | print(degrees) 79 | n_degrees.sort() 80 | print(n_degrees) 81 | 82 | dist = np.zeros(len(n_degrees), dtype=np.float32) 83 | 84 | for i in range(len(n_degrees)): 85 | d_size = len(degrees) 86 | j = 0 87 | while j < d_size: 88 | if n_degrees[i] == degrees[j]: 89 | dist[i] += 1 90 | degrees.remove(n_degrees[i]) 91 | j -= 1 92 | d_size -= 1 93 | else: 94 | break 95 | j += 1 96 | print(dist) 97 | dist = dist / len(self.net) 98 | print(dist) 99 | return (dist, n_degrees) 100 | 101 | 102 | def printDegrees(self): 103 | degrees = [] 104 | for i in range(len(self.net)): 105 | node = self.net[i] 106 | degrees.append(str(node.degree) + ' ') 107 | print("".join(degrees)) 108 | 109 | def plotDegreeDist(self): 110 | 111 | dict, degrees =self.degreeDistribution() 112 | 113 | plt.plot(degrees, dict) 114 | plt.ylim([dict.min(), dict.max()]) 115 | plt.xlim([degrees[0], degrees[-1]]) 116 | plt.ylabel("P(k)") 117 | plt.xlabel("Degrees") 118 | plt.show() 119 | 120 | 121 | def connectTwoNode(self, i, j, prob_a=1, prob_b=100): 122 | node1 = self.net[i] 123 | node2 = self.net[j] 124 | for x in range(prob_a): 125 | prob = self.random.randint(0, prob_b) 126 | if prob == 7: 127 | node1.addAdjecent(j) 128 | node2.addAdjecent(i) 129 | 130 | def createRandomNet(self, n_node, prob_a=1, prob_b=100): 131 | for i in range(0, n_node): 132 | node = Node(i) 133 | self.net.append(node) 134 | 135 | for i in range(n_node): 136 | for j in range(i+1, n_node): 137 | self.connectTwoNode(i, j, prob_a, prob_b) 138 | 139 | --------------------------------------------------------------------------------