Example #1
0
 def test_import_export(self):
     # write BN 
     xmlbif = XMLBIF(self.bn, "Test Net")
     xmlbif.write("test_out.xmlbif")
     # read BN
     bn2 = XMLBIF.read("test_out.xmlbif")
     for node1 in self.bn.get_nodes():
         
         name_found = False
         cpd_equal = False
         value_range_equal = False
         str_equal = False
         pos_equal = False
         for node2 in bn2.get_nodes():
             # Test node names
             if node1.name == node2.name:
                 name_found = True
                 cpd_equal = node1.get_cpd == node2.get_cpd
                 value_range_equal = node1.get_value_range() == node2.get_value_range()
                 str_equal = str(node1) == str(node2)
                 pos_equal = node1.pos == node2.pos
         self.assertTrue(name_found)
         self.assertTrue(cpd_equal)
         self.assertTrue(value_range_equal)
         self.assertTrue(str_equal)
         self.assertTrue(pos_equal)
     # remove file
     os.remove("test_out.xmlbif")
Example #2
0
cpt_weather0_init = numpy.array([.6, .4])
weather0_init.set_probability_table(cpt_weather0_init, [weather0_init])

cpt_weather0 = numpy.array([.6, .4])
weather0.set_probability_table(cpt_weather0, [weather0])

cpt_weather = numpy.array([[.7, .5],
                           [.3, .5]])
weather.set_probability_table(cpt_weather, [weather, weather0])
cpt_ice_cream_eaten = numpy.array([[.9, .2],
                                   [.1, .8]])
ice_cream_eaten.set_probability_table(cpt_ice_cream_eaten, [ice_cream_eaten, weather])

from primo.utils import XMLBIF
xmlbif = XMLBIF(twoTBN, "Test")
xmlbif.write("test.xmlbif")

dbn.B0 = B0
dbn.twoTBN = twoTBN

N = 1000
T = 2

time_slice = 0
def get_evidence_function():
    global time_slice
    evidence = {}
    if time_slice == 1:
        time_slice = time_slice + 1
        evidence = {weather:"Sun"}