@Test public void when_askBatchSizeZeroAndStorageEmpty_expect_emptyBatch() { MockRandom randomMock = new MockRandom(null, new int[] { 0 }); ExpReplay<Integer> sut = new ExpReplay<Integer>(5, 1, randomMock); List<Transition<Integer>> results = sut.getBatch(0); assertEquals(0, results.size()); }
public ArrayList<Transition<A>> getBatch(int size) { ArrayList<Transition<A>> batch = new ArrayList<>(size); int storageSize = storage.size(); int actualBatchSize = Math.min(storageSize, size); int[] actualIndex = new int[actualBatchSize]; IntSet set = new IntOpenHashSet(); for( int i=0; i<actualBatchSize; i++ ){ int next = rnd.nextInt(storageSize); while(set.contains(next)){ next = rnd.nextInt(storageSize); } set.add(next); actualIndex[i] = next; } for (int i = 0; i < actualBatchSize; i ++) { Transition<A> trans = storage.get(actualIndex[i]); batch.add(trans.dup()); } return batch; }
ExpReplay implements IExpReplay<A> { public ArrayList<Transition<A>> getBatch(int size) { ArrayList<Transition<A>> batch = new ArrayList<>(size); int storageSize = storage.size(); int actualBatchSize = Math.min(storageSize, size); int[] actualIndex = new int[actualBatchSize]; IntSet set = new IntOpenHashSet(); for( int i=0; i<actualBatchSize; i++ ){ int next = rnd.nextInt(storageSize); while(set.contains(next)){ next = rnd.nextInt(storageSize); } set.add(next); actualIndex[i] = next; } for (int i = 0; i < actualBatchSize; i ++) { Transition<A> trans = storage.get(actualIndex[i]); batch.add(trans.dup()); } return batch; } }
ExpReplay implements IExpReplay<A> { public ArrayList<Transition<A>> getBatch(int size) { ArrayList<Transition<A>> batch = new ArrayList<>(size); int storageSize = storage.size(); int actualBatchSize = Math.min(storageSize, size); int[] actualIndex = new int[actualBatchSize]; IntSet set = new IntOpenHashSet(); for( int i=0; i<actualBatchSize; i++ ){ int next = rnd.nextInt(storageSize); while(set.contains(next)){ next = rnd.nextInt(storageSize); } set.add(next); actualIndex[i] = next; } for (int i = 0; i < actualBatchSize; i ++) { Transition<A> trans = storage.get(actualIndex[i]); batch.add(trans.dup()); } return batch; } ExpReplay(int maxSize, int batchSize, Random rnd); }
ExpReplay implements IExpReplay<A> { public ArrayList<Transition<A>> getBatch(int size) { ArrayList<Transition<A>> batch = new ArrayList<>(size); int storageSize = storage.size(); int actualBatchSize = Math.min(storageSize, size); int[] actualIndex = new int[actualBatchSize]; IntSet set = new IntOpenHashSet(); for( int i=0; i<actualBatchSize; i++ ){ int next = rnd.nextInt(storageSize); while(set.contains(next)){ next = rnd.nextInt(storageSize); } set.add(next); actualIndex[i] = next; } for (int i = 0; i < actualBatchSize; i ++) { Transition<A> trans = storage.get(actualIndex[i]); batch.add(trans.dup()); } return batch; } ExpReplay(int maxSize, int batchSize, Random rnd); ArrayList<Transition<A>> getBatch(int size); ArrayList<Transition<A>> getBatch(); void store(Transition<A> transition); @Override int getDesignatedBatchSize(); int getBatchSize(); }
ExpReplay implements IExpReplay<A> { public ArrayList<Transition<A>> getBatch(int size) { ArrayList<Transition<A>> batch = new ArrayList<>(size); int storageSize = storage.size(); int actualBatchSize = Math.min(storageSize, size); int[] actualIndex = new int[actualBatchSize]; IntSet set = new IntOpenHashSet(); for( int i=0; i<actualBatchSize; i++ ){ int next = rnd.nextInt(storageSize); while(set.contains(next)){ next = rnd.nextInt(storageSize); } set.add(next); actualIndex[i] = next; } for (int i = 0; i < actualBatchSize; i ++) { Transition<A> trans = storage.get(actualIndex[i]); batch.add(trans.dup()); } return batch; } ExpReplay(int maxSize, int batchSize, Random rnd); ArrayList<Transition<A>> getBatch(int size); ArrayList<Transition<A>> getBatch(); void store(Transition<A> transition); @Override int getDesignatedBatchSize(); int getBatchSize();  }