1. Learn
  2. /
  3. Courses
  4. /
  5. Deep Reinforcement Learning in Python

Connected

Exercise

Sampling from the PER buffer

Before you can use the Prioritized Experience Buffer class to train your agent, you still need to implement the .sample() method. This method takes as argument the size of the sample you want to draw, and returns the sampled transitions as tensors, along with their indices in the memory buffer and their importance weight.

A buffer with capacity 10 has been pre-loaded in your environment for you to sample from.

Instructions

100 XP
  • Calculate the sampling probability associated with each transition.
  • Draw the indices corresponding to the transitions in the sample; np.random.choice(a, s, p=p) takes a sample of size s with replacement from the array a, based on probability array p.
  • Calculate the importance weight associated with each transition.