Lab 5: Social Networks
Lab 5: Social Networks
NetID:
In this lab, we will look at Social Networks and their properties.
Part 1: Network Representation using Graphs (20 minutes)
We will use circles to represent nodes, and lines between these circles (called "edges") to represent connections between nodes. These diagrams containing nodes and edges are called "graphs".
In a social network the nodes (also called vertices) represent people and the edges represent relationships between them.
In a social network the nodes (also called vertices) represent people and the edges represent relationships between them.
In[]:=
Graph{sa,ad},VertexLabelsAutomatic,
Out[]=
A Toy Graph
A Toy Graph
Consider this toy graph g of a social network. The nodes represent people and the edges represent friendship between them.
In[]:=
g=
;
Problem 1
Problem
1
How many people are there on this network? How many distinct friendships are represented?
(Hint: Use VertexCount and EdgeCount)
(Hint: Use VertexCount and EdgeCount)
Answer
Answer
In[]:=
VertexCount[g]
Out[]=
10
In[]:=
EdgeCount[g]
Out[]=
20
Problem 2
Problem
2
In[]:=
g
Out[]=
What is the maximum number of hops needed to get from one person to another i.e. what is the diameter of the graph? (Hint: Use GraphDiameter)
Answer
Answer
In[]:=
GraphDiameter[g]
Out[]=
3
Problem 3
Problem
3
What is the minimum number of hops you have to traverse to get from person #6 to person #1? (i.e. what is the shortest distance between nodes #6 and #1?)
Trace out this path (list out the shortest path from node #6 to #1).
(Hint: Use FindShortestPath, HighLightGraph and PathGraph)
Trace out this path (list out the shortest path from node #6 to #1).
(Hint: Use FindShortestPath, HighLightGraph and PathGraph)
Answer
Answer
In[]:=
FindShortestPath[g,6,1]
Out[]=
{6,7,3,1}
In[]:=
HighlightGraph[g,PathGraph[FindShortestPath[g,6,1]]]
Out[]=
Problem 4
Problem
4
Who is the person with the most friends (i.e. the node with the highest vertex degree - the hub of the graph) and who is the person with the least number of friends (the node with the lowest vertex degree) on this social network?
(Hint: Use VertexDegree)
(Hint: Use VertexDegree)
Answer
Answer
In[]:=
VertexList[g]
Out[]=
{1,2,3,4,5,6,7,8,9,10}
In[]:=
VertexDegree[g]
Out[]=
{4,5,5,4,4,1,5,4,2,6}
Most connections: 10 (it has a vertex degree of 6)
Least connection: 6 (it has a vertex degree of 1)
Least connection: 6 (it has a vertex degree of 1)
Problem 5
Problem
5
Is it possible to find a path from every person to every other person? (i.e. is this graph connected?)
(Hint: Use ConnectedGraphQ)
(Hint: Use ConnectedGraphQ)
Answer
Answer
In[]:=
ConnectedGraphQ[g]
Out[]=
True
Part 2: Social Networks as Small World Graphs (40 minutes)
Get the Data for the Graph
Get the Data for the Graph
Social network of an online community:
The online community represents a prototypical example of a complex evolving social network in which connections between users are established over time by online messages. An edge annotation EdgeWeight describes the number of messages sent from a user.
The online community represents a prototypical example of a complex evolving social network in which connections between users are established over time by online messages. An edge annotation EdgeWeight describes the number of messages sent from a user.
Source: https://datarepository.wolframcloud.com/resources/Online-Social-Network
Retrieve the graph:
In[]:=
sng=ResourceData["Online Social Network"]
Out[]=
Graph
Note: Disconnected Graph
Note: Disconnected Graph
Problem 6
Problem
6
Answer
Answer
Properties of the Graph: Small Number of Hops
Properties of the Graph: Small Number of Hops
What is the diameter of the graph? What does it mean to have this value for the graph diameter?
(Hint: Use GraphDiameter)
(Hint: Use GraphDiameter)
Answer
Answer
What is the distance between the nodes:
◼
Node #1 and node #800?
◼
Node #57 and node #758?
◼
Node #13 and node #196? What does this mean?
Answer
Answer
Properties of the Graph: Nodes with High Degree
Properties of the Graph: Nodes with High Degree
What is the highest number of edges associated with a vertex in this graph?
(Hint: Use VertexDegree and Max)
(Hint: Use VertexDegree and Max)
Answer
Answer
◼
Which vertex has the highest number of connections?
◼
What is its vertex degree?
◼
What can you say about this vertex?
Answer
Answer
Properties of the Graph: Dense Local Structure
Properties of the Graph: Dense Local Structure
Let’s look at the part of the graph around vertex 103:
Now you pick a node at random. Use the following line of code.
Show the neighborhood of this node in the graph.
Answer
Answer
Answer
Answer
Find all cliques with 5 vertices.
Answer
Answer
Part 3: The Wisdom and/or Madness of the Crowds
Here is a paper published in Nature that talks about social learning strategies that can regulate the tug-of-war between the collective “wisdom” of a group of individuals and their maladaptive “herding”.
We will look at an interactive online game called “The Wisdom and/or Madness of the Crowds”. You can open it here: https://ncase.me/crowds/
Play the game and jot down three things you learned about human networks.
Answer
Answer
◼
◼
◼
Submitting your work
Submitting your work
1
. Publish your notebook
1
.1
.From the cloud notebook, click on “Publish” at the top right corner.
1
.2
.From the desktop notebook, use the menu option File -> Publish to Cloud
2
.Copy the published link
3
.Add it to the top of the notebook, below your netID
4
.Print to PDF
5
.Upload to Gradescope
6
.Just to be sure, maybe ping your TA Sattwik on Slack that you have submitted.