@Test public void when_CallingBuildStackedNextObservationsAndShapeRankIsGreaterThan2_expect_ResultWithOneMoreDimensionAndObservationsStackedOnDimension0() { List<Transition<Integer>> transitions = new ArrayList<Transition<Integer>>(); double[][] obs1 = new double[][] { { 0.0, 1.0, 2.0 }, { 3.0, 4.0, 5.0 }, { 6.0, 7.0, 8.0 }, }; Observation observation1 = buildObservation(obs1); double[] nextObs1 = new double[] { 100.0, 101.0, 102.0 }; Observation nextObservation1 = buildNextObservation(obs1, nextObs1); transitions.add(buildTransition(observation1, 0, 0.0, nextObservation1)); double[][] obs2 = new double[][] { { 10.0, 11.0, 12.0 }, { 13.0, 14.0, 15.0 }, { 16.0, 17.0, 18.0 }, }; Observation observation2 = buildObservation(obs2); double[] nextObs2 = new double[] { 110.0, 111.0, 112.0 }; Observation nextObservation2 = buildNextObservation(obs2, nextObs2); transitions.add(buildTransition(observation2, 0, 0.0, nextObservation2)); INDArray result = Transition.buildStackedNextObservations(transitions); double[][][] expected = new double[][][] { new double[][] { nextObs1, obs1[0], obs1[1] }, new double[][] { nextObs2, obs2[0], obs2[1] } }; assertExpected(expected, result); }
public static <A> INDArray buildStackedNextObservations(List<Transition<A>> transitions) { int size = transitions.size(); long[] shape = getShape(transitions); INDArray[] array = new INDArray[size]; for (int i = 0; i < size; i++) { Transition<A> trans = transitions.get(i); INDArray obs = trans.getObservation().getData(); long historyLength = obs.shape()[0]; if(historyLength != 1) { INDArray historyPart = obs.get(new INDArrayIndex[]{NDArrayIndex.interval(0, historyLength - 1)}); array[i] = Nd4j.concat(0, trans.getNextObservation(), historyPart); } else { array[i] = trans.getNextObservation(); } } return Nd4j.concat(0, array).reshape(shape); }
Transition { public static <A> INDArray buildStackedNextObservations(List<Transition<A>> transitions) { int size = transitions.size(); long[] shape = getShape(transitions); INDArray[] array = new INDArray[size]; for (int i = 0; i < size; i++) { Transition<A> trans = transitions.get(i); INDArray obs = trans.getObservation().getData(); long historyLength = obs.shape()[0]; if(historyLength != 1) { INDArray historyPart = obs.get(new INDArrayIndex[]{NDArrayIndex.interval(0, historyLength - 1)}); array[i] = Nd4j.concat(0, trans.getNextObservation(), historyPart); } else { array[i] = trans.getNextObservation(); } } return Nd4j.concat(0, array).reshape(shape); } }
Transition { public static <A> INDArray buildStackedNextObservations(List<Transition<A>> transitions) { int size = transitions.size(); long[] shape = getShape(transitions); INDArray[] array = new INDArray[size]; for (int i = 0; i < size; i++) { Transition<A> trans = transitions.get(i); INDArray obs = trans.getObservation().getData(); long historyLength = obs.shape()[0]; if(historyLength != 1) { INDArray historyPart = obs.get(new INDArrayIndex[]{NDArrayIndex.interval(0, historyLength - 1)}); array[i] = Nd4j.concat(0, trans.getNextObservation(), historyPart); } else { array[i] = trans.getNextObservation(); } } return Nd4j.concat(0, array).reshape(shape); } Transition(Observation observation, A action, double reward, boolean isTerminal); private  Transition(Observation observation, A action, double reward, boolean isTerminal, INDArray nextObservation); }
Transition { public static <A> INDArray buildStackedNextObservations(List<Transition<A>> transitions) { int size = transitions.size(); long[] shape = getShape(transitions); INDArray[] array = new INDArray[size]; for (int i = 0; i < size; i++) { Transition<A> trans = transitions.get(i); INDArray obs = trans.getObservation().getData(); long historyLength = obs.shape()[0]; if(historyLength != 1) { INDArray historyPart = obs.get(new INDArrayIndex[]{NDArrayIndex.interval(0, historyLength - 1)}); array[i] = Nd4j.concat(0, trans.getNextObservation(), historyPart); } else { array[i] = trans.getNextObservation(); } } return Nd4j.concat(0, array).reshape(shape); } Transition(Observation observation, A action, double reward, boolean isTerminal); private  Transition(Observation observation, A action, double reward, boolean isTerminal, INDArray nextObservation); void setNextObservation(Observation nextObservation); static INDArray concat(INDArray[] history); Transition<A> dup(); static INDArray buildStackedObservations(List<Transition<A>> transitions); static INDArray buildStackedNextObservations(List<Transition<A>> transitions); }
Transition { public static <A> INDArray buildStackedNextObservations(List<Transition<A>> transitions) { int size = transitions.size(); long[] shape = getShape(transitions); INDArray[] array = new INDArray[size]; for (int i = 0; i < size; i++) { Transition<A> trans = transitions.get(i); INDArray obs = trans.getObservation().getData(); long historyLength = obs.shape()[0]; if(historyLength != 1) { INDArray historyPart = obs.get(new INDArrayIndex[]{NDArrayIndex.interval(0, historyLength - 1)}); array[i] = Nd4j.concat(0, trans.getNextObservation(), historyPart); } else { array[i] = trans.getNextObservation(); } } return Nd4j.concat(0, array).reshape(shape); } Transition(Observation observation, A action, double reward, boolean isTerminal); private  Transition(Observation observation, A action, double reward, boolean isTerminal, INDArray nextObservation); void setNextObservation(Observation nextObservation); static INDArray concat(INDArray[] history); Transition<A> dup(); static INDArray buildStackedObservations(List<Transition<A>> transitions); static INDArray buildStackedNextObservations(List<Transition<A>> transitions);  }