<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Distribution Test Tables
This example demonstrates how to create some conditional probability tables and a bayesian network.
Step1:  First let's define some conditional probability tables.
Step2:  Then let's convert them into distribution objects.
Step3:  Next we can convert these distributions into states.
Step4:  Now that we have our states created, we can finally start making our bayesian network.
Step5:  Then we define the edges.
Step6:  We finish by baking the network to finalize its structure.
Step7:  Now we can check on the structure of our bayesian network.
<ASSISTANT_TASK:>
Python Code:
from pomegranate import *
import math
Explanation: Distribution Test Tables
This example demonstrates how to create some conditional probability tables and a bayesian network.
End of explanation
c_table = [[0, 0, 0, 0.6],
           [0, 0, 1, 0.4],
           [0, 1, 0, 0.7],
           [0, 1, 1, 0.3],
           [1, 0, 0, 0.2],
           [1, 0, 1, 0.8],
           [1, 1, 0, 0.9],
           [1, 1, 1, 0.1]]
d_table = [[ 0, 0, 0.5 ],
           [ 0, 1, 0.5 ],
           [ 1, 0, 0.3 ],
           [ 1, 1, 0.7 ]]
f_table = [[ 0, 0, 0, 0.8 ],
           [ 0, 0, 1, 0.2 ],
           [ 0, 1, 0, 0.3 ],
           [ 0, 1, 1, 0.7 ],
           [ 1, 0, 0, 0.6 ],
           [ 1, 0, 1, 0.4 ],
           [ 1, 1, 0, 0.9 ],
           [ 1, 1, 1, 0.1 ]]
e_table = [[ 0, 0, 0.7 ],
           [ 0, 1, 0.3 ],
           [ 1, 0, 0.2 ],
           [ 1, 1, 0.8 ]]
g_table = [[ 0, 0, 0, 0.34 ],
           [ 0, 0, 1, 0.66 ],
           [ 0, 1, 0, 0.83 ],
           [ 0, 1, 1, 0.17 ],
           [ 1, 0, 0, 0.77 ],
           [ 1, 0, 1, 0.23 ],
           [ 1, 1, 0, 0.12 ],
           [ 1, 1, 1, 0.88 ]]
Explanation: First let's define some conditional probability tables.
End of explanation
a = DiscreteDistribution({ 0: 0.5, 1: 0.5 })
b = DiscreteDistribution({ 0: 0.7, 1: 0.3 })
e = ConditionalProbabilityTable( e_table, [b] )
c = ConditionalProbabilityTable( c_table, [a,b] )
d = ConditionalProbabilityTable( d_table, [c] )
f = ConditionalProbabilityTable( f_table, [c,e] )
g = ConditionalProbabilityTable( g_table, [c,e] )
Explanation: Then let's convert them into distribution objects.
End of explanation
a_s = State( a, "a" )
b_s = State( b, "b" )
c_s = State( c, "c" )
d_s = State( d, "d" )
e_s = State( e, "e" )
f_s = State( f, "f" )
g_s = State( g, "g" )
Explanation: Next we can convert these distributions into states.
End of explanation
model = BayesianNetwork( "derp" )
model.add_nodes( a_s, b_s, c_s, d_s, e_s, f_s, g_s )
Explanation: Now that we have our states created, we can finally start making our bayesian network.
End of explanation
model.add_edge( a_s, c_s )
model.add_edge( b_s, c_s )
model.add_edge( c_s, d_s )
model.add_edge( c_s, f_s )
model.add_edge( b_s, e_s )
model.add_edge( e_s, f_s )
model.add_edge( c_s, g_s )
model.add_edge( e_s, g_s )
Explanation: Then we define the edges.
End of explanation
model.bake()
Explanation: We finish by baking the network to finalize its structure.
End of explanation
print("\n".join( "{:10.10} : {}".format( state.name, belief.parameters[0] ) for state, belief in zip( model.states, model.predict_proba({}, max_iterations=100) ) ))
Explanation: Now we can check on the structure of our bayesian network.
End of explanation
<END_TASK>