def add_bn_tab(self, title): tab_bn = BoxDiscreteBN(self.window) self.tabber.append_page(tab_bn, Gtk.Label(title)) self.goto_last_tab() # register the opened file return tab_bn
from gi.repository import Gtk from lib_sallybn.disc_bayes_net.BoxDiscreteBN import BoxDiscreteBN import os # working directory os.chdir("../") # Load file file = "examples/simplebn.sly" # file = "examples/disc_bn_recommendation_letter.txt" # Create window window = Gtk.Window() window.set_size_request(800, 600) ## Box BM box = BoxDiscreteBN(window) box.load_bn_from_file(file) window.add(box) window.show_all() window.connect("delete-event", Gtk.main_quit) Gtk.main()
# CPTs cprob_b = { "['true1', 'true']": [.3, .7], "['true1', 'false']": [.9, .1], "['false1', 'true']": [.05, .95], "['false1', 'false']": [.5, .5] } cprob_a = [.3, .7] cprob_c = [.2, .8] disc_bn.set_cprob("A", cprob_a) disc_bn.set_cprob("B", cprob_b) disc_bn.set_cprob("C", cprob_c) ###### SHOW box = BoxDiscreteBN(window, disc_bn=disc_bn) box.on_organize(None) window.add(box) new_vertices = [] def opa(): # time.sleep(2) new_vertex = "D " + str(random.random()) disc_bn.add_vertex(new_vertex) new_vertices.append(new_vertex) ## edges if len(new_vertices) > 2: de = random.sample(new_vertices, 2) disc_bn.add_edge(de)
eh1 = Observation(10.0, 20.0, "Human_Sensor", ["true", "false"], "true") eh2 = Observation(5, 19, "Human_Sensor", ["true", "false"], "false") eh3 = Observation(15, 18, "Human_Sensor", ["true", "false"], "true") eh4 = Observation(16, 17, "Human_Sensor", ["true", "false"], "true") eh5 = Observation(-124.4577, 108.0135, "Human_Sensor", ["true", "false"], "true") # bn, bn_evidences = engine.infer_bn([eh2, eh3, eh4, eh1, eh5, ]) bn, bn_evidences = engine.infer_bn([eh1, eh2, eh3, eh4]) # shape_writer.write(bn, engine.vertex_locations, bn_evidences) # geojson.write(bn, engine.vertex_locations, bn_evidences, output_folder='../output_shapes') ###### SHOW # # Create window window = Gtk.Window() window.set_size_request(800, 600) box = BoxDiscreteBN(window, disc_bn=bn) box.evidences = bn_evidences box.organize_graph(random=False) box.set_mode(Mode.run) window.add(box) window.show_all() window.connect("delete-event", Gtk.main_quit) Gtk.main()