statenames=node_mi.statenames) # create new network dbnet = Network("Soliman2014DBN") # add nodes to network dbnet.add_nodes([node_m, node_k] + aarray + marray) # add link: must be prior to defining nodes dbnet.add_link() # define nodes dbnet.define_nodes() # compile the net dbnet.compile_net() # enable autoupdate dbnet.set_autoupdate() # save the network dbnet.save_net("Soliman2014DBN.dne") # inferences pfarray = [] for ai in aarray: beliefs = dbnet.get_node_beliefs(ai) aistate = np.searchsorted(ai.bins, acrit + 1e-10) - 1 aitruncrv = ai.truncate_rv(aistate, lmd=trunclmd) lt = np.sum( beliefs[:aistate]) + beliefs[aistate] * aitruncrv.cdf(acrit) pfarray.append(1 - lt) aimeanarray = [] aistdarray = []
# add node netp.add_nodes([visitAsia]) netp.add_nodes([smoking]) netp.add_nodes([tuberculosis]) netp.add_nodes([cancer]) netp.add_nodes([tbOrCa, xRay]) # add link: must before define nodes netp.add_link() # define nodes netp.define_nodes() # compile the net netp.compile_net() # enable auto updating netp.set_autoupdate() # save the network netp.save_net('ChestClinicNew.dne') # prior belief beliefs = netp.get_node_beliefs(tuberculosis) belief = beliefs[0] print 'The probability of tuberculosis is {:f}\n'.format(belief) # posterior belief netp.enter_finding(xRay, 0) beliefs = netp.get_node_beliefs(tuberculosis) belief = beliefs[0] print 'Given an abnormal X-ray,' print ' the probability of tuberculosis is {:f}\n'.format(belief)
node_mi.assign_cpt(probs,label=np.asarray(label),statenames=node_mi.statenames) # create new network dbnet = Network("Soliman2014DBN") # add nodes to network dbnet.add_nodes([node_m, node_k]+aarray+marray) # add link: must be prior to defining nodes dbnet.add_link() # define nodes dbnet.define_nodes() # compile the net dbnet.compile_net() # enable autoupdate dbnet.set_autoupdate() # save the network dbnet.save_net("Soliman2014DBN.dne") # inferences pfarray = [] for ai in aarray: beliefs = dbnet.get_node_beliefs(ai) aistate = np.searchsorted(ai.bins, acrit)-1 aitruncrv = ai.truncate_rv(aistate,lmd=trunclmd) lt = np.sum(beliefs[:aistate])+beliefs[aistate]*aitruncrv.cdf(acrit) pfarray.append(1-lt) aimeanarray = [] aistdarray = [] for ai in aarray: