Ejemplo n.º 1
0
  /**
   * 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();
  }
  public static ObjectPair<double[][], double[][]> trainingToArray(MLDataSet training) {
    int length = (int) training.getRecordCount();
    double[][] a = new double[length][training.getInputSize()];
    double[][] b = new double[length][training.getIdealSize()];

    int index = 0;
    for (MLDataPair pair : training) {
      EngineArray.arrayCopy(pair.getInputArray(), a[index]);
      EngineArray.arrayCopy(pair.getIdealArray(), b[index]);
      index++;
    }

    return new ObjectPair<double[][], double[][]>(a, b);
  }