private double backwardPropagateDelta(double[] output) {
    double error = 0.0;
    for(int i = 0; i < delta[n - 1].length - 1; i++) {
      double o = x[n - 1][i];
      delta[n - 1][i] = o * (1.0 - o) * (output[i] - o);
      error += Math.pow(output[i] - o, 2.0);
    }
    delta[n - 1][delta[n - 1].length - 1] = 0.0;

    for(int i = n - 2; i >= 0; i--) {
      for(int j = 0; j < delta[i].length; j++) {
        double sum = 0.0;
        for(int k = 0; k < delta[i + 1].length; k++) {
          sum += delta[i + 1][k] * weight[i + 1][k][j];
        }
        double o = x[i][j];
        delta[i][j] = o * (1.0 - o) * sum;
      }
    }

    return error;
  }