semitable / lb-foraging

Level-based Foraging (LBF): A multi-agent environment for RL
MIT License
151 stars 64 forks source link

The max_obs of observation range may not correct #11

Closed GoingMyWay closed 2 years ago

GoingMyWay commented 2 years ago

Dear authors, after checking the code, I found that in https://github.com/semitable/lb-foraging/blob/master/lbforaging/foraging/environment.py#L125

            field_x = self.field.shape[1]
            field_y = self.field.shape[0]
            # field_size = field_x * field_y

            max_food = self.max_food
            max_food_level = self.max_player_level * len(self.players)

            min_obs = [-1, -1, 0] * max_food + [-1, -1, 0] * len(self.players)
            max_obs = [field_x, field_y, max_food_level] * max_food + [
                field_x,
                field_y,
                self.max_player_level,
            ] 

and

return gym.spaces.Box(np.array(min_obs), np.array(max_obs), dtype=np.float32)

For 8x8 grid, the field_x and field_y are 8. However, the positions of the grids are within the range of [0, 7]. In gym.spaces.Box (https://github.com/openai/gym/blob/master/gym/spaces/box.py#L26), it is [0, 8]. I guess it will out of range. It will not cause any error if you do not predict the obs and modify the obs.

Could you please check it? If so, I will make a PR.

semitable commented 2 years ago

Thanks @GoingMyWay Yes, that makes sense to me. I didn't really bother much with the observation space since it doesn't appear to cause any issues when the observation space (is a superset of) contains the actual observations. I am happy to merge a PR if this fixes some use case you have in mind.

GoingMyWay commented 2 years ago

Thanks @GoingMyWay Yes, that makes sense to me. I didn't really bother much with the observation space since it doesn't appear to cause any issues when the observation space (is a superset of) contains the actual observations. I am happy to merge a PR if this fixes some use case you have in mind.

Thanks. I encountered this problem when I tried to predict x and y. The grid size is 8x8. I got x=8 and it was out of the bound.