Bipartitní grafy

Intermediate Network Analysis in Python

Eric Ma

Data Carpentry instructor and author of nxviz package

Bipartitní grafy

  • Graf rozdělený do dvou množin
  • Uzly jsou propojeny pouze s uzly v druhé části
  • Kontrast: „unipartitní"
Intermediate Network Analysis in Python

Bipartitní grafy: příklad

ch1-2.007.png

Intermediate Network Analysis in Python

Bipartitní grafy v NetworkX

import networkx as nx
G = nx.Graph()

numbers = range(3) G.add_nodes_from(numbers, bipartite='customers')
letters = ['a', 'b'] G.add_nodes_from(letters, bipartite='products')
Intermediate Network Analysis in Python

Bipartitní grafy v NetworkX

list(G.nodes(data=True))
[(0, {'bipartite': 'customers'}),
 (1, {'bipartite': 'customers'}),
 (2, {'bipartite': 'customers'}),
 ('b', {'bipartite': 'products'}),
 ('a', {'bipartite': 'products'})]
Intermediate Network Analysis in Python

Centralita stupně

  • Definice: $$\frac{\text{počet sousedů}}{\text{počet možných sousedů}}$$
  • Počet možných sousedů závisí na typu grafu
Intermediate Network Analysis in Python

Metriky centrality pro bipartitní grafy

  • Jmenovatel: počet uzlů v opačné části, nikoli všechny ostatní uzly

ch1-2.021.png

Intermediate Network Analysis in Python

Filtrování grafů

cust_nodes = [n for n, d in G.nodes(data=True) if  
                  d['bipartite'] == 'customers']
cust_nodes
[(0, {'bipartite': 'customers'}),
 (1, {'bipartite': 'customers'}),
 (2, {'bipartite': 'customers'})]
nx.bipartite.degree_centrality(G, cust_nodes)
{0: 0.5,
 1: 0.5,
 2: 1.0,
 'a': 0.333,
 'b': 1.0}
Intermediate Network Analysis in Python

Lass uns üben!

Intermediate Network Analysis in Python

Preparing Video For Download...