Kshitij

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment-3.3
Student Name: Kshitij Kashyap UID: 21BCS11493
Branch: CSE Section/Group: 21BCS_SN-911-B
Semester: 5th Date of Performance: 06-11-23
Subject Name: SOCIAL NETWORKS LAB
Subject Code: 21CSP-345

AIM: Demonstrate the emergence of the Power Law in World Wide Web (WWW)
graphs; generate a random graph with a power-law degree distribution.

Objective: The objective of this experiment is to demonstrate the emergence of


the Power Law in World Wide Web (WWW) graphs and generate a random graph
with a power-law degree distribution.

Input/Apparatus used Requirement Analysis: Google Chrome, Online tools,


Python IDE, libraries (NetworkX)

Hardware Requirement: - Computer/Laptop minimum 4GB, Windows, Power


Supply
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Code / Script:
import networkx as nx
import matplotlib.pyplot as plt
# Generate a random graph with a power-law degree distribution
G = nx.powerlaw_cluster_graph(200, 3, 0.1)
# Get the degree distribution of the graph
degree_distribution = nx.degree_histogram(G)
# Create lists for degree values and their corresponding counts
degrees = [degree for degree, count in enumerate(degree_distribution) if count > 0]
counts = [count for count in degree_distribution if count > 0]
# Print the degree distribution
for degree, count in zip(degrees, counts):
print("Degree:", degree, "Count:", count)
# Plot the degree distribution
plt.bar(degrees, counts)
plt.xlabel("Degree")
plt.ylabel("Count")
plt.title("Degree Distribution")
plt.show()
# Draw the graph
pos = nx.spring_layout(G, seed=42) # Define a layout for the nodes for consistent visualization
nx.draw(G, pos, node_size=20, node_color='lightblue', with_labels=False)
plt.title("Random Graph with Power-Law Degree Distribution")
plt.show()
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

LEARNING OUTCOMES:

1. Understanding Power Law Distribution:


• Developing a deep understanding of the power law distribution, one of the
most prevalent phenomena in complex networks.
• Learning about the principles of heavy-tailed distributions where a few
elements (nodes) have significantly higher degrees than the majority.
2. Network Modelling and Simulation:
• Acquiring the skills to create, model, and simulate networks in Python using
libraries like NetworkX.
• Learning how to generate random graphs that exhibit power-law degree
distributions, which involves creating nodes and assigning degrees according
to the power law.
3. Data Analysis and Evaluation:
• Developing the ability to analyze and visualize network properties, such as
degree distributions.
• Learning how to verify and evaluate whether a generated network follows a
power law distribution by applying statistical tests and visualizing the data.

You might also like