예제 #1
0
  /**
   * Configuration parameters for NeuralNetEvaluator are:
   *
   * <ul>
   *   <li><code>train-data: complex</code> Train data set used in individuals evaluation.
   *       <ul>
   *         <li><code>train-data[@file-name] String </code> File name of train data
   *       </ul>
   *   <li><code>test-data: complex</code> Test data set used in individuals evaluation.
   *       <ul>
   *         <li><code>test-data[@file-name] String </code> File name of test data
   *       </ul>
   *   <li><code>[@normalize-data]: boolean (default = false)</code> If this parameter is set to
   *       <code>true</code> data sets values are normalizated after reading their contents
   *   <li><code>[input-interval] (complex)</code> Input interval of normalization.
   *   <li><code>[output-interval] (complex)</code> Output interval of normalization.
   * </ul>
   *
   * <p>
   *
   * @param settings Configuration object from which the properties are read
   */
  public void configure(Configuration settings) {

    // Set trainData
    unscaledTrainData = new DoubleTransposedDataSet();
    unscaledTrainData.configure(settings.subset("train-data"));

    // Set testData
    unscaledTestData = new DoubleTransposedDataSet();
    unscaledTestData.configure(settings.subset("test-data"));

    // Set normalizer
    normalizer = new Normalizer();

    // Set dataNormalized
    dataNormalized = settings.getBoolean("[@normalize-data]", false);

    // Set dataNormalized
    logTransformation = settings.getBoolean("[@log-input-data]", false);

    if (dataNormalized) {
      // Normalization Input Interval
      Interval interval = new Interval();
      // Configure interval
      interval.configure(settings.subset("input-interval"));
      // Set interval
      setInputInterval(interval);
      // Normalization Output Interval
      interval = new Interval();
      // Configure range
      interval.configure(settings.subset("output-interval"));
      // Set interval
      setOutputInterval(interval);
    }
  }
예제 #2
0
 /**
  * Check if this internal attribute value is valid
  *
  * @return true|false
  */
 @Override
 public boolean isValid(double internalValue) {
   return interval.contains(((Double) internalValue).doubleValue());
 }
예제 #3
0
  /** Normalize data */
  private void normalizeData() {
    if (dataNormalized) {
      // Obtain maximum and minimum values
      unscaledMin = new double[unscaledTrainData.getNofvariables()];
      unscaledMax = new double[unscaledTrainData.getNofvariables()];
      double temp;
      for (int i = 0; i < unscaledTrainData.getNofvariables(); i++) {
        unscaledMax[i] = unscaledTrainData.getMaxValueOf(i);
        temp = unscaledTestData.getMaxValueOf(i);
        if (temp > unscaledMax[i]) unscaledMax[i] = temp;
        unscaledMin[i] = unscaledTrainData.getMinValueOf(i);
        temp = unscaledTestData.getMinValueOf(i);
        if (temp < unscaledMin[i]) unscaledMin[i] = temp;
      }

      // Obtain maximum and minimum desired values
      double[] scaledMin = new double[unscaledTrainData.getNofvariables()];
      double[] scaledMax = new double[unscaledTrainData.getNofvariables()];
      for (int i = 0; i < unscaledTrainData.getNofvariables(); i++) {
        if (i < unscaledTrainData.getNofinputs()) {
          scaledMin[i] = inputInterval.getLeft();
          scaledMax[i] = inputInterval.getRight();
        } else {
          scaledMin[i] = outputInterval.getLeft();
          scaledMax[i] = outputInterval.getRight();
        }
      }

      // Normalize trainData
      scaledTrainData = unscaledTrainData.copy();
      normalizer.scaleDS(scaledTrainData, scaledMax, scaledMin, unscaledMax, unscaledMin);

      // Normalize trainData
      scaledTestData = unscaledTestData.copy();
      normalizer.scaleDS(scaledTestData, scaledMax, scaledMin, unscaledMax, unscaledMin);
    }

    // Remove constant inputs
    int newNofinputs = 0;
    boolean[] toRemove = unscaledTrainData.obtainConstantsInputs();

    for (int i = 0; i < toRemove.length; i++) if (!toRemove[i]) newNofinputs++;

    unscaledTrainData.removeInputs(toRemove, newNofinputs);
    unscaledTestData.removeInputs(toRemove, newNofinputs);

    if (dataNormalized) {
      scaledTrainData.removeInputs(toRemove, newNofinputs);
      scaledTestData.removeInputs(toRemove, newNofinputs);

      // Log transformation
      if (logTransformation) {
        double[][] inputs = scaledTrainData.getAllInputs();

        for (int i = 0; i < inputs.length; i++)
          for (int j = 0; j < inputs[i].length; j++) inputs[i][j] = Math.log(inputs[i][j]);

        inputs = scaledTestData.getAllInputs();

        for (int i = 0; i < inputs.length; i++)
          for (int j = 0; j < inputs[i].length; j++) inputs[i][j] = Math.log(inputs[i][j]);
      }

    }

    // Log transformation
    else if (logTransformation) {
      double[][] inputs = unscaledTrainData.getAllInputs();

      for (int i = 0; i < inputs.length; i++)
        for (int j = 0; j < inputs[i].length; j++) inputs[i][j] = Math.log(inputs[i][j]);

      inputs = unscaledTestData.getAllInputs();

      for (int i = 0; i < inputs.length; i++)
        for (int j = 0; j < inputs[i].length; j++) inputs[i][j] = Math.log(inputs[i][j]);
    }
  }