You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because if the number of layers is different from the number of tiles then the "tiledState" array will not have the right dimension.
Also, here nTiles = nBins = 8. So if we have 8 bins per axis we have 7 actual tiles per axis and np.digitize will return a number between 1 and 7 (because the if condition is strictly inferior/superior) so a total of 49 tiles.
Furthermore, I think idx should be idx = x * y + row * (nTiles-1)**2 - 1 because of the fact that np.digitize returns values between [1, 7] and not between [0, 7]. The values will then be for each row [0, 48], [49, 97], [98, 146], etc. Because with the original idx: idx = (x + 1) * (y + 1) + row * nTiles**2 - 1 there will be some index values that can never be used in tiledState (for example, it will always start at index n°3: (1+1) * (1+1) + 0 - 1 = 3).
I think it is because in the slide when you introduce the index equation during the chapter "Linear methods and tiling" the first possible value for x and y is (x,y) = (0,0). But the first value possible with np.digitize is (x,y) = (1,1). If we want the index equation to still be true we should maybe write:
deftile_state(pos_bins, vel_bins, obs, n_bins=8, n_layers=8):
position, velocity=obs# The number of tiles per axis is the number of bins per axis - 1n_tiles=n_bins-1tiled_state=np.zeros(n_tiles*n_tiles*n_layers)
forrowinrange(n_layers):
ifposition>pos_bins[row][0] and \
position<pos_bins[row][n_bins-1]:
ifvelocity>vel_bins[row][0] and \
velocity<vel_bins[row][n_bins-1]:
x=np.digitize(position, pos_bins[row])
y=np.digitize(velocity, vel_bins[row])
idx= (x*y) + (row*n_tiles**2) -1tiled_state[idx] =1.0else:
breakelse:
breakreturntiled_state
And I find the following result:
But maybe there is something I did not understand?
Best regards,
Victor Douet
The text was updated successfully, but these errors were encountered:
vdouet
changed the title
Wrong array dimension in tdZeroApprox.py
Wrong array dimension/index in tdZeroApprox.py
May 17, 2020
Hi,
For the code for TD(0) approximation 'tdZeroApprox.py' in Unit-8-The-Mountaincar.
Line 19 when the numpy array 'tiledState' is created:
Shouldn't it be:
Because if the number of layers is different from the number of tiles then the "tiledState" array will not have the right dimension.
Also, here nTiles = nBins = 8. So if we have 8 bins per axis we have 7 actual tiles per axis and
np.digitize
will return a number between 1 and 7 (because the if condition is strictly inferior/superior) so a total of 49 tiles.Furthermore, I think
idx
should beidx = x * y + row * (nTiles-1)**2 - 1
because of the fact thatnp.digitize
returns values between [1, 7] and not between [0, 7]. The values will then be for each row [0, 48], [49, 97], [98, 146], etc. Because with the original idx:idx = (x + 1) * (y + 1) + row * nTiles**2 - 1
there will be some index values that can never be used in tiledState (for example, it will always start at index n°3: (1+1) * (1+1) + 0 - 1 = 3).I think it is because in the slide when you introduce the index equation during the chapter "Linear methods and tiling" the first possible value for x and y is (x,y) = (0,0). But the first value possible with
np.digitize
is (x,y) = (1,1). If we want the index equation to still be true we should maybe write:and then we can write:
But here is the modified code I used:
And I find the following result:
But maybe there is something I did not understand?
Best regards,
Victor Douet
The text was updated successfully, but these errors were encountered: