State size/Observation space
rtang23 opened this issue · comments
Is there any command that will allow me to grab the state size or the observation space of the environment?
for the observation space, environments define an observation_space
property (a proprietary gym object for spaces). To get the raw shape of the numpy array state use observation_space.shape
. You can also sample from the space using observation_space.sample()
. Heres a quick test script
from gym_super_mario_bros import make
env = make('SuperMarioBros-v0')
print(env.observation_space)
print(env.observation_space.shape)
print(env.observation_space.sample())
By state size, I'm assuming you mean the number of bytes required for a given state? There is no direct command but the calculation is as follows:
f = 256 * 240 * 3 = 184,320 # the number of bytes per frame (tensor)
r = 4 # the number of bytes for a reward (float)
d = 1 # the number of bytes for a done flag (boolean)
s = f + r + d = 184,325 bytes
I made a script to get the empirical state size from the
import sys
import numpy as np
from gym_super_mario_bros import make
env = make('SuperMarioBros-v0')
env.reset()
state, reward, done, info = env.step(0)
size = (
np.prod(state.shape) * state.itemsize +
sys.getsizeof(reward) +
sys.getsizeof(done)
)
print('{}B per state'.format(size))
I get 184368B per state
when I run the above snippet. It appears that both booleans and floats are actually allocated 24 bytes.
You're a goddam hero!