def transform(self, state): # Normalize values to range from [0, 1] for use in transformations position, velocity = state position = (position + 1.2) / 1.8 velocity = (velocity + 0.07) / 0.14 assert 0 <= position <= 1 assert 0 <= velocity <= 1 position *= 2 velocity *= 2 if self.mode == "tile": if self.iht is None: self.iht = IHT(self.state_space) tiling = tiles(self.iht, 64, [position, velocity], [0]) + \ tiles(self.iht, 64, [position], [1]) + \ tiles(self.iht, 64, [velocity], [2]) return {index: 1 for index in tiling} elif self.mode == "raw": return dict(enumerate(state)) else: raise Error("Invalid environment mode. Must be tile or raw")
def __init__(self, size, num_tiles, num_tilings): self.iht = IHT(size) self.num_tiles = num_tiles self.num_tilings = num_tilings