erdogant / bnlearn

Python package for Causal Discovery by learning the graphical structure of Bayesian networks. Structure Learning, Parameter Learning, Inferences, Sampling methods.
https://erdogant.github.io/bnlearn
Other
469 stars 45 forks source link

bn.plot #68

Open natank1 opened 1 year ago

natank1 commented 1 year ago

For some reasons, bn.plot doesnt work it creates alerets but not the graph

erdogant commented 1 year ago

I just released an update to fix the colab interactive plots.

But for the static plots, does this work for you?

import bnlearn as bn
model = bn.import_DAG('sprinkler', CPD=True)
df = bn.sampling(model, n=1000, methodtype='bayes')
fig = bn.plot(model, params_static={'visible': True})

Maybe try to force to show the plot fig['ax'].show()

natank1 commented 1 year ago

That's the message Traceback (most recent call last): File "/Users/natank/checkpoint/IOT_PROJECT/deepcover/training/rr5.py", line 3, in df = bn.sampling(model, n=1000, methodtype='bayes') TypeError: sampling() got an unexpected keyword argument 'methodtype'

On Fri, Dec 30, 2022 at 12:46 AM Erdogan Taskesen @.***> wrote:

I just released an update to fix the colab interactive plots.

But for the static plots, does this work for you?

import bnlearn as bn model = bn.import_DAG('sprinkler', CPD=True) df = bn.sampling(model, n=1000, methodtype='bayes') fig = bn.plot(model, params_static={'visible': True})

Maybe try to force to show the plot fig['ax'].show()

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367620916, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2Z2R6TZB5ISCIX2FVMDWPYIE5ANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

erdogant commented 1 year ago

can you check the version?

import bnlearn
bnlearn__version__
natank1 commented 1 year ago

0.4.2 (I downgraded)

On Fri, Dec 30, 2022 at 9:24 AM Erdogan Taskesen @.***> wrote:

can you check the version?

import bnlearn bnlearnversion

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367768216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2ZZJ3AQ2OF6ZEWGSPG3WP2E4LANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

natank1 commented 1 year ago

When I upgraded I got this

0.7.11 [bnlearn] >Import [bnlearn] >Check whether CPDs sum up to one. [bnlearn] >Check whether CPDs associated with the nodes are consistent: True [bnlearn] >Set node properties. [bnlearn] >Set edge properties. [bnlearn] >Plot based on Bayesian model

With no grpah

On Fri, Dec 30, 2022 at 9:32 AM Natan Katz @.***> wrote:

0.4.2 (I downgraded)

On Fri, Dec 30, 2022 at 9:24 AM Erdogan Taskesen @.***> wrote:

can you check the version?

import bnlearn bnlearnversion

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367768216, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2ZZJ3AQ2OF6ZEWGSPG3WP2E4LANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

erdogant commented 1 year ago

What is your Python version?

There is one newer update. force install from pypi: pip install -U bnlearn

did you try this:

from matplotlib.pyplot import plot, draw
draw()

or fig['ax'].show()

natank1 commented 1 year ago

It opens and instantaneously close. Namely, i see on the bar the sign of a plot appears and disappears before the graph comes

On Fri, Dec 30, 2022 at 9:42 AM Erdogan Taskesen @.***> wrote:

There is one newer update. force install from pypi: pip install -U bnlearn

did you try this:

from matplotlib.pyplot import plot, draw draw()

or fig['ax'].show()

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367774740, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2Z7SOACXM363E7KSDZTWP2G6TANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

natank1 commented 1 year ago

If I run in debug :

print(bn.version) model = bn.import_DAG('sprinkler', CPD=True) df = bn.sampling(model, n=1000, methodtype='bayes') fig = bn.plot(model, params_static={'visible': True}) print ("hi")

and put the toggle on the last print Ican see the graph but it then removes it perhaps it is something about my pycharm (akthough I dont have these issues in regular matplotlib)

On Fri, Dec 30, 2022 at 9:49 AM Natan Katz @.***> wrote:

It opens and instantaneously close. Namely, i see on the bar the sign of a plot appears and disappears before the graph comes

On Fri, Dec 30, 2022 at 9:42 AM Erdogan Taskesen @.***> wrote:

There is one newer update. force install from pypi: pip install -U bnlearn

did you try this:

from matplotlib.pyplot import plot, draw draw()

or fig['ax'].show()

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367774740, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2Z7SOACXM363E7KSDZTWP2G6TANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

erdogant commented 1 year ago

Can you try this: plt.show(block=False)

natank1 commented 1 year ago

plot ? fix.plot? pyplot.plot?

On Fri, Dec 30, 2022 at 9:42 AM Erdogan Taskesen @.***> wrote:

There is one newer update. force install from pypi: pip install -U bnlearn

did you try this:

from matplotlib.pyplot import plot, draw draw()

or fig['ax'].show()

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367774740, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2Z7SOACXM363E7KSDZTWP2G6TANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

erdogant commented 1 year ago

Did you try to change the backend of matplotlb? See this thread on stack.

import matplotlib
matplotlib.use("gtk")

or maybe %matplotlib inline

natank1 commented 1 year ago

ValueError: 'gtk' is not a valid value for backend; supported values are

Different values gave different messages . which version of matplotlib do I have to use? which netwrokx?

On Fri, Dec 30, 2022 at 11:50 AM Erdogan Taskesen @.***> wrote:

Did you try to change the backend of matplotlb? See this https://stackoverflow.com/questions/7534453/matplotlib-does-not-show-my-plot-although-i-call-pyplot-show thread on stack.

import matplotlib matplotlib.use("gtk")

or maybe %matplotlib inline

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367826031, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2ZZP7ZZKHPQH26RWVCDWP2V75ANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

erdogant commented 1 year ago

I use the latest one.

natank1 commented 1 year ago

Upgraded to 3.6.2 , it still doesnt know gtk

On Fri, Dec 30, 2022 at 12:37 PM Erdogan Taskesen @.***> wrote:

I use the latest one.

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367848434, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2Z6TKGJVJTJ2CRX7EV3WP23OLANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

erdogant commented 1 year ago

What do you have?

import matplotlib.rcsetup as rcsetup
print(rcsetup.all_backends)
natank1 commented 1 year ago

['GTK3Agg', 'GTK3Cairo', 'GTK4Agg', 'GTK4Cairo', 'MacOSX', 'nbAgg', 'QtAgg', 'QtCairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']

On Fri, Dec 30, 2022 at 2:26 PM Erdogan Taskesen @.***> wrote:

What do you have?

import matplotlib.rcsetup as rcsetup print(rcsetup.all_backends)

— Reply to this email directly, view it on GitHub https://github.com/erdogant/bnlearn/issues/68#issuecomment-1367893312, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7W2ZYOEJNKTU7M4HQLLK3WP3IGJANCNFSM6AAAAAATL3XJWU . You are receiving this because you authored the thread.Message ID: @.***>

erdogant commented 1 year ago

You can try to set it to: matplotlib.use("GTK3Agg") You can also try this: %matplotib inline

erdogant commented 1 year ago

Otherwise, I recommend creating a new environment. Maybe something did accidentally break.

erdogant commented 1 year ago

There was also a thread about empty figures in matplotlib: https://github.com/matplotlib/matplotlib/issues/12074 Maybe it is also helpful to you.

oliver3 commented 1 year ago

Maybe this will be fixed after https://github.com/erdogant/bnlearn/pull/71

erdogant commented 5 days ago

New version of Bnlearn is released that is related to this one too. See #103