/**
   * 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();
  }
Esempio n. 2
0
  private MLDataSet[] splitDataSet(MLDataSet data) {

    MLDataSet[] subsets = new MLDataSet[numSplit];

    for (int i = 0; i < subsets.length; i++) {
      subsets[i] = new BasicMLDataSet();
    }

    for (int i = 0; i < data.getRecordCount(); i++) {
      MLDataPair pair = BasicMLDataPair.createPair(INPUT_COUNT, OUTPUT_COUNT);
      data.getRecord(i, pair);
      subsets[i % numSplit].add(pair);
    }

    return subsets;
  }