Betweenness Centrality for a vertices in an adjacency matrix

48 次查看(过去 30 天)
Hello,
I'm trying to calculate the betweenness centrality for all nodes in an adjacency matrix. It is a weighted network. As far as I know, the Input should be the distance matrix which I have obtained from the adjacency matrix.
Then, I found the following code: http://www.mathworks.com/matlabcentral/fileexchange/10922-matlabbgl/content/matlab_bgl/betweenness_centrality.m I'm not 100% sure, but I think that this is my solution. However, I'm still new to MatLab and can't get the code running. I read some questions about varargin, but I still don't know what I need to put in here and what is meant by "set_matlab_bgl_options % for the standard options."
Any help is highly appreciated. I'm currently writing my thesis and desperately need betweenness scores for my network :) Thanks a lot!!!

回答(6 个)

Rodrigo Mesa-Arango
Don't worry about varargin, what you actually need is an sparse matrix as input. Look at the sample code below.
(Make sure the matlabbgl code is in the path)
>> y = [ 0 1 0 0 0; 0 0 1 0 5; 0 0 0 1 0; 0 0 0 0 0; 0 0 0 5 0]
y =
0 1 0 0 0
0 0 1 0 5
0 0 0 1 0
0 0 0 0 0
0 0 0 5 0
>> s =sparse(y)
s =
(1,2) 1
(2,3) 1
(3,4) 1
(5,4) 5
(2,5) 5
>> [bc,E] = betweenness_centrality(s)
bc =
0
3
2
0
0
E =
(1,2) 4
(2,3) 4
(3,4) 3
(5,4) 1
(2,5) 2
Where bc is the node betweenness centrality and E the edge betweenness
  2 个评论
uzma khan
uzma khan 2016-2-25
编辑:uzma khan 2016-2-25
I'm trying to calculate the betweenness centrality for all edges in an adjacency matrix.when i used [bc,E] = betweenness_centrality(s) it gave the following error Undefined function or variable 'betweenness_centrality'.please someone help me how to find edge betweenness in Matlab.

请先登录,再进行评论。


Steven Lord
Steven Lord 2021-4-7
Since this question was asked we have added the graph and digraph objects to MATLAB. Use one of those functions to create an object from the adjacency matrix (depending on whether your network is undirected or directed) then call the centrality function on the object.
  4 个评论
Muhammad Tabish Bilal
Hi Steven, I am working with a city transportation network and initially analysing the structure of network in MATLAB, I found out that the recent function of CENTRALITY added to MATLAB only results into node centrality. Whereas i am also intrested in edge centrality, is there any way to calculate that in MATLAB directly without going through long scripts?
Christine Tobler
Christine Tobler 2022-4-7
Hi Muhammad,
Short answer is MATLAB doesn't have a function for edge centrality instead of node centrality. Longer answer is I think I can give you a workaround that's effectively the same, but can you make a new post with this question? It will get a bit too long to answer in a comment.

请先登录,再进行评论。


Narges M
Narges M 2013-7-23

Christian
Christian 2013-7-23
Hey Narges,
thank you for your answer. I finally found this code, that seems to be running too:
However, if I take the distance as 1./Adjacency_Matrix it just returns zeros. I thought it is possible to calculate betweenness from the inverse of the adjacency matrix for each vertex. Do you, or does anybody know where the catch might be?
Thanks Christian

Antonio Serda
Antonio Serda 2022-2-3
If you try to calculate the inverse of the adjacency matrix the main diagonal will transfomr to inf. Try to make the diagonal 0 again.

Muhammad Tabish Bilal
Hi all,
I just managed to solve the problem with finding the Edge betweeness of any sort of network. First i recommend to download the MATLABBLG files from this link
After adding it to the path of your current working directory. You can call the function of edge betweeness as:
[bc, E] = betweenness_centrality(s)
keep in mind that "s" should be a sparse matrix not the normal adjacency matrix. This will give you the weighted edge betweenness of your network graph.
Cheers!!!

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by