def load_bn_from_file(self, file_name):
        """
        Load a bayesian network to show.
        Initially, the bn can be loaded by itself, but vertex positions must be loaded independently.
        """
        try:
            # load bayesian network
            self.disc_bn = DiscreteBayesianNetworkExt()
            self.disc_bn.load(file_name)

            ### Load Vertex locations
            json_data = dic_from_json_file(file_name)
            # Vertex locations
            if "vertex_loc" in json_data.keys():
                self.dict_to_gpoints(json_data["vertex_loc"])
            else:
                vl = ugraphic.create_vertex_locations(self.disc_bn)
                self.dict_to_gpoints(vl)

        except Exception:
            ugraphic.show_warning(self.window,
                                  "Error loading the Bayesian Network",
                                  Exception)
            return

        self._draw_mode_edit()
Beispiel #2
0
    def set_mode(self, mode):
        """
        Select Edit or Run mode.
        """
        self.mode = mode
        if self.mode == Mode.edit_edge or self.mode == Mode.edit_vertex:
            self.bedit.set_active(True)

            self.toolbar_edit.set_visible(True)
            self.toolbar_evidence.set_visible(False)


            if self.mode == Mode.edit_vertex:
                self.bvertex.set_active(True)

        elif self.mode == Mode.run:
            self.brun.set_active(True)

            # Validate BN
            for v in self.disc_bn.get_vertices():
                # Validate cycles
                try:
                    self.disc_bn.toporder()
                except Exception:
                    ugraphic.show_warning(self.window,
                                          "The Bayesian Network contains cycles.")
                    return

                # Validate that the BN has all the cpts
                ok = self.disc_bn.validate_cprob(v)
                if not ok:
                    ugraphic.show_warning(self.window,
                                          v + " is not valid.",
                                          "please, check the probability table.")
                    self.bedit.set_active(True)
                    return
            # compute marginals
            self.marginals = self.disc_bn.compute_marginals(self.evidences)

            self.toolbar_edit.set_visible(False)
            self.toolbar_evidence.set_visible(True)
            self.bclear_evidence.set_visible_horizontal(True)
            print "aqui pasa"

        self.selected_vertex = None
        self.selected_edge = None
        self.draw_graph()
    def set_mode(self, mode):
        """
        Select Edit or Run mode.
        """
        self.mode = mode
        if self.mode == Mode.edit_edge or self.mode == Mode.edit_vertex:
            self.bedit.set_active(True)

            self.toolbar_edit.set_visible(True)
            self.toolbar_evidence.set_visible(False)

            if self.mode == Mode.edit_vertex:
                self.bvertex.set_active(True)

        elif self.mode == Mode.run:
            self.brun.set_active(True)

            # Validate BN
            for v in self.disc_bn.get_vertices():
                # Validate cycles
                try:
                    self.disc_bn.toporder()
                except Exception:
                    ugraphic.show_warning(
                        self.window, "The Bayesian Network contains cycles.")
                    return

                # Validate that the BN has all the cpts
                ok = self.disc_bn.validate_cprob(v)
                if not ok:
                    ugraphic.show_warning(
                        self.window, v + " is not valid.",
                        "please, check the probability table.")
                    self.bedit.set_active(True)
                    return
            # compute marginals
            self.marginals = self.disc_bn.compute_marginals(self.evidences)

            self.toolbar_edit.set_visible(False)
            self.toolbar_evidence.set_visible(True)
            self.bclear_evidence.set_visible_horizontal(True)
            print "aqui pasa"

        self.selected_vertex = None
        self.selected_edge = None
        self.draw_graph()
Beispiel #4
0
    def load_bn_from_file(self, file_name):
        """
        Load a bayesian network to show.
        Initially, the bn can be loaded by itself, but vertex positions must be loaded independently.
        """
        try:
            # load bayesian network
            self.disc_bn = DiscreteBayesianNetworkExt()
            self.disc_bn.load(file_name)

            ### Load Vertex locations
            json_data = dic_from_json_file(file_name)
            # Vertex locations
            if "vertex_loc" in json_data.keys():
                self.dict_to_gpoints(json_data["vertex_loc"])
            else:
                vl = ugraphic.create_vertex_locations(self.disc_bn)
                self.dict_to_gpoints(vl)

        except Exception:
            ugraphic.show_warning(self.window, "Error loading the Bayesian Network", Exception)
            return

        self._draw_mode_edit()