* Randomly sample a batch of items from the replay buffer. * * The sampling is done *without* replacement. * * @param {number} batchSize Size of the batch. * @return {Array } Sampled items.
(batchSize)
| 59 | * @return {Array<any>} Sampled items. |
| 60 | */ |
| 61 | sample(batchSize) { |
| 62 | if (batchSize > this.maxLen) { |
| 63 | throw new Error( |
| 64 | `batchSize (${batchSize}) exceeds buffer length (${this.maxLen})`); |
| 65 | } |
| 66 | tf.util.shuffle(this.bufferIndices_); |
| 67 | |
| 68 | const out = []; |
| 69 | for (let i = 0; i < batchSize; ++i) { |
| 70 | out.push(this.buffer[this.bufferIndices_[i]]); |
| 71 | } |
| 72 | return out; |
| 73 | } |
| 74 | } |
no outgoing calls
no test coverage detected