public static double evaluate(ErrorCalculationMode m, double[] actual, double[] ideal) {
   ErrorCalculation.setMode(m);
   ErrorCalculation error = new ErrorCalculation();
   for (int i = 0; i < actual.length; i++) {
     error.updateError(actual[i], ideal[i]);
   }
   return error.calculate();
 }
  public static double calculateRegressionError(MLRegression method, MLDataSet data) {

    final ErrorCalculation errorCalculation = new ErrorCalculation();
    if (method instanceof MLContext) ((MLContext) method).clearContext();

    for (final MLDataPair pair : data) {
      final MLData actual = method.compute(pair.getInput());
      errorCalculation.updateError(
          actual.getData(), pair.getIdeal().getData(), pair.getSignificance());
    }
    return errorCalculation.calculate();
  }
  /**
   * Calculate the error for this neural network. The error is calculated using
   * root-mean-square(RMS).
   *
   * @param data The training set.
   * @return The error percentage.
   */
  public double calculateError(final MLDataSet data) {
    final ErrorCalculation errorCalculation = new ErrorCalculation();

    final double[] actual = new double[this.outputCount];
    final MLDataPair pair = BasicMLDataPair.createPair(data.getInputSize(), data.getIdealSize());

    for (int i = 0; i < data.getRecordCount(); i++) {
      data.getRecord(i, pair);
      compute(pair.getInputArray(), actual);
      errorCalculation.updateError(actual, pair.getIdealArray(), pair.getSignificance());
    }
    return errorCalculation.calculate();
  }