ivan-vasilev / neuralnetworks

java deep learning algorithms and deep neural networks with gpu acceleration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XOR test fails

slowGitHum opened this issue · comments

I'm trying to learn to use this package. I've played with this for a couple of days. I think the following nn should work:

public static float XOR_INPUT[][] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}};
public static float XOR_TARGET[][] = {{0.0f}, {1.0f}, {1.0f}, {0.0f}};

public static void main(String[] args) {

    // execution mode
    Environment.getInstance().setExecutionMode(EXECUTION_MODE.SEQ);

    // create the network
    NeuralNetworkImpl mlp = NNFactory.mlpSigmoid(new int[]{2, 3, 1}, false);

    // training and testing data providers
    SimpleInputProvider trainInputProvider = new SimpleInputProvider(XOR_INPUT, XOR_TARGET);
    SimpleInputProvider testInputProvider = new SimpleInputProvider(XOR_INPUT, XOR_TARGET);

    OutputError outputError = new XorOutputError();

    // trainer
    BackPropagationTrainer<?> bpt = TrainerFactory.backPropagation(mlp, 
            trainInputProvider, 
            testInputProvider, 
            outputError,
            new NNRandomInitializer(new MersenneTwisterRandomInitializer(-0.01f, 0.01f), 0.5f) 
            , 0.02f // learning rate
            , 0.7f // momentum
            , 0f // l1weightDecay
            , 0f // l2 weightDecay
            , 0f // dropout rate
            , 1 // training batch size
            , 1 // test batch size
            , 200);       // epochs

    // log data
    bpt.addEventListener(new LogTrainingListener(Thread.currentThread().getStackTrace()[1].getMethodName(), true, true));

    // early stopping
    bpt.addEventListener(new EarlyStoppingListener(testInputProvider, 100, 0.015f));

    // train
    bpt.train();

    // test
    bpt.test();
}

But I get 50% error!!! Changing the number of hidden neurons doesn't change anything.

What am I missing ????

Thanks in advance.

Dwight