Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XOR test fails #37

Open
slowGitHum opened this issue Aug 19, 2015 · 0 comments
Open

XOR test fails #37

slowGitHum opened this issue Aug 19, 2015 · 0 comments

Comments

@slowGitHum
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant