Graph/centrality- Is there a way to avoid "Expected Cost to be positive" error?

Hi! I'm conducting centrality analysis on a set of nodes (XYZ) and edges. My edge cost is euclidean distance. However, I currently get an error each time I calculated weighted closeness or weighted betweeness saying that "expected cost to be positive." Why am I getting this error?
Here is my code:
figure('Name','Closeness-weighted')
wcc = centrality(G,'closeness','Cost',G.Edges.Weight);
p.NodeCData = wcc;
title('Closeness Centrality Scores - Weighted')
It is a large node dataset, and I think some of the edges start and end at the same node. Is this the problem? Can i remove these easily?
Sorry! I'm a beginner. Any help or resources would be greatly appreciated.

 Risposta accettata

After contacting technical support, there is currently a bug in the centrality functions with large datasets (>100 nodes). They are currently looking into it. :)

Più risposte (1)

Are any of your weights non-positive? Specifically check if any are equal to 0.

4 Commenti

There are a lot equal to zero, I'm wondering if this might have to do with how I created my edges in arcgis. Some points are connected to the same point (i.e. pointTo, PointFrom are the same), but others are not but they still read zero. Ideas? Here is my edge weight calc...
[s,t] = findedge(G); %calls the edges.
xyz = [nodes_info.Northing nodes_info.Easting nodes_info.RASTERVALU] %creates a variable for the distance calculation.
G.Edges.Weight = vecnorm(xyz(s,:)-xyz(t,:),2,2); %distance calc.
Is there a function to skip the zeros? Or does it have to be included for the centrality function to work? :)
If the edges start and end at the same location, are they self loops or are they connecting two nodes that happen to be at the same place? If the former consider specifying 'omitselfloops' when you construct the graph to eliminate those self loops.
Hi Steven! Thanks for this, I added omitselfloops which definitely cleaned up the data a lot. I'm still getting the the positivity error though, perhaps it is the second option... or ( I've added a picture so you can see what's going on) some points are not connected to the main network as shown... perhaps this is where the problem lies? Any ideas? :)
Thanks again!

Accedi per commentare.

Categorie

Scopri di più su Networks in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by