Background
Background
The book “Analyzing Narratives in Social Networks” authored by Zvi lotker is divided into three main parts. This notebook provides some code used in the first part of the book.
Part I of the book analyzes narratives in static social networks. Questions are asked such as how to use algorithms to locate conflicts in drama scripts and social networks; how to partition a network into communities based on narrative; what constitutes a static point of view of an individual in a social network. The book presents new methods to analyse scripts of plays and movies.
◼
Zvi Lotker is with the department of Computer Engineering, Bar Ilan University, ISRAEL.
◼
Yehuda Ben-Shimol is with the Electrical and Computer Engineering School, Ben-Gurion University, ISRAEL.
What is a script
What is a script
Definition
Definition
Example
Example
Frequency Graph
Frequency Graph
From Script to AB Graph
From Script to AB Graph
Common community detection vs. the algorithms proposed in the book
Common community detection vs. the algorithms proposed in the book
For explanations on common community detection algorithms see
https://en.wikipedia.org/wiki/Community_structure
http://digitalinterface.blogspot.com/2013/05/community-detection-in-graphs.html
https://en.wikipedia.org/wiki/Community_structure
http://digitalinterface.blogspot.com/2013/05/community-detection-in-graphs.html
The various community detection schemes (which are also implemented in Mathematica) are not suitable to find the narrative embedded in the script. There are two main drawbacks
1
.There is no way to hint the community detection algorithms of the intentions of the human user.
2
.The existing community detection cannot “explain” their findings of the communities “found” in the graph.
The analysis scheme proposed in the book takes care of these two issues by introducing the terms “anchors” and “decision matrix”, as will be discussed later. Both allow to “ask” the algorithm specific questions and provide hints to the algorithms. This way the human user can interact in a “two-way conversation” (i.e., dialog).
“Traditional” graph communities algorithms
“Traditional” graph communities algorithms
Links
Links
In[]:=
FindGraphCommunities/@{hamletABD,hamletAB}
Out[]=
{{{All,BERNARDO,Captain,First Ambassador,First Player,First Sailor,FRANCISCO,Ghost,GUILDENSTERN,HAMLET,HORATIO,Lord,LUCIANUS,MARCELLUS,OSRIC,PRINCE FORTINBRAS,ROSENCRANTZ,Servant},{CORNELIUS,Danes,First Priest,Gentleman,KING CLAUDIUS,LAERTES,LORD POLONIUS,Messenger,OPHELIA,Prologue,QUEEN GERTRUDE,REYNALDO,VOLTIMAND},{First Clown,Second Clown},{Player King,Player Queen}},{{All,BERNARDO,Captain,First Ambassador,First Player,First Sailor,FRANCISCO,Ghost,GUILDENSTERN,HAMLET,HORATIO,Lord,LUCIANUS,MARCELLUS,OSRIC,PRINCE FORTINBRAS,ROSENCRANTZ,Servant},{CORNELIUS,Danes,First Priest,Gentleman,KING CLAUDIUS,LAERTES,LORD POLONIUS,Messenger,OPHELIA,Prologue,QUEEN GERTRUDE,REYNALDO,VOLTIMAND},{First Clown,Second Clown},{Player King,Player Queen}}}
In[]:=
method={"Modularity","Centrality","CliquePercolation","Hierarchical","Spectral","VertexMoving"};Manipulate[Show[HighlightGraph[hamletABD,gc=FindGraphCommunities[hamletABD,Methodmet];lgc=Framed[Style[ToString[Length[gc]]<>" Communities",Bold,Large,Red,FontFamily"Times"]];gc],ImageSize600,PlotLabel->lgc],{met,method},SaveDefinitionsTrue]
Out[]=
Most of the common algorithms identify too many communities. Anyway, detecting communities needs to correspond to the narative embedded in the script.
The proposed algorithms from the book
The proposed algorithms from the book
The book uses two basic geometric narratives data structures: metric space and frequency graph. In the following subsections we define the metric space and show how to convert a frequency graph into a a metric space.
Metric space
Metric space
Definition
A metric space is a function which defines the distance between any two points or members of a set.
A metric space is an ordered pair where is a set, and is a metric on .
The distance function dis is defined as follows
1. Identity of indiscernible: if and only if
2. Symmetry:
3. Triangle Inequality:
A metric space is a function which defines the distance between any two points or members of a set.
A metric space is an ordered pair
(V;dis)
V
dis
V
The distance function dis is defined as follows
dis:V×V
1. Identity of indiscernible:
dis(x,y)=0
x=y
2. Symmetry:
dis(x,y)=dis(y,x)
3. Triangle Inequality:
dis(x,y)+dis(y,z)>=dis(x,z)
The frequency graph needs to transformed into a metric space. This is achieved in two steps:
AB
1
.Convert the frequency to distance ->=1. The reflexive frequency becomes zero, i.e., =0. Any vertices that are not connected in (i.e., =0) are associated with the distance =∞. The problem is that the matrix does not always satisfies the triangle inequality.
f
i,j
x
i,j
f
i,j
x
i,i
AB
f
i,j
x
i,j
[]
x
i,j
2
.Using the Floyd-Warshall algorithm transforms the matrix into a metric space, i.e.,
[]
x
i,j
[]->[]
x
i,j
m
i,j
Compute the matrix of distances (metric space) from the Hamlet frequency graph
In[]:=
hamletMetricSpace=FromFrequencyGraph2Metricspace[hamletAB];
checking the triangle inequality
In[]:=
With[{n=Length[hamletMetricSpace]},And@@Flatten[Table[hamletMetricSpace[[i,j]]+hamletMetricSpace[[j,k]]>=hamletMetricSpace[[i,k]],{i,n},{j,n},{k,n}]]]
Decision matrix
Decision matrix
Definitions and explanations
Definitions and explanations
The decision matrix is a tool that allows us to “ask” vertices “what are their opinions” on various alternatives. One of the main drawbacks of community detection algorithms is the lack of the possibility to “explain” how and why they generated their results. The decision matrix is a mean that allows to overcome this drawback.
DefinitionThe matrix ψ is called a decision matrix when the rows are the decision vectors which "grade" or "rate" the various options available to the node according to the total order .
Functionality
Functionality
In[]:=
DisanceFromSetToPoint[distMat_,S1_,p_]:=(* distMat - a distances matrix of the metricspace S1 - a subset of indexes , p - an index of a point in the metricspaceThe output is the distans of p to S1 *)Min[distMat[[p]][[S1]]]
In[]:=
FromMetricspaceS2DecisionMatrix[distMat_,V1_]:=(* Input: distMat - a distances matrix of the metricspace A - a set of disjoint k subsets V1Output: The Decision Matrix ψ*)Table[DisanceFromSetToPoint[distMat,V1[[j]],i],{i,Length[distMat]},{j,Length[V1]}]
Example
Example
We generate the decision matrix for two characters (i.e., anchors) defining two distinct groups of characters in the play: King Claudius and Lord Polonius. The distance (in the metric space) of each character to the two anchors is computed. Since the the metric space does not relate to names, we associate the name of each character in the play to its corresponding position in the vertices list to ease the human use.
Out[]=
All1,BERNARDO2,Captain3,CORNELIUS4,Danes5,First Ambassador6,First Clown7,First Player8,First Priest9,First Sailor10,FRANCISCO11,Gentleman12,Ghost13,GUILDENSTERN14,HAMLET15,HORATIO16,KING CLAUDIUS17,LAERTES18,Lord19,LORD POLONIUS20,LUCIANUS21,MARCELLUS22,Messenger23,OPHELIA24,OSRIC25,Player King26,Player Queen27,PRINCE FORTINBRAS28,Prologue29,QUEEN GERTRUDE30,REYNALDO31,ROSENCRANTZ32,Second Clown33,Servant34,VOLTIMAND35
In[]:=
poloniusVsClaudiusDecisionMatrix=FromMetricspaceS2DecisionMatrix[hamletMetricSpace,{{namesToIndex["KING CLAUDIUS"]},{namesToIndex["LORD POLONIUS"]}}]
Adapting the community detection algorithms to conflict functions (universal community detection)
Adapting the community detection algorithms to conflict functions (universal community detection)
Background
Background
We will show two universal ways of doing that mapping: Voronoi diagram that work metric space and voting, which uses Markov chains.
Voronoi (Chapter 6 in the book)
Voronoi (Chapter 6 in the book)
Voronoi - background
Voronoi - background
Voronoi - description
Voronoi - description
The presented Voronoi partition algorithm is universal in the sense that it can generate any required partition, based on the selected anchors. In the extreme case that all vertices are set as distinct anchors, the resulted partition is the distinct vertices. By refining the selection of the anchors, this algorithm
Voronoi examples from Hamlet’s script
Voronoi examples from Hamlet’s script
Example1 - KING CLAUDIUS (party 1) vs. LORD POLONIUS (party 2)
Example 2 - 3 parties: KING CLAUDIUS (party 1) vs. LORD POLONIUS (party 2) vs. QUEEN GERTRUDE + OPHELIA (party 3)
Example 3 - “GUILDENSTERN (party 1) vs. ROSENCRANTZ (party 2)
Example 4 - affirmative action
We would like to make the parties to have (approximately) the same power. This is done using affirmative action: we “normalize” the decision matrix such that each party has the (approximately) the same number of members. The median statistical function can be used for that.
Voting (Chapter 7 in the book)
Voting (Chapter 7 in the book)
Markov Process
Markov Process
Voting: Algorithmic Description
Voting: Algorithmic Description
There are four steps in the voting algorithm
The presented algorithms are written with the sake of clarity in mind. Large problems are preferably solved using matrix multiplications which are much more computationally efficient. This also holds if there are many parties.
Voting examples from the Hamlet script
Voting examples from the Hamlet script
Example1 - KING CLAUDIUS (party 1) vs. LORD POLONIUS (party 2)
Example 2 - 3 parties: KING CLAUDIUS (party 1) vs. LORD POLONIUS (party 2) vs. QUEEN GERTRUDE + OPHELIA (party 3)
Example 3 - “GUILDENSTERN (party 1) vs. ROSENCRANTZ (party 2)
Example 4 - affirmative action
We would like to make the parties to have (approximately) the same power. This is done using affirmative action: we “normalize” the decision matrix such that each party has the (approximately) the same number of members. The median statistical function can be used for that.
Conclusions
Conclusions
The book presents new methods to analyse scripts of plays and movies. Temporal analysis also shows the Lord Polonius is the real traitor since he also betrayed the faith of his daughter Ophelia. Polonuis, driven by his lust of power, cancels Ophelia’s engagements to Claudius, and after the murder sends Ophelia to the monastery, thus preventing her from being both a queen and a mother.
