示例#1
0
    def extract_features(self,state):

        feature = np.zeros(11)
        state_info = self.get_info_from_state(state)
        current_dist = np.linalg.norm(state_info[0,:]-state_info[1,:])
        
        agent_pos = state_info[0]
        goal_pos = state_info[1]
        diff_x = goal_pos[0] - agent_pos[0]
        diff_y = goal_pos[1] - agent_pos[1]

        feature[self.determine_index(diff_x, diff_y)] = 1

        if self.prev_dist is None or self.prev_dist == current_dist:

            feature[8+1] = 1
            self.prev_dist = current_dist
            return reset_wrapper(feature)

        if self.prev_dist > current_dist:

            feature[8+0] = 1

        if self.prev_dist < current_dist:

            feature[8+2] = 1

        self.prev_dist = current_dist

        return reset_wrapper(feature)
示例#2
0
    def extract_features(self, state):

        feat = state
        pos = feat[0]
        vel = feat[1]
        pad = np.ones(1)
        pos_repr = self.get_binary_representation(pos, self.disc_pos,
                                                  self.pos_range)
        vel_repr = self.get_binary_representation(vel, self.disc_vel,
                                                  self.vel_range)

        if self.pad:
            return reset_wrapper(
                np.concatenate((pos_repr, vel_repr, pad), axis=0))
        else:
            return reset_wrapper(np.concatenate((pos_repr, vel_repr), axis=0))
示例#3
0
    def extract_features(self,state):

        feature = np.zeros(self.state_size)
        agent_pos = self.get_info_from_state(state)

        index = agent_pos[0]*self.cols+agent_pos[1]
        feature[index] = 1

        feature = reset_wrapper(feature)

        return feature
示例#4
0
    def extract_features(self, state):

        pos = state[0]
        vel = state[1]

        rescaled_pos = self.rescale_value(pos, self.disc_pos, self.pos_range)
        pos_vector = np.zeros(self.disc_pos)
        pos_vector[rescaled_pos] = 1

        rescaled_vel = self.rescale_value(vel, self.disc_vel, self.vel_range)
        vel_vector = np.zeros(self.disc_vel)
        vel_vector[rescaled_vel] = 1
        #pdb.set_trace()
        return reset_wrapper(np.concatenate((pos_vector, vel_vector), axis=0))
示例#5
0
    def extract_features(self, state):
        '''exctract the features'''
        #pdb.set_trace()
        state = self.get_info_from_state(state)

        rel_positions = self.get_relative_coords(state)
        state = self.update_relative_coords(rel_positions, self.heading_direction)
        #print('Rel state info:', state)
        mod_state = np.zeros(4+9+3+12)

        #a = int((window_size**2-1)/2)
        mod_state[self.heading_direction] = 1
        agent_pos = state[0]
        goal_pos = state[1]
        diff_r = goal_pos[0] - agent_pos[0]
        diff_c = goal_pos[1] - agent_pos[1]
        '''
        if diff_x >= 0 and diff_y >= 0:
            mod_state[1] = 1
        elif diff_x < 0  and diff_y >= 0:
            mod_state[0] = 1
        elif diff_x < 0 and diff_y < 0:
            mod_state[3] = 1
        else:
            mod_state[2] = 1
        '''
        index = self.determine_index(diff_r, diff_c)
        mod_state[4+index] = 1

        feat = self.closeness_indicator(state)

        mod_state[13:16] = feat

        for i in range(2, len(state)):

            #as of now this just measures the distance from the center of the obstacle
            #this distance has to be measured from the circumferance of the obstacle

            #new method, simulate overlap for each of the neighbouring places
            #for each of the obstacles
            obs_pos = state[i]
            orient, dist = self.get_orientation_distance(agent_pos, obs_pos)
            if dist >= 0 and orient >= 0:
                mod_state[16+dist*4+orient] = 1 # clockwise starting from the inner most circle

            
        return reset_wrapper(mod_state)
示例#6
0
    def extract_features(self, state):

        #pdb.set_trace()
        agent_state, goal_state, obstacles = self.get_info_from_state(state)

        mod_state = np.zeros(self.state_rep_size)

        #a = int((window_size**2-1)/2)
        
        agent_pos = agent_state['position']
        goal_pos = goal_state
        diff_r = goal_pos[0] - agent_pos[0]
        diff_c = goal_pos[1] - agent_pos[1]
        '''
        if diff_x >= 0 and diff_y >= 0:
            mod_state[1] = 1
        elif diff_x < 0  and diff_y >= 0:
            mod_state[0] = 1
        elif diff_x < 0 and diff_y < 0:
            mod_state[3] = 1
        else:
            mod_state[2] = 1
        '''
        index = self.determine_index(diff_r,diff_c)
        mod_state[index] = 1
        feat = self.closeness_indicator(agent_pos, goal_pos)

        mod_state[9:12] = feat

        for i in range(len(obstacles)):

            #as of now this just measures the distance from the center of the obstacle
            #this distance has to be measured from the circumferance of the obstacle

            #new method, simulate overlap for each of the neighbouring places
            #for each of the obstacles
            obs_pos = obstacles[i]['position']
            orient, dist, is_hit = self.get_orientation_distance(agent_pos, obs_pos)
            if dist >= 0 and orient >= 0:
                mod_state[12+dist*4+orient] = 1 # clockwise starting from the inner most circle

            if is_hit:
                mod_state[-1]=1
            
        return reset_wrapper(mod_state)
示例#7
0
    def extract_features(self,state):

        #pdb.set_trace()
        agent_state, goal_state, obstacles = self.get_info_from_state(state)
        window_size = self.window_size
        block_width = self.grid_size
        step = self.step_size
        window_rows = window_cols = window_size
        row_start =  int((window_rows-1)/2)
        col_start = int((window_cols-1)/2)

        mod_state = np.zeros(12+window_size**2)

        #a = int((window_size**2-1)/2)
        
        agent_pos = agent_state['position']
        goal_pos = goal_state
        diff_r = goal_pos[0] - agent_pos[0]
        diff_c = goal_pos[1] - agent_pos[1]
        '''
        if diff_x >= 0 and diff_y >= 0:
            mod_state[1] = 1
        elif diff_x < 0  and diff_y >= 0:
            mod_state[0] = 1
        elif diff_x < 0 and diff_y < 0:
            mod_state[3] = 1
        else:
            mod_state[2] = 1
        '''
        index = self.determine_index(diff_r, diff_c)
        mod_state[index] = 1

        feat = self.closeness_indicator(agent_state, goal_state)

        mod_state[self.gl_size:self.gl_size+self.rl_size] = feat

        for i in range(len(obstacles)):

            #as of now this just measures the distance from the center of the obstacle
            #this distance has to be measured from the circumferance of the obstacle

            #new method, simulate overlap for each of the neighbouring places
            #for each of the obstacles
            obs_pos = obstacles[i]['position']
            obs_width = self.obs_width
            for r in range(-row_start,row_start+1,1):
                for c in range(-col_start,col_start+1,1):
                    #c = x and r = y
                    #pdb.set_trace()
                    temp_pos = np.asarray([agent_pos[0] + r*step, 
                                agent_pos[1] + c*step])

                    if self.overlay_bins:
                        pygame.draw.rect(self.game_display, (0,0,0),[temp_pos[1]-(self.agent_width/2), temp_pos[0]- \
                                    (self.agent_width/2), self.agent_width, self.agent_width],1)
   
                    if self.check_overlap(temp_pos,obs_pos):
                        pos = self.block_to_arrpos(r,c)

                        mod_state[pos+self.gl_size+self.rl_size]=1

        pygame.display.update()

        return reset_wrapper(mod_state)
示例#8
0
    def extract_features(self, state):

        return reset_wrapper(state)