/**
   * Normalize a single column to the input vector.
   *
   * @param colDef The column to normalize.
   * @param outputColumn The current position in the vector.
   * @param output The vector to output to.
   * @param isInput Is this an input column.
   * @param value The value to normalize.
   * @return The new current position in the vector.
   */
  public int normalizeToVector(
      ColumnDefinition colDef, int outputColumn, double[] output, boolean isInput, String value) {
    MissingHandler handler = null;

    if (this.unknownValues.contains(value)) {
      if (!this.missingHandlers.containsKey(colDef)) {
        throw new EncogError(
            "Do not know how to process missing value \""
                + value
                + "\" in field: "
                + colDef.getName());
      }
      handler = this.missingHandlers.get(colDef);
    }

    if (colDef.getDataType() == ColumnType.continuous) {
      double d = parseDouble(value);
      if (handler != null) {
        d = handler.processDouble(colDef);
      }
      return this.normStrategy.normalizeColumn(colDef, isInput, d, output, outputColumn);
    } else {
      if (handler != null) {
        value = handler.processString(colDef);
      }
      return this.normStrategy.normalizeColumn(colDef, isInput, value, output, outputColumn);
    }
  }
Пример #2
0
  /**
   * Calculate the error for the given method and dataset.
   *
   * @param method The method to use.
   * @param data The data to use.
   * @return The error.
   */
  public double calculateError(MLMethod method, MLDataSet data) {
    if (this.dataset.getNormHelper().getOutputColumns().size() == 1) {
      ColumnDefinition cd = this.dataset.getNormHelper().getOutputColumns().get(0);
      if (cd.getDataType() == ColumnType.nominal) {
        return EncogUtility.calculateClassificationError((MLClassification) method, data);
      }
    }

    return EncogUtility.calculateRegressionError((MLRegression) method, data);
  }