Example #1
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))
Example #2
0
    # 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:"
    for i in xrange(e.nstates()):
        print 'Given m4={:.1f} and m5={:.1f}, the probability of {} is {:f}'.format(m4measure, m5measure, e.statenames[i], beliefs[i])
    r4beliefs = dbnet.get_node_beliefs(r4)
    r5beliefs = dbnet.get_node_beliefs(r5)
    r4rvs = [r4.truncate_rv(pstate) for pstate in np.arange(r4.nstates())]
    r5rvs = [r5.truncate_rv(pstate) for pstate in np.arange(r5.nstates())]
    np.savez('bndiscrete10.npz', r4beliefs=r4beliefs, r5beliefs=r5beliefs,
            r4bins=r4.bins, r5bins=r5.bins, r4rvs=r4rvs, r5rvs=r5rvs)

    # posterior belief 2
    dbnet.retract_nodefindings(m4)
    #dbnet.retract_netfindings()
    m4measure = 150; m5measure=100
    m4state = np.searchsorted(m4.bins, m4measure)-1
    if m4state<0: m4state=0
    dbnet.enter_finding(m4, m4state)
    #m5state = np.searchsorted(m5.bins, m5measure)-1
    #if m5state<0: m5state=0
    #dbnet.enter_finding(m5, m5state)
    beliefs = dbnet.get_node_beliefs(e)
Example #3
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))
Example #4
0
    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:"
    for i in xrange(e.nstates()):
        print 'Given m4={:.1f} and m5={:.1f}, the probability of {} is {:f}'.format(
            m4measure, m5measure, e.statenames[i], beliefs[i])
    r4beliefs = dbnet.get_node_beliefs(r4)
    r5beliefs = dbnet.get_node_beliefs(r5)
    r4rvs = [r4.truncate_rv(pstate) for pstate in np.arange(r4.nstates())]
    r5rvs = [r5.truncate_rv(pstate) for pstate in np.arange(r5.nstates())]
    np.savez('bndiscrete10.npz',
             r4beliefs=r4beliefs,
             r5beliefs=r5beliefs,
             r4bins=r4.bins,
             r5bins=r5.bins,
             r4rvs=r4rvs,
             r5rvs=r5rvs)

    # posterior belief 2
    dbnet.retract_nodefindings(m4)
    #dbnet.retract_netfindings()
    m4measure = 150
    m5measure = 100
    m4state = np.searchsorted(m4.bins, m4measure) - 1