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

I cannot create an instance of BeliefPropagation from a FactorGraph #1732

Open
vicen opened this issue Feb 22, 2024 · 2 comments
Open

I cannot create an instance of BeliefPropagation from a FactorGraph #1732

vicen opened this issue Feb 22, 2024 · 2 comments

Comments

@vicen
Copy link

vicen commented Feb 22, 2024

Subject of the issue

I cannot create an instance of BeliefPropagation from a FactorGraph
AttributeError: module 'networkx' has no attribute 'cliques_containing_node'

The problem appears to be that pgmpy uses an outdated version of networkx in the triangulate method.

Your environment

standard Google colab environment

  • pgmpy version (0.1.24)
  • Python version 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]
  • Operating System on linux

Steps to reproduce

from pgmpy.inference.ExactInference import BeliefPropagation

def create_factor(i, j, J):
  values = [np.exp(J * x_i * x_j) for x_i in [-1, 1] for x_j in [-1, 1]]
  return DiscreteFactor(variables=[i, j],
                        cardinality=[2, 2],
                        values=values,
                        state_names={0:[-1,1],1:[-1,1]})
f = dict()
f[(0,1)] = create_factor(0,1,2)
f[(1,2)] = create_factor(1,2,2)
f[(2,3)] = create_factor(2,3,2)
f[(3,0)] = create_factor(3,0,2)

G = FactorGraph()
G.add_nodes_from([0,1,2,3])
G.add_factors(*f.values())
G.add_edges_from([(v, f) for f in f.values() for v in f.variables])
bp = BeliefPropagation(G)

Expected behaviour

The BeliefPropagation object should be correctly created

Actual behaviour

Tell us what happens instead
AttributeError: module 'networkx' has no attribute 'cliques_containing_node'

@tristantreb
Copy link
Contributor

tristantreb commented Feb 23, 2024

Hi, I've plugged your code snippet on my IDE (VSCode). It worked. What's your networkx version (I've got 3.1)?

Here is my setting:
pgmpy 0.1.19
networkx 3.1
python 3.10.13
macOS Ventura 13.2

@ankurankan
Copy link
Member

@vicen This has been fixed since the last release (0.1.24) but hasn't been released yet. Updating pgmpy to the github dev branch should fix the error:

pip install git+https://github.com/pgmpy/pgmpy.git@dev

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

3 participants