##################################### # Code for answering question 4 of the application # Create a graph using the DPA-algorithm generated_graph = make_graph_DPA(27700, 13) # Compute and print the edges generated tot_edges = 0 for key, value in generated_graph.items(): tot_edges += len(value) print print "Total number of edges created =", tot_edges print # Compute the in-degree distribution in_degree_dist = degree.in_degree_distribution(generated_graph) # Normalize the in-degree distribution and create lists of the data to plot total = 0 citation_number = [] citation_distr = [] for dummy_key, value in in_degree_dist.items(): total += value for key, value in in_degree_dist.items(): citation_number.append(key) citation_distr.append(float(value) / total) # Create plot of the result print print "====> Creating the plot." plt.loglog(citation_number, citation_distr, 'b.', linestyle='None')
counter = 1 for key, value in citation_graph.items(): print counter, key, value counter += 1 if counter > 10: break print ##################################### # Code for answering question 1 of the application # Compute the in-degree distribution in_degree_dist = degree.in_degree_distribution(citation_graph) # Normalize the in-degree distribution and create lists of the data to plot total = 0 citation_number = [] citation_distr = [] for dummy_key, value in in_degree_dist.items(): total += value for key, value in in_degree_dist.items(): citation_number.append(key) citation_distr.append(float(value) / total) # Create plot of the result plt.loglog(citation_number, citation_distr, 'b.', linestyle='None') plt.grid(True) plt.title("Plot 1: loglog plot citation distribution")