Beispiel #1
0
            public void Learn(List <SygmoidNeural> learn)
            {
                CSVFileGetData cSVFileGetData = new CSVFileGetData();

                for (int g = 0; g < Epoch; g++)
                {
                    // считать данные
                    cSVFileGetData.GetData(g);
                    // передать данные на вход
                    for (int i = 0; i < 784; i++)
                    {
                        if (cSVFileGetData.Data[i] == 0.0)
                        {
                        }
                        learn[i].X = cSVFileGetData.Data[i];
                    }

                    int count = 0;
                    foreach (ILearn n in learn)
                    {
                        //Console.WriteLine(count);
                        n.Function();
                        n.OutWeight();
                        count++;
                    }
                    // передать ошибку выходным нейронам
                    for (int i = 884; i < 894; i++)
                    {
                        learn[i].ErrorNumber = Math.Abs(learn[i].XResult - cSVFileGetData.TrueAnswer[i - 884]);
                        //Console.WriteLine(OutputNeurals[i].ErrorNumber+"Error output");
                        //Console.WriteLine();
                        //Console.WriteLine();
                        //Console.WriteLine();
                        //Console.WriteLine();
                        //Console.WriteLine(OutputNeurals[i].XResult+"--------------");
                        //Console.WriteLine(OutputNeurals[i].X + "Input-");
                    }


                    for (int i = learn.Count - 1; i >= 0; i--)
                    {
                        //Console.WriteLine(i + " learn elemnt");
                        learn[i].Learn();
                    }
                    Console.WriteLine(g + " epoch complete");
                    double SumLayerInput  = 0;
                    double SumLayerHidden = 0;
                    double SumLayerOutput = 0;

                    foreach (SygmoidNeural n in InputNeurals)
                    {
                        SumLayerInput += n.ErrorNumberLayer;
                    }

                    foreach (SygmoidNeural n in HiddenNeurals)
                    {
                        SumLayerHidden += n.ErrorNumberLayer;
                    }

                    foreach (SygmoidNeural n in OutputNeurals)
                    {
                        SumLayerOutput += n.ErrorNumberLayer;
                    }

                    Console.WriteLine(SumLayerInput + " SumLayerInput");

                    Console.WriteLine(SumLayerHidden + " SumLayerHidden");

                    Console.WriteLine(SumLayerOutput + " SumLayerOutput");

                    SumLayerInput  = 0;
                    SumLayerHidden = 0;
                    SumLayerOutput = 0;

                    //for (int i = 0; i < 10; i++)
                    //{
                    //    Console.WriteLine(AllNeurals[i].Weight[0].weight + "------------neural epoch");
                    //}
                    //Console.WriteLine();
                    //Console.WriteLine();
                    //Console.WriteLine();

                    //foreach (SygmoidNeural n in HiddenNeurals)
                    //{
                    //    if (n.Weight != null)
                    //    {
                    //        foreach (Weight nn in n.Weight)
                    //            Console.WriteLine(nn.weight + "-------------------");
                    //    }
                    //}
                }
            }
Beispiel #2
0
            public void ToDetermine()
            {
                // считать данные
                CSVFileGetData cSVFileGetData = new CSVFileGetData();
                List <double>  outAnswer      = new List <double>();

                for (int g = 500; g < 530; g++)
                {
                    // передать данные на входные нейроны
                    cSVFileGetData.GetData(g);

                    for (int i = 0; i < InputNeurals.Count; i++)
                    {
                        //if (i == 295)
                        //{
                        //    Console.WriteLine(cSVFileGetData.Data[i] + "-----------------");
                        //}
                        //Console.WriteLine(cSVFileGetData.Data[i] + "-----------------"+i);
                        InputNeurals[i].X = cSVFileGetData.Data[i];
                    }

                    //for(int i=0;i<784;i++)
                    //{
                    //    Console.WriteLine(AllNeurals[i].X + " AllNeurals input");
                    //    Console.WriteLine(InputNeurals[i].X + " InputNeurals input");
                    //}
                    // посчитать результат
                    foreach (SygmoidNeural n in AllNeurals)
                    {
                        n.Function();
                        n.OutWeight();
                    }



                    foreach (SygmoidNeural n in OutputNeurals)
                    {
                        Console.WriteLine(n.XResult);
                        //Console.WriteLine(n.X + "-----------------------");
                        outAnswer.Add(n.XResult);
                    }

                    //for (int i = 884; i < 894; i++)
                    //{
                    //    Console.WriteLine(AllNeurals[i].XResult + " AllNeurals input");
                    //    //Console.WriteLine(OutputNeurals[i - 884].XResult + " OutputNeurals input");
                    //}


                    // считать результат выходных нейронов
                    for (int i = 0; i < outAnswer.Count; i++)
                    {
                        if (CompareBoolean(outAnswer[i], outAnswer))
                        {
                            //foreach (double nn in outAnswer)
                            //{
                            //    Console.WriteLine(nn);
                            //}

                            Console.WriteLine("Answer:" + i + ". Real answer:" + cSVFileGetData.TrueAnswerNumber);
                            break;
                        }
                    }

                    outAnswer.Clear();



                    // другой метод подсчёта

                    // передать данные на входные нейроны
                    for (int i = 0; i < InputNeurals.Count; i++)
                    {
                        //if (i == 295)
                        //{
                        //    Console.WriteLine(cSVFileGetData.Data[i] + "-----------------");
                        //}
                        //Console.WriteLine(cSVFileGetData.Data[i] + "-----------------"+i);
                        InputNeurals[i].X = cSVFileGetData.Data[i];
                    }

                    // пропустить через сигмоид
                    for (int i = 0; i < InputNeurals.Count; i++)
                    {
                        InputNeurals[i].XResult = SygmoidFunction(InputNeurals[i].X);
                        InputNeurals[i].X       = 0;
                    }

                    double X;
                    // посчитать результат
                    for (int i = 0; i < HiddenNeurals.Count; i++)
                    {
                        X = 0;
                        for (int ii = 0; ii < HiddenNeurals[i].PreviousLayer.Count; ii++)
                        {
                            X += HiddenNeurals[i].PreviousLayer[ii].XResult * HiddenNeurals[i].PreviousWeight[ii].weight;
                        }
                        HiddenNeurals[i].X = X;
                    }

                    // пропустить через сигмоид
                    for (int i = 0; i < HiddenNeurals.Count; i++)
                    {
                        HiddenNeurals[i].XResult = SygmoidFunction(HiddenNeurals[i].X);
                        HiddenNeurals[i].X       = 0;
                    }



                    for (int i = 0; i < OutputNeurals.Count; i++)
                    {
                        X = 0;
                        for (int ii = 0; ii < OutputNeurals[i].PreviousLayer.Count; ii++)
                        {
                            X += OutputNeurals[i].PreviousLayer[ii].XResult * OutputNeurals[i].PreviousWeight[ii].weight;
                        }
                        OutputNeurals[i].X = X;
                    }

                    // пропустить через сигмоид
                    for (int i = 0; i < OutputNeurals.Count; i++)
                    {
                        OutputNeurals[i].XResult = SygmoidFunction(OutputNeurals[i].X);
                        OutputNeurals[i].X       = 0;
                    }

                    foreach (SygmoidNeural n in OutputNeurals)
                    {
                        Console.WriteLine(n.XResult);
                        //Console.WriteLine(n.X + "-----------------------");
                        outAnswer.Add(n.XResult);
                    }

                    // считать результат выходных нейронов
                    for (int i = 0; i < outAnswer.Count; i++)
                    {
                        if (CompareBoolean(outAnswer[i], outAnswer))
                        {
                            //foreach (double nn in outAnswer)
                            //{
                            //    Console.WriteLine(nn);
                            //}

                            Console.WriteLine("Answer:" + i + ". Real answer:" + cSVFileGetData.TrueAnswerNumber);
                            break;
                        }
                    }

                    outAnswer.Clear();

                    Console.WriteLine();
                    Console.WriteLine(g + " Iteration complete");
                    Console.WriteLine();
                }
            }