import numpy from primo.networks import BayesianNetwork from primo.nodes import ContinuousNodeFactory cnf = ContinuousNodeFactory() age = cnf.createGaussNode("Plant_age") #parameterization age_b0=numpy.array([4]) age_variance=numpy.array([[2]]) age.set_density_parameters(age_b0,age_variance) for i in range(8): print age.sample()
from primo.densities import GaussParameters from primo.densities import NDGauss from primo.inference.mcmc import MCMC from primo.evidence import EvidenceEqual as EvEqual from primo.evidence import EvidenceInterval as EvInterval import numpy # Construct some simple BayesianNetwork. In this example it models # the linear relationship between the age of a plant and the height that # it has grown up to (+noise) bn = BayesianNetwork() cnf = ContinuousNodeFactory() # create the nodes age = cnf.createExponentialNode("Age") sun = cnf.createBetaNode("Sun") ground = cnf.createGaussNode("Ground") growth = cnf.createGaussNode("Growth") height = cnf.createBetaNode("Height") diameter = cnf.createExponentialNode("Diameter") children = cnf.createExponentialNode("Children") # add the nodes to the network bn.add_node(age) bn.add_node(sun) bn.add_node(ground) bn.add_node(growth)
#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 age_parameters=ExponentialParameters(0.0,{})
from primo.densities import BetaParameters from primo.densities import GaussParameters from primo.densities import NDGauss from primo.inference.mcmc import MCMC from primo.evidence import EvidenceEqual as EvEqual from primo.evidence import EvidenceInterval as EvInterval import numpy #Construct some simple BayesianNetwork. In this example it models #the linear relationship between the age of a plant and the height that #it has grown up to (+noise) bn = BayesianNetwork() cnf = ContinuousNodeFactory() #create the nodes age = cnf.createExponentialNode("Age") sun = cnf.createBetaNode("Sun") ground = cnf.createGaussNode("Ground") growth = cnf.createGaussNode("Growth") height = cnf.createBetaNode("Height") diameter = cnf.createExponentialNode("Diameter") children = cnf.createExponentialNode("Children") #add the nodes to the network bn.add_node(age) bn.add_node(sun) bn.add_node(ground) bn.add_node(growth)