Esempio n. 1
0
def network_plot(ancestor_pno, adj, colormap, show=True, savefn=None, title="PCA coloring in Patent "):
    # colormap maps from node name to color.
    G = get_graph(adj)
    G.graph["ancestor"] = ancestor_pno
    ancestor_idx = G.nodes().index(G.graph["ancestor"])
    # defaults to black.
    node_colors = [hex2rgb(colormap.get(node, "#ffffff")) for node in G.nodes()]
    default_node_size = 50
    node_sizes = [default_node_size for node in G.nodes()]
    node_sizes[ancestor_idx] = 6 * default_node_size
    f = plt.figure()
    f.set_size_inches(18.5, 10.5)
    nx.draw_networkx(
        G,
        nx.spring_layout(G, iterations=20000),
        # cmap=plt.get_cmap('jet'),
        node_color=node_colors,
        node_size=node_sizes,
        with_labels=False,
        fontsize=1,
        # font_weight = 'bold',
        linewidths=0.5,
        width=0.5,
    )
    plt.title(title + str(ancestor_pno))
    if savefn is not None:
        print "saving plot..."
        plt.savefig(savefn, dpi=100)
    if show:
        plt.show()
Esempio n. 2
0
def community_colors(db, pno, threshold, show_vis = False, savefn=None):
    # Get the patents in the lineage and the adjacency dictionary. 
    lineage = crawl_lineage(
        db, pno, n_generations = 5, 
        enforce_func = lambda x: len(x.get('citedby', [])) >= threshold,
        flatten=True
    )
    adj = subnet_adj_dict(lineage)

    # detect communities
    detector = detect.CommunityDetector(adj)
    communities = detector.run()
    n_communities = len(communities)
    community_lookup = util.get_community_lookup(communities)

    # assign each patent a color, and provide a lookup dictionary
    colors = visualize.discrete_color_scheme(n_communities+1)
    node_color_lookup = {node: colors[community_lookup[node]] for node in adj.keys()}
    
    # make the visualization.
    G = visualize.get_graph(adj)
    G.graph['ancestor'] = pno
    ancestor_idx = G.nodes().index(G.graph['ancestor'])
    node_colors = [colors[community_lookup[node]] for node in G.nodes()]
    node_colors[G.nodes().index(G.graph['ancestor'])] = colors[n_communities]
    default_node_size = 60
    node_sizes = [default_node_size for node in G.nodes()]
    node_sizes[ancestor_idx] = 6*default_node_size
    f = plt.figure()
    f.set_size_inches(18.5, 10.5)
    if savefn is not None or show_vis:
        nx.draw_networkx(
            G, 
            nx.spring_layout(G, iterations=20000), 
            node_color=node_colors, 
            node_size = node_sizes,
            with_labels = False,
            fontsize=1,
#            font_weight = 'bold',
            linewidths=.5,
            width=.5
        )
    if savefn is not None:
        plt.title('Communities in Patent {}'.format(pno))
        plt.savefig(savefn, dpi=100)
    if show_vis:
        plt.show()
    return node_color_lookup
Esempio n. 3
0
def network_plot(ancestor_pno,
                 adj,
                 colormap,
                 show=True,
                 savefn=None,
                 title='PCA coloring in Patent '):
    # colormap maps from node name to color.
    G = get_graph(adj)
    G.graph['ancestor'] = ancestor_pno
    ancestor_idx = G.nodes().index(G.graph['ancestor'])
    # defaults to black.
    node_colors = [
        hex2rgb(colormap.get(node, '#ffffff')) for node in G.nodes()
    ]
    default_node_size = 50
    node_sizes = [default_node_size for node in G.nodes()]
    node_sizes[ancestor_idx] = 6 * default_node_size
    f = plt.figure()
    f.set_size_inches(18.5, 10.5)
    nx.draw_networkx(
        G,
        nx.spring_layout(G, iterations=20000),
        #cmap=plt.get_cmap('jet'),
        node_color=node_colors,
        node_size=node_sizes,
        with_labels=False,
        fontsize=1,
        #font_weight = 'bold',
        linewidths=.5,
        width=.5)
    plt.title(title + str(ancestor_pno))
    if savefn is not None:
        print "saving plot..."
        plt.savefig(savefn, dpi=100)
    if show:
        plt.show()
Esempio n. 4
0
patent_adj = data.get_patent_adj()

# Build a community detector object and run the algorithm
detector = detect.CommunityDetector(patent_adj)
communities = detector.run()
n_communities = len(communities)

#Build a lookup table for node to color.
community_lookup = {}
for i,c in enumerate(communities):
    for pno in c:
        community_lookup[pno] = i

colors = visualize.discrete_color_scheme(n_communities+1)


# Get a graph from the adjacency list.
G = visualize.get_graph(patent_adj)
G.graph['ancestor'] = 4723129
node_colors = [colors[community_lookup[node]] for node in G.nodes()]

# Set the ancestor to its own color.
node_colors[G.nodes().index(G.graph['ancestor'])] = colors[n_communities]
nx.draw(G, nx.spring_layout(G, iterations=10000), cmap=plt.get_cmap('jet'), node_color=node_colors, node_size=100)
#nx.draw_spring(G, cmap=plt.get_cmap('jet'), node_color=node_colors, node_size=100)





Esempio n. 5
0
# what detector.A and detector.S after a phase1 and phase2
A = np.array([[ 4.,  1.,  1.],
            [ 1.,  3.,  0.],
            [ 1.,  0.,  3.]])
S = np.array([[ 1.,  0.,  0.],
        [ 0.,  1.,  0.],
        [ 0.,  0.,  1.]])

# Build a community detector object and run the algorithm
detector = detect.CommunityDetector(wiki_adj_dict)
communities = detector.run()
n_communities = len(communities)

# Build a lookup table for node to color.
community_lookup = {}
for i,c in enumerate(communities):
    for pno in c:
        community_lookup[pno] = i

colors = visualize.discrete_color_scheme(n_communities)


# Get a graph from the adjacency list.
G = visualize.get_graph(wiki_adj_dict)
node_colors = [colors[community_lookup[node]] for node in G.nodes()]

# Set the ancestor to its own color.
#node_colors[G.nodes().index(G.graph['ancestor'])] = colors[n_communities]
nx.draw(G, cmap=plt.get_cmap('jet'), node_color=node_colors)
#