Esempio n. 1
0
        public static void Test()
        {
            NeuralNetwork neuralNetwork = new NeuralNetwork(new[] { 3, 2, 2 });

            neuralNetwork.W[0] = new Matrix(3, 2, new double[] {
                0.22, 0.10,
                0.08, -0.16,
                -0.07, 0.15
            });

            neuralNetwork.W[1] = new Matrix(2, 2, new double[] {
                0.10, 0.20,
                -0.05, 0.10
            });

            neuralNetwork.BackPropagation(new Vector(new[] { 5d, 10, 15 }),
                                          new Vector(new[] { 0d, 1 }),
                                          0.5);
        }
Esempio n. 2
0
        public void Teach()
        {
            Errors.Clear();

            DateTime t1 = DateTime.Now;

            for (int epoсh = 0; epoсh < EPOCH_NUMBER; epoсh++)
            {
                double epohError = 0;
                //System.Diagnostics.Debug.WriteLine("----" + "epoсh" + epoсh+"----");

                string[] folders = Directory.GetDirectories(m_folder);
                for (int i = 0; i < folders.Length; i++)
                {
                    string[] files = Directory.GetFiles(folders[i]);
                    for (int j = 0; j < files.Length; j++)
                    {
                        char ch = Path.GetFileName(folders[i])[0];

                        double[,,] arrImage = BitmapConverter.BitmapToDoubleRgb(new Bitmap(files[j]));
                        Vector input = ArrayImageService.formInputVectorForNeuralNetwork(arrImage);

                        double err = m_network.BackPropagation(input, LettersInformator.GetVectorForLetter(ch), 0.5);
                        //System.Diagnostics.Debug.WriteLine(String.Format("letter: '{0}'  error: {1:0.0000}", ch, err));

                        epohError += err;
                    }
                }

                Errors.Add(epohError);
                //System.Diagnostics.Debug.WriteLine(String.Format("EPOCH: '{0}'  ERROR: {1:0.0000}", epoсh, epohError));
                //System.Diagnostics.Debug.WriteLine("_________________________________");
            }

            DateTime t2 = DateTime.Now;

            System.Diagnostics.Debug.WriteLine("Время обучения: " + (t2 - t1));
        }