def setUp(self): # Create BayesNet self.bn = BayesianNetwork() # Create Nodes weather0 = DiscreteNode("Weather0", ["Sun", "Rain"]) weather = DiscreteNode("Weather", ["Sun", "Rain"]) ice_cream_eaten = DiscreteNode("Ice Cream Eaten", [True, False]) # Add nodes self.bn.add_node(weather0) self.bn.add_node(weather) self.bn.add_node(ice_cream_eaten) # Add edges self.bn.add_edge(weather, ice_cream_eaten) self.bn.add_edge(weather0, weather) # Set probabilities cpt_weather0 = numpy.array([.6, .4]) weather0.set_probability_table(cpt_weather0, [weather0]) cpt_weather = numpy.array([[.7, .5], [.3, .5]]) weather.set_probability_table(cpt_weather, [weather0, weather]) ice_cream_eaten.set_probability(.9, [(ice_cream_eaten, True), (weather, "Sun")]) ice_cream_eaten.set_probability(.1, [(ice_cream_eaten, False), (weather, "Sun")]) ice_cream_eaten.set_probability(.2, [(ice_cream_eaten, True), (weather, "Rain")]) ice_cream_eaten.set_probability(.8, [(ice_cream_eaten, False), (weather, "Rain")])
#About this example: #This example shows how approximate inference can be used query a purely continuous #bayesian network. At first that network is being constructed and afterwards it #is passed to an MCMC object that is used to answer several kinds of questions: #-Prior marginal #-Posterior marginal #-Probability of evidence #-Maximum a-posteriori hypothesis #Construct some simple BayesianNetwork. #topology bn = BayesianNetwork() cnf=ContinuousNodeFactory() age = cnf.createExponentialNode("Plant_age") height = cnf.createGaussNode("Plant_height") diameter = cnf.createBetaNode("Plant_diameter") bn.add_node(age) bn.add_node(height) bn.add_node(diameter) bn.add_edge(age,height) bn.add_edge(age,diameter) #parameterization #Semantics: Many young plants and the higher the age the lower the probabilty #->lambda=2.0
def setUp(self): self.bn = BayesianNetwork()