code: private double computeOutputError(double[] output, double[] gradient) {
          if (output.length != outputLayer.units) {
              throw new IllegalArgumentException(String.format("Invalid output vector size: %d, expected: %d", output.length, outputLayer.units));
          }
  
          double error = 0.0;
          for (int i = 0; i < outputLayer.units; i++) {
              double out = outputLayer.output[i];
              double g = output[i] - out;
  
              if (errorFunction == ErrorFunction.LEAST_MEAN_SQUARES) {
                  error += 0.5 * g * g;
              } else if (errorFunction == ErrorFunction.CROSS_ENTROPY) {
                  if (activationFunction == ActivationFunction.SOFTMAX) {
                      error -= output[i] * log(out);
                  } else if (activationFunction == ActivationFunction.LOGISTIC_SIGMOID) {
                      // We have only one output neuron in this case.
                      error = -output[i] * log(out) - (1.0 - output[i]) * log(1.0 - out);
                  }
              }
  
              if (errorFunction == ErrorFunction.LEAST_MEAN_SQUARES && activationFunction == ActivationFunction.LOGISTIC_SIGMOID) {
                  g *= out * (1.0 - out);
              }
  
              gradient[i] = g;
          }
  
          return error;
      }
docs: Compute the network output error.
  @param output the desired output.
  @param gradient the array to store gradient on output.
  @return the error defined by loss function.