pub fn tiles_wrap(
size: usize,
num_tilings: usize,
floats: &[f64],
wrap_widths: &[Option<isize>],
ints: Option<&[isize]>,
) -> Vec<usize>Expand description
A wrap-around version of tiles, described in the original implementation.
§Arguments
size—the upper bounds of all returned indicesnum_tilings—indicates the number of tile indices to be generated (i.e. the length of the returnedVec). This value hould be a power of two greater or equal to four times the number of floats according to the original implementation.floats—a list of floating-point numbers to be tiledwrap_widths—a list of optional integer wrapping points.ints—an optional list of integers that will also be tiled; all distinct integers will result in different tilings. In reinforcement learning, discrete actions are often provided here.
§Return Value
The returned Vec<usize> is a vector containing exactly num_tilings elements, with each member being an index of a tile encoded by the function. Each member will always be >= 0 and <= size - 1.
§Examples
From the original implementation:
The tilings we have discussed so far stretch out to infinity with no need to specify a range for them. This is cool, but sometimes not what you want. Sometimes you want the variables to wrap-around over some range. For example, you may have an angle variable that goes from 0 to 2π and then should wrap around, that is, you would like generalization to occur between angles just greater than 0 and angles that are nearly 2π. To accommodate this, we provide some alternative, wrap-around versions of the tiling routines.
These versions take an additional input, wrap_widths, which parallels the float structure (array or list), and which specifies for each float the width of the range over which it wraps. If you don’t want a float to wrap, it’s wrap_width should be
None. The wrap_width is in the same units as the floats, but should be an integer. This can be confusing, so let’s do a simple 1D example. Suppose you have one real input, an angle theta. Theta is originally in radians, that is, in [0,2π), which you would like to wrap around at 2π. Remember that these functions all have their tile boundaries at the integers, so if you passed in theta directly there would be tile boundaries at 0, 1, and 2, i.e., just a few tiles over the whole range, which is probably not what you want. So let’s say what we want! Suppose we want tilings with 10 tiles over the [0,2π) range. Then we have to scale theta so that it goes from 0 to 10 (instead of 0 to 2π). One would do this by multiplying theta by 10/2π. With the new scaled theta, the wrapping is over [0,10), for a wrap_width of 10.
Here is the code for the above case, assuming we want 16 tilings over the original [0, 2π) range with a memory size of 512:
tiles_wrap(
512,
16,
&[theta * 10. / (2.0 * std::f64::consts::PI)],
&[Some(10)],
None
);Note that the code would be exactly the same if the original range of theta was [-π,+π]. Specifying the complete range of wrapping (rather than just the width) is not necessary for the same reason as we did not need to give a range at all in the previous routines.
As another example, suppose you wanted to cover the 2π x 3 rectangular area with 16 tilings, each with a width of generalization one-tenth of the space in each dimension, and with wrap-around in the second dimension but not the first. In rust you would do:
tiles_wrap(
512,
16,
&[x / (3. * 0.1), y / (2.0 * std::f64::consts::PI * 0.1)],
&[None, Some(10)],
None
);