code: public Gradient[] calcGradient(IDQN current, Stack<MiniTrans<Integer>> rewards) {
  
          MiniTrans<Integer> minTrans = rewards.pop();
  
          int size = rewards.size();
  
          int[] shape = getHistoryProcessor() == null ? mdp.getObservationSpace().getShape()
                          : getHistoryProcessor().getConf().getShape();
          int[] nshape = Learning.makeShape(size, shape);
          INDArray input = Nd4j.create(nshape);
          INDArray targets = Nd4j.create(size, mdp.getActionSpace().getSize());
  
          double r = minTrans.getReward();
          for (int i = size - 1; i >= 0; i--) {
              minTrans = rewards.pop();
  
              r = minTrans.getReward() + conf.getGamma() * r;
              input.putRow(i, minTrans.getObs());
              INDArray row = minTrans.getOutput()[0];
              row = row.putScalar(minTrans.getAction(), r);
              targets.putRow(i, row);
          }
  
          return current.gradient(input, targets);
      }
docs: calc the gradient based on the n-step rewards