Ejemplo n.º 1
0
                float(i) / len(labels) * 100, np.array_str(probs, precision=3))
            probs = probs / np.sum(probs) * pod
            probs[0] = probs[0] + (1. - pod)
            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 + 1e-10) - 1
        aitruncrv = ai.truncate_rv(aistate, lmd=trunclmd)
        lt = np.sum(
Ejemplo n.º 2
0
cancer.assign_cpt(cancerCpt, statenames=['present', 'absent'])
tbOrCaCpt = np.array([[1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [0.0, 1.0]])
tbOrCa.assign_cpt(tbOrCaCpt, statenames=['true', 'false'])
xRayCpt = np.array([[0.98, 0.02], [0.05, 0.95]])
xRay.assign_cpt(xRayCpt, statenames=['abnormal', 'normal'])

# 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)
Ejemplo n.º 3
0
            probs = rv_am.cdf(node_mi.bins[1:])-rv_am.cdf(node_mi.bins[:-1])
            print 'labels: {}, progress: {}%, prob: {}'.format(label,
                float(i)/len(labels)*100, np.array_str(probs,precision=3))
            probs = probs/np.sum(probs)*pod
            probs[0] = probs[0]+(1.-pod)
            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)
Ejemplo n.º 4
0
cancer.assign_cpt(cancerCpt, statenames=['present','absent'])
tbOrCaCpt = np.array([[1.0, 0.0], [1.0, 0.0], [1.0, 0.0], [0.0, 1.0]])
tbOrCa.assign_cpt(tbOrCaCpt, statenames=['true','false'])
xRayCpt = np.array([[0.98, 0.02], [0.05, 0.95]])
xRay.assign_cpt(xRayCpt, statenames=['abnormal','normal'])

# 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)