pik-copan / pyunicorn

Unified Complex Network and Recurrence Analysis Toolbox
http://pik-potsdam.de/~donges/pyunicorn/
Other
195 stars 86 forks source link

`Network.nsi_local_clustering()` might encounter divide by zero when `typical_weight` is given #206

Closed fkuehlein closed 5 months ago

fkuehlein commented 7 months ago

Network.nsi_local_clustering(typical_weight=w) will contain NaNs if k = Network.nsi_degree() contains 1.s because it divides by (k * (k-1.0)) when w is not None. This is the case for Network.SmallTestNetwork():

from pyunicorn.core import Network

net = Network.SmallTestNetwork()
res = net.nsi_local_clustering(typical_weight=2.0)

produces

Calculating corrected n.s.i. local clustering coefficients...
pyunicorn/src/pyunicorn/core/network.py:2847: RuntimeWarning: invalid value encountered in divide
  return (numerator/typical_weight**2 - 3.0*k - 1.0) / (k * (k-1.0))

test_network.py::test_nsi_local_clustering() does not cover the case of given typical_weight parameter. Note that the implementation is in line with the description paper. But how can k = 1. be accounted for?


Side note: The TODO list at the top of core/network.py contains

# - find segfault problem in a.w. shortest path betweenness

I can't find any method called aw_/nsi_shortest_path_betweenness or similar. What is meant by this, can the TODO be removed? (EDIT: resolved as of f9f158a)

fkuehlein commented 6 months ago

introducing minimal denominator as in RecurrencePlot should suffice:

https://github.com/pik-copan/pyunicorn/blob/3c179b4ecc8b26acfd96a7d02f8ede2a3be2f5cb/src/pyunicorn/timeseries/recurrence_plot.py#L158-L159