The evolution of power— A graph analysis of game of thrones

Yvonne Che
4 min readSep 5, 2019

--

I read and learned so much from others on this great platform. Today, I finally decided to write one of my own stories. A fun project I completed recently was a study of the evolution of power in the Game of Thrones TV series, seasons 2 to 5. I described the connections between people using a graph network, i.e. characters and their relationships were modeled as nodes and edges respectively. The evolution of power is revealed by graph analysis — community detection and centrality analyses. Complex society is formed by hierarchical groups. Community detection is used to unravel this network architecture. Centrality analyses are used to score the importance of nodes in a graph: how much impact they have in a community, whether they act like a bridge between communities, for instance. Story first, then technical details. Since masterpiece always has multiple storylines, here, I focus on Jon Snow, Daenerys Targaryen and Cersei Lannister.

Season 2 to Season 3:

From an isolated force, Daenerys Targaryen establishes some weak connections with the main continent (Westeros). Jon Snow force (that does not necessarily mean he is the leader in this community, a more precise description is the community Jon Snow assigned to) grows bigger. Both Cersei and Tyrion Lannister are leaders in their community, with a lot of power.

Node color: community assignments. Node size: influence score

Season 3 to Season 4:

The society is becoming more divided, as the number of communities increases. It is the same with our feelings that the cruelty of Joffrey, and Cersei’s aggressiveness to other families make the society more divided.

Node color: community assignments. Node size: influence score

Season 4 to Season 5:

Cersei Lannister force shrinks. Her control of power is very limited. Even though it looks like she is always in the center of power, that’s because she is the queen and daughter of Tywin Lannister and it was them that actually own the power. Tyrion Lannister is a resourceful man, his left really sabotaged their original community. Jon Snow’s influence rises.

Node color: community assignments. Node size: influence score

Technical details

Import files to Neo4j graph database (data source: https://github.com/mathbeveridge/gameofthrones/tree/master/data):

WITH “file:///got-s5-nodes.csv” AS fp
LOAD CSV WITH HEADERS FROM fp AS row
MERGE (character:Character {id:row.Id})
SET character.name=row.Label

WITH “file:///got-s5-edges.csv” AS uri
LOAD CSV WITH HEADERS FROM uri AS row
MATCH (origin:Character {id: row.Source})
MATCH (destination:Character {id: row.Target})
MERGE (origin)-[:Season5 {weight: toInteger(row.Weight)}]->(destination)

PS: Import data directly from website like the following should work, but for some reason, it didn’t work for me:

WITH “https://github.com/neo4j-graph-analytics/book/raw/master/data/*csv" AS fp

For community detection and centrality analyses, you can either type the following in Neo4j Brower or use Graph Algorithm Playground.

Louvain community detection:

:param label => 'Character';:param relationshipType => 'Season2';:param limit => 50;:param config => {
concurrency: 8,
direction: 'Both',
weightProperty: null,
defaultValue: 1,
writeProperty: 'louvain',
includeIntermediateCommunities: false,
intermediateCommunitiesWriteProperty: 'louvainIntermediate',
communityProperty: ''
};
CALL algo.louvain($label, $relationshipType, $config)MATCH (node:Character)
WHERE not(node[$config.writeProperty] is null)
RETURN node, node[$config.writeProperty] AS community, node[$config.intermediateCommunitiesWriteProperty] as communities
LIMIT $limit

Article rank analysis

:param label => 'Character';:param relationshipType => 'Season2';:param limit => 50;:param config => {
concurrency: 8,
direction: 'Both',
weightProperty: null,
defaultValue: 1,
dampingFactor: 0.85,
iterations: 20,
writeProperty: 'articlerank'
};
CALL algo.articleRank($label, $relationshipType, $config)MATCH (node:Character)
WHERE not(node[$config.writeProperty] is null)
RETURN node, node[$config.writeProperty] AS score
ORDER BY score DESC
LIMIT $limit

Comments on analyses:

Which algorithm to use?

That’s always a question. I would say having an intuition of the dataset is essential, like domain/prior knowledge, so you can have an expectation of your results.

Second, knowing math is quite necessary. For instance, to cluster a non-linear system, DBSCAN would be a better choice than k-Means. If to cluster data with distribution likely to obey central limit theorem, Gaussian Mixture would be a first choice.

Third, for a complex system, we always need to use comprehensive analyses to draw a conclusion. The results get from each analyses should be consistent.

The End

When you see the title, you may expect reading something philosophical like “how a Great Power’s position steadily alters in peacetime, is as important to this study as how it fights in wartime” (The Rise and Fall of the Great Powers by Paul Kennedy). But instead, my writing style is quite plain. If you have other insights from my analyses, or want to help to improve my writing, please feel free to share with me!

--

--