The Wayback Machine - https://web.archive.org/web/20240724195113/https://www.geeksforgeeks.org/degree-centrality-centrality-measure/
Open In App

Degree Centrality (Centrality Measure)

Last Updated : 21 Jul, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
Degree In graph theory, the degree (or valency) of a vertex of a graph is the number of edges incident to the vertex, with loops counted twice.[1] The degree of a vertex  v is denoted  \deg(v) or  \deg v. The maximum degree of a graph G, denoted by \Delta (G), and the minimum degree of a graph, denoted by \delta (G), are the maximum and minimum degree of its vertices. In the graph on the right, the maximum degree is 5 and the minimum degree is 0. In a regular graph, all degrees are the same, and so we can speak of the degree of the graph. Degree Centrality Historically first and conceptually simplest is degree centrality, which is defined as the number of links incident upon a node (i.e., the number of ties that a node has). The degree can be interpreted in terms of the immediate risk of a node for catching whatever is flowing through the network (such as a virus, or some information). In the case of a directed network (where ties have direction), we usually define two separate measures of degree centrality, namely indegree and outdegree. Accordingly, indegree is a count of the number of ties directed to the node and outdegree is the number of ties that the node directs to others. When ties are associated to some positive aspects such as friendship or collaboration, indegree is often interpreted as a form of popularity, and outdegree as gregariousness. The degree centrality of a vertex v , for a given graph G:=(V,E) with |V| vertices and |E| edges, is defined as C_{D}(v)=\deg(v) Calculating degree centrality for all the nodes in a graph takes \Theta(V^2) in a dense adjacency matrix representation of the graph, and for edges takes \Theta(E) in a sparse matrix representation. The definition of centrality on the node level can be extended to the whole graph, in which case we are speaking of graph centralization. Let v* be the node with highest degree centrality in G. Let X:=(Y,Z) be the |Y| node connected graph that maximizes the following quantity (with y* being the node with highest degree centrality in X): H=\sum _{{j=1}}^{{|Y|}}[C_{D}(y*)-C_{D}(y_{j})] Correspondingly, the degree centralization of the graph G is as follows: C_D(G)= \frac{\displaystyle{\sum^{|V|}_{i=1}{[C_D(v*)-C_D(v_i)]}}}{H} The value of H is maximized when the graph X contains one central node to which all other nodes are connected (a star graph), and in this case {H=(n-1)\cdot ((n-1)-1)=n^{2}-3n+2}. Following is the code for the calculation of the degree centrality of the graph and its various nodes.
import networkx as nx
  
def degree_centrality(G, nodes):
    r"""Compute the degree centrality for nodes in a bipartite network.
  
    The degree centrality for a node `v` is the fraction of nodes 
    connected to it.
  
    Parameters
    ----------
    G : graph
       A bipartite network
  
    nodes : list or container
      Container with all nodes in one bipartite node set.
  
    Returns
    -------
    centrality : dictionary
       Dictionary keyed by node with bipartite degree centrality as the value.
  
    Notes
    -----
    The nodes input parameter must contain all nodes in one bipartite node set,
    but the dictionary returned contains all nodes from both bipartite node
    sets.
  
    For unipartite networks, the degree centrality values are 
    normalized by dividing by the maximum possible degree (which is 
    `n-1` where `n` is the number of nodes in G). 
  
    In the bipartite case, the maximum possible degree of a node in a
    bipartite node set is the number of nodes in the opposite node set
    [1]_.  The degree centrality for a node `v` in the bipartite
    sets `U` with `n` nodes and `V` with `m` nodes is
  
    .. math::
  
        d_{v} = \frac{deg(v)}{m}, \mbox{for} v \in U ,
  
        d_{v} = \frac{deg(v)}{n}, \mbox{for} v \in V ,
  
  
    where `deg(v)` is the degree of node `v`.        
  
      
    """
    top = set(nodes)
    bottom = set(G) - top
    s = 1.0/len(bottom)
    centrality = dict((n,d*s) for n,d in G.degree_iter(top))
    s = 1.0/len(top)
    centrality.update(dict((n,d*s) for n,d in G.degree_iter(bottom)))
    return centrality

                    
The above function is invoked using the networkx library and once the library is installed, you can eventually use it and the following code has to be written in python for the implementation of the Degree centrality of a node.
import networkx as nx
G=nx.erdos_renyi_graph(100,0.5)
d=nx.degree_centrality(G)
print(d)

                    
The result is as follows:
{0: 0.5252525252525253, 1: 0.4444444444444445, 2: 0.5454545454545455, 3: 0.36363636363636365, 4: 0.42424242424242425, 5: 0.494949494949495, 6: 0.5454545454545455, 7: 0.494949494949495, 8: 0.5555555555555556, 9: 0.5151515151515152, 10: 0.5454545454545455, 11: 0.5151515151515152, 12: 0.494949494949495, 13: 0.4444444444444445, 14: 0.494949494949495, 15: 0.4141414141414142, 16: 0.43434343434343436, 17: 0.5555555555555556, 18: 0.494949494949495, 19: 0.5151515151515152, 20: 0.42424242424242425, 21: 0.494949494949495, 22: 0.5555555555555556, 23: 0.5151515151515152, 24: 0.4646464646464647, 25: 0.4747474747474748, 26: 0.4747474747474748, 27: 0.494949494949495, 28: 0.5656565656565657, 29: 0.5353535353535354, 30: 0.4747474747474748, 31: 0.494949494949495, 32: 0.43434343434343436, 33: 0.4444444444444445, 34: 0.5151515151515152, 35: 0.48484848484848486, 36: 0.43434343434343436, 37: 0.4040404040404041, 38: 0.5656565656565657, 39: 0.5656565656565657, 40: 0.494949494949495, 41: 0.5252525252525253, 42: 0.4545454545454546, 43: 0.42424242424242425, 44: 0.494949494949495, 45: 0.595959595959596, 46: 0.5454545454545455, 47: 0.5050505050505051, 48: 0.4646464646464647, 49: 0.48484848484848486, 50: 0.5353535353535354, 51: 0.5454545454545455, 52: 0.5252525252525253, 53: 0.5252525252525253, 54: 0.5353535353535354, 55: 0.6464646464646465, 56: 0.4444444444444445, 57: 0.48484848484848486, 58: 0.5353535353535354, 59: 0.494949494949495, 60: 0.4646464646464647, 61: 0.5858585858585859, 62: 0.494949494949495, 63: 0.48484848484848486, 64: 0.4444444444444445, 65: 0.6262626262626263, 66: 0.5151515151515152, 67: 0.4444444444444445, 68: 0.4747474747474748, 69: 0.5454545454545455, 70: 0.48484848484848486, 71: 0.5050505050505051, 72: 0.4646464646464647, 73: 0.4646464646464647, 74: 0.5454545454545455, 75: 0.4444444444444445, 76: 0.42424242424242425, 77: 0.4545454545454546, 78: 0.494949494949495, 79: 0.494949494949495, 80: 0.4444444444444445, 81: 0.48484848484848486, 82: 0.48484848484848486, 83: 0.5151515151515152, 84: 0.494949494949495, 85: 0.5151515151515152, 86: 0.5252525252525253, 87: 0.4545454545454546, 88: 0.5252525252525253, 89: 0.5353535353535354, 90: 0.5252525252525253, 91: 0.4646464646464647, 92: 0.4646464646464647, 93: 0.5555555555555556, 94: 0.5656565656565657, 95: 0.4646464646464647, 96: 0.494949494949495, 97: 0.494949494949495, 98: 0.5050505050505051, 99: 0.5050505050505051}
The above result is a dictionary depicting the value of degree centrality of each node. The above is an extension of my article series on the centrality measures. Keep networking!!! References You can read more about the same at https://en.wikipedia.org/wiki/Centrality#Degree_centrality http://networkx.readthedocs.io/en/networkx-1.10/index.html

Previous Article
Next Article

Similar Reads

Katz Centrality (Centrality Measure)
In graph theory, the Katz centrality of a node is a measure of centrality in a network. It was introduced by Leo Katz in 1953 and is used to measure the relative degree of influence of an actor (or node) within a social network. Unlike typical centrality measures which consider only the shortest path (the geodesic) between a pair of actors, Katz ce
7 min read
Percolation Centrality (Centrality Measure)
A slew of centrality measures exist to determine the ‘importance’ of a single node in a complex network. However, these measures quantify the importance of a node in purely topological terms, and the value of the node does not depend on the ‘state’ of the node in any way. It remains constant regardless of network dynamics. This is true even for the
3 min read
Betweenness Centrality (Centrality Measure)
In graph theory, betweenness centrality is a measure of centrality in a graph based on shortest paths. For every pair of vertices in a connected graph, there exists at least one shortest path between the vertices such that either the number of edges that the path passes through (for unweighted graphs) or the sum of the weights of the edges (for wei
6 min read
Network Centrality Measures in a Graph using Networkx | Python
Centrality Measures allows us to pinpoint the most important nodes of a Graph. This essentially helps us to identify : Influential nodes in a Social Network. Nodes that disseminate information to many nodes Hubs in a transportation network Important pages in the Web Nodes that prevent the Network from breaking up Firstly, we need to consider the fa
6 min read
Measure similarity between images using Python-OpenCV
Prerequisites: Python OpenCVSuppose we have two data images and a test image. Let's find out which data image is more similar to the test image using python and OpenCV library in Python.Let's first load the image and find out the histogram of images.Importing library import cv2 Importing image data image = cv2.imread('test.jpg') Converting to gray
2 min read
How to measure elapsed time in Python?
In Python, we can measure the elapsed time on executing a code segment or a Python script using some built-in Python modules. Here we will cover the usage of time, timeit and datetime module. Using Python timeit Module to measure elapsed time in Python Python timeit module is often used to measure the execution time of small code snippets. We can a
6 min read
How to Measure the Binary Cross Entropy Between the Target and the Input Probabilities in PyTorch?
In this article, we are going to see how to Measure the Binary Cross Entropy between the target and the input probabilities in PyTorch using Python. We can measure this by using the BCELoss() method of torch.nn module. BCELoss() method The BCELoss() method measures the Binary Cross Entropy between the target and the input probabilities by creating
2 min read
How to measure the mean absolute error (MAE) in PyTorch?
In this article, we are going to see how to measure the Mean Absolute Error (MAE) in PyTorch. [Tex]\text{MAE} = \sum\limits_{i = 1}^n {\left| {{y_i} - \widehat {{y_i}}} \right|}[/Tex] The Mean absolute error (MAE) is computed as the mean of the sum of absolute differences between the input and target values. This is an objective function in many of
3 min read
Measure Size of an Object Using Python OpenCV
In this article, we will learn about how to measure the size of an object using OpenCV which is implemented in Python. It is implemented by finding the contours around it. This can be done by first loading an image of an object, converting it to grayscale, and applying a threshold to separate the object from the background. It then finds the object
3 min read
Measure one litre using two vessels and infinite water supply
There are two vessels of capacities 'a' and 'b' respectively. We have infinite water supply. Give an efficient algorithm to make exactly 1 litre of water in one of the vessels. You can throw all the water from any vessel any point of time. Assume that 'a' and 'b' are Coprimes.Following are the steps: Let V1 be the vessel of capacity 'a' and V2 be t
15 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg