question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BeliefPropagation fails with IndexError

See original GitHub issue

Subject of the issue

BeliefPropagation fails with error IndexError: only integers, slices (":"), ellipsis ("..."), numpy.newaxis ("None") and integer or boolean arrays are valid indices.

Your environment

  • pgmpy version: 0.1.15
  • Python version: Python 3.7.12
  • Operating System: Google Colab

Steps to reproduce

import os
from pgmpy.readwrite import BIFReader
def load_network(network_name):
  url = f"https://www.bnlearn.com/bnrepository/{network_name}/{network_name}.bif.gz"
  os.system(f"wget {url} -q")
  fn = f"{network_name}.bif.gz"
  os.system(f"gzip -qd -f {fn} -q")
  fn = f"{network_name}.bif"
  reader = BIFReader(fn)
  os.system(f"rm {fn}")
  model = reader.get_model()
  model.states = reader.get_states()
  
  return model

network_name = 'asia' #@param ["asia", "cancer", "earthquake", "sachs", "survey"]
model = load_network('asia')

from pgmpy.inference import BeliefPropagation
belief_propagation = BeliefPropagation(model)
belief_propagation.query(variables=['lung', 'bronc'],
                                         evidence={'asia': 'yes', 
                                                           'tub': 'no', 
                                                           'xray':'yes'})

This produces IndexError: only integers, slices (":"), ellipsis ("..."), numpy.newaxis ("None") and integer or boolean arrays are valid indices.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ankurankancommented, Oct 2, 2021

Interesting. This throws the error for me only sometimes and works fine other times. I will check why this is happening. Thanks again for reporting this.

1reaction
ankurankancommented, Sep 24, 2021

Also, just FYI an easier way to load models from the bn repository is to use get_example_model:

from pgmpy.utils import get_example_model
asia = get_example_model('asia')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Loopy Belief Propagation: Convergence and Effects ... - People
First, we consider the error resulting from taking the product (3) of a number of incoming approximate messages. ut).
Read more >
BELIEF PROPAGATION
Here we will adopt the artificial intelligence terminology. It is straightforward to prove that belief propagation exactly computes marginals on tree factor ...
Read more >
Time Series Prediction with LSTM Recurrent Neural Networks ...
In this tutorial, we will develop a number of LSTMs for a standard time series prediction problem. The problem and the chosen configuration ......
Read more >
US7698239B2 - Self-evolving distributed system performance ...
As messages take more time to propagate through the network, ... At step 545, if the health index error value falls into a...
Read more >
sitemap-questions-333.xml - Stack Overflow
... /questions/6566826/segment-tree-with-lazy-propagation-time-limit-problem ... .com/questions/7184796/debugging-indexerror-trivial-sum-generation-problem ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found