Пример #1
0
    # 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:
        beliefs = dbnet.get_node_beliefs(ai)
        aimean,aivar = ai.node_stats(beliefs,lmd=trunclmd)
        aimeanarray.append(aimean)
        aistdarray.append(np.sqrt(aivar))
Пример #2
0
    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 = []
    for ai in aarray:
        beliefs = dbnet.get_node_beliefs(ai)
        aimean, aivar = ai.node_stats(beliefs, lmd=trunclmd)
        aimeanarray.append(aimean)
        aistdarray.append(np.sqrt(aivar))
Пример #3
0
    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("Straub2010Ex2.dne")

    # no evidence
    print "Prior Belief:"
    beta0 = []
    for e in earray[1:]:
        beliefs = dbnet.get_node_beliefs(e)
        beta0.append(-stats.norm.ppf(beliefs[1]))
    uhbeliefs0 = dbnet.get_node_beliefs(uh)

    # evidence 1: survive up to year 5, h5=80
    print "Evidence 1: survive up to year 5, h5=80"
    for e in earray[1:6]:
        dbnet.enter_finding(e,0)
    h5ev = 80
    h5 = harray[4]
    h5state = np.searchsorted(h5.bins, h5ev)-1
    dbnet.enter_finding(h5, h5state)
    beta1 = []
    for e in earray[1:]:
        beliefs = dbnet.get_node_beliefs(e)
        beta1.append(-stats.norm.ppf(beliefs[1]))
Пример #4
0
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)

netp.enter_finding(visitAsia, 0)
beliefs = netp.get_node_beliefs(tuberculosis)
belief = beliefs[0]
print 'Given an abnormal X-ray and a visit to Asia,'
print '         the probability of tuberculosis is {:f}\n'.format(belief)
Пример #5
0
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)

netp.enter_finding(visitAsia, 0)
beliefs = netp.get_node_beliefs(tuberculosis)
belief = beliefs[0]
print 'Given an abnormal X-ray and a visit to Asia,'
print '         the probability of tuberculosis is {:f}\n'.format(belief)
Пример #6
0
    # add nodes to network
    dbnet.add_nodes([r5, r4, m5, m4, e])
    # 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("Straub2010Ex1.dne")

    # prior belief
    beliefs = dbnet.get_node_beliefs(e)
    print "Prior Belief:"
    for i in xrange(e.nstates()):
        print 'The probability of {} is {:f}'.format(e.statenames[i], beliefs[i])


    # posterior belief 1
    m4measure = 50; m5measure=100
    m4state = np.searchsorted(m4.bins, m4measure)-1
    if m4state<0: m4state=0
    m5state = np.searchsorted(m5.bins, m5measure)-1
    if m5state<0: m5state=0
    dbnet.enter_finding(m4, m4state)
    dbnet.enter_finding(m5, m5state)
    beliefs = dbnet.get_node_beliefs(e)
    print "\nPosterior Belief:"
Пример #7
0
    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("Straub2010Ex2.dne")

    # no evidence
    print "Prior Belief:"
    beta0 = []
    for e in earray[1:]:
        beliefs = dbnet.get_node_beliefs(e)
        beta0.append(-stats.norm.ppf(beliefs[1]))
    uhbeliefs0 = dbnet.get_node_beliefs(uh)

    # evidence 1: survive up to year 5, h5=80
    print "Evidence 1: survive up to year 5, h5=80"
    for e in earray[1:6]:
        dbnet.enter_finding(e, 0)
    h5ev = 80
    h5 = harray[4]
    h5state = np.searchsorted(h5.bins, h5ev) - 1
    dbnet.enter_finding(h5, h5state)
    beta1 = []
    for e in earray[1:]:
        beliefs = dbnet.get_node_beliefs(e)
        beta1.append(-stats.norm.ppf(beliefs[1]))
Пример #8
0
# add nodes to network
dbnet.add_nodes([x1, x2, y])
# add link: must before define 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("BNexample1.dne")

# prior belief
beliefs = dbnet.get_node_beliefs(y)
print "Prior Belief:"
for i in xrange(y.nstates()):
    print 'The probability of {} is {:f}'.format(y.statenames[i], beliefs[i])

x1beliefs = dbnet.get_node_beliefs(x1)
# statesvalues = x1.statenames.astype(float)
x1stats = x1.node_stats(x1beliefs)
print 'The mean of {} is {:f}'.format(x1.name, x1stats[0])
print 'The std of {} is {:f}'.format(x1.name, np.sqrt(x1stats[1]))

x2beliefs = dbnet.get_node_beliefs(x2)
# statesvalues = x2.statenames.astype(float)
x2stats = x2.node_stats(x2beliefs, lmd=lmd)
print 'The mean of {} is {:f}'.format(x2.name, x2stats[0])
print 'The std of {} is {:f}'.format(x2.name, np.sqrt(x2stats[1]))
Пример #9
0
    # add nodes to network
    dbnet.add_nodes([r5, r4, m5, m4, e])
    # 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("Straub2010Ex1.dne")

    # prior belief
    beliefs = dbnet.get_node_beliefs(e)
    print "Prior Belief:"
    for i in xrange(e.nstates()):
        print 'The probability of {} is {:f}'.format(e.statenames[i],
                                                     beliefs[i])

    # posterior belief 1
    m4measure = 50
    m5measure = 100
    m4state = np.searchsorted(m4.bins, m4measure) - 1
    if m4state < 0: m4state = 0
    m5state = np.searchsorted(m5.bins, m5measure) - 1
    if m5state < 0: m5state = 0
    dbnet.enter_finding(m4, m4state)
    dbnet.enter_finding(m5, m5state)
    beliefs = dbnet.get_node_beliefs(e)