# 9.5. Anna Karenina Network Assignment¶

Using your `networkx`

tools,
read in `the graph for *Anna Karenina* (AK).`

Following
the model used in analyzing *Les Miserables* in
the ipython notebook demo for networkx, draw
a graph for AK that labels only the top 10 most
central characters.

Note

All the points covered here are covered Help with this homework assigned for this module is also available in the using_networkx Ipython notebook zipfile.

Experiment with adding 20 more characters to the top characters shown. You will be turning in

whatever images you think are the best (possibly more than 1 because different images may have different advantages);

The identity of the

edgethat has the highest weight (that is, the pair of characters that have appeared in the most scenes together) and what that weight is (the number of shared scenes). Since all the`networkx`

betweenness functions return dictionaries, the following code snippet may be of use. It extracts a ranked list from dictionary`DD`

:>>> L = [x[0] for x in sorted(DD.items(),key=lambda x: x[1],reverse=True)]An example of two characters that do not have an edge between them (they share no scenes).

Consider the

Florentine Families graph, which depicts the alliances among Renaissance Florentine familes, as established by marriage ties. It so happens this graph can be constructed in`networkx`

with`G = nx.florentine_families_graph()`

. Run classical`nx.betweenness_centrality`

on this graph (see Section Introduction to Networkx), find the most central families, and compare the results with random walk betweenness_centrality, also available as`nx.current_flow_betweenness_centrality`

. Does a different family get chosen as the most central?

Extra credit:

- Experiment with different layout algorithms. This will require a trip to
`networkx`

documentation pages (in particular, the Drawing section of the reference manual).- The model for
Les Miserablesdiscussed in class only introduced you to Betweenness Centrality as a measure of centrality. Experiment with ranking nodes by Degree-centrality instead of Betweenness-Centrality. Then use top 10 most important nodes as chosen by degree centrality in drawing a graph. Are the result images better, worse, pretty much the same? Discuss why.- Read Mark Newman’s paper on
`random walk betweenness centrality`

. There may be things you don’t understand, but soldier on and read the part in which he discusses applying his new model to examples. At the very end he talks about the results of his new centrality measure on theFlorentine Families graph, which depicts the alliances among Renaissance Florentine familes, as established by marriage ties. As noted above, this graph can be constructed in`networkx`

with`G = nx.florentine_families_graph()`

. Relate the differences you saw above when ran`nx.betweenness_centrality`

and`nx.random_walk_betweenness_centarlity`

to Newman’s discussion.