public double Evaluate(BasicNetwork network, IMLDataSet training)
        {
            var    rprop         = new ResilientPropagation(network, training);
            double startingError = network.CalculateError(training);

            for (int i = 0; i < ITERATIONS; i++)
            {
                rprop.Iteration();
            }
            double finalError = network.CalculateError(training);

            return(startingError - finalError);
        }
Пример #2
0
        static void Main(string[] args)
        {
            IMLDataSet   trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
            BasicNetwork network     = EncogUtility.SimpleFeedForward(2, 6, 0, 1, false);

            EncogUtility.TrainToError(network, trainingSet, 0.01);
            double error = network.CalculateError(trainingSet);

            Console.WriteLine($"Error before save to EG: {error}");
            EncogDirectoryPersistence.SaveObject(new FileInfo(FILENAME), network);
            network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(new FileInfo(FILENAME));
            error   = network.CalculateError(trainingSet);
            Console.WriteLine($"Error after load from EG: {error}");
        }
Пример #3
0
        public void Execute(IExampleInterface app)
        {
            this.app = app;
            IMLDataSet   trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
            BasicNetwork network     = EncogUtility.SimpleFeedForward(2, 6, 0, 1, false);

            EncogUtility.TrainToError(network, trainingSet, 0.01);
            double error = network.CalculateError(trainingSet);

            EncogDirectoryPersistence.SaveObject(new FileInfo(FILENAME), network);
            double error2 = network.CalculateError(trainingSet);

            app.WriteLine("Error before save to EG: " + Format.FormatPercent(error));
            app.WriteLine("Error before after to EG: " + Format.FormatPercent(error2));
        }
Пример #4
0
        public void Execute(IExampleInterface app)
        {
            this.app = app;
            this.app = app;
            IMLDataSet   trainingSet = new BasicMLDataSet(XOR_INPUT, XOR_IDEAL);
            BasicNetwork network     = EncogUtility.SimpleFeedForward(2, 6, 0, 1, false);

            EncogUtility.TrainToError(network, trainingSet, 0.01);
            double error = network.CalculateError(trainingSet);

            SerializeObject.Save("encog.ser", network);
            network = (BasicNetwork)SerializeObject.Load("encog.ser");
            double error2 = network.CalculateError(trainingSet);

            app.WriteLine("Error before save to ser: " + Format.FormatPercent(error));
            app.WriteLine("Error before after to ser: " + Format.FormatPercent(error2));
        }
Пример #5
0
        public double[][] Train(double[][] trainingData, double[][] validationData)
        {
            var error = new List <double[]>();

            PrepareNormalizerFor(trainingData, validationData);

            var trainingSet   = PrepareSet(trainingData);
            var validationSet = PrepareSet(validationData);

            var training = new Backpropagation(_network, trainingSet, _settings.LearningRate, _settings.Momentum)
            {
                BatchSize = 1
            };

            for (int epoch = 0; epoch < _settings.Iterations; epoch++)
            {
                training.Iteration();
                double trainingError = -1;
                double testingError  = -1;

                if (_settings.Type == ProblemType.Regression)
                {
                    trainingError = _network.CalculateError(trainingSet);
                    if (validationSet != null)
                    {
                        testingError = _network.CalculateError(validationSet);
                    }
                }
                else
                {
                    trainingError = CalculateClassificationError(trainingSet);
                    if (validationSet != null)
                    {
                        testingError = CalculateClassificationError(validationSet);
                    }
                }
                var errorIter = new[] { epoch, trainingError, testingError };
                error.Add(errorIter);
                Console.WriteLine($"Epoch #{epoch} [{training.Error}] TrainingError: {errorIter[1]} ValidationError: {errorIter[2]}");
            }
            training.FinishTraining();

            return(error.ToArray());
        }
Пример #6
0
        private void BtnComprobar_Click(object sender, EventArgs e)
        {
            try
            {
                if (i0 != null)
                {
                    this.conect.Open();

                    OleDbCommand    comando    = new OleDbCommand(string.Format("select ArchivoNeuronal,Tamano from tbl_firmas where Pnombre = '{0}' and PApellido = '{1}' ", txtNombre.Text, txtApellido.Text), this.conect);
                    OleDbDataReader lector     = comando.ExecuteReader();
                    string          dirArchivo = null;

                    if (lector.HasRows)
                    {
                        while (lector.Read())
                        {
                            dirArchivo = Application.StartupPath + "\\" + lector.GetString(0);
                            tam        = lector.GetString(1);
                        }

                        BasicNetwork RedExtraida = (BasicNetwork)EncogDirectoryPersistence.LoadObject(new FileInfo(dirArchivo));

                        IMLDataSet par = new BasicMLDataSet(E, IDEAL);

                        double Respuesta = RedExtraida.CalculateError(par);

                        if (Respuesta <= .20)
                        {
                            MessageBox.Show("La firma Introducida Tiene un nivel de aceptacion del : " + Convert.ToString(100 - Math.Round(Respuesta, 3) * 100) + "%, la firma ha sido ACEPTADA");
                        }
                        else
                        {
                            MessageBox.Show("La firma Introducida Tiene un nivel de aceptacion del : " + Convert.ToString(100 - Math.Round(Respuesta, 3) * 100) + "%, la firma ha sido RECHAZADA");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Nombre y apellido no existe");
                    }
                }
                else
                {
                    MessageBox.Show("No hay imagen cargada");
                }
            }
            catch (System.ArgumentException)
            {
                MessageBox.Show("Verifique que la imagen tenga un tamaño de " + tam);
            }
            this.conect.Close();
        }
        public double EvaluateMPROP(BasicNetwork network, IMLDataSet data)
        {
            var  train = new ResilientPropagation(network, data);
            long start = DateTime.Now.Ticks;

            Console.WriteLine(@"Training 20 Iterations with MPROP");
            for (int i = 1; i <= 20; i++)
            {
                train.Iteration();
                Console.WriteLine("Iteration #" + i + " Error:" + train.Error);
            }
            //train.finishTraining();
            long   stop = DateTime.Now.Ticks;
            double diff = new TimeSpan(stop - start).Seconds;

            Console.WriteLine("MPROP Result:" + diff + " seconds.");
            Console.WriteLine("Final MPROP error: " + network.CalculateError(data));
            return(diff);
        }
Пример #8
0
        static void Main(string[] args)
        {
            string       ruta_datos = "C:\\Users\\soyal\\Downloads\\Muestra2RGBC.csv";
            StreamReader lector     = new StreamReader(ruta_datos);
            var          lineas     = new List <string[]>();

            string[] Linea;
            while (!lector.EndOfStream)
            {
                Linea = lector.ReadLine().Split(',');
                lineas.Add(Linea);
            }
            double[][] Input  = new double[lineas.Count][];
            double[][] Output = new double[lineas.Count][];
            for (int i = 0; i < lineas.Count; i++)
            {
                Input[i]     = new double[4];
                Output[i]    = new double[6];
                Input[i][0]  = Convert.ToDouble(lineas[i][0]);      //Canal R
                Input[i][1]  = Convert.ToDouble(lineas[i][1]);      //Canal G
                Input[i][2]  = Convert.ToDouble(lineas[i][2]);      //Canal B
                Input[i][3]  = Convert.ToDouble(lineas[i][3]);      //Canal C
                Output[i][0] = Convert.ToDouble(lineas[i][4]);      //1 si es rojo
                Output[i][1] = Convert.ToDouble(lineas[i][5]);      //1 si es naranja
                Output[i][2] = Convert.ToDouble(lineas[i][6]);      //1 si es amarillo
                Output[i][3] = Convert.ToDouble(lineas[i][7]);      //1 si es verde
                Output[i][4] = Convert.ToDouble(lineas[i][8]);      //1 si es azul
                Output[i][5] = Convert.ToDouble(lineas[i][9]);      //1 si es cafe
                Console.WriteLine("\t" + Input[i][0] + "\t" + Input[i][1] + "\t" + Input[i][2] + "\t" + Input[i][3] + "\t" + Output[i][0] + "\t" + Output[i][1] + "\t" + Output[i][2] + "\t" + Output[i][3] + "\t" + Output[i][4] + "\t" + Output[i][5] + "\t");
            }
            Console.ReadKey();
            string       ruta_red    = "C:\\Users\\soyal\\Downloads\\TrainRGBC4to6.csv";
            IMLDataSet   trainingSet = new BasicMLDataSet(Input, Output);                     //Se dan entradas y salidas a la red
            BasicNetwork network     = EncogUtility.SimpleFeedForward(4, 200, 200, 6, false); //Diseño de red

            EncogUtility.TrainToError(network, trainingSet, 0.0001);                          //Método de entrenamiento
            double error = network.CalculateError(trainingSet);

            EncogDirectoryPersistence.SaveObject(new FileInfo(ruta_red), network);  //Guardar red entrenada
            Console.WriteLine("Ready");
            Console.ReadKey();
        }
Пример #9
0
        static void Main(string[] args)
        {
            //Datos excel
            string       ruta_datos = "C:\\Users\\soyal\\OneDrive - UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO\\Documentos\\2020-2\\InteligenciaArtificial\\Encog\\DatosEntrenamiento.csv";
            StreamReader lector     = new StreamReader(ruta_datos);
            var          lineas     = new List <string[]>();

            string[] Linea;
            while (!lector.EndOfStream)
            {
                Linea = lector.ReadLine().Split(',');
                lineas.Add(Linea);
            }


            double[][] Input  = new double[lineas.Count][];
            double[][] Output = new double[lineas.Count][];
            for (int i = 0; i < lineas.Count; i++)
            {
                Input[i]     = new double[2];
                Output[i]    = new double[1];
                Input[i][0]  = Convert.ToDouble(lineas[i][0]);;
                Input[i][1]  = Convert.ToDouble(lineas[i][1]);
                Output[i][0] = Convert.ToDouble(lineas[i][2]);
                Console.WriteLine("|" + Input[i][0] + "|" + Input[i][1] + "|" + Output[i][0] + "|");
            }

            Console.ReadKey();

            string       ruta_red    = "C:\\Users\\soyal\\OneDrive - UNIVERSIDAD NACIONAL AUTÓNOMA DE MÉXICO\\Documentos\\2020-2\\InteligenciaArtificial\\Encog\\Train.txt";
            IMLDataSet   trainingSet = new BasicMLDataSet(Input, Output);                 //Se dan entradas y salidas a la red
            BasicNetwork network     = EncogUtility.SimpleFeedForward(2, 6, 0, 1, false); //Diseño de red

            EncogUtility.TrainToError(network, trainingSet, 0.0001);                      //Método de entrenamiento
            double error = network.CalculateError(trainingSet);

            EncogDirectoryPersistence.SaveObject(new FileInfo(ruta_red), network);  //Guardar red entrenada
            Console.WriteLine("Ready");
            Console.ReadKey();
        }
Пример #10
0
        void trainWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int epoch = 1;

            do
            {
                if (trainWorker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }
                else
                {
                    Wait(100);
                    train.Iteration();
                    var IterationResults = new KeyValuePair <int, double> [2];
                    IterationResults[0] = new KeyValuePair <int, double>(epoch, train.Error);;
                    IterationResults[1] = new KeyValuePair <int, double>(epoch, network.CalculateError(crossValidationSet));
                    trainWorker.ReportProgress(epoch, IterationResults);
                    epoch++;
                }
            } while (train.Error > 0.01);
        }
Пример #11
0
 /// <summary>
 /// Calculate the error for the neural network with a given set of weights.
 /// </summary>
 /// <param name="weights">The weights to use.</param>
 /// <returns>The current error.</returns>
 public double Fn(double[] weights)
 {
     NetworkCODEC.ArrayToNetwork(weights, _network);
     return(_network.CalculateError(Training));
 }
Пример #12
0
 /// <summary>
 /// Calculate the score for the network.
 /// </summary>
 /// <param name="network">The network to calculate for.</param>
 /// <returns>The score.</returns>
 public double CalculateScore(BasicNetwork network)
 {
     return(network.CalculateError(this.training));
 }
Пример #13
0
 /// <summary>
 /// Calculate the score for the network. 
 /// </summary>
 /// <param name="network">The network to calculate for.</param>
 /// <returns>The score.</returns>
 public double CalculateScore(BasicNetwork network)
 {
     return network.CalculateError(this.training);
 }