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

Error in GibbsSampling.sample() #1017

Closed
pmplant opened this issue Jun 21, 2018 · 1 comment
Closed

Error in GibbsSampling.sample() #1017

pmplant opened this issue Jun 21, 2018 · 1 comment

Comments

@pmplant
Copy link

pmplant commented Jun 21, 2018

Subject of the issue

GibbsSampling.sample() is non-functioning, provided example does not work.

Your environment

  • pgmpy version
    Name: pgmpy
    Version: 0.1.6

  • Python version
    Python 3.6.5

  • Operating System
    Linux
    4.15.0-23-generic

Steps to reproduce

Run the example code provided in the definition of GibbsSampling.sample()

from pgmpy.factors.discrete import TabularCPD
from pgmpy.models import BayesianModel
from pgmpy.sampling import GibbsSampling

intel_cpd = TabularCPD('intel', 2, [[0.7], [0.3]])
sat_cpd = TabularCPD('sat', 2, [[0.95, 0.2], [0.05, 0.8]], evidence=['intel'], evidence_card=[2])
student = BayesianModel()
student.add_nodes_from(['intel', 'sat'])
student.add_edge('intel', 'sat')
student.add_cpds(intel_cpd, sat_cpd)
gibbs_chain = GibbsSampling(student)
gibbs_chain.sample(size=3)

Expected behaviour

It should work

Actual behaviour

It don't

Traceback (most recent call last):
  File "gibbexample.py", line 12, in <module>
    gibbs_chain.sample(size=3)
  File "/home/pmp/.local/lib/python3.6/site-packages/pgmpy/sampling/Sampling.py", line 382, in sample
    sampled[0] = np.array([st for var, st in self.state])
ValueError: setting an array element with a sequence.
@ankurankan
Copy link
Member

Fixed.

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