SNA is a powerful research technique.
SNA is essentially graph theory. A network is made up of nodes and edges.
Edges can have direction.
Edges can be weighted
Nodes can be of a type (social roles)
Yellow = experts answering questions; Red = novices http://lithosphere.lithium.com/t5/science-of-social-blog/ Social-Graphs-The-Art-and-the-Insights/ba-p/5713
Lots of dialogue back and forth between users http://lithosphere.lithium.com/t5/science-of-social-blog/ Social-Graphs-The-Art-and-the-Insights/ba-p/5713
Q&A + Discussion http://lithosphere.lithium.com/t5/science-of-social-blog/ Social-Graphs-The-Art-and-the-Insights/ba-p/5713
Experts are scattered in community http://lithosphere.lithium.com/t5/science-of-social-blog/ Social-Graphs-The-Art-and-the-Insights/ba-p/5713
please ensure you have Python v2.7 and Networkx v1.7
$ pip freeze # alternatively, if you do not have these installed, # you can create an account on pythonanywhere.com
import networkx # import library g = networkx.Graph() # create undirected graph object g.add_edge(1,2) # add data g.add_edge(3,1) g.add_node(4) print g.number_of_nodes() # 4 print g.nodes() # [1, 2, 3, 4] print g.number_of_edges() # 2 print g.edges() # [(1, 2), (1, 3)]
g = networkx.DiGraph() # directed graph g.add_edges_from([("A","B"), ("C","A")]) print g.in_degree(with_labels=True) # {'A': 1, 'C': 0, 'B': 1} print g.out_degree(with_labels=True) # {'A': 1, 'C': 1, 'B': 0} print g.neighbors("A") # ['B'] print g.neighbors("B") #['A']
print g.degree() # {1: 2, 2: 1, 3: 1, 4: 0} print networkx.betweenness_centrality(g) # {1: 0.3333333333333333, 2: 0.0, 3: 0.0, 4: 0.0} print networkx.degree_centrality(g) # {1: 0.6666666666666666, 2: 0.3333333333333333, # 3: 0.3333333333333333, 4: 0.0}
Time for magic tricks.
# Verify your python installation $ python --version # Make sure networkx can be used. $ python -c "import networkx;" # Open up your text editor
Open up a text editor
PythonAnywhere.com has one built in.
Exercise..
# Script: https://github.com/katychuang/PyData2013-SNATutorial/blob/master/virus.py # Documentation: http://networkx.github.com/documentation/latest/contents.html # MatPlotLib: http://matplotlib.org/users/gridspec.html
"Social interaction design is the application of levers to steer and guide emerging social practices" -- Adrian Chan, Gravity7
Space | Forward |
---|---|
Left, Down, Page Down | Next slide |
Right, Up, Page Up | Previous slide |
P | Open presenter console |
H | Toggle this help |