Package org.encog.mathutil.error

Examples of org.encog.mathutil.error.ErrorCalculation


   * {@inheritDoc}
   */
  @Override
  public final void iteration() {

    final ErrorCalculation errorCalculation = new ErrorCalculation();

    for (final MLDataPair pair : this.training) {
      // calculate the error
      final MLData output = this.network.compute(pair.getInput());

      for (int currentAdaline = 0; currentAdaline < output.size(); currentAdaline++) {
        final double diff = pair.getIdeal().getData(currentAdaline)
            - output.getData(currentAdaline);

        // weights
        for (int i = 0; i <= this.network.getInputCount(); i++) {
          final double input;

          if (i == this.network.getInputCount()) {
            input = 1.0;
          } else {
            input = pair.getInput().getData(i);
          }

          this.network.addWeight(0, i, currentAdaline,
              this.learningRate * diff * input);
        }
      }

      errorCalculation.updateError(output.getData(), pair.getIdeal()
          .getData(),pair.getSignificance());
    }

    // set the global error
    setError(errorCalculation.calculate());
  }
View Full Code Here


   * @param data
   *            The training set.
   * @return The error percentage.
   */
  public final 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();
  }
View Full Code Here

    if (this.mustInit) {
      initWeight();
    }

    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

   }

  public static double calculateRegressionError(MLRegression method,
      MLDataSet data) {
   
    final ErrorCalculation errorCalculation = new ErrorCalculation();
    if( method instanceof MLContext )
      ((MLContext)method).clearContext();

    for (final MLDataPair pair : data) {
      final MLData actual = method.compute(pair.getInput());
      errorCalculation.updateError(actual.getData(), pair.getIdeal()
          .getData(),pair.getSignificance());
    }
    return errorCalculation.calculate();
  }
View Full Code Here

public class CalculateRegressionError {
 
  public static double calculateError(final MLRegression method,
      final MLDataSet data) {
    final ErrorCalculation errorCalculation = new ErrorCalculation();
   
    // clear context
    if( method instanceof MLContext ) {
      ((MLContext)method).clearContext();
    }

    // calculate error
    for (final MLDataPair pair : data) {
      final MLData actual = method.compute(pair.getInput());
      errorCalculation.updateError(actual.getData(), pair.getIdeal()
          .getData(),pair.getSignificance());
    }
    return errorCalculation.calculate();
  }
View Full Code Here

   */
  public static double evaluate(final svm_parameter param, final svm_problem prob,
      final double[] target) {
    int totalCorrect = 0;

    final ErrorCalculation error = new ErrorCalculation();

    if ((param.svm_type == svm_parameter.EPSILON_SVR)
        || (param.svm_type == svm_parameter.NU_SVR)) {
      for (int i = 0; i < prob.l; i++) {
        final double ideal = prob.y[i];
        final double actual = target[i];
        error.updateError(actual, ideal);
      }
      return error.calculate();
    } else {
      for (int i = 0; i < prob.l; i++) {
        if (target[i] == prob.y[i]) {
          ++totalCorrect;
        }
View Full Code Here

        {1,2,3,5},
        {5,6,7,8},
        {9,10,11,12},
        {13,14,15,16} };
   
    ErrorCalculation error = new ErrorCalculation();
   
    for(int i=0;i<ideal.length;i++)
    {
      error.updateError(actual_good[i], ideal[i], 1.0);
    }
    TestCase.assertEquals(0.0,error.calculateRMS());
   
    error.reset();
   
    for(int i=0;i<ideal.length;i++)
    {
      error.updateError(actual_bad[i], ideal[i], 1.0);
    }
    TestCase.assertEquals(250,(int)(error.calculateRMS()*1000));
   
  }
 
View Full Code Here

 
  private void internalCompute(int outputNeuron) {
    double e;

    int row = 0;
    ErrorCalculation error = new ErrorCalculation();
   
    double[] derivative = new double[weightCount];
   
    // Loop over every training element
    for (final MLDataPair pair : this.training) {
      EngineArray.fill(derivative, 0);
      final MLData networkOutput = this.network.compute(pair.getInput());

      e = pair.getIdeal().getData(outputNeuron) - networkOutput.getData(outputNeuron);     
      error.updateError(networkOutput.getData(outputNeuron), pair.getIdeal().getData(outputNeuron));
     
      int currentWeight = 0;
     
      // loop over the output weights
      int outputFeedCount  = network.getLayerTotalNeuronCount(network.getLayerCount()-2);
      for(int i=0;i<this.network.getOutputCount();i++) {
        for(int j=0;j<outputFeedCount;j++) {
          double jc;
         
          if (i == outputNeuron) {
            jc = computeDerivative(pair.getInput(), outputNeuron,
                currentWeight, this.dStep,
                networkOutput.getData(outputNeuron), row);
          } else {
            jc = 0;
          }
     
          this.gradients[currentWeight] += jc *e;
          derivative[currentWeight] = jc;
          currentWeight++;
        }
      }
     
      // Loop over every weight in the neural network
      while( currentWeight<this.network.getFlat().getWeights().length) {
        double jc = computeDerivative(
            pair.getInput(), outputNeuron, currentWeight,
            this.dStep,
            networkOutput.getData(outputNeuron), row);
        derivative[currentWeight] = jc;
        this.gradients[currentWeight] += jc *e;
        currentWeight++;
      }

      row++;
      updateHessian(derivative);
    }
   
   

    sse+= error.calculateESS();
  }
View Full Code Here

   * @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();
  }
View Full Code Here

    if (this.mustInit) {
      initWeight();
    }

    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

TOP

Related Classes of org.encog.mathutil.error.ErrorCalculation

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.