A.I. learns to play | Neural Network + Genetic Algorithm

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • This is how I created an AI that learns to play the game and beats it!
    #neuroevolution #geneticalgorithm #artificialintelligence
    Watch the full evolution and relax -
    • A.I. beats the Game (f...
    For more videos please subscribe -
    bit.ly/normaliz...
    Support me if you can ❤️
    www.paypal.com...
    www.buymeacoff...
    Article on this -
    towardsdatasci...
    Source code -
    github.com/Suj...
    The game -
    suji04.github....
    The coding train's playlist on genetic algorithm
    • 9: Genetic Algorithms ...
    Facebook -
    / nerdywits
    Instagram -
    / normalizednerd
    Twitter -
    / normalized_nerd
    ----------------------------------------------------------------------------------------
    The music used is under a Creative Commons license
    Artist: incompetech.com/
    Almost in F - Tranquillity by Kevin incompetech.com...

Комментарии • 78

  • @SolvingOptimizationProblems
    @SolvingOptimizationProblems 4 года назад +1

    Great simulation. Neural network coupled with genetic algorithm is very interesting. Thanks for sharing!

  • @theankitkurmi
    @theankitkurmi 4 года назад +1

    I really loved this. I will surely learn from your video and implement this on my own.

    • @NormalizedNerd
      @NormalizedNerd  4 года назад +1

      Thanks! I've uploaded the code on github (link in description). You can check that out to get started.

  • @markadyash
    @markadyash 3 года назад +1

    Vro amazing keep making such ai I love to learn this from you 😊

  • @bhaskarjyotisarma8919
    @bhaskarjyotisarma8919 4 года назад +11

    Hey, it was awesome!! I believe that some more inputs such as next bar height, speed of the bars or the frame, etc might help in gaining the maturity stage much sooner. It is just my opinion. Also, more hidden layers may help those creatures store much info (in form of weights oviously) in their individual brains, thus they transfers more genetic info to their offsprings.

  • @shyhuludyong
    @shyhuludyong 2 года назад +1

    Always left one individual unchanged from th previous generation, in case of all mutations caused worse performance.

  • @HyperCodec
    @HyperCodec Год назад

    Preserving the champion(s) to the next gen helps deal with bad mutations

  • @ayushmanbt
    @ayushmanbt 4 года назад +4

    The collision is elastic: it's his choice😂

    • @NormalizedNerd
      @NormalizedNerd  4 года назад

      lol...should have used "choice" instead of "wish" XD

  • @sull5307
    @sull5307 3 года назад +2

    Hey did you try with elitism option which keeps the best score ball into the next generetion ?

    • @NormalizedNerd
      @NormalizedNerd  3 года назад +1

      Nice suggestion...I didn't use elitism here.

    • @tomdagan9878
      @tomdagan9878 3 года назад

      I thought about that too. Not close to being able to do this but I remember code bullet doing it and it made sure there were no backwards steps in the evolution

  • @Antonio-lt1sp
    @Antonio-lt1sp 4 года назад +2

    Great job! How did you select the number of hidden layers?

    • @NormalizedNerd
      @NormalizedNerd  4 года назад +2

      Well I knew that the problem I'm trying to solve is pretty simple so I don't need to build a complex architecture. Another thing I had to keep in mind is if I increase the complexity then it would become computation intensive. So I decided to have 1 hidden layer.

    • @Antonio-lt1sp
      @Antonio-lt1sp 4 года назад

      @@NormalizedNerd many thanks! Actually I asked the wrong question, sorry: how did you select the number of 'nodes' in the hidden layer? Was it by trial-and-error, or was there any kind of rule of thumb?

    • @Anonymous-tr7mb
      @Anonymous-tr7mb 2 года назад

      @@Antonio-lt1sp Hi, don't know if this will help but usually there is a bit of a rule of thumb. My rule of thumb is it is roughly around the number of inputs + 2 and this usually works. Hope this helps!

  • @SamSarwat90
    @SamSarwat90 2 года назад +1

    Just some remarks:
    1. If you do not use mutation, it does not mean that the children will be identical. That's an unlikely scenario given reasonable crossovers and different parents. Mutation is there to add change after the crossover has been applied, since there is a level of "determinism" hidden in the crossover operators, for example convex crossover, which will restrict the children in the convex hull of the parents.
    2. No, the next generation will not be worse because of mutation. Just no. When the population of children and parents has been grouped, the survival operator is applied to select the parents for next generation and discard the others. In your case, it seems you are not using the elitist approach, i.e. you are not enforcing the survival of the fittest solution. Mutation never changes the state of an existing solution, it is only used during the phase of creating the solution, with a certain probability.
    Other than that, great video.

  • @kiskas618
    @kiskas618 4 года назад +7

    Can you really call it genetic algorithm when you skip recombination? Aren't we more in the territory of evolution strategy, then?

  • @d3nt391
    @d3nt391 2 года назад +2

    This is super cool. At the beginning when all the balls roll right into the rectangle, how do balls which bounce higher but land on the same rectangle have a higher fitness? If the fitness function is just horizontal distance

  • @ANKITRAJ-fe8dh
    @ANKITRAJ-fe8dh 4 года назад +4

    Is it Reinforcement learning?
    Its showing score so it clicked my mind..

    • @NormalizedNerd
      @NormalizedNerd  4 года назад +3

      I appreciate the thinking process. It is true that the aim of RL and GA is the same (to maximize reward/fitness score). But the techniques are completely different. For example, in RL we have no concept of population, generations, selection etc. And one more thing, GA is largely based on heuristics where as RL involves strong mathematical ground.

    • @ANKITRAJ-fe8dh
      @ANKITRAJ-fe8dh 4 года назад

      @@NormalizedNerd thanks for the rply, it's been a good help...
      May I connect to you on any social platform?

    • @NormalizedNerd
      @NormalizedNerd  4 года назад

      @ANKIT RAJ you can follow me on twitter @normalized_nerd

    • @revimfadli4666
      @revimfadli4666 3 года назад

      Some would classify GA and evolution strategies(ES) as _generational_ RL, and PPO, A3C as _ontological_ RL.
      The best thing is that the two can be combined in interesting ways :)

  • @sankarsanbhattacheryya7498
    @sankarsanbhattacheryya7498 4 года назад +1

    Nice video. What is the parent selection method used in this? Picking a random parent based on probabilities which in turn depend on fitness? Also in a particular generation, do you include the best agent so far (which might not have come from the previous generation, but from, say, 10 generations before)?

    • @NormalizedNerd
      @NormalizedNerd  4 года назад

      @Sankarsan Bhattacheryya Oh a lot of questions! (and I like this)
      1. Yes, parents are picked based on their fitness score. You can think like this...First we are calculating the probabilities based on the fitness score then according to the probabilities the parents are chosen.
      2. I'm always picking the parents only from the current generation. Remember when we are selecting a parent we are changing its weights before creating its offspring. We are expecting that next generation will always contain better agents so we are keeping track of earlier generations.

  • @vinayyadhav
    @vinayyadhav 4 года назад +2

    So I guess there is no backpropagation happening. You base the weights of the next generation NN based on the weights of the best performing individuals from your previous population using GA. Did I understand it right? Awesome work!

    • @NormalizedNerd
      @NormalizedNerd  4 года назад +1

      You have mentioned a great point! Yes, no back prop (gradient based learning) is happening here. The weights of the best performing NNs are transferred to the next generation. While transferring, we change weights slightly (aka mutate) in the hope that modified weights will work even better.

  • @revimfadli4666
    @revimfadli4666 3 года назад +2

    You might be able to use crossover if you use node mutation or enforced subpopulations(ESP)

    • @NormalizedNerd
      @NormalizedNerd  3 года назад +1

      Will try them in future...

    • @revimfadli4666
      @revimfadli4666 3 года назад

      @@NormalizedNerd amazing! Those algorithms need more recognition
      Well-done & concise explanations on your videos' topics btw

  • @learningtree8179
    @learningtree8179 3 года назад

    Your fitness function is not good imo, from my understanding you are basically scoring with proportion to time

  • @nanotechno9864
    @nanotechno9864 Год назад

    Hello, great video, can you share the code that is behind this plz ?

  • @pojeby
    @pojeby 3 года назад +1

    I was wondering why it didn't learn how to play in like 5 generations until 6:41 - only one hidden layer :(

    • @NormalizedNerd
      @NormalizedNerd  3 года назад

      Haha...that too with only 8 neurons!

    • @pojeby
      @pojeby 3 года назад

      @@NormalizedNerd were you normalizing the inputs? Which activation function was used?

  • @dewmi4403
    @dewmi4403 Год назад

    if that is how human evolution work, we just saw Nikola Tesla

  • @10xGarden
    @10xGarden 4 года назад +2

    9:26 Elon musk spotted

  • @kaushalgagan6723
    @kaushalgagan6723 3 года назад +2

    This video made my day..🤩

  • @sanjaybora380
    @sanjaybora380 2 года назад

    You should keep the originals of the previous generation also

  • @aioasis
    @aioasis Год назад

    Your game seems a lot like flappy bird.

  • @lachlanstanding7386
    @lachlanstanding7386 3 года назад

    Ok, so why is this better than back propagation? If you used back propagation every "generation" would be correcting itself towards the correct answer rather than just moving the weights randomly.

    • @SamSarwat90
      @SamSarwat90 2 года назад

      This is not a genetic algorithm. If you are not using a crossover operator, its not a genetic algorithm, point. Too many mistakes about GA to be honest. This is basically a population based algorithm with just some stochastic movement.

  • @neeldasgupta2441
    @neeldasgupta2441 3 года назад +1

    this is a very good explanation of the genetic algorithm.

  • @medooazmi
    @medooazmi 3 года назад +1

    the great thing about ai is that it moves at simple rules but it leads to a complicated result

  • @Zzzzoder
    @Zzzzoder 4 года назад +1

    What does the bar at the bottom center do?

    • @NormalizedNerd
      @NormalizedNerd  4 года назад

      I added that to control the speed of simulation. It's useful for debugging purpose.

  • @rshsrhserhserh1268
    @rshsrhserhserh1268 3 года назад

    I tried it on trading. My subjects are still didnt understand they have to sell to earn money. How can you solve it on stochastic environment without gradiant-free and no reward system ? They are still like buy,buy,buy,buy,buy ...

    • @NormalizedNerd
      @NormalizedNerd  3 года назад

      I guess the problem is with fitness function.

    • @rshsrhserhserh1268
      @rshsrhserhserh1268 3 года назад

      @@NormalizedNerd fitness is basically profit from end of the trading session

    • @NormalizedNerd
      @NormalizedNerd  3 года назад

      @@rshsrhserhserh1268 Ok that should work. Btw when you agents are supposed to sell? I mean did you use a sigmoid output (buy if closer to 10, sell if closer to 0)?

    • @rshsrhserhserh1268
      @rshsrhserhserh1268 3 года назад

      @@NormalizedNerd after predicting values (buy,sell,hold) like (0,75, 0,30, 0.15) using argmax function so it's selecting buy action (0.75). After buying with that condition next prediction is so similiar to the old one like (0.74, 0.29, 0.14). So it's predicting next best action is "buy" again even though the input state is refreshed with new stock price and portfolio status (after buying it's 1000 etc.). I used every one of the activation functions they all are the same.

    • @NormalizedNerd
      @NormalizedNerd  3 года назад

      @@rshsrhserhserh1268 If you are using the softmax at the last layer then the probability values should add upto 1. In your example it's not.

  • @PritishMishra
    @PritishMishra 3 года назад

    Best RUclipsr...

  • @dmaximus73
    @dmaximus73 3 года назад

    This is freaking me out

  • @sagarshrestha5800
    @sagarshrestha5800 3 года назад

    Can we add the judgmental ability to the balls to determine how high the wall is. It seems it just jumps on prediction not from the information coming from the surroundings

    • @NormalizedNerd
      @NormalizedNerd  3 года назад

      You can see that I'm taking wall height and location as an input to the neural network so it must be taking making the decision based on its surroundings too.

  • @10xGarden
    @10xGarden 4 года назад +1

    Nice energy 👌♥️🖤

  • @sher.5027
    @sher.5027 2 года назад

    nice video, loved the game and explanation.

  • @ayushmanbt
    @ayushmanbt 4 года назад

    Can there be a video on how to make the game and write the AI as well as how to write the AI if you don't have access to the source code of the game

    • @NormalizedNerd
      @NormalizedNerd  4 года назад

      Making a game and writing the AI may be covered in future videos. If we don't have access to the source code of the game then we can take screenshots continuously and use CNNs to extract features out of it.

  • @lonewolf796
    @lonewolf796 3 года назад

    but where is code?

    • @NormalizedNerd
      @NormalizedNerd  3 года назад

      Please see the video description. There's a link to my github.

  • @sayantansadhu6380
    @sayantansadhu6380 4 года назад

    Wow this was awesome 😍😍