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

How it works #17

Open
abacaj opened this issue Nov 14, 2016 · 15 comments
Open

How it works #17

abacaj opened this issue Nov 14, 2016 · 15 comments

Comments

@abacaj
Copy link

abacaj commented Nov 14, 2016

I know you linked to the article regarding the algorithm but it would be useful to have a walk-through (high-level) of what the Neuroevolution is doing in the case of this game.

For example, talking about what the inputs are (location on screen?) and what the outputs are (go up, or down).

Thank you, great example.

@sunrei
Copy link

sunrei commented Nov 15, 2016

As far as I learned from code it takes 2 inputs:

  • normalized vertical position of the bird (Y coordinate divided by canvas height)
  • normalized vertical position of next gap between pipes (Y coordinate of the bottom edge of top pipe / canvas height)

It doesn't care about bottom pipe and the gap size, and horizontal distance to next gap.

In terms of the game the bird instantly falling down with acceleration (like normal gravity effect), and moving up is supposed to be done by hitting ceretain key on keyboard (e.g. Up or Space) and it looks like jump from the current position of the bird.
It's also possible to hold the key pressed and bird will go up with constant speed and upon releasing the key bird performs additional jump.

We have 1 output here - floating number from 0 to 1. If it is greater than 0.5 we assume that bird needs to go up, so it translates it as pressing (or keep holding) UP key, otherwise - releasing the key.

@xviniette
Copy link
Owner

i will add explanation in README.

@Grabber
Copy link

Grabber commented Nov 15, 2016

It is a little off-topic, but has anyone tried to apply the underlying concepts to price modeling on e-commerce? I can clearly see an analogy to real transactional application.

@ylin
Copy link

ylin commented Dec 7, 2016

@xviniette: I too am trying to understand how the neuroevolution algorithm works. I'm a total beginner to AI, and I wish to understand more about reinforcement learning algorithms like this one.

Is there an academic paper such as the ones on https://arxiv.org that goes over the math behind neuroevolution.js?

Much appreciated.

@NicoJuicy
Copy link

Much appreciated if you add explanation in README :)

@kotAPI
Copy link

kotAPI commented Aug 18, 2017

@xviniette Still waiting for the tutorial!

@ylin
Copy link

ylin commented Aug 28, 2017 via email

@planktonfun
Copy link

Cannot quite get XOR to work right bellow 0.3 error rate

@AmrAlaa-exe
Copy link

@planktonfun
Provide your code, please.

@planktonfun
Copy link

planktonfun commented Jan 24, 2018

@AmrAlaa-exe here you go:

var Neuroevolution = require('./Neuroevolution.js');

//Default options values
var options = {
    network:[2, [2], 1],    // Perceptron structure
    population:50,          // Population by generation
    elitism:0.2,            // Best networks kepts unchanged for the next generation (rate)
    randomBehaviour:0.2,    // New random networks for the next generation (rate)
    mutationRate:0.1,       // Mutation rate on the weights of synapses
    mutationRange:0.5,      // Interval of the mutation changes on the synapse weight
    historic:0,             // Latest generations saved
    lowHistoric:false,      // Only save score (not the network)
    scoreSort:-1,           // Sort order (-1 = desc, 1 = asc)
    nbChild:1               // number of child by breeding
}

// Initialize
var ne = new Neuroevolution(options);

// Generate first or next generation
var generation;

var trainingSet = [
    [[1,1],0],
    [[0,0],0],
    [[0,1],1],
    [[1,0],1]
];

// Error is 100% by default try to minimize it to 0%
var errorpercent = 1;

while(errorpercent >= 0.25) {
    generation = ne.nextGeneration();

    for (var i = options.population - 1; i >= 0; i--) {
        var errorrate = 0;
        for (var j = trainingSet.length - 1; j >= 0; j--) {
            var input = trainingSet[j][0];
            var expected = trainingSet[j][1];

            var result = Math.round(generation[i].compute(input));

            if(result != expected) {
                errorrate += 1;
            }
        }

        errorpercent = errorrate/4;
        ne.networkScore(generation[i], ((errorrate/4)*100)-100);
        console.log(errorpercent*100);
    }
}

console.log(
    Math.round(generation[0].compute([1,1])),
    Math.round(generation[0].compute([0,1])),
    Math.round(generation[0].compute([1,0])),
    Math.round(generation[0].compute([0,0]))
);

@xviniette
Copy link
Owner

I tried and it works on my end. Try to increase the mutationRange.

@planktonfun
Copy link

@xviniette Finally It works when the mutation is at 80% after 3868 iterations thanks! Was starting to lose hope at 400 iterations, and 21282 iterations 50% Mutation.

@ShuhuaGao
Copy link

@sunrei Thanks for you explanation. I guess in fact only the relative position matters, i.e., the vertical distance between the bird and the first upper pipe before it. thus, this task can be modeled as a 1-input-1-output function fitting (or binary classification) problem, where the neural networks come in.

@rhysstubbs
Copy link

rhysstubbs commented Mar 20, 2019

Which Neuroevolution algorithm is this using, is it NEAT? If not, the answer I am really after is whether it evolves the hyper-parameters (i.e. network topology) or not?

@ShuhuaGao
Copy link

@rhysstubbs It is not the standard NEAT. Only the network connection weights are evolved, I think. That is, use genetic algorithm instead of back-propagation to train the network.

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