Pomegranate: network.bake() error: AttributeError: 'list' object has no attribute 'distribution'

Created on 21 Sep 2016  路  3Comments  路  Source: jmschrei/pomegranate

Hello,

I got the error written in the subject when I try to execute the tutorial of Bayesian networks.
The complete error message is the following:

File "pomegranate/BayesianNetwork.pyx", line 163, in pomegranate.BayesianNetwork.BayesianNetwork.bake (pomegranate\BayesianNetwork.c:3710)
AttributeError: 'list' object has no attribute 'distribution'

The code I'm testing is the same as for the tutorial:

from pomegranate import *

asia = DiscreteDistribution( { 'True' : 0.5, 'False' : 0.5 } )

tuberculosis = ConditionalProbabilityTable(
[[ 'True', 'True', 0.2 ],
[ 'True', 'False', 0.8 ],
[ 'False', 'True', 0.01 ],
[ 'False', 'False', 0.99 ]], [asia])

smoking = DiscreteDistribution( { 'True' : 0.5, 'False' : 0.5 } )

lung = ConditionalProbabilityTable(
[[ 'True', 'True', 0.75 ],
[ 'True', 'False', 0.25 ],
[ 'False', 'True', 0.02 ],
[ 'False', 'False', 0.98 ]], [smoking] )

bronchitis = ConditionalProbabilityTable(
[[ 'True', 'True', 0.92 ],
[ 'True', 'False', 0.08 ],
[ 'False', 'True', 0.03 ],
[ 'False', 'False', 0.97 ]], [smoking] )

tuberculosis_or_cancer = ConditionalProbabilityTable(
[[ 'True', 'True', 'True', 1.0 ],
[ 'True', 'True', 'False', 0.0 ],
[ 'True', 'False', 'True', 1.0 ],
[ 'True', 'False', 'False', 0.0 ],
[ 'False', 'True', 'True', 1.0 ],
[ 'False', 'True', 'False', 0.0 ],
[ 'False', 'False', 'True', 0.0 ],
[ 'False', 'False', 'False', 1.0 ]], [tuberculosis, lung] )

xray = ConditionalProbabilityTable(
[[ 'True', 'True', 0.885 ],
[ 'True', 'False', 0.115 ],
[ 'False', 'True', 0.04 ],
[ 'False', 'False', 0.96 ]], [tuberculosis_or_cancer] )

dyspnea = ConditionalProbabilityTable(
[[ 'True', 'True', 'True', 0.96 ],
[ 'True', 'True', 'False', 0.04 ],
[ 'True', 'False', 'True', 0.89 ],
[ 'True', 'False', 'False', 0.11 ],
[ 'False', 'True', 'True', 0.96 ],
[ 'False', 'True', 'False', 0.04 ],
[ 'False', 'False', 'True', 0.89 ],
[ 'False', 'False', 'False', 0.11 ]], [tuberculosis_or_cancer, bronchitis])

s0 = State(asia, name="asia")
s1 = State(tuberculosis, name="tuberculosis")
s2 = State(smoking, name="smoker")

network = BayesianNetwork( "asia" )
network.add_nodes([s0,s1,s2])

network.add_edge(s0,s1)
network.add_edge(s1,s2)

network.bake()

Thanks in advance.
William

Most helpful comment

Good catch. Instead of network.add_nodes([s0,s1,s2]), make it network.add_nodes(s0, s1, s2). I recently changed that so it's no longer a list.

All 3 comments

I'm using Python 2.7 on a windows machine

Good catch. Instead of network.add_nodes([s0,s1,s2]), make it network.add_nodes(s0, s1, s2). I recently changed that so it's no longer a list.

Thanks, it worked.

Was this page helpful?
0 / 5 - 0 ratings