Calculate the error of a neural network. Encog currently supports three error calculation modes. See ErrorCalculationMode for more info.
示例#1
0
 public static double CalculateError(IMLRegression method, IMLDataSet data)
 {
     ErrorCalculation calculation = new ErrorCalculation();
     while (method is IMLContext)
     {
         ((IMLContext) method).ClearContext();
         break;
     }
     foreach (IMLDataPair pair in data)
     {
         IMLData data2 = method.Compute(pair.Input);
         calculation.UpdateError(data2.Data, pair.Ideal.Data, pair.Significance);
     }
     return calculation.Calculate();
 }
        /// <summary>
        /// Calculate an error for a method that uses regression.
        /// </summary>
        /// <param name="method">The method to evaluate.</param>
        /// <param name="data">The training data to evaluate with.</param>
        /// <returns>The error.</returns>
        public static double CalculateError(IMLRegression method,
                                            IMLDataSet data)
        {
            var errorCalculation = new ErrorCalculation();

            // clear context
            if (method is IMLContext)
            {
                ((IMLContext) method).ClearContext();
            }

            // calculate error
            foreach (IMLDataPair pair  in  data)
            {
                IMLData actual = method.Compute(pair.Input);
                errorCalculation.UpdateError(actual, pair.Ideal, pair.Significance);
            }
            return errorCalculation.Calculate();
        }
示例#3
0
        /// <inheritdoc/>
        public override sealed void Iteration()
        {
            var errorCalculation = new ErrorCalculation();

            foreach (IMLDataPair pair  in  _training)
            {
                // calculate the error
                IMLData output = _network.Compute(pair.Input);

                for (int currentAdaline = 0; currentAdaline < output.Count; currentAdaline++)
                {
                    double diff = pair.Ideal[currentAdaline]
                                  - output[currentAdaline];

                    // weights
                    for (int i = 0; i <= _network.InputCount; i++)
                    {
                        double input;

                        if (i == _network.InputCount)
                        {
                            input = 1.0d;
                        }
                        else
                        {
                            input = pair.Input[i];
                        }

                        _network.AddWeight(0, i, currentAdaline,
                                          _learningRate*diff*input);
                    }
                }

                errorCalculation.UpdateError(output, pair.Ideal, pair.Significance);
            }

            // set the global error
            Error = errorCalculation.Calculate();
        }
        /// <summary>
        ///     The SSE error with the current weights.
        /// </summary>
        /// <returns></returns>
        private double CalculateError()
        {
            var result = new ErrorCalculation();

            for (int i = 0; i < _trainingLength; i++)
            {
                _pair = _indexableTraining[i];
                IMLData actual = _network.Compute(_pair.Input);
                result.UpdateError(actual, _pair.Ideal, _pair.Significance);
            }

            return result.CalculateSSE();
        }
示例#5
0
文件: SVMTrain.cs 项目: neismit/emds
 private static double x308cb2f3483de2a6(svm_parameter x0d173b5435b4d6ad, svm_problem xdee3898b83df48b4, double[] x11d58b056c032b03)
 {
     ErrorCalculation calculation;
     int num2;
     double num3;
     int num5;
     int num = 0;
     if (0 == 0)
     {
         if ((((uint) num3) & 0) != 0)
         {
             goto Label_0134;
         }
         goto Label_0108;
     }
     goto Label_008C;
     Label_0055:
     if (num2 >= xdee3898b83df48b4.l)
     {
         return calculation.Calculate();
     }
     Label_008C:
     num3 = xdee3898b83df48b4.y[num2];
     double actual = x11d58b056c032b03[num2];
     if (((uint) num3) < 0)
     {
         goto Label_0108;
     }
     calculation.UpdateError(actual, num3);
     num2++;
     if ((((uint) num3) - ((uint) num3)) >= 0)
     {
         goto Label_0055;
     }
     Label_00D4:
     if ((((uint) num5) & 0) == 0)
     {
         while (num5 < xdee3898b83df48b4.l)
         {
             while (x11d58b056c032b03[num5] == xdee3898b83df48b4.y[num5])
             {
                 num++;
                 if ((((uint) actual) + ((uint) actual)) <= uint.MaxValue)
                 {
                     break;
                 }
             }
             num5++;
         }
     }
     goto Label_0134;
     Label_0108:
     calculation = new ErrorCalculation();
     if (((x0d173b5435b4d6ad.svm_type != 3) && ((((uint) num5) | 3) != 0)) && (x0d173b5435b4d6ad.svm_type != 4))
     {
         num5 = 0;
         if ((((uint) num3) + ((uint) actual)) <= uint.MaxValue)
         {
             goto Label_00D4;
         }
         goto Label_008C;
     }
     num2 = 0;
     goto Label_0055;
     Label_0134:
     return ((100.0 * num) / ((double) xdee3898b83df48b4.l));
 }
        /// <summary>
        /// Process training for pure batch mode (one single batch).
        /// </summary>
        protected void ProcessPureBatch()
        {
            var errorCalc = new ErrorCalculation();
            _visited.Clear();

            foreach (IMLDataPair pair in _training) {
            var input = pair.Input;
            var ideal = pair.Ideal;
            var actual = _network.Compute(input);
            var sig = pair.Significance;

            errorCalc.UpdateError(actual, ideal, sig);

            for (int i = 0; i < _network.OutputCount; i++) {
                var diff = (ideal[i] - actual[i])
                        * sig;
                IFreeformNeuron neuron = _network.OutputLayer.Neurons[i];
                CalculateOutputDelta(neuron, diff);
                CalculateNeuronGradient(neuron);
            }
            }

            // Set the overall error.
            Error = errorCalc.Calculate();

            // Learn for all data.
            Learn();
        }
        /// <summary>
        /// Process training batches.
        /// </summary>
        protected void ProcessBatches()
        {
            int lastLearn = 0;
            var errorCalc = new ErrorCalculation();
            _visited.Clear();

            foreach (IMLDataPair pair in _training) {
            var input = pair.Input;
            var ideal = pair.Ideal;
            var actual = _network.Compute(input);
            var sig = pair.Significance;

            errorCalc.UpdateError(actual, ideal, sig);

            for (int i = 0; i < _network.OutputCount; i++) {
                double diff = (ideal[i] - actual[i])
                        * sig;
                IFreeformNeuron neuron = _network.OutputLayer.Neurons[i];
                CalculateOutputDelta(neuron, diff);
                CalculateNeuronGradient(neuron);
            }

            // Are we at the end of a batch.
            lastLearn++;
            if( lastLearn>=BatchSize ) {
                lastLearn = 0;
                Learn();
            }
            }

            // Handle any remaining data.
            if( lastLearn>0 ) {
            Learn();
            }

            // Set the overall error.
            Error = errorCalc.Calculate();
        }
示例#8
0
 public override sealed void Iteration()
 {
     ErrorCalculation calculation = new ErrorCalculation();
     using (IEnumerator<IMLDataPair> enumerator = this._x823a2b9c8bf459c5.GetEnumerator())
     {
         IMLDataPair pair;
         IMLData data;
         int num;
         double num2;
         int num3;
         double num4;
         goto Label_0032;
     Label_0015:
         calculation.UpdateError(data.Data, pair.Ideal.Data, pair.Significance);
     Label_0032:
         if (enumerator.MoveNext())
         {
             goto Label_010B;
         }
         if ((((uint) num2) - ((uint) num2)) > uint.MaxValue)
         {
             goto Label_0071;
         }
         goto Label_0151;
     Label_0058:
         num3++;
     Label_005E:
         if (num3 <= this._x87a7fc6a72741c2e.InputCount)
         {
             goto Label_00AE;
         }
         num++;
     Label_0071:
         if (num < data.Count)
         {
             goto Label_00ED;
         }
         goto Label_0015;
     Label_0084:
         this._x87a7fc6a72741c2e.AddWeight(0, num3, num, (this._x9b481c22b6706459 * num2) * num4);
         goto Label_0058;
     Label_00A1:
         num4 = 1.0;
         goto Label_0084;
     Label_00AE:
         if (num3 == this._x87a7fc6a72741c2e.InputCount)
         {
             goto Label_00A1;
         }
         num4 = pair.Input[num3];
         if ((((uint) num) + ((uint) num)) <= uint.MaxValue)
         {
             goto Label_0084;
         }
         goto Label_0058;
     Label_00E6:
         num = 0;
         goto Label_0071;
     Label_00ED:
         num2 = pair.Ideal[num] - data[num];
         num3 = 0;
         goto Label_005E;
     Label_010B:
         pair = enumerator.Current;
         if ((((uint) num4) & 0) != 0)
         {
             goto Label_00AE;
         }
         data = this._x87a7fc6a72741c2e.Compute(pair.Input);
         goto Label_00E6;
     }
     Label_0151:
     this.Error = calculation.Calculate();
 }