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

induced_graph example in the documentation of Variable Elimination fails #1724

Open
mroavi opened this issue Jan 31, 2024 · 3 comments
Open

Comments

@mroavi
Copy link

mroavi commented Jan 31, 2024

Subject of the issue

induced_graph example in https://pgmpy.org/exact_infer/ve.html throws the following error:

AttributeError: module 'networkx' has no attribute 'graph_clique_number'

Your environment

  • pgmpy version: 0.1.24
  • Python version: Python 3.11.6
  • Operating System: Arch Linux x86_64

Steps to reproduce

Run the induced_graph example in https://pgmpy.org/exact_infer/ve.html:

import numpy as np
import pandas as pd
from pgmpy.models import BayesianNetwork
from pgmpy.inference import VariableElimination
values = pd.DataFrame(np.random.randint(low=0, high=2, size=(1000, 5)),
                      columns=['A', 'B', 'C', 'D', 'E'])
model = BayesianNetwork([('A', 'B'), ('C', 'B'), ('C', 'D'), ('B', 'E')])
model.fit(values)
inference = VariableElimination(model)
inference.induced_width(['C', 'D', 'A', 'B', 'E'])

Expected behaviour

Executing the last line should result in the induced width.

Actual behaviour

The following error is thrown:

AttributeError: module 'networkx' has no attribute 'graph_clique_number'
@ankurankan
Copy link
Member

@mroavi This doesn't throw any errors for me:

In [2]: import numpy as np
   ...: import pandas as pd
   ...: from pgmpy.models import BayesianNetwork
   ...: from pgmpy.inference import VariableElimination
   ...: values = pd.DataFrame(np.random.randint(low=0, high=2, size=(1000, 5)),
   ...:                       columns=['A', 'B', 'C', 'D', 'E'])
   ...: model = BayesianNetwork([('A', 'B'), ('C', 'B'), ('C', 'D'), ('B', 'E')])
   ...: model.fit(values)
   ...: inference = VariableElimination(model)
   ...: inference.induced_width(['C', 'D', 'A', 'B', 'E'])
Out[2]: 3

Could you please check which version of networkx you are using? I am using the latest 3.2.1

@mroavi
Copy link
Author

mroavi commented Feb 1, 2024

I also have networkx 3.2.1. Here is the rest of my installed dependencies:

pip list
Package Version
asttokens 2.4.1
decorator 5.1.1
executing 2.0.1
filelock 3.13.1
fsspec 2023.12.2
ipython 8.21.0
jedi 0.19.1
Jinja2 3.1.3
joblib 1.3.2
MarkupSafe 2.1.4
matplotlib-inline 0.1.6
mpmath 1.3.0
networkx 3.2.1
numpy 1.26.3
nvidia-cublas-cu12 12.1.3.1
nvidia-cuda-cupti-cu12 12.1.105
nvidia-cuda-nvrtc-cu12 12.1.105
nvidia-cuda-runtime-cu12 12.1.105
nvidia-cudnn-cu12 8.9.2.26
nvidia-cufft-cu12 11.0.2.54
nvidia-curand-cu12 10.3.2.106
nvidia-cusolver-cu12 11.4.5.107
nvidia-cusparse-cu12 12.1.0.106
nvidia-nccl-cu12 2.19.3
nvidia-nvjitlink-cu12 12.3.101
nvidia-nvtx-cu12 12.1.105
opt-einsum 3.3.0
packaging 23.2
pandas 2.2.0
parso 0.8.3
patsy 0.5.6
pexpect 4.9.0
pgmpy 0.1.24
pip 23.3.2
prompt-toolkit 3.0.43
ptyprocess 0.7.0
pure-eval 0.2.2
Pygments 2.17.2
pyparsing 3.1.1
python-dateutil 2.8.2
pytz 2023.4
scikit-learn 1.4.0
scipy 1.12.0
setuptools 65.5.0
six 1.16.0
stack-data 0.6.3
statsmodels 0.14.1
sympy 1.12
threadpoolctl 3.2.0
torch 2.2.0
tqdm 4.66.1
traitlets 5.14.1
triton 2.2.0
typing_extensions 4.9.0
tzdata 2023.4
wcwidth 0.2.13

These are the steps I used to create my environment:

python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install pgmpy ipython

@ankurankan
Copy link
Member

@mroavi Interesting. I can't think of any other reason this could be happening. Could you maybe check the networkx version in your python prompt just to make sure that the it is using the correct environment?

import networkx
networkx.__version__

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