WOLFRAM NOTEBOOK

ECE101 Lab (Spring 2025)

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[]:=
Graph{sa,ad},VertexLabelsAutomatic,
Out[]=

A Toy Social Network (5 points)

Consider this toy graph g of a social network. The nodes represent people and the edges represent friendship between them.
In[]:=
g=Graph[{"Alice""Bob","Bob""Claire","Claire""Jose","Dave""Jose","Eliza""Jose","Jose""Gabby","Gabby""Hong","Hong""Bob","Inaya""Eliza","Eliza""Alice","Alice""Claire","Bob""Dave","Claire""Eliza","Dave""Gabby","Claire""Gabby","Alice""Hong","Gabby""Fahim","Hong""Jose","Inaya""Dave","Jose""Bob"},VertexLabels->"Name"]
Out[]=
Problem
1
How many people are there on this network? How many distinct friendships are represented?
Hint: Use VertexCount and EdgeCount

Answer

Problem
2
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

Problem
3
The following code shows the shortest path from Inaya to Hong:
In[]:=
HighlightGraph[g,PathGraph[FindShortestPath[g,"Inaya","Hong"]]]
Out[]=
What is the minimum number of hops you have to traverse to get from Fahim to Alice? (i.e. what is the shortest distance between these nodes?)
Trace out this path on the graph.
Hint: Use FindShortestPath, HighLightGraph and PathGraph

Answer

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 GraphHub and VertexDegree

Answer

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

Answer

Part 2: Social Networks as Small World Graphs (40 minutes)

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.
Retrieve the data for the graph:
In[]:=
sng=ResourceData["Online Social Network"]

Note: Disconnected Graph

Exploring Properties of the Graph (10 points)

The various properties of the graph provide us information about the graph.
List the summary properties of the social network graph:
In[]:=
ResourceData["Online Social Network",All]["Summary"]
Out[]=
Name
Online Social Network
VertexCount
1899
EdgeCount
20296
Description
Social network of an online community.
ByteCount
2816.03
kB
Problem 6 (1 point)
List any 10 vertices in this graph.
(Hint: Use VertexList and RandomSample)

Answer

Small World Properties of the Graph: Small Number of Hops

Problem 7 (1 point)
What is the diameter of the graph? What do you think it means to have this value for the graph diameter?
(Hint: Use GraphDiameter)

Answer

Problem 8 (2 points)
Find the distance between the following nodes
(Hint: Use GraphDistance):
  • Node #1 and node #800?
  • Node #57 and node #758?
  • Node #13 and node #196? What does this mean?
  • Now you pick two nodes at random and find the distance between them on the graph.
  • Answer

    Small World Properties of the Graph: Heavy Tail (Few Nodes with Very High Degree)

    Problem 9 (1 point)
    Which vertex has the highest number of connections?
    What is its vertex degree?
    (Hint: Use GraphHub and VertexDegree)
    What term would you use for this node, if this was a person in a real-life social network?

    Answer

    Problem 10 (2 points)
    The following code shows a histogram of the number of connections/edges (vertex degree) for the vertices/nodes in the graph.
    How many nodes have >= 200 connections?
    How many nodes have <= 50 connections?
    If you hover over each bin in the histogram, you can see the number of samples (nodes) in that bin. So you can count manually how many total nodes are in the bins 200-250, 250-300, 300-350 or 0-50.
    You can also use the code below:

    Answer

    Are there “loners” in the graph (people with no connections whatsoever)?
    If yes how many?
    If no what is the minimum number of connections a node has in this graph? How many nodes with this number of connections?
    Hint: You can modify the code from the previous problem slightly to answer this.

    Answer

    Small World Properties of the Graph: Densely Connected

    Problem 13 (1 point)
    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.
    Visualize the neighborhood of this node in the graph.

    Answer

    Small World Properties of the Graph: Local Cliques

    Problem 14 (1 point)
    Are there cliques in the graph? Find one of the largest cliques.
    (Hint: Use FindClique)

    Answer

    Problem 15 (1 point)
    Here is how to find all the cliques in the graph that contain exactly 5 vertices.
    Find all cliques with 4 vertices.

    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 two things you learned about human networks.

    Answer

  • Submitting your work

    1
    .
    Ensure you have filled in your NetID at the top of the notebook
    2
    .
    Save the notebook as a PDF file (Alternately, "Print to PDF" but please ensure the PDF looks ok and is not garbled)
    3
    .
    Upload to Canvas Lab 5
    Wolfram Cloud

    You are using a browser not supported by the Wolfram Cloud

    Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


    I understand and wish to continue anyway »

    You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.