Practical File Iqman Ns
Practical File Iqman Ns
On
Bachelor in Engineering
IN COMPUTER SCIENCE AND ENGINEERING
Submitted by
ACKNOWLEDGEMENT
I would like to express a special thanks of gratitude to my mentor, Dr. Gulshan Goyal for your
guidance and support throughout my semester. I made this practical file from my heart with
utmost sincerity. I am very thankful to all those who helped me and guided me through the
project. I would also like to acknowledge my parents who provided all the resources that were
required to complete it.
Network Science Practical (CS-801)
INDEX
Sr. Name of Experiment Start End Page Signature
No. Date Date No.
5(b). For a given set of Situation, calculate spearman rho and kendall tau distance. 13-02- 20- 33
equatio Write a implement bottom-up parsing (Operator Precedence 2024 02-
program 2024
PRACTICAL NO - 1
1.2 INPUT
1. Set of alphabets
2. Prefix to construct corresponding DFA
3. Suffix to construct corresponding DFA
4. Substring to construct corresponding DFA
5. A string to check whether it is recognized by generated DFA or not
1.3. THEORY
Network science is an interdisciplinary field that studies the structure and behavior of
networks, which are systems of interconnected components. This field has applications in
numerous domains, including social networks, biological networks, information networks,
and technological networks. Understanding network science involves analyzing the patterns
of connections (edges) between entities (nodes) and exploring the implications of these
patterns.
Bipartite Networks: Networks with two distinct types of nodes, with edges only between
nodes of different types.
4
Network Science Practical (CS-801) 5
Network Properties
Network Models :
5
Network Science Practical (CS-801) 6
1.Gephi
2. Cytoscape
• A platform for visualizing complex networks and integrating these with any type of
attribute data.
• Extensively used in biological research for visualizing molecular interaction
networks.
• Supports plugins (apps) for extended functionality.
6
Network Science Practical (CS-801) 7
3. Pajek
4. NetworkX
• A Python library for the creation, manipulation, and study of complex networks.
• Integrates well with other Python scientific computing libraries like NumPy and
Matplotlib.
• Suitable for network analysis and visualization in Python.
7
Network Science Practical (CS-801) 8
8
Network Science Practical (CS-801) 9
PRACTICAL NO – 2
2.1. Aim:
a) To generate random graph using ER model.
b) To show variation of random graph with respect to network science using
Poisson and binomial distribution
2.2. Theory
In graph theory, the Erdos–Rényi model is either of two closely related models for generating
random graphs.
There are two closely related variants of the Erdos–Rényi (ER) random graph model.
In the G(n, M) model, a graph is chosen uniformly at random from the collection of all graphs
which have n nodes and M edges. For example, in the G(3, 2) model, each of the three
possible graphs on three vertices and two edges are included with probability 1/3.
In the G(n, p) model, a graph is constructed by connecting nodes randomly. Each edge is
included in the graph with probability p independent from every other edge. Equivalently, all
Fig 2.1 : A graph generated by the binomial model of Erdos and Rényi (p =
0.01)
9
Network Science Practical (CS-801) 10
The article will basically deal with the G (n,p) model where n is the no of nodes to be created
and p defines the probability of joining of each node to the other.
With the notation above, a graph in G(n, p) has on average edges. The distribution of the
degree of any particular vertex is binomial:
If np < 1, then a graph in G(n, p) will almost surely have no connected components of size
larger than O(log(n)).
If np = 1, then a graph in G(n, p) will almost surely have a largest component whose size is
of order .
If np
c > 1, where c is a constant, then a graph in G(n, p) will almost surely have a unique giant
component containing a positive fraction of the vertices. No other component will contain
more than O(log(n)) vertices.
If
, then a graph in G(n, p) will almost surely contain isolated vertices, and thus be disconnected.
If
, then a graph in G(n, p) will almost surely be connected.
Thus is a sharp threshold for the connectedness of G(n, p). Further properties of the graph
can be described almost precisely as n tends to infinity. For example, there is a k(n)
(approximately equal to 2log2(n)) such that the largest clique in G(n, 0.5) has almost surely
either size k(n) or k(n) + 1. Thus, even though finding the size of the largest clique in a graph
is NP-complete, the size of the largest clique in a “typical” graph (according to this model) is
very well understood.
Next I’ll describe the code to be used for making the ER graph. For implementation of the
code below, you’ll need to install the netwrokx library as well you’ll need to install the
matplotlib library.
10
Network Science Practical (CS-801) 11
Code :
Output :
11
Network Science Practical (CS-801) 12
Code :
Output :
12
Network Science Practical (CS-801) 13
2.4 Theory :
To demonstrate the variation of a random graph with respect to network science, we can
use the Poisson and Binomial distributions to model the degree distribution of nodes. In the
context of random graphs, especially the Erdős–Rényi model G(n,p), where ,
n is the number of nodes and
p is the probability of an edge between any two nodes, the degree distribution of nodes
can be approximated using these distributions.
Binomial Distribution:
Poisson Distribution:
To visualize the variation of random graphs with respect to these distributions, we can:
Generate random graphs using the Erdős–Rényi model for different values of 𝑛 and
p.
Compare the observed degree distributions with the theoretical Binomial and Poisson
distributions.
13
Network Science Practical (CS-801) 14
Code :
Output :
14
Network Science Practical (CS-801) 15
Q5: What can the variation of random graphs using Poisson and binomial distributions
reveal?
Ans: Analyzing the variation using Poisson and binomial distributions can reveal insights
into the connectivity patterns, robustness, and phase transitions of networks in different
random graph scenarios.
15
Network Science Practical (CS-801) 16
PRACTICAL NO – 3
3.2 . Theory :
A common feature of real world networks is the presence of hubs, or a few nodes that are
highly connected to other nodes in the network. The presence of hubs will give the degree
distribution a long tail, indicating the presence of nodes with a much higher degree than most
other nodes.
Scale-free networks are characterized by a power-law degree distribution, where a few nodes
(hubs) have a very high degree while most nodes have a relatively low degree. One of the
most popular models for generating scale-free networks is the Barabási–Albert (BA) model,
which uses a preferential attachment mechanism.
EQUATION :
Scale-free networks are a type of network characterized by the presence of large hubs. A
scale-free network is one with a power-law degree distribution. For an undirected network,
we can just write the degree distribution as :
16
Network Science Practical (CS-801) 17
where γ is some exponent. This form of Pdeg(k) decays slowly as the degree k increases,
increasing the likelihood of finding a node with a very large degree.
CODE :
17
Network Science Practical (CS-801) 18
3.3. Explanation
Degree Distribution: The degree sequence and count are calculated and plotted on a log-log
scale to show the power-law distribution.
Network Visualization: The network is visualized using the spring layout to depict the
structure clearly.
OUTPUT PLOTS :
18
Network Science Practical (CS-801) 19
19
Network Science Practical (CS-801) 20
3.4. EXPLANATION :
Graph Generation:
Degree Distribution:
Network Visualization:
Hubs: The presence of highly connected nodes (hubs) that dominate the network structure.
Robustness and Vulnerability: Scale-free networks are robust against random failures but
vulnerable to targeted attacks on hubs.
Degree Distribution: The degree distribution follows a power-law, indicating that a few nodes
have many connections while most have few.
Social Networks: Many social networks, such as LinkedIn or Facebook, exhibit scale-free
properties where some individuals (nodes) have a very large number of connections (friends,
followers).
Internet: The structure of the Internet is scale-free, with a few highly connected routers
forming the network's backbone.
Biological Networks: Protein-protein interaction networks and metabolic networks in biology
often show scale-free characteristics.
20
Network Science Practical (CS-801) 21
3.7. CONCLUSION :
Scale-free networks are a fundamental concept in network science, reflecting the structure of
many real-world networks. By implementing the Barabási–Albert model, you can generate
and analyze these networks, exploring their unique properties and implications in various
fields. The provided code helps in visualizing and understanding the degree distribution and
overall network structure, laying the groundwork for further exploration and research in
network science.
21
Network Science Practical (CS-801) 22
22
Network Science Practical (CS-801) 23
PRACTICAL NO – 4
4.2. Theory :
Complex networks are structures that consist of nodes (also called vertices) and edges (links)
connecting pairs of nodes. They are termed "complex" due to their intricate topology, which
often displays non-trivial characteristics like clustering, small-world properties, and scale-
free distributions. Understanding complex networks is essential in many fields, including
sociology, biology, computer science, and physics.
In this model, each pair of nodes is connected with a fixed probability p. This leads to a
binomial degree distribution, which can be approximated by a Poisson distribution for large
networks.
Begins with a regular ring lattice where each node is connected to k nearest neighbors. Each
edge is then randomly rewired with a probability p, introducing randomness while
maintaining high clustering.
Builds the network using a preferential attachment mechanism. Nodes are added one at a
time, and each new node forms m edges to existing nodes with a probability proportional to
their current degree.
23
Network Science Practical (CS-801) 24
Social Networks: Understanding the structure of social interactions, information spread, and
influence within communities.
Biological Networks: Analyzing protein-protein interactions, gene regulatory networks, and
metabolic pathways.
Technological Networks: Studying the internet's structure, power grids, and communication
networks.
Information Networks: Exploring citation networks, hyperlink structures on the web, and data
dissemination.
Begins with a regular ring lattice where each node is connected to k nearest neighbors. Each
edge is then randomly rewired with a probability p, introducing randomness while
maintaining high clustering.
Code :
24
Network Science Practical (CS-801) 25
OUTPUT PLOTS :
25
Network Science Practical (CS-801) 26
4.5. CONCLUSION :
Complex networks provide a rich framework for analyzing and understanding the structure
and dynamics of interconnected systems. By studying models like random graphs, small-
world networks, and scale-free networks, we can gain insights into various real-world
networks' resilience, efficiency, and vulnerability. Practical implementations using tools like
NetworkX and Matplotlib allow for detailed exploration and visualization of these complex
structures.
26
Network Science Practical (CS-801) 27
27
Network Science Practical (CS-801) 28
PRACTICAL NO – 5 (A)
5.1. Aim: For a given network, calculate and display the following centrality
measures: Degree, closeness. betweenness, Eigen.
5.2. Theory :
IDEA : To calculate and display the centrality measures (degree, closeness, betweenness,
and eigenvector centrality) for a given network, you can use the NetworkX library in Python.
Below is a step-by-step guide along with a complete code example for these calculations and
visualizations.
Step-by-Step Guide :
1. Generate or Load a Network: You can create a random graph or load an existing network.
Closeness Centrality: Measures how close a node is to all other nodes in the network.
Betweenness Centrality: Measures the extent to which a node lies on paths between other
nodes.
Eigenvector Centrality: Measures the influence of a node based on the connections it has
to other high-influence nodes.
3. Visualize the Network with Centrality Measures: Use color and size to represent
centrality measures.
28
Network Science Practical (CS-801) 29
CODE :
29
Network Science Practical (CS-801) 30
OUTPUT :
30
Network Science Practical (CS-801) 31
31
Network Science Practical (CS-801) 32
Q4: What is Eigenvector centrality, and how does it differ from degree centrality?
Ans: Eigenvector centrality measures a node's influence based on the centrality of its
neighbors, considering not just the number of connections but the quality of those
connections, unlike degree centrality which only counts direct links.
32
Network Science Practical (CS-801) 33
PRACTICAL NO – 5 (B)
5(b).1. Aim: For a given set of situation, Calculate Spearman rho and
Kendall-Tau ranking distance.
5(b).2. Theory :
Spearman's rho: Measures the rank correlation between two sets of rankings. It assesses
how well the relationship between two variables can be described using a monotonic function.
Kendall's tau: Measures the ordinal association between two sets of rankings. It assesses the
similarity of the orderings of the data when ranked by each of the quantities.
To calculate the Spearman's rho and Kendall's tau ranking distance for a given set of
situations, you can use Python libraries like ‘scipy’ which provides functions for these
calculations. Below, I provide an example that demonstrates how to calculate these rank
correlation coefficients for two given sets of rankings.
33
Network Science Practical (CS-801) 34
OUTPUT :
5(b).3. EXPLANATION
Data Preparation:
rankings1 and rankings2 are the two sets of rankings for which we want to calculate the rank
correlation coefficients.
34
Network Science Practical (CS-801) 35
Q5: Why are Spearman's rho and Kendall-Tau important in rank correlation
analysis?
Ans: Spearman's rho and Kendall-Tau are important because they provide insights into the
relationship between ranked variables, helping to understand and quantify the
consistency and strength of the rankings in various situations.
35
Network Science Practical (CS-801) 36
PRACTICAL NO – 6 (A)
6.2. Theory :
PageRank is an algorithm used by search engines to rank web pages in their search results. It
was developed by Larry Page and Sergey Brin, the co-founders of Google, while they were
students at Stanford University. PageRank forms the foundation of Google's search algorithm
and plays a crucial role in determining the relevance and importance of web pages on the
internet.
PageRank operates on the principle of "voting" or "recommendation" among web pages. The
underlying idea is that a page is important if it is linked to by other important pages. However,
not all links are equal. PageRank considers both the quantity and quality of links to a page.
Link Analysis:
PageRank is based on the notion of "voting" or "endorsement" by other pages. When one
page links to another, it is essentially casting a vote for the linked page's importance.
A page with many incoming links is considered more important than a page with fewer links.
Importance Distribution:
Iterative Calculation:
PageRank is calculated iteratively. Initially, all pages are assigned an equal score. In each
iteration, the PageRank of each page is updated based on the PageRank scores of the pages
linking to it.
This process continues until the PageRank scores converge to stable values.
Damping Factor:
To address the issue of dangling nodes (pages with no outgoing links) and dead ends, a
damping factor (typically set to around 0.85) is introduced.
The damping factor represents the probability that a user will continue clicking on links rather
than jumping to a random page.
36
Network Science Practical (CS-801) 37
PageRank can be understood using the "random surfer" model. In this model, a surfer starts
on a random page and follows links, occasionally jumping to a random page.
The PageRank score of a page represents the likelihood that a random surfer will be on that
page at any given time.
In search engines, pages with higher PageRank scores are considered more relevant and are
displayed higher in search results.
PageRank is one of many factors used by search engines to determine the relevance and
ranking of web pages.
To visualize PageRank for a given network, you can use the NetworkX library to calculate
the PageRank values and Matplotlib to visualize the results. Below is an example
demonstrating how to compute and visualize PageRank for a network.
Step-by-Step Guide :
37
Network Science Practical (CS-801) 38
CODE :
38
Network Science Practical (CS-801) 39
OUTPUT :
6.4 EXPLANATION
Network Generation:
PageRank Calculation:
pagerank_values = nx.pagerank(G): Computes the PageRank values for all nodes in the
graph.
39
Network Science Practical (CS-801) 40
Network Visualization:
Advanced Visualization :
For larger and more complex networks, additional visual adjustments and enhancements can
be made:
Adjust Node Size and Color: Better differentiation between high and low PageRank nodes.
Interactive Visualization: Using libraries such as plotly or Bokeh for interactive network
visualization.
Community Detection: Highlighting communities or clusters within the network.
PageRank revolutionized web search by providing a scalable and effective method for
ranking web pages. Its importance extends beyond search engines and is used in various
fields, including:
40
Network Science Practical (CS-801) 41
41
Network Science Practical (CS-801) 42
PRACTICAL NO – 6 (B)
6(b).2. Theory :
The power method is an iterative algorithm used to find the dominant (largest magnitude)
eigenvalue and its corresponding eigenvector of a square matrix. It relies on the concept of
eigenvalues and eigenvectors, which are fundamental properties of square matrices.
For a square matrix A, an eigenvector x and its corresponding eigenvalue 𝜆 satisfy the
equation 𝐴𝑥=𝜆𝑥.
Eigenvectors represent directions within the matrix that are only scaled by the matrix, while
eigenvalues represent the scaling factor.
Dominant Eigenvalue:
In many cases, matrices have one dominant eigenvalue (largest magnitude) that determines
their behavior. The power method focuses on finding this dominant eigenvalue.
Power Iteration:
The power method iteratively applies the matrix A to an initial vector 𝑥0 and normalizes the
resulting vector. The iteration continues until convergence, where the vector xk
approaches the dominant eigenvector of 𝐴
Convergence:
Under certain conditions, such as the matrix having a single dominant eigenvalue or being
irreducible and aperiodic (for Markov matrices), the power method converges to the dominant
eigenvalue and its associated eigenvector.
Convergence is typically assessed by monitoring the change in the vector between iterations
or by setting a tolerance threshold.
Eigenvalue Estimation:
After convergence, the dominant eigenvalue can be estimated as the ratio of the
corresponding components of the iterates.
The corresponding eigenvector is the normalized final iterate.
42
Network Science Practical (CS-801) 43
Limitations:
The power method may converge slowly or fail to converge for matrices with multiple
eigenvalues of similar magnitudes or for matrices with a dominant eigenvalue that is negative.
It also requires the matrix 𝐴 to be diagonalizable, meaning it must have a complete set of
linearly independent eigenvectors.
43
Network Science Practical (CS-801) 44
OUTPUT :
6(b).4. EXPLANATION :
• The power_method function takes the matrix A as input along with optional
parameters for tolerance and maximum iterations.
• It initializes a random vector x and iterates until convergence, updating x at each step.
• The dominant eigenvalue is estimated as the dot product of the final y and x.
44
Network Science Practical (CS-801) 45
Q2: How does the power method work to find the maximum eigenvalue?
Ans: The power method works by repeatedly multiplying a non-zero vector by the matrix,
normalizing the result, and converging to the dominant eigenvector, from which the
largest eigenvalue can be derived.
Q3: What are the initial steps to start the power method?
Ans: To start the power method, choose an initial non-zero vector, multiply it by the matrix,
normalize the resulting vector, and repeat the process until convergence.
45
Network Science Practical (CS-801) 46
PRACTICAL NO – 7
7.2. Theory :
The Laplacian matrix, also known as the Kirchhoff matrix or admittance matrix, is a square
matrix used to represent the topology and properties of a network. It is commonly used in
various fields, including graph theory, network analysis, and physics. Here's how you can
generate and interpret the Laplacian matrix for a network:
L=D−A
Where:
D is the diagonal degree matrix, where Dii represents the degree of node 𝑖.,
A is the adjacency matrix of the network.
Connection Strength:
The Laplacian matrix captures the strength of connections between nodes in the network.
Off-diagonal L represent the negative of the weights or conductances of the edges between
nodes.
Node Degrees:
The diagonal entries of the Laplacian matrix correspond to the degrees of the nodes in the
network.
Larger diagonal entries indicate higher degrees, while smaller entries represent nodes with
fewer connections.
Graph Connectivity:
The Laplacian matrix characterizes the connectivity and topology of the network.
46
Network Science Practical (CS-801) 47
Spectral Properties:
The eigenvalues of L provide information about the network's structure and dynamics, such
as its robustness and synchronization properties.
47
Network Science Practical (CS-801) 48
OUTPUT:
INTERPRETATION :
7.4. CONCLUSION :
By generating and interpreting the Laplacian matrix, you can gain valuable insights into the
connectivity, structure, and dynamics of the network. It serves as a fundamental tool for
analyzing networks in various domains, including social networks, transportation networks,
and biological networks.
48
Network Science Practical (CS-801) 49
L=D-A
Q2: What properties does the Laplace matrix reveal about a network?
Ans: The Laplace matrix reveals important properties such as connectivity, the number of
connected components (given by the multiplicity of the zero eigenvalue), and can be
used to study graph partitioning and clustering.
Q4: What can the eigenvalues of the Laplace matrix tell us about the network?
Ans The eigenvalues of the Laplace matrix provide insights into the network's
connectivity and robustness, with the smallest non-zero eigenvalue (algebraic
connectivity) indicating how well connected the network is.
Q5: How does the Laplace matrix relate to graph theory concepts such as cuts and
flows in a network?
Ans: In graph theory, the Laplace matrix is closely related to concepts of cuts and flows. It
helps identify minimum cuts, which separate the network into distinct components, and
is used in optimizing network flows by solving related linear algebra problems, such as
finding the maximum flow or analyzing the network's resistance to cuts and disruptions.
49
Network Science Practical (CS-801) 50
PRACTICAL NO – 8
8.2. Theory :
The SI, SIS, and SIR models are compartmental models used to describe the dynamics of
infectious diseases within a population. These models divide the population into different
compartments based on their disease status and track the flow of individuals between these
compartments over time. Here's a brief overview of the theory behind each model:
SI Model (Susceptible-Infectious) -:
Compartments:
S (Susceptible): Individuals who are susceptible to the disease and can become infected.
I (Infectious): Individuals who are infected and capable of transmitting the disease.
Assumptions:
Once individuals become infected, they remain infectious for the duration of the simulation.
There is no recovery or immunity from the disease.
Dynamics:
Susceptible individuals become infected at a rate proportional to the product of the
susceptible and infectious populations.
The rate of change in the susceptible population is negative, indicating that susceptible
individuals are being infected.
The rate of change in the infectious population is positive, indicating that individuals are
becoming infected.
Compartments:
S (Susceptible): Individuals who are susceptible to the disease and can become infected.
I (Infectious): Individuals who are infected and capable of transmitting the disease.
Assumptions:
Infected individuals can recover from the disease and become susceptible again.
There is no immunity acquired from previous infections.
50
Network Science Practical (CS-801) 51
Dynamics:
Infected individuals recover from the disease at a constant rate and become susceptible again.
The rate of change in the susceptible population is influenced by both infection and recovery.
The rate of change in the infectious population is influenced by infection and recovery.
Compartments:
S (Susceptible): Individuals who are susceptible to the disease and can become infected.
I (Infectious): Individuals who are infected and capable of transmitting the disease.
R (Recovered): Individuals who have recovered from the disease and are immune.
Assumptions:
Infected individuals can recover from the disease and acquire immunity, becoming immune
to reinfection.
Dynamics:
Infected individuals recover from the disease at a constant rate and become immune.
The rate of change in the infectious population is influenced by infection and recovery.
51
Network Science Practical (CS-801) 52
SI MODEL :
In the SI model, individuals remain infectious once infected and do not recover. The basic
dynamics of the model are described by the following set of ordinary differential equations
(ODEs):
SIS Model:
In the SIS model, individuals can recover from the infection and become susceptible again.
The dynamics are governed by the following ODEs:
SIR Model:
In the SIR model, individuals recover from the infection and become immune. The dynamics
are given by:
52
Network Science Practical (CS-801) 53
53
Network Science Practical (CS-801) 54
OUTPUT :
8.4. INTERPRETATION :
The plots show the dynamics of the susceptible, infectious, and recovered populations over
time for each epidemic model.
In the SI model, the infectious population grows continuously without recovery.
In the SIS model, the infectious population fluctuates as individuals recover and become
susceptible again.
In the SIR model, the infectious population initially grows but eventually decreases as
individuals recover and become immune.
8.5. CONCLUSION :
These compartmental models provide a framework for understanding the spread of infectious
diseases within a population and can be used to explore various scenarios, interventions, and
control strategies. By tracking the flow of individuals between compartments over time, these
models can help inform public health policies and interventions to mitigate the impact of
infectious diseases.
54
Network Science Practical (CS-801) 55
Q2: How does the SIS epidemic model differ from the SI model?
Ans: The SIS (Susceptible-Infected-Susceptible) model allows individuals to transition from
susceptible to infected and back to susceptible, representing diseases where recovery
does not confer immunity, and individuals can be reinfected.
Q3: What additional state is included in the SIR epidemic model compared to the SI
and SIS models?
Ans: The SIR (Susceptible-Infected-Recovered) model includes a recovered (R) state, where
individuals who recover from the infection gain immunity and do not return to the
susceptible state, modeling diseases where recovery leads to immunity.
Q4: How are the transitions between states typically modeled in these epidemic
models?
Ans:Transitions between states in epidemic models are typically modeled using
differential equations that describe the rate of change of the population in each state
based on parameters such as infection rate and recovery rate.
Q5: Why are SI, SIS, and SIR models important in epidemiology?
Ans: SI, SIS, and SIR models are important in epidemiology because they provide a
framework for understanding the spread of infectious diseases, predicting outbreak
dynamics, and evaluating the impact of interventions such as vaccination and social
distancing.
55
Network Science Practical (CS-801) 56
PRACTICAL NO – 9
9.2. Theory
Assumptions:
• Each individual in the network can be in one of two states: "Ignorant" (unaware of the
rumor) or "Spreader" (aware of the rumor and actively spreading it).
• Spreaders transmit the rumor to ignorant individuals with a certain probability per
interaction.
Dynamics:
• Initially, a small subset of individuals (seed nodes) is selected as spreaders, while the
rest are ignorant.
• In each time step, spreaders interact with other individuals, transmitting the rumor to
ignorant individuals with a certain probability.
• Ignorant individuals become spreaders upon hearing the rumor for the first time.
• The process continues until no more individuals become spreaders, indicating that the
rumor has saturated the network or died out.
Parameters:
• Initial Conditions: The number and identity of seed nodes selected as spreaders at the
beginning of the simulation.
56
Network Science Practical (CS-801) 57
9.3. IMPLEMENTATION :
Here's a simple Python implementation of the rumor spreading model using a random
network structure:
import networkx as nx: Imports the NetworkX library, which is used for generating and
analyzing complex networks.
import numpy as np: Imports NumPy, which is used for numerical computations.
57
Network Science Practical (CS-801) 58
nx.erdos_renyi_graph(100, 0.1):
Generates a random Erdős-Rényi graph with 100 nodes and edge probability 0.1. This creates
a random network where each pair of nodes has a 0.1 probability of being connected by an
edge.
Setting Parameters:
p_transmission = 0.1: Probability of transmission, representing the likelihood that a spreader
transmits the rumor to an ignorant individual during an interaction.
seed_nodes = [0, 1]: Initial spreaders, representing the nodes initially selected to spread the
rumor.
max_steps = 100: Maximum number of steps for the simulation.
9.5. PARAMETERS :
Represents the likelihood that a spreader transmits the rumor to an ignorant individual during
an interaction. In this example, it's set to 0.1, meaning each spreader has a 10% chance of
transmitting the rumor during an interaction.
Initial spreaders selected to start spreading the rumor in the network. In this example, nodes
0 and 1 are chosen as seed nodes.
58
Network Science Practical (CS-801) 59
Defines the maximum number of steps for the simulation. Once this limit is reached or no
more individuals become spreaders, the simulation stops. In this example, it's set to 100.
OUTPUT :
1. WHEN :
2. WHEN :
number of nodes = 50
p_transmission = 0.1
seed_nodes = [0, 1]
max_steps = 100
59
Network Science Practical (CS-801) 60
Q5: What insights can be gained from studying rumor spreading models?
Ans: Studying rumor spreading models can provide insights into the dynamics of
information dissemination, the impact of network structure on rumor propagation,
strategies to control or mitigate the spread of rumors, and the role of influential nodes
in accelerating or inhibiting spreading.
60
Network Science Practical (CS-801) 61
PRACTICAL NO – 10 (A)
10.2. Theory :
The diffusion of innovation theory, proposed by Everett Rogers, provides a framework for
understanding how new ideas, products, or technologies spread and are adopted within a
population over time. This theory can be applied to determine factors affecting a particular
dataset by examining how various characteristics of the innovation and the social system
influence its adoption. Here's how you can use the diffusion of innovation theory to analyze
factors affecting a dataset:
Innovation Attributes:
• Trialability: The ability to experiment with the innovation on a limited basis before
making a full commitment.
• Observability: The extent to which the results of an innovation are visible to others.
Adoption Process:
• Persuasion: Individuals form attitudes toward the innovation and weigh its advantages
and disadvantages.
61
Network Science Practical (CS-801) 62
• Confirmation: Individuals evaluate the outcomes of their adoption decision and may
reinforce or reverse it.
Define the innovation or change represented by the dataset. This could be a new technology,
product, policy, or idea.
Examine the dataset's attributes in relation to the five innovation characteristics (relative
advantage, compatibility, complexity, trialability, observability).
Determine how these attributes influence the adoption and usage patterns observed in the
dataset.
Analyze demographic, social, economic, and contextual factors that affect adoption within
the dataset.
Consider factors such as individual characteristics, social networks, organizational
influences, and external environment.
62
Network Science Practical (CS-801) 63
63
Network Science Practical (CS-801) 64
Q2: How can the diffusion of innovation theory be applied to determine factors
affecting a particular dataset?
Ans: The diffusion of innovation theory can be applied by analyzing the adoption patterns
within the dataset, identifying which factors influence the rate and extent of adoption,
and categorizing adopters based on their characteristics and behavior.
Q3: What are the key factors considered in the diffusion of innovation theory?
Ans: Key factors in the diffusion of innovation theory include the perceived relative
advantage of the innovation, compatibility with existing norms and values, complexity
or ease of understanding, trialability or observability, and the presence of opinion
leaders or influencers.
Q4: How can the adoption curve from the diffusion of innovation theory help analyze
the dataset?
Ans: The adoption curve helps in segmenting the dataset based on the timing and rate of
adoption, allowing for the identification of early adopters who may exhibit different
behaviors or preferences compared to late adopters.
Q5: What insights can be gained from applying the diffusion of innovation theory to
a dataset?
Ans: Applying the diffusion of innovation theory can provide insights into the factors driving
adoption or resistance to change within the dataset, inform targeted strategies for
promoting adoption, and aid in predicting future trends or patterns of adoption.
64
Network Science Practical (CS-801) 65
PRACTICAL NO – 10 (B)
10.2. Theory :
Degree Centrality:
Nodes with high degree centrality are well-connected to other nodes in the network.
They play a central role in the network and have the potential to reach many other nodes
quickly.
Betweenness Centrality:
Nodes with high betweenness centrality act as bridges or intermediaries in the network.
They control the flow of information between different parts of the network and are crucial
for maintaining connectivity.
Closeness Centrality:
Nodes with high closeness centrality are close to all other nodes in the network in terms of
shortest path distance.
They can quickly access information from and spread information to other nodes in the
network.
65
Network Science Practical (CS-801) 66
In this code:
Then, we calculate three centrality measures: degree centrality, betweenness centrality, and
closeness centrality.
Next, we find the node with the highest centrality score for each measure using the max()
function and key parameter.
Finally, we print the most influencing node and its centrality score for each measure.
OUTPUT :
Centrality Measures:
• degree_centrality: Degree centrality values for each node in the network.
• betweenness_centrality: Betweenness centrality values for each node in the network.
• closeness_centrality: Closeness centrality values for each node in the network.
10(b).5. CONCLUSION :
By calculating and analyzing these centrality measures, we can identify the most
influential node in a network, which plays a critical role in information dissemination,
network connectivity, and overall network dynamics. These measures help us understand
the structure and function of the network and identify key nodes that may be targeted for
interventions.
66
Network Science Practical (CS-801) 67
Q2: How does centrality help identify the most influencing node in a network?
Ans: Centrality measures such as degree centrality, betweenness centrality, and Eigenvector
centrality quantify different aspects of node importance, helping to identify nodes that
act as key connectors, intermediaries, or highly connected hubs.
Q3: What is closeness centrality, and how does it contribute to identifying influential
nodes?
Ans: Closeness centrality measures how close a node is to all other nodes in the network,
indicating its accessibility and potential influence on spreading information or influence
efficiently.
Q4: How are centrality and closeness measures calculated in network analysis?
Ans: Centrality measures like degree, betweenness, and Eigenvector centrality are
calculated based on the node's connections and their positions in the network, while
closeness centrality is calculated based on the average shortest path distance from a
node to all other nodes.
Q5: What can be inferred by identifying the most influencing node in a network?
Ans: Identifying the most influencing node can provide insights into key players, opinion
leaders, or critical points of control within the network, guiding strategies for
communication, resource allocation, or targeted interventions.
67