MCPcopy
hub / github.com/tensorflow/tfjs-examples / sample

Method sample

snake-dqn/replay_memory.js:61–73  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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}

Callers 2

trainOnReplayBatchMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected