예제 #1
0
    def main():
        bnet = QuWetGrass.build_bnet()
        brute_eng = EnumerationEngine(bnet, is_quantum=True)
        # introduce some evidence
        bnet.get_node_named("WetGrass").active_states = [1]
        node_list = brute_eng.bnet_ord_nodes
        brute_pot_list = brute_eng.get_unipot_list(node_list)

        bnet = QuWetGrass.build_bnet()
        monte_eng = MCMC_Engine(bnet, is_quantum=True)
        # introduce some evidence
        bnet.get_node_named("WetGrass").active_states = [1]
        num_cycles = 1000
        warmup = 200
        node_list = monte_eng.bnet_ord_nodes
        monte_pot_list = monte_eng.get_unipot_list(node_list, num_cycles,
                                                   warmup)

        bnet = QuWetGrass.build_bnet()
        jtree_eng = JoinTreeEngine(bnet, is_quantum=True)
        # introduce some evidence
        bnet.get_node_named("WetGrass").active_states = [1]
        node_list = jtree_eng.bnet_ord_nodes
        jtree_pot_list = jtree_eng.get_unipot_list(node_list)

        for k in range(len(node_list)):
            print(node_list[k].name)
            print("brute engine:", brute_pot_list[k])
            print("monte engine:", monte_pot_list[k])
            print("jtree engine:", jtree_pot_list[k])
            print("\n")
예제 #2
0
    def main():
        bnet = WetGrass.build_bnet()
        brute_eng = EnumerationEngine(bnet)
        # introduce some evidence
        bnet.get_node_named("WetGrass").active_states = [1]
        node_list = brute_eng.bnet_ord_nodes
        brute_pot_list = brute_eng.get_unipot_list(node_list)

        bnet = WetGrass.build_bnet()
        monte_eng = MCMC_Engine(bnet)
        # introduce some evidence
        bnet.get_node_named("WetGrass").active_states = [1]
        num_cycles = 1000
        warmup = 200
        node_list = monte_eng.bnet_ord_nodes
        monte_pot_list = monte_eng.get_unipot_list(node_list, num_cycles,
                                                   warmup)

        bnet = WetGrass.build_bnet()
        jtree_eng = JoinTreeEngine(bnet)
        # introduce some evidence
        bnet.get_node_named("WetGrass").active_states = [1]
        node_list = jtree_eng.bnet_ord_nodes
        jtree_pot_list = jtree_eng.get_unipot_list(node_list)

        for k in range(len(node_list)):
            print(node_list[k].name)
            print("brute engine:", brute_pot_list[k])
            print("monte engine:", monte_pot_list[k])
            print("jtree engine:", jtree_pot_list[k])
            print("\n")

        bnet.write_bif('../examples_cbnets/WetGrass.bif', False)
        bnet.write_dot('../examples_cbnets/WetGrass.dot')
예제 #3
0
        ra.potential.pot_arr[0, :] = [.4, .6]

        sp.potential.pot_arr[1, :] = [.7, .3]
        sp.potential.pot_arr[0, :] = [.2, .8]

        we.potential.pot_arr[1, 1, :] = [.01, .99]
        we.potential.pot_arr[1, 0, :] = [.01, .99]
        we.potential.pot_arr[0, 1, :] = [.01, .99]
        we.potential.pot_arr[0, 0, :] = [.99, .01]

        return BayesNet(nodes)


if __name__ == "__main__":
    bnet = WetGrass.build_bnet()
    brute_eng = EnumerationEngine(bnet)
    # introduce some evidence
    bnet.get_node_named("WetGrass").active_states = [1]
    node_list = brute_eng.bnet_ord_nodes
    brute_pot_list = brute_eng.get_unipot_list(node_list)

    bnet = WetGrass.build_bnet()
    monte_eng = MCMC_Engine(bnet)
    # introduce some evidence
    bnet.get_node_named("WetGrass").active_states = [1]
    num_cycles = 1000
    warmup = 200
    node_list = monte_eng.bnet_ord_nodes
    monte_pot_list = monte_eng.get_unipot_list(node_list, num_cycles, warmup)

    bnet = WetGrass.build_bnet()
예제 #4
0
        return BayesNet(nodes)


if __name__ == "__main__":
    bnet = WetGrass.build_bnet()

    # introduce some evidence
    bnet.get_node_named("WetGrass").active_states = [1]

    id_nums = sorted([node.id_num for node in bnet.nodes])
    node_list = [bnet.get_node_with_id_num(k) for k in id_nums]

    # this is simpler but erratic
    # node_list = list(bnet.nodes)

    brute_eng = EnumerationEngine(bnet)
    brute_pot_list = brute_eng.get_unipot_list(node_list)

    # print("bnet pots after brute")
    # # check that bnet pots are not modified by engine
    # for node in node_list:
    #     print(node.name)
    #     print(node.potential, "\n")

    monte_eng = MCMC_Engine(bnet)
    num_cycles = 1000
    warmup = 200
    monte_pot_list = monte_eng.get_unipot_list(
            node_list, num_cycles, warmup)

    # print("bnet pots after monte")
예제 #5
0
        return BayesNet(nodes)


if __name__ == "__main__":
    bnet = QuWetGrass.build_bnet()

    # introduce some evidence
    bnet.get_node_named("WetGrass").active_states = [1]

    id_nums = sorted([node.id_num for node in bnet.nodes])
    node_list = [bnet.get_node_with_id_num(k) for k in id_nums]

    # this is simpler but erratic
    # node_list = list(bnet.nodes)

    brute_eng = EnumerationEngine(bnet, is_quantum=True)
    brute_pot_list = brute_eng.get_unipot_list(node_list)

    # print("bnet pots after brute")
    # # check that bnet pots are not modified by engine
    # for node in node_list:
    #     print(node.name)
    #     print(node.potential, "\n")

    monte_eng = MCMC_Engine(bnet, is_quantum=True)
    num_cycles = 1000
    warmup = 200
    monte_pot_list = monte_eng.get_unipot_list(node_list, num_cycles, warmup)

    # print("bnet pots after monte")
    # # check that bnet pots are not modified by engine