Beispiel #1
0
 /** Utility method to switch from List<Double> to MLData */
 public static BasicNeuralData neuralDataFromListOfDouble(List<Double> doubleList) {
   BasicNeuralData result = new BasicNeuralData(doubleList.size());
   for (int i = 0; i < doubleList.size(); i++) {
     result.setData(i, doubleList.get(i));
   }
   return result;
 }
Beispiel #2
0
  public static NeuralDataSet generateTraining() {
    NeuralDataSet result = new BasicNeuralDataSet();
    for (int i = 0; i < DIGITS.length; i++) {
      BasicNeuralData ideal = new BasicNeuralData(DIGITS.length);

      // setup input
      NeuralData input = image2data(DIGITS[i]);

      // setup ideal
      for (int j = 0; j < DIGITS.length; j++) {
        if (j == i) ideal.setData(j, 1);
        else ideal.setData(j, -1);
      }

      // add training element
      result.add(input, ideal);
    }
    return result;
  }
  /**
   * Generate input neural data for the specified index.
   *
   * @param index The index to generate neural data for.
   * @return The input neural data generated.
   */
  public BasicNeuralData generateInputNeuralData(final int index) {
    if (index + this.inputWindowSize > this.points.size()) {
      throw new TemporalError(
          "Can't generate input temporal data " + "beyond the end of provided data.");
    }

    final BasicNeuralData result = new BasicNeuralData(this.inputNeuronCount);
    int resultIndex = 0;

    for (int i = 0; i < this.inputWindowSize; i++) {
      int descriptionIndex = 0;

      for (final TemporalDataDescription desc : this.descriptions) {
        if (desc.isInput()) {
          result.setData(resultIndex++, formatData(desc, index + i));
        }
        descriptionIndex++;
      }
    }
    return result;
  }