private double[] forwardPropagate(double[] input) {
    if(input == null || input.length + 1 != x[0].length) {
      throw new RuntimeException("Wrong number of input elements.");
    }

    x[0][x[0].length - 1] = 1.0;
    for(int i = 0; i < input.length; i++) {
      x[0][i] = input[i];
    }

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

    double[] output = new double[x[n - 1].length - 1];
    for(int i = 0; i < output.length; i++) {
      output[i] = x[n - 1][i];
    }

    return output;
  }