@Test public void when_callingGetTargetExpectedQValuesOfLast_expect_INDArrayWithCorrectShape() { IOutputNeuralNet targetMock = mock(IOutputNeuralNet.class); List<StateActionPair<Integer>> experience = new ArrayList<StateActionPair<Integer>>() { { add(new StateActionPair<Integer>(new Observation(Nd4j.create(new double[] { 1.1, 1.2 }).reshape(1, 2)), 0, 1.0, false)); add(new StateActionPair<Integer>(new Observation(Nd4j.create(new double[] { 2.1, 2.2 }).reshape(1, 2)), 1, 2.0, false)); add(new StateActionPair<Integer>(new Observation(Nd4j.create(new double[] { 3.1, 3.2 }).reshape(1, 2)), 2, 3.0, false)); add(new StateActionPair<Integer>(new Observation(Nd4j.create(new double[] { 4.1, 4.2 }).reshape(1, 2)), 3, 4.0, false)); } }; final NeuralNetOutput neuralNetOutput = new NeuralNetOutput(); neuralNetOutput.put(CommonOutputNames.QValues, Nd4j.create(new double[] { -4.1, -4.2 }).reshape(1, 2)); when(targetMock.output(any(Observation.class))).thenReturn(neuralNetOutput); INDArray result = sut.getTargetExpectedQValuesOfLast(targetMock, experience, null); ArgumentCaptor<Observation> observationCaptor = ArgumentCaptor.forClass(Observation.class); verify(targetMock, times(1)).output(observationCaptor.capture()); Observation observation = observationCaptor.getValue(); assertEquals(4.1, observation.getData().getDouble(0), 0.00001); assertEquals(4.2, observation.getData().getDouble(1), 0.00001); assertEquals(-4.1, result.getDouble(0), 0.00001); assertEquals(-4.2, result.getDouble(1), 0.00001); }
@Override public INDArray getTargetExpectedQValuesOfLast(IOutputNeuralNet target, List<StateActionPair<Integer>> trainingBatch, INDArray features) { Observation lastObservation = trainingBatch.get(trainingBatch.size() - 1).getObservation(); return target.output(lastObservation) .get(CommonOutputNames.QValues); }
NonRecurrentNStepQLearningHelper extends NStepQLearningHelper { @Override public INDArray getTargetExpectedQValuesOfLast(IOutputNeuralNet target, List<StateActionPair<Integer>> trainingBatch, INDArray features) { Observation lastObservation = trainingBatch.get(trainingBatch.size() - 1).getObservation(); return target.output(lastObservation) .get(CommonOutputNames.QValues); } }
NonRecurrentNStepQLearningHelper extends NStepQLearningHelper { @Override public INDArray getTargetExpectedQValuesOfLast(IOutputNeuralNet target, List<StateActionPair<Integer>> trainingBatch, INDArray features) { Observation lastObservation = trainingBatch.get(trainingBatch.size() - 1).getObservation(); return target.output(lastObservation) .get(CommonOutputNames.QValues); } NonRecurrentNStepQLearningHelper(int actionSpaceSize); }
NonRecurrentNStepQLearningHelper extends NStepQLearningHelper { @Override public INDArray getTargetExpectedQValuesOfLast(IOutputNeuralNet target, List<StateActionPair<Integer>> trainingBatch, INDArray features) { Observation lastObservation = trainingBatch.get(trainingBatch.size() - 1).getObservation(); return target.output(lastObservation) .get(CommonOutputNames.QValues); } NonRecurrentNStepQLearningHelper(int actionSpaceSize); @Override INDArray createLabels(int trainingBatchSize); @Override INDArray getExpectedQValues(INDArray allExpectedQValues, int idx); @Override void setLabels(INDArray labels, long idx, INDArray data); @Override INDArray getTargetExpectedQValuesOfLast(IOutputNeuralNet target, List<StateActionPair<Integer>> trainingBatch, INDArray features); }
NonRecurrentNStepQLearningHelper extends NStepQLearningHelper { @Override public INDArray getTargetExpectedQValuesOfLast(IOutputNeuralNet target, List<StateActionPair<Integer>> trainingBatch, INDArray features) { Observation lastObservation = trainingBatch.get(trainingBatch.size() - 1).getObservation(); return target.output(lastObservation) .get(CommonOutputNames.QValues); } NonRecurrentNStepQLearningHelper(int actionSpaceSize); @Override INDArray createLabels(int trainingBatchSize); @Override INDArray getExpectedQValues(INDArray allExpectedQValues, int idx); @Override void setLabels(INDArray labels, long idx, INDArray data); @Override INDArray getTargetExpectedQValuesOfLast(IOutputNeuralNet target, List<StateActionPair<Integer>> trainingBatch, INDArray features);  }