Skip to content
DeepForgeby svx
All problems

Tile Coding Index

Problem

Compute the tile-coding index for a continuous state.

Each dimension maps to int((state[i] + offsets[i] * widths[i]) // widths[i]) mod n_tiles[i], then dimensions are combined with mixed-radix strides, last dimension fastest. Return the integer index.

Hint

Offsets shift the grid so different tilings cover different boundaries.

Test cases

case 1
in: [[0.5,0.5],[0.1,0.1],[0,0],[10,10]]
expected: 44
case 2
in: [[0.95,0.05],[0.1,0.1],[0,0],[10,10]]
expected: 90
case 3
in: [[0.5,0.5],[0.1,0.1],[0.5,0.5],[10,10]]
expected: 55
case 4
in: [[0.25],[0.5],[0],[4]]
expected: 0
Starter codePython
def tile_coding_index(state, widths, offsets, n_tiles):
    # Your code here
    pass

4 test cases · run your code against them in the editor