示例#1
0
 def graph_data_handler(self, channel, data):
     msg = map_data.decode(data)
     for cell in msg.vertex_:
         idx = cell.idx_
         self.vertex_[idx].ig_ = cell.ig_
         self.vertex_[idx].p_ = cell.p_
         if self.vertex_[idx].p_ == 0.0:
             self.vertex_[idx].occupancy_ = "FREE"
         elif self.vertex_[idx].p_ == 1.0:
             self.vertex_[idx].occupancy_ = "OCCUPIED"
 def graph_data_handler(self, channel, data):
     msg = map_data.decode(data)
     for cell in msg.vertex_:
         idx = cell.idx_
         self.vertex_[idx].ig_ = cell.ig_
         self.vertex_[idx].p_ = cell.p_
         if self.vertex_[idx].p_ == 0.0:
             self.vertex_[idx].occupancy_ = "FREE"
         elif self.vertex_[idx].p_ == 1.0:
             self.vertex_[idx].occupancy_ = "OCCUPIED"
     self.graph_vis("Origin")
     self.graph_vis()
     unknown_graph = Grid(False)
     unknown_graph.gp(self)
示例#3
0
    def graph_data_handler(self, channel, data):
        msg = map_data.decode(data)
        for cell in msg.vertex_:
            idx = cell.idx_
            self.vertex_[idx].ig_ = cell.ig_
            self.vertex_[idx].p_ = cell.p_
            if self.vertex_[idx].p_ == 0.0:
                self.vertex_[idx].occupancy_ = "FREE"
            elif self.vertex_[idx].p_ == 1.0:
                self.vertex_[idx].occupancy_ = "OCCUPIED"

        self.L2_error_total_ = 0.0
        self.max_ig_ = 0.0
        self.max_ig_vertex_ = []
        self.bayesian_opt_ = 0.0
        self.bayesian_relative_err_ = 0.0
    def graph_data_handler(self, channel, data):
        msg = map_data.decode(data)
        for cell in msg.vertex_:
            idx = cell.idx_
            if cell.isROIs_:
                self.ROIs_.append(idx)
            if cell.isSamples_:
                self.training_x_.append(idx)
                self.training_y_.append(cell.ig_)
                self.ig_ = cell.ig_
            else:
                self.ig_ = math.inf
            self.vertex_[idx].p_ = cell.p_
            if self.vertex_[idx].p_ == 0.0:
                self.vertex_[idx].occupancy_ = "FREE"
            elif self.vertex_[idx].p_ == 1.0:
                self.vertex_[idx].occupancy_ = "OCCUPIED"

        self.L2_error_total_ = 0.0
        self.max_ig_ = 0.0
        self.max_ig_vertex_ = []
        self.bayesian_opt_ = 0.0
        self.bayesian_relative_err_ = 0.0

        print("Collected all data from LCM for bayesian optimization.")
        for idx in self.vertex_.keys():
            vert = self.vertex_[idx]
            if vert.isROIs_:
                print("Vertex: {}, Inside of ROIs".format(vert.idx_))
            else:
                print("Vertex: {}, Outside of ROIs".format(vert.idx_))

            if vert.isSamples_:
                print("Vertex: {}, Is sample data".format(vert.idx_))
            else:
                print("Vertex: {}, Not sample data".format(vert.idx_))

            print("============================================")
    def graph_data_handler(self, channel, data):
        self.ROIs_ = []
        self.NZIG_ = []
        self.samples_ = []
        msg = map_data.decode(data)
        for cell in msg.vertex_:
            idx = cell.idx_
            if cell.isROIs_:
                self.ROIs_.append(idx)
                self.vertex_[idx].isROIs_ = True
            if cell.isNZIG_:
                self.NZIG_.append(idx)
            if cell.isSamples_:
                self.samples_.append(idx)
                self.vertex_[idx].ig_ = cell.ig_
                self.vertex_[idx].isSamples_ = True
            # else:
            #     self.vertex_[idx].ig_ = math.inf
            self.set_probability(idx, round(cell.p_, 3))

        self.L2_error_total_ = 0.0
        self.max_ig_ = 0.0
        self.max_ig_vertex_ = []
        self.bayesian_opt_ = 0.0
        self.bayesian_relative_err_ = 0.0

        # print("The size of nzig is {}".format(len(self.NZIG_)))
        for idx in self.NZIG_:
            self.adjacent_prob(idx)
            # print("Vertex {}. Surronding prob is {}".format(idx,self.vertex_[idx].surrounding_p_))
            # print("Vertex {}, Prob is {}".format(idx,self.vertex_[idx].p_))

        # Update the the surronding probability for each cell inside of ROIs and construct training_x
        for idx in self.samples_:
            # self.adjacent_prob(idx)
            # print("Vertex {}, surrounding probability is {}".format(idx,self.vertex_[idx].surrounding_p_))
            if self.vertex_[idx].surrounding_p_ not in self.training_x_:
                self.training_x_.append(self.vertex_[idx].surrounding_p_)
                self.training_y_.append([self.vertex_[idx].ig_])
                # self.training_x_.sort()
                # self.training_y_.sort()
                # self.training_y_.reverse()
                for kk, item in enumerate(self.training_x_):
                    if item == self.vertex_[idx].surrounding_p_:
                        if self.training_y_[kk] != [self.vertex_[idx].ig_]:
                            self.training_x_.remove(
                                self.vertex_[idx].surrounding_p_)
                            self.training_y_.remove([self.vertex_[idx].ig_])

        # for idx,x in enumerate(self.training_x_):
        #     print("sample X: {}, sample Y: {}".format(x,self.training_y_[idx]))
        # plt.plot(self.training_x_,self.training_y_,'b*')
        # plt.show()

        # print("Collected all data from LCM for bayesian optimization.")
        # for idx in self.vertex_.keys():
        #     vert = self.vertex_[idx]
        #     if vert.isROIs_:
        #         print("Vertex: {}, Inside of ROIs".format(vert.idx_))
        #     else:
        #         print("Vertex: {}, Outside of ROIs".format(vert.idx_))

        #     if vert.isSamples_:
        #         print("Vertex: {}, Is sample data".format(vert.idx_))
        #     else:
        #         print("Vertex: {}, Not sample data".format(vert.idx_))

        #     print("============================================")

        print("The training data is {}".format(len(self.training_x_)))