def get_normalized_in_degree_distr(graph): """ :param graph: :return: """ size = len(graph.keys()) degree_distr = in_degree_distribution(graph) normalized = {} for degree in degree_distr: normalized[degree] = degree_distr[degree]/float(size) return normalized
""" extract a dpa graph :param number_total_nodes: total n nodes :param number_init_nodes: a initial graph with m nodes :return: a dictionary of a dpa graph """ graph_pool = dpat(number_init_nodes) output_graph = pj1.make_complete_graph(number_init_nodes) for new_node in range(number_init_nodes, number_total_nodes): neighbor_nodes = graph_pool.run_trial(number_init_nodes) output_graph[new_node] = neighbor_nodes return output_graph dpa_graph = get_dpa_graph(27770, 13) id_distribution_dpa = pj1.in_degree_distribution(dpa_graph) nor_id_distribution_dpa = pj1.normalization(id_distribution_dpa) #print nor_citation_distribution fig, ax = plt.subplots() input_data = [[key, nor_id_distribution_dpa[key]] for key in nor_id_distribution_dpa.keys()] input_data.sort() input_x = [component[0] for component in input_data] input_y = [component[1] for component in input_data] ax.plot(input_x, input_y) ax.set_title('normalized distribution of DPA') ax.set_xscale('log') ax.set_yscale('log')
:param prob: probability :return: dictionary undirected graph which nodes are generated randomly """ graph_idd = {} for node_i in xrange(node_number): value = [] for node_j in xrange(node_number): if node_i != node_j: random_prob = random.random() if random_prob < prob: value.append(node_j) graph_idd[node_i] = value return graph_idd er_distribution = pj1.in_degree_distribution(er_algorithm(1000, 0.5)) nor_er_distribution = pj1.normalization(er_distribution) fig, ax = plt.subplots() input_data = [[key, nor_er_distribution[key]] for key in nor_er_distribution.keys()] input_data.sort() input_x = [component[0] for component in input_data] input_y = [component[1] for component in input_data] ax.plot(input_x, input_y) ax.set_title('Distribution of ER algorithm (1000 nodes, prob is 0.5)') #ax.set_xscale('log') #ax.set_yscale('log') plt.show()