使用多种训练方法,使用Encog训练人工神经网络(ANN)

5
我想知道在使用 resilient propagation 训练之前,使用遗传算法、粒子群优化和模拟退火等方法训练前馈神经网络是否能够改善结果。
以下是我正在使用的代码:
                    CalculateScore score = new TrainingSetScore(trainingSet);
                    StopTrainingStrategy stop = new StopTrainingStrategy();
                    StopTrainingStrategy stopGA = new StopTrainingStrategy();
                    StopTrainingStrategy stopSIM = new StopTrainingStrategy();
                    StopTrainingStrategy stopPSO = new StopTrainingStrategy();

                    Randomizer randomizer = new NguyenWidrowRandomizer();
                    //Backpropagation train = new Backpropagation((BasicNetwork) network, trainingSet, 0.2, 0.1);
                    //  LevenbergMarquardtTraining train = new LevenbergMarquardtTraining((BasicNetwork) network, trainingSet);
                    int population = 500;
                    MLTrain trainGA =  new MLMethodGeneticAlgorithm(new MethodFactory(){
                        @Override
                        public MLMethod factor() {
                            final BasicNetwork result = createNetwork();
                            ((MLResettable)result).reset();
                            return result;
                        }}, score,population);


                    Date dStart = new Date();

                    int epochGA = 0;
                    trainGA.addStrategy(stopGA);
                    do{
                        trainGA.iteration();
                        if(writeOnStdOut)
                            System.out.println("Epoch Genetic #" + epochGA + " Error:" + trainGA.getError());
                        epochGA++;//0000001
                        previousError = trainGA.getError();
                        Date dtemp = new Date();
                        totsecs = ((double)(dtemp.getTime()-dStart.getTime())/1000);
                    } while(previousError > maximumAcceptedErrorTreshold && epochGA < (maxIterations/5) && !stopGA.shouldStop()  && totsecs < (secs/3));

                    NeuralPSO trainPSO = new NeuralPSO((BasicNetwork) network, randomizer, score, 100);

                    int epochPSO = 0;
                    trainPSO.addStrategy(stopPSO);
                     dStart = new Date();
                    do{
                        trainPSO.iteration();
                        if(writeOnStdOut)
                            System.out.println("Epoch Particle Swarm #" + epochPSO + " Error:" + trainPSO.getError());
                        epochPSO++;//0000001
                        previousError = trainPSO.getError();
                        Date dtemp = new Date();
                        totsecs = ((double)(dtemp.getTime()-dStart.getTime())/1000);
                    } while(previousError > maximumAcceptedErrorTreshold && epochPSO < (maxIterations/5) && !stopPSO.shouldStop() && totsecs < (secs/3));

                    MLTrain trainSIM = new NeuralSimulatedAnnealing((MLEncodable) network, score, startTemperature, stopTemperature, cycles);

                    int epochSA = 0;
                    trainSIM.addStrategy(stopSIM);
                    dStart = new Date();
                    do{
                        trainSIM.iteration();
                        if(writeOnStdOut)
                            System.out.println("Epoch Simulated Annealing #" + epochSA + " Error:" + trainSIM.getError());
                        epochSA++;//0000001
                        previousError = trainSIM.getError();
                        Date dtemp = new Date();
                        totsecs = ((double)(dtemp.getTime()-dStart.getTime())/1000);
                    } while(previousError > maximumAcceptedErrorTreshold && epochSA < (maxIterations/5) && !stopSIM.shouldStop() && totsecs < (secs/3));




                    previousError = 0;
                    BasicTraining train = getTraining(method,(BasicNetwork) network, trainingSet);


                    //train.addStrategy(new Greedy());
                    //trainAlt.addStrategy(new Greedy());
                    HybridStrategy strAnneal = new HybridStrategy(trainSIM);

                    train.addStrategy(strAnneal);
                    //train.addStrategy(strGenetic);
                    //train.addStrategy(strPSO);

                    train.addStrategy(stop);
                    // 
                    //  Backpropagation train = new Backpropagation((ContainsFlat) network, trainingSet, 0.7, 0.3);
                    dStart = new Date();

                    int epoch = 1;

                    do {
                        train.iteration();
                        if(writeOnStdOut)
                            System.out.println("Epoch #" + epoch + " Error:" + train.getError());
                        epoch++;//0000001
                        if(Math.abs(train.getError()-previousError)<0.0000001) iterationWithoutImprovement++; else iterationWithoutImprovement = 0;
                        previousError = train.getError();

                        Date dtemp = new Date();
                        totsecs = ((double)(dtemp.getTime()-dStart.getTime())/1000);
                    } while(previousError > maximumAcceptedErrorTreshold && epoch < maxIterations && !stop.shouldStop() && totsecs < secs);//&& iterationWithoutImprovement < maxiter);

正如您所看到的那样,这是一系列的训练算法,旨在提高整体训练效果。

请告诉我它是否有意义以及代码是否正确。 它似乎正在工作,但我想要确定,因为有时候我会看到 GA 所取得的进展被 PSO 重置。

谢谢。

1个回答

1
似乎很合理,但是不会起作用。使用RPROP的默认参数,这个序列可能不起作用。原因在于,在先前的训练之后,神经网络的权重将接近局部最优解。由于接近局部最优解,只有微小的权重变化才能更接近最优解(降低误差率)。默认情况下,RPROP在权重矩阵上使用0.1的initialUpdate值。对于一个如此接近最优解的网络来说,这是一个巨大的值。这时候你就像是“把公牛放进了瓷器店”。第一次迭代会使网络远离最优解,并且实质上开始了一个新的全局搜索。
降低initialUpdate值应该会有所帮助。我不确定可以降低多少。你可以查看使用你的数据进行训练时平均的RPROP权重更新值,以获得一个概念。或者尝试将其设置为非常小的值,然后逐步增加。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接