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

runtime warning for add-edge #154

Open
flyaflya opened this issue Aug 2, 2022 · 2 comments
Open

runtime warning for add-edge #154

flyaflya opened this issue Aug 2, 2022 · 2 comments
Labels

Comments

@flyaflya
Copy link

flyaflya commented Aug 2, 2022

For the following code:

pgm = daft.PGM(dpi = 150, alternate_style="outer")

pgm.add_node("sb","Start\nBalance", 1, 4, aspect = 2.2, observed = True, plot_params = {'facecolor': 'cadetblue'})
pgm.add_node("ba","Bet\nAmount", 1, 3, aspect = 2.2, shape = "rectangle", plot_params = {'facecolor': 'thistle'})

pgm.add_edge("sb", "ba")
pgm.render()

I get a runtime warning error message:

/usr/local/lib/python3.7/dist-packages/daft.py:843: RuntimeWarning: divide by zero encountered in double_scalars
  * (np.sign(dy) or 1.0)
<matplotlib.axes._axes.Axes at 0x7f2085d4d190>

image

The graph renders just fine, but I am unsure whether I am doing something wrong or if the Warning should not really occur. Thanks!

@dfm
Copy link
Member

dfm commented Aug 2, 2022

Looks like this warning originates here (the line numbers have changed since the release):

daft/daft.py

Line 851 in 75a4052

* np.abs(dy / dx)

when the node shape is "rectangle" and dx = 0. This definitely seems like a bug and should be looked into!

@dfm dfm added the bug label Aug 2, 2022
@flyaflya
Copy link
Author

flyaflya commented Aug 2, 2022

In that case, I should mention that something similar occurs when using a horizontal edge from the rectangle as well:

pgm = daft.PGM(node_fc="aliceblue", dpi = 150, alternate_style="outer")

pgm.add_node("sb","Start\nBalance", 1, 4, aspect = 2.2, observed = True, plot_params = {'facecolor': 'cadetblue'})
pgm.add_node("ba","Bet\nAmount", 1, 3, aspect = 2.2, shape = "rectangle", plot_params = {'facecolor': 'thistle'})
pgm.add_node("w","Winnings", 2.7, 3, aspect = 2.2, alternate = True)

pgm.add_edge("sb", "ba")
pgm.add_edge("ba","w")
pgm.render()

yields:

/usr/local/lib/python3.7/dist-packages/daft.py:852: RuntimeWarning: divide by zero encountered in double_scalars
  * (np.sign(dy) or 1.0)
/usr/local/lib/python3.7/dist-packages/daft.py:857: RuntimeWarning: divide by zero encountered in double_scalars
  dxx2 = self.scale * 0.5 * np.abs(dx / dy) * (np.sign(dx) or 1.0)
<matplotlib.axes._axes.Axes at 0x7f220e0761d0>

image

Thanks for looking into it!!! I really like the package.👍

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

No branches or pull requests

2 participants