埃尔曼网络不停

时间:2014-11-10 04:22:49

标签: java machine-learning neural-network encog

我对XOR运算符的Elman网络训练不会停止,它会进行数百万次迭代。任何帮助将不胜感激!

package org.encog.example;

import org.encog.Encog;
import org.encog.engine.network.activation.ActivationSigmoid;
import org.encog.ml.train.MLTrain;
import org.encog.neural.data.NeuralDataSet;
import org.encog.neural.data.basic.BasicNeuralDataSet;
import org.encog.neural.networks.BasicNetwork;
import org.encog.neural.networks.training.propagation.back.Backpropagation;
import org.encog.neural.pattern.ElmanPattern;

public class XORRNN {

    // 4 row, 2 column
    public static double XOR_INPUT[][] = { { 0.0, 0.0 }, { 1.0, 0.0 },
            { 0.0, 1.0 }, { 1.0, 1.0 } };

    // 4 row, 1 column
    public static double XOR_IDEAL[][] = { { 0.0 }, { 1.0 }, { 1.0 }, { 0.0 } };

    public static void main(String[] args) {

        //create Elman RNN
        ElmanPattern elmanPattern = new ElmanPattern();
        elmanPattern.setInputNeurons(2);
        elmanPattern.addHiddenLayer(4);
        elmanPattern.setOutputNeurons(1);
        elmanPattern.setActivationFunction(new ActivationSigmoid());
        BasicNetwork network = (BasicNetwork) elmanPattern.generate();

        //read training data
        NeuralDataSet trainingSet = new BasicNeuralDataSet(XOR_INPUT, XOR_IDEAL);

        //set training method
        MLTrain train = new Backpropagation(network, trainingSet, 0.000001, 0.0);


        //training
        int epoch = 1;

        do{
            train.iteration();          
            System.out.println("Iteration: " + epoch + ", Error: " + train.getError());
            epoch ++;
        }while(train.getError() > 0.01);

        //shut down
        Encog.getInstance().shutdown();
    }
}

1 个答案:

答案 0 :(得分:0)

如果您想训练非时间序列的东西,请尝试使用前馈神经网络。你不会对Elman和4个训练集元素非常成功。如果您想了解如何为Elman构建XOR数据的示例,请参阅以下内容:

https://github.com/encog/encog-java-examples/blob/master/src/main/java/org/encog/examples/neural/recurrent/elman/ElmanXOR.java