适用于 c# 的 Encog 3.3 库:我的网络上收到 0.79 错误,但没有改善

本文关键字:错误 Encog 网络 我的 适用于 | 更新日期: 2023-09-27 18:34:28

我是编程新手,我正在尝试学习Encog 3.3库。我致力于制作我的第一个网络。我能够编写和理解代码;但是,我的错误率没有低于 0.79,我使用了 TANH 激活功能。我的网络假设根据我输入的一组变量返回三个值中的 1 个 -1,0,1。有没有人有同样的问题?

这是代码:

        static void Main(string[] args)
    { 
        // creating the neural net : network
        var network = new BasicNetwork();
        network.AddLayer(new BasicLayer(null, true,21));
        network.AddLayer(new BasicLayer( new ActivationTANH(), true,15));
        network.AddLayer(new BasicLayer(new ActivationTANH(), true, 15));
        network.AddLayer(new BasicLayer(new ActivationTANH(), true,1));
        network.Structure.FinalizeStructure();
        network.Reset();

     // creating the training Data
        string Path = "";
        var listArray = GetFile(Path); 
        int amountNumbersY = GetYSize(listArray);
        int amountNumbers = GetXSize(listArray[1]);
        string[,] matrixString = new string[listArray.Length, amountNumbers];                    matrixString = splitter(listArray, amountNumbers); 
        double[][] allData = new double[amountNumbers][]; 
        for (int i = 0; i < allData.Length; i++) 
            allData[i] = new double[amountNumbersY]; 
        allData = ConvertToDouble(matrixString, amountNumbers);
        // creating the inpuit and output
        double[][] XOR_INPUT = new double[amountNumbersY][];  
        for (int i = 0; i < amountNumbersY; i++)
        {
            XOR_INPUT[i] = new double[amountNumbers - 1];
        }
        double[][] XOR_IDEAL = new double[amountNumbersY][];
        for (int i = 0; i < amountNumbersY; i++)
        {
            XOR_IDEAL[i] = new double[1];
        }

        XOR_INPUT = GetInput(allData, amountNumbers, amountNumbersY, 1);
        XOR_IDEAL = GetIdealOutPut(allData, amountNumbers, amountNumbersY, 1);
         // normalizing the Arrays
        double[][] temp_Input = new double[amountNumbersY-1][];
         for (int i = 0; i < amountNumbersY-1; i++) // initializing the x axis
        {
            temp_Input[i] = new double[amountNumbers - 1];
        }
         double[][] temp_Ideal = new double[amountNumbersY-1][]; // same as above for output matrix
        for (int i = 0; i < amountNumbersY-1; i++)
        {
            temp_Ideal[i] = new double[1];
        }
        double[][] closedLoop_temp_Input = new double[amountNumbersY-1][];
        for (int i = 0; i < amountNumbersY-1; i++) // initializing the x axis
        {
            closedLoop_temp_Input[i] = new double[amountNumbers - 1];
        }
        double[][] closedLoop_temp_Ideal = new double[amountNumbersY-1][]; 
        for (int i = 0; i < amountNumbersY-1; i++)
        {
            closedLoop_temp_Ideal[i] = new double[1];
        }
        var hi = 1;
        var lo = -1;
        var norm = new NormalizeArray { NormalizedHigh = hi, NormalizedLow = lo };
        for (int i = 0; i < amountNumbersY-1; i++)
        { 
            temp_Input[i] = norm.Process( XOR_INPUT[i]);
        }
        closedLoop_temp_Input = EngineArray.ArrayCopy(temp_Input);
        var Ideal_Stats = new NormalizedField(NormalizationAction.Normalize,"Temp_Ideal",1,-1,-1,1);
        for (int i = 0; i < amountNumbersY - 1; i++)
        {
            temp_Ideal[i][0] = Ideal_Stats.Normalize(XOR_IDEAL[i][0]);
        }
        closedLoop_temp_Ideal = EngineArray.ArrayCopy(temp_Ideal);
        IMLDataSet trainingSet = new BasicMLDataSet(closedLoop_temp_Input, closedLoop_temp_Ideal);

         // training the network
        IMLTrain train = new ResilientPropagation( network, trainingSet);
        ICalculateScore score = new TrainingSetScore(trainingSet);
        IMLTrain annealing = new NeuralSimulatedAnnealing(network,score,10,2,10);
        int epoch = 1;
         do
         {
             if (epoch == 50)
             {
                 int i = 0;
                 do
                 {
                     annealing.Iteration();
                     Console.WriteLine("Annealing: " + i +", Error: " + annealing.Error);
                     i++;
                 } while (i < 5);
             }
             train.Iteration();
               Console.WriteLine(@" Epoch: "+epoch+ @", Error: "+train.Error+"...");
             epoch ++;
         } while ( train.Error<0.01 || epoch < 1000);
     // testing the network

    }
}

}

适用于 c# 的 Encog 3.3 库:我的网络上收到 0.79 错误,但没有改善

训练率不下降是机器学习中最常见的问题之一。 通常是因为提供给模型的数据根本不支持预测。 您正在训练神经网络来预测给定输入的输出。 考虑是否要对以下输入和预期输出进行训练。 数据可能嘈杂或矛盾。

几点建议。 首先,将训练数据转储到文件中并查看它。 这是你所期望的吗? 是介于 -1 和 1 之间的所有值。 在训练之前,您有相当多的代码发生。 那里可能有问题。

您还采用了某种混合训练方法,包括 RPROP 和退火。 也许只是坚持RPROP,看看会发生什么。