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

Training does not reliably converge, even with the simple XOR problem #155

Closed
reneheijnemans opened this issue Dec 22, 2020 · 1 comment
Closed

Comments

@reneheijnemans
Copy link

I am not sure that this is a known issue, but I cannot get the neural network to converge reliably.

In many instances, it just cannot solve the simple XOR problem.

For instance, I had serialized one of the randomly generated NeuralNetworks that displays this problem:

Is this just an issue with the activation function? Then it would be helpful to explain this in the README.
Or is there a bug in the code?

import {NeuralNetwork} from "./nn/nn";

let nn;

const training_data = [
    {
        inputs: [0, 0],
        outputs: [0],
    },
    {
        inputs: [0, 1],
        outputs: [1],
    },
    {
        inputs: [1, 0],
        outputs: [1],
    },
    {
        inputs: [1, 1],
        outputs: [0],
    },
]

function setup() {
    createCanvas(400, 400);

    nn = NeuralNetwork.deserialize({"input_nodes":2,"hidden_nodes":2,"output_nodes":1,"weights_ih":{"rows":2,"cols":2,"data":[[-0.12692590266986858,-0.844955757436316],[-0.9357427469178123,0.8173651578783794]]},"weights_ho":{"rows":1,"cols":2,"data":[[-0.5832662974097391,0.5308947844782579]]},"bias_h":{"rows":2,"cols":1,"data":[[0.39650732687505963],[-0.49808473788143637]]},"bias_o":{"rows":1,"cols":1,"data":[[0.2908941132572971]]},"averageError":0,"learning_rate":0.01,"activation_function":{}});
    global.nn = nn;
}

function draw() {
    background(0);

    for (let i = 0; i < 1000; i++) {
        let data = random(training_data);
        nn.train(data.inputs, data.outputs);
    }

}

global.setup = setup;
global.draw = draw;
global.NeuralNetwork = NeuralNetwork;

The XOR example at https://codingtrain.github.io/Toy-Neural-Network-JS/examples/xor/ also faces this issue ; when refreshing a few times, it will result in the wrong separation visualization.

@reneheijnemans
Copy link
Author

Never mind,

The coding challenge in Coding Challenge #92: XOR Problem https://www.youtube.com/watch?v=188B6k_F9jU
explains this phenomenon as it is getting stuck due to not enough paths for it to solve the problem.
Possibly this could be solved by picking the weights more carefully.

Daniel's solution mentioned in the video by adding additional hidden nodes solves this problem.

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