Package org.encog.ml.data

Examples of org.encog.ml.data.MLData


  /**
   * {@inheritDoc}
   */
  @Override
  public MLData compute(final MLData input) {
    final MLData temp = computeInstar(input);
    return computeOutstar(temp);
  }
View Full Code Here


   * Compute the instar layer.
   * @param input The input.
   * @return The output.
   */
  public MLData computeInstar(final MLData input) {
    final MLData result = new BasicMLData(this.instarCount);
    int w, i, j;
    double sum, sumWinners, maxOut;
    int winner = 0;
    final boolean[] winners = new boolean[this.instarCount];

    for (i = 0; i < this.instarCount; i++) {
      sum = 0;
      for (j = 0; j < this.inputCount; j++) {
        sum += this.weightsInputToInstar.get(j, i) * input.getData(j);
      }
      result.setData(i, sum);
      winners[i] = false;
    }
    sumWinners = 0;
    for (w = 0; w < this.winnerCount; w++) {
      maxOut = Double.MIN_VALUE;
      for (i = 0; i < this.instarCount; i++) {
        if (!winners[i] && (result.getData(i) > maxOut)) {
          winner = i;
          maxOut = result.getData(winner);
        }
      }
      winners[winner] = true;
      sumWinners += result.getData(winner);
    }
    for (i = 0; i < this.instarCount; i++) {
      if (winners[i]
          && (Math.abs(sumWinners) > Encog.DEFAULT_DOUBLE_EQUAL)) {
        result.getData()[i] /= sumWinners;
      } else {
        result.getData()[i] = 0;
      }
    }

    return result;
  }
View Full Code Here

    }

    final ErrorCalculation error = new ErrorCalculation();

    for (final MLDataPair pair : this.training) {
      final MLData out = this.network.computeInstar(pair.getInput());

      final int j = EngineArray.indexOfLargest(out.getData());
      for (int i = 0; i < this.network.getOutstarCount(); i++) {
        final double delta = this.learningRate
            * (pair.getIdeal().getData(i) - this.network
                .getWeightsInstarToOutstar().get(j, i));
        this.network.getWeightsInstarToOutstar().add(j, i, delta);
      }

      final MLData out2 = this.network.computeOutstar(out);
      error.updateError(out2.getData(), pair.getIdeal().getData(), pair.getSignificance());
    }

    setError(error.calculate());
  }
View Full Code Here

   * Compute the outstar layer.
   * @param input The input.
   * @return The output.
   */
  public MLData computeOutstar(final MLData input) {
    final MLData result = new BasicMLData(this.outstarCount);

    double sum = 0;

    for (int i = 0; i < this.outstarCount; i++) {
      sum = 0;
      for (int j = 0; j < this.instarCount; j++) {
        sum += this.weightsInstarToOutstar.get(j, i) * input.getData(j);
      }
      result.setData(i, sum);
    }
    return result;
  }
View Full Code Here

   *            The input to this synapse.
   * @return The output from this synapse.
   */
  @Override
  public MLData compute(final MLData input) {
    final MLData result = new BasicMLData(this.outputCount);

    // clear from previous
    EngineArray.fill(this.preActivation, 0.0);
    EngineArray.fill(this.postActivation, 0.0);
    this.postActivation[0] = 1.0;

    // copy input
    EngineArray.arrayCopy(input.getData(), 0, this.postActivation, 1,
        this.inputCount);

    // iterate through the network activationCycles times
    for (int i = 0; i < this.activationCycles; ++i) {
      internalCompute();
    }

    // copy output
    EngineArray.arrayCopy(this.postActivation, this.outputIndex,
        result.getData(), 0, this.outputCount);

    return result;
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  @Override
  public int classify(MLData input) {
    MLData output = compute(input);
    return EngineArray.maxIndex(output.getData());
  }
View Full Code Here

  protected void processPureBatch() {
    final ErrorCalculation errorCalc = new ErrorCalculation();
    this.visited.clear();

    for (final MLDataPair pair : this.training) {
      final MLData input = pair.getInput();
      final MLData ideal = pair.getIdeal();
      final MLData actual = this.network.compute(input);
      final double sig = pair.getSignificance();

      errorCalc.updateError(actual.getData(), ideal.getData(), sig);

      for (int i = 0; i < this.network.getOutputCount(); i++) {
        final double diff = (ideal.getData(i) - actual.getData(i))
            * sig;
        final FreeformNeuron neuron = this.network.getOutputLayer()
            .getNeurons().get(i);
        calculateOutputDelta(neuron, diff);
        calculateNeuronGradient(neuron);
View Full Code Here

    int lastLearn = 0;
    final ErrorCalculation errorCalc = new ErrorCalculation();
    this.visited.clear();

    for (final MLDataPair pair : this.training) {
      final MLData input = pair.getInput();
      final MLData ideal = pair.getIdeal();
      final MLData actual = this.network.compute(input);
      final double sig = pair.getSignificance();

      errorCalc.updateError(actual.getData(), ideal.getData(), sig);

      for (int i = 0; i < this.network.getOutputCount(); i++) {
        final double diff = (ideal.getData(i) - actual.getData(i))
            * sig;
        final FreeformNeuron neuron = this.network.getOutputLayer()
            .getNeurons().get(i);
        calculateOutputDelta(neuron, diff);
        calculateNeuronGradient(neuron);
View Full Code Here

          && section.getSubSectionName().equals("SAMPLES")) {
        for (final String line : section.getLines()) {
          final List<String> cols = EncogFileSection
              .splitColumns(line);
          int index = 0;
          final MLData inputData = new BasicMLData(inputCount);
          for (int i = 0; i < inputCount; i++) {
            inputData.setData(i,
                CSVFormat.EG_FORMAT.parse(cols.get(index++)));
          }
          final MLData idealData = new BasicMLData(outputCount);
          idealData.setData(0,CSVFormat.EG_FORMAT.parse(cols.get(index++)));
          final MLDataPair pair = new BasicMLDataPair(inputData,idealData);
          samples.add(pair);
        }
      }
    }
View Full Code Here

    bmu.reset();

    // Determine the BMU for each training element.
    for (final MLDataPair pair : data) {
      final MLData input = pair.getInput();
      bmu.calculateBMU(input);
    }

    // update the error
    return bmu.getWorstDistance() / 100.0;
View Full Code Here

TOP

Related Classes of org.encog.ml.data.MLData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.