用于c#的Encog 3.3库:我的网络出现0.79错误,但没有改善

时间:2014-12-17 00:47:29

标签: c# networking encog

我是编程新手,我正在尝试学习Encog 3.3库。我努力建立我的第一个网络。我能够写和理解守则;但是,我的错误率不低于0.79,我使用了TANH激活功能。我的网络假设根据我输入的一组变量返回三个值-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


    }
}

}

1 个答案:

答案 0 :(得分:0)

培训率不下降是机器学习中最常见的问题之一。通常是因为给予模型的数据不支持预测。您正在训练神经网络以预测输入的输出。考虑一下你是否要训练以下输入和预期输出。数据可能有噪音或者可能相互矛盾。

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

你也有一种混合训练方法,有RPROP和退火。也许只是坚持RPROP,看看会发生什么。