Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisionError: float division #25

Open
kksspprr opened this issue Jun 8, 2020 · 1 comment
Open

ZeroDivisionError: float division #25

kksspprr opened this issue Jun 8, 2020 · 1 comment

Comments

@kksspprr
Copy link

kksspprr commented Jun 8, 2020

Hi,

the following code snippet works around 50% of the time and throws "ZeroDivisionError" 50% of the time.

forceatlas2 = ForceAtlas2(
# Behavior alternatives
outboundAttractionDistribution=True, # Dissuade hubs
linLogMode=False, # NOT IMPLEMENTED
adjustSizes=False, # Prevent overlap (NOT IMPLEMENTED)
edgeWeightInfluence=1.0,
# Performance
jitterTolerance=1.0, # Tolerance
barnesHutOptimize=True,
barnesHutTheta=1.2,
multiThreaded=False, # NOT IMPLEMENTED
# Tuning
scalingRatio=2.0,
strongGravityMode=False,
gravity=0.5,
# Log
verbose=True)

G = nx.complete_graph(2)

forceatlas2.forceatlas2_networkx_layout(G, pos=None, iterations=1000)

Output when it works:

0%| | 0/1000 [00:00<?, ?it/s]

0%| | 0/1000 [00:00<?, ?it/s]

100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:00<00:00, 112015.38it/s]
BarnesHut Approximation took 0.00 seconds

Output when it doesn't work

0%| | 0/1000 [00:00<?, ?it/s]

0%| | 0/1000 [00:00<?, ?it/s]
ZeroDivisionError: float division

@victorbenichoux
Copy link
Collaborator

Hi,
Thanks for reporting this error.

Indeed, I can reproduce it here. It only seems to be the case for two nodes, and occurs because at some point coordinates for all nodes vanish (due to a combination of gravity and strong-connectedness), which makes the totalEffectiveTraction vanish as well and raise a ZeroDivisionError.
A similar error occurs when all positions are initialized to the same value.

I will open a pull request fixing these errors.

Victor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants