NaN in small worldness

Home Forums Software Bugs (Braph 1.0) NaN in small worldness

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #26066
    Allison Chen


    I am using the braph to calculate the small-worldness. when the density<40, the small worldness is NaN. I guess when we get a disconnected node, the path length goes to infinity (this is intuitive I think). We may need to use the harmonic mean to avoid this. Could you please revise the source code to avoid this? Besides, when comparing the nodal measures for two groups, the p-values for different measures are different, but the fdr are always the same. Why does this happen? Thanks!


    Mite Mijalkov

    Hi Allison,

    Thank you for using Braph. I hope that you will find it useful during the course of your research.

    Regarding the p-values for between group comparison: The fdr column represents the highest p-value that is significant after fdr correction. This value is calculated at a given density, among the multiple comparisons performed between all regions. That is why, when the region changes, the fdr value stays the same. However, since the multiple comparisons are different for each region, the associated uncorrected p-value changes. We discussed this issue previously on this forum and you can find more detailed explanations at: and .

    Regarding the small worldness calculation, you are right. This situation happens when the network is unconnected. Practically, this results in NaN for the path length of the disconnected nodes which then affects the calculation of the mean. To help you with this, could you let me know what type of analysis you are running (weighted or binary undirected (or directed from the command line) so that I can send you a list of changes that need to be done in order to get the harmonic mean.

    Hope these explanations help. If you need any additional help, please do not hesitate to ask.


    • This reply was modified 5 years, 2 months ago by Mite Mijalkov.
    Hojoon lee

    We have a same issue regarding NaN in graph measure generation.
    We are using bud analysis.
    Can you share the required steps for harmonic mean implementation?
    Thanks in advance.

    Best wishes
    Hojoon Lee

    Kyoo Ho Cho

    I am doing a MRI (Structural covariance) cohort analysis.
    for 2 groups.(Normal and patient)
    During graph measure generation, other
    normal control has full Global and nodal features (graphs)
    But paitient group has NO “char.path.length (NOT wihtin subgroups)” and “small worldness”
    Each above two parameter with (within subgroups) is present. But I never did ‘subgroup’ analysis
    (I attach the screenshot)
    P.S calculation duration at each density takes about 6 hours. Is there any way to speed it up?

    Thank you very much

    Mite Mijalkov

    Dear Hojoon Lee,

    Thanks for using Braph and I hope that it proves to be a valuable tool in your research.

    If you would like to implement harmonic mean implementation of the path length calculation, you would need to change the file GraphBU.m. Locate the method “measure” in the GraphBU.m file. Line 459 just calculates the mean of the path length of each node (in the original code). In order to implement the harmonic mean, just substitute line 459, with the following:

    tmp =;
    res = mean(tmp.^(-1)).^(-1);

    which is the expression for the harmonic mean.

    Hope this works. If there is anything more I can help you with, please let me know.


    Mite Mijalkov

    Hi Cho,

    Thank you for using Braph.

    The issue with small worldness (and characteristic path length) is that they cannot be calculated (especially for small densities) due to the disconnections of some nodes in the graph. This is due to their current implementation, in which first the nodal path lengths for each node are calculated and then they are averaged out in order to calculate the characteristic path length. Therefore, if any disconnected nodes exist in the graph, the nodal path length will return NaN and the characteristic path length cannot be calculated.

    As an alternative, you might want to calculate them only within connected subgraphs, where there are no disconnected nodes. If you calculate the small worldness from the command line, you can specify a second argument (“wsg”) as a function input, which ,if set to true, will calculate the small worldness within the connected component of the network. You can find the codes for this on line 1427 in the file Graph.m (for calculating the small worldness) and on line 460 in GraphBU.m (within the method “measure”) for the differences of calculating the path length only within the connected components. Currently, the default value of this argument is set to false. If you would like to change this so that the small worldness is always calculated within the connected components you can do so by changing line 1439 of Graph.m file.

    Another alternative method is to implement the harmonic mean as I explained above.

    I realize that the calculation of the small-worldness takes a lot of time. This is due to the fact that in order to calculate the small-worldness the network needs to be randomized many times, and currently, the randomization algorithm implemented in Braph is very slow. We hope that we can implement faster alternative methods in Braph soon.

    Hope this helps you. Please do not hesitate to ask if you would need any more help.


Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.