예제 #1
0
    def EditWeightUp(self,event):
        if event.widget.find_withtag(CURRENT):
            widget = event.widget.find_withtag(CURRENT)[0]
            tags = self.canvas.gettags(widget)
            if "edges" in tags:
                (tail,head) = self.edge[widget]
                
                transition_probabilities=ProbEditorBasics.ProbDict({})
                for head in self.G.OutNeighbors(tail):
                    weight=self.G.GetEdgeWeight(0,tail,head)
                    label = "-> %d" % head
                    transition_probabilities.update({label:weight})
                    
                if transition_probabilities.sum==0:
                    key_list=transition_probabilities.keys()
                    for key in key_list:
                        transition_probabilities[key]=1.0/len(key_list)
                e = ProbEditorBasics.emission_data(transition_probabilities)
                d = ProbEditorDialogs.emission_dialog(self, e,
                                                      "transition probs from state %d" % tail)
                if d.success():
                    # write back normalized probabilities
                    for key in transition_probabilities.keys():
                        head = int(key[3:])
                        self.G.SetEdgeWeight(0, tail, head, transition_probabilities[key]/transition_probabilities.sum)

            else: # We have a vertex
                v = self.FindVertex(event)
                if v != None:
                    self.G.vertices[v].editEmissions(self.master)
예제 #2
0
    def EditWeightUp(self, event):
        if event.widget.find_withtag(CURRENT):
            widget = event.widget.find_withtag(CURRENT)[0]
            tags = self.canvas.gettags(widget)
            if "edges" in tags:
                (tail, head) = self.edge[widget]

                transition_probabilities = ProbEditorBasics.ProbDict({})
                for head in self.G.OutNeighbors(tail):
                    weight = self.G.GetEdgeWeight(0, tail, head)
                    label = "-> %d" % head
                    transition_probabilities.update({label: weight})

                if transition_probabilities.sum == 0:
                    key_list = transition_probabilities.keys()
                    for key in key_list:
                        transition_probabilities[key] = 1.0 / len(key_list)
                e = ProbEditorBasics.emission_data(transition_probabilities)
                d = ProbEditorDialogs.emission_dialog(
                    self, e, "transition probs from state %d" % tail)
                if d.success():
                    # write back normalized probabilities
                    for key in transition_probabilities.keys():
                        head = int(key[3:])
                        self.G.SetEdgeWeight(
                            0, tail, head, transition_probabilities[key] /
                            transition_probabilities.sum)

            else:  # We have a vertex
                v = self.FindVertex(event)
                if v != None:
                    self.G.vertices[v].editEmissions(self.master)
예제 #3
0
    def EditPrior(self):
        if self.G.Order() == 0:
            return

        emission_probabilities = ProbEditorBasics.ProbDict({})
        for state in self.G.vertices.values():
            label  = str(state.id)
            weight = state.initial
            emission_probabilities.update({label:weight})

        emission_probabilities.renorm_to(1.0)

        e = ProbEditorBasics.emission_data(emission_probabilities)
        d = ProbEditorDialogs.emission_dialog(self, e, "initial probabilities")

        if d.success():
            # write back normalized probabilities
            emission_probabilities.renorm_to(1.0)
            for key in emission_probabilities.keys():
                state = self.G.vertices[int(key)]
                state.initial = typed_assign(state.initial, emission_probabilities[key])
예제 #4
0
    def EditPrior(self):
        if self.G.Order() == 0:
            return

        emission_probabilities = ProbEditorBasics.ProbDict({})
        for state in self.G.vertices.values():
            label  = str(state.id)
            weight = state.initial
            emission_probabilities.update({label:weight})

        emission_probabilities.renorm_to(1.0)

        e = ProbEditorBasics.emission_data(emission_probabilities)
        d = ProbEditorDialogs.emission_dialog(self, e, "initial probabilities")

        if d.success():
            # write back normalized probabilities
            emission_probabilities.renorm_to(1.0)
            for key in emission_probabilities.keys():
                state = self.G.vertices[int(key)]
                state.initial = typed_assign(state.initial, emission_probabilities[key])