Invalid MEX-file error when using betweenness_centrality.m script - not sure why!

Hey all,
I am trying to run the 'betweenness_centrality.m' script from the MatlabBGL package.
I am using a 64-bit macbook air and am using the matlab version 'Matlab2023a'.
However, when I try to run it, I get the following error:
Invalid MEX-file '/Users/macbook/Desktop/UCL PhD
Work/py_scripts/betweenness_centrality_mex.mexmaci64':
dlopen(/Users/macbook/Desktop/UCL PhD
Work/py_scripts/betweenness_centrality_mex.mexmaci64, 0x0006): Library not loaded:
'@loader_path/libmex.dylib'
Referenced from: '/Users/macbook/Desktop/UCL PhD
Work/py_scripts/betweenness_centrality_mex.mexmaci64'
Reason: tried: '/Users/macbook/Desktop/UCL PhD Work/py_scripts/libmex.dylib' (no
such file), '/usr/local/lib/libmex.dylib' (no such file),
'/usr/lib/libmex.dylib' (no such file)
Error in betweenness_centrality (line 110)
bc = betweenness_centrality_mex(A,weight_arg);
Error in Spacesocialproject (line 3)
bc = betweenness_centrality(G);
I have ensured that the 'betweenness_centrality_mex.mexmaci64' file is in the same directory as the matlab scripts.
I would be so grateful for a helping hand as to why this may be!

6 comentarios

This isn't a direct answer to your question about the MEX-file in that third-party package but are you aware that MATLAB now has (and has had, for several years) graph and network algorithm functionality? The centrality function for graph and digraph objects can compute betweenness centrality.
Thank you so so much!
When I try the following, I get the same betweenness centrality values as on python (bcn variable):
import matlab.graph.*;
G = graph(G);
bc = centrality(G,'betweenness');
However, when I try calculting closeness centrality, the outputs are different between python and matlab.
Why might this be?
Matlab code:
import matlab.graph.*;
G = graph(G);
cc = centrality(G,'closeness');
Python code:
import networkx as nx
import pandas as pd
newframe2 = pd.read_excel(r'/Users/macbook/Desktop/UCL PhD Work/py_scripts/Betweennesscentralitymatrix.xlsx',header=None)
graph = nx.from_numpy_matrix(newframe2.values)
closeness = nx.closeness_centrality(graph)
df_closeness = pd.DataFrame(columns=['Node', 'Closeness Centrality'])
for node, centrality in closeness.items():
df_closeness = df_closeness.append({'Node': node, 'Closeness Centrality': centrality}, ignore_index=True)
df_closeness['Node'] = df_closeness['Node'].astype(int)
df_closeness.to_csv(r'/Users/macbook/Desktop/UCL PhD Work/py_scripts/Closenesscentralitymatrixfinal.xlsx')
df_closeness['Closeness Centrality'] = df_closeness['Closeness Centrality'].round(6)
df_closeness.to_csv(r'/Users/macbook/Desktop/UCL PhD Work/py_scripts/Closenesscentralitymatrixfinal_rounded.csv', index=False)
I don't have any experience with the MatlabBGL third-party toolbox, but I suspect from the fact that you're calling import that you're trying to use the functions it contains. If the G you pass into graph is the adjacency matrix, you can do the same thing using the functionality included in MATLAB if you restart your session (to remove the import) and call the graph function in MATLAB.
rng default
A = sprand(10, 10, 0.25); % Random adjacency matrix
G = graph(A+A');
C = centrality(G, 'betweenness')
C = 10×1
14.9167 1.9167 8.0000 0 3.5833 0 1.2500 1.0000 2.0833 5.2500
We can visualize the graph and highlight the "most central" node.
h = plot(G);
[~, mostCentral] = max(C);
highlight(h, mostCentral, 'MarkerSize', 2*h.MarkerSize) % Double its size
Thank you so much for this! I think what I meant was more with regards to why the closeness centrality values slightly differ on python and matlab? :)
On a good note, the same node is highlighted as the one with the highest degree centrality when I plot them on python and matlab.
First four closeness centrality values on python:
0: 0.28888888888888886, 1: 0.28888888888888886, 2: 0.28888888888888886, 3: 0.25742574257425743,
First four closeness centrality values on matlab:
cc =
0.0111
0.0111
0.0111
0.0099
Thus, there are slight differences in the raw values themselves when comparing matlab and python outputs.
Might you know why this is?
Looks like they differ by a scaling factor.
format longg
P = [0.28888888888888886, 0.28888888888888886, 0.28888888888888886, 0.25742574257425743];
M = [0.0111, 0.0111, 0.0111, 0.0099];
scaleFactor = P./M
scaleFactor = 1×4
26.026026026026 26.026026026026 26.026026026026 26.002600260026
I'm betting if you actually used all the decimal places stored in the values in MATLAB each element of the scaling factor vector would be even closer to the same number.
I don't know what scaling factor or method Python uses. If you forced me to guess perhaps their definition doesn't divide by like the definition on the centrality documentation page does?
Thank you so much! Yes, I thought there was some sort of scaling factor that related them :)

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Preguntada:

el 31 de Mayo de 2023

Comentada:

el 31 de Mayo de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by