[][src]Struct tilecoding::IHT

pub struct IHT { /* fields omitted */ }

An index-hash-table, or IHT. It will allow to collect tile indices up to a certain size, after which collisions will start to occur. The underlying storage is a HashMap

Methods

impl IHT[src]

pub fn new(size: usize) -> IHT[src]

Create a new IHT with the given size. The tiles function will never report an index >= this size.

pub fn full(&self) -> bool[src]

Convenience function to determine if the IHT is full. If it is, new tilings will result in collisions rather than new indices.

pub fn count(&self) -> usize[src]

Convenience function to determine how full the IHT is. The maximum value will be the IHT size

pub fn size(&self) -> usize[src]

Convenience function get the size of the IHT, in case you forgot what it was

pub fn tiles(
    &mut self,
    num_tilings: usize,
    floats: &[f64],
    ints: Option<&[isize]>
) -> Vec<usize>
[src]

This function takes a series of floating point and integer values, and encodes them as tile indices using the underlying IHT to deal with collisions.

Arguments

  • num_tilings—indicates the number of tile indices to be generated (i.e. the length of the returned Vec). 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 tiled
  • 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

// initialize an index-hash-table with size `1024`
let mut iht = IHT::new(1024);
 
// find the indices of tiles for the point (x, y) = (3.6, 7.21) using 8 tilings:
let indices = iht.tiles(8, &[3.6, 7.21], None);
 
// this is the first time we've used the IHT, so we will get the starting tiles:
assert_eq!(indices, vec![0, 1, 2, 3, 4, 5, 6, 7]);
 
// a nearby point:
let indices = iht.tiles(8, &[3.7, 7.21], None);
 
// differs by one tile:
assert_eq!(indices, vec![0, 1, 2, 8, 4, 5, 6, 7]);
 
// and a point more than one away in any dim
let indices = iht.tiles(8, &[-37.2, 7.0], None);
 
// will have all different tiles
assert_eq!(indices, vec![9, 10, 11, 12, 13, 14, 15, 16]);

Auto Trait Implementations

impl Send for IHT

impl Sync for IHT

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]