Betweenness Centrality for a vertices in an adjacency matrix
30 ビュー (過去 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!!!
0 件のコメント
回答 (6 件)
Rodrigo Mesa-Arango
2014 年 2 月 14 日
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
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.
Souarv De
2021 年 4 月 6 日
編集済み: Souarv De
2021 年 4 月 9 日
@Rodrigo Mesa-ArangoWhat is the y? Is it a adjaceny matrix or distance matrix?
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.
6 件のコメント
Gerhard
2024 年 8 月 21 日 8:28
Thank you very much, I know that the question comes late but I'm looking for a workaround function for edge centrality instead of node centrality
Thanks you
Christine Tobler
2024 年 8 月 23 日 16:18
Hi Gerhard,
Right, so there are two ways to do this, one fast but that doesn't match exactly, and a slower one that should match exactly:
Fast, qualitatively similar:
% Make a random graph
rng default; g = digraph(sprandn(10, 10, 0.1));
% Extract its nodes and edges
[s, t] = findedge(g); w = g.Edges.Weight;
n = numnodes(g);
e = numedges(g);
% Make an auxiliary graph where every edge of the original graph is
% represented by a node:
auxNodes = (numnodes(g)+1:numnodes(g)+numedges(g))';
G = digraph([s; auxNodes], [auxNodes, t], [w; zeros(size(w))]);
fastC = centrality(G, 'betweenness');
fastC = fastC(n+1:end);
plot(g, EdgeLabel=fastC)
This isn't exactly edge betweenness, because instead of looking at all paths between any node and any other node, we will also treat edges as nodes, so we're counting all paths from any node or edge to any other node or edge.
Qualitatively, I don't think it makes much of a difference, but it's not the numbers you would expect.
Slow but exact version:
To avoid this, we need to only insert a node on one edge at a time. This is much more expensive, since we're throwing most of the centrality scores away in each iteration.
for ii=1:e
ind = [1:ii-1 ii+1:e];
Gii = digraph([s(ind); s(ii); n+1], [t(ind); n+1; t(ii)], [w(ind); w(ii); 0]);
c = centrality(Gii, 'betweenness');
exactC(ii) = c(end);
end
plot(g, EdgeLabel=exactC)
Here you can count that the number on each edge is the number of pairs of start and target nodes who are connected by a shortest path through that edge.
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.
0 件のコメント
Muhammad Tabish Bilal
2022 年 4 月 7 日
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!!!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Directed Graphs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!