9.6: Genetic Algorithm: Improved Fitness Function - The Nature of Code

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 พ.ย. 2024

ความคิดเห็น • 59

  • @bryangarcia7363
    @bryangarcia7363 8 ปีที่แล้ว +39

    I don't know how I didn't found you earlier, I'm going to watching every single video in your playlists

  • @tumvoodoo
    @tumvoodoo 7 ปีที่แล้ว +22

    I love you man, you are the best teacher i've known.

  • @SStrigido
    @SStrigido 5 ปีที่แล้ว +6

    I'm kind of proud of myself for thinking of that after watching a few of the previous videos and writing my own algorithm.
    I think your videos are amazing! Keep up the good work. 👍

  • @tyfoodsforthought
    @tyfoodsforthought 4 ปีที่แล้ว +2

    So grateful to be looking into Genetic Algorithms now and have your videos available as a reference. Amazing instruction as always! Thank you!

  • @Dezzles
    @Dezzles 7 ปีที่แล้ว +1

    While having a bit of a play around I found a fairly efficient fitness function where instead of just using the number of matches, keep track of the number of matching characters in a row and add that instead of 1, resetting to 0 if a mismatch is found. Managed to get my code down to ~85 generations rather than 300-600

  • @SaintPepsiSanCoca
    @SaintPepsiSanCoca 8 ปีที่แล้ว +2

    Thank you so much for these video's they're helping me understand so much more about coding and how things work. also love that you tell us to try and do something with the example given it's a really really good exercise

  • @albertdadzie4567
    @albertdadzie4567 7 ปีที่แล้ว

    Thank you. Genetic Algorithm understood for my next project.

  • @ramkumarr1725
    @ramkumarr1725 3 ปีที่แล้ว

    Good to see this demo. I read about it in some algorithms book 😂

  • @perladelacruz6515
    @perladelacruz6515 4 ปีที่แล้ว

    So fun to watch! great video thanks!

  • @Dhsoanw71
    @Dhsoanw71 7 ปีที่แล้ว +5

    Really interesting. But can you also explain the drawbacks of exponentially increasing the fitness function ?

    • @tiileaf
      @tiileaf 6 ปีที่แล้ว +3

      Aman Ag Your mating pool array will take up more memory.

    • @DehimVerveen
      @DehimVerveen 6 ปีที่แล้ว +6

      I'd guess there would be a higher chance of getting stuck at a local maximum.

  • @toni01597
    @toni01597 6 ปีที่แล้ว

    gifted teacher

  • @hannesthorsell3566
    @hannesthorsell3566 2 ปีที่แล้ว

    Simply making the fitness function exponential runs into the same problem as the linear one, except of course at the start of the process rather than at the end. However, it should be noted that this is not at all as big an issue. I'd recommend doing something like this.fitness = pow(this.fitness, 1 + x*averageFitness), where averageFitness is the average of the fitness values of the previous generation, and x is a factor you can change to increase or decrease the effect of the average fitness (I used x=1 in my code). This has the effect of being (almost) linear when the average fitness is low, which is what we want, and growing more and more exponential as the average fitness increases. In essence, this allows you to more finely select breeding pairs once the playing field has been leveled and everyone is roughly equally fit. We are increasing the pressure of selection.
    An analogy would be breeding frogs to jump high. At the start we simply select high jumping frogs. However, because of physical limits frogs can only jump so high. After a while almost all frogs will be jumping at almost the same height, and we're essentially picking at random, not making much improvement. Taking the average fitness into account, however, is like using a magnifying glass, turning very small differences in jump height into larger ones, allowing us to better select frogs to breed.
    As a final note one might ask why this "averaging out" happens, and why convergence is slow towards the end. In essence, it's because as you get closer to the optimum fewer and fewer mutations are beneficial. This allows the slower of the pack to catch up, making all individuals very close in fitness. This can be seen with this program, where you sometimes get situations were almost everyone is identical, having to randomly mutate only a few letters to get a perfect match.

  • @spinLOL533
    @spinLOL533 4 ปีที่แล้ว

    these videos are very helpful, thank you

  • @eppermarshall67
    @eppermarshall67 7 ปีที่แล้ว +1

    I found that if the crossover is based on the weight of the fitness it can perform faster. If for example you want the crossover between .7 and .8 fitness you have a ~.46 chance from the the first and .53 from the second (.7/(.7+.8)). In the loop you can generate a random(1) and check if it is less then this.fitness/sum, then set child genes to this.genes at i.

  • @DasAntiNaziBroetchen
    @DasAntiNaziBroetchen 4 ปีที่แล้ว +1

    The problem I'm facing is, regardless of how I square or multiply scores, every set of genes always ends up with a similar score like all the other ones and thing's aren't improving nearly as fast as I want them to. They also aren't really improving in the way I want them to.
    Granted, my problem is much more complicated because I don't already know the answer (cuz what would the point be otherwise?) and my application is somewhat of a physics simulation.

  • @pedroferreira3371
    @pedroferreira3371 7 ปีที่แล้ว +4

    I am having some trouble with this code. I made one that works in the same way of yours, but in python; and when I add an exponencial function in Fitness it becomes slow, cause of the size of the list that store all that data. How can I solve it? It seens that as I am storing toons of arrays it is filling my memory.
    By the way, that is an awesome serie, I am waching all your videos!

  • @XoIoRouge
    @XoIoRouge 6 ปีที่แล้ว

    You're so entertaining, I watch on 1.25x speed

  • @branhoff
    @branhoff 5 ปีที่แล้ว

    What is the draw back to using an exponential function as opposed to al linear function? Given the efficiency you demonstrated here, why would anyone use a linear function to reward fitness?

  • @plinioviniciusalvesdossant3933
    @plinioviniciusalvesdossant3933 6 ปีที่แล้ว +1

    Hello!
    I ran into a problem that I think you didn't mention in the video. When you take score of an individual and divide it by the length of the target phrase, you always get a numer between zero and one, right? And when you take that value squared, or taken to the fourth power, or whatever, you end up with a smaller number (for example: 0.2^2=0.04). Depending on small that number is across the population, you might end up with no individuals in the mating pool at all, because the fitnesses are so small. And that's what happened to me. Am I missing something? Am I doing something wrong? Thanks!

    • @plinioviniciusalvesdossant3933
      @plinioviniciusalvesdossant3933 6 ปีที่แล้ว +1

      Another problem that I just realized is that the fitness is decreasing instead of increasing =/

  • @mctrjalloh6082
    @mctrjalloh6082 6 ปีที่แล้ว

    Hi Dan. Can you do series on Reinforcement Learning too? Thanks.

  • @rovixen8668
    @rovixen8668 5 ปีที่แล้ว +1

    0:44 The first phrase of the list XD

  • @6431nnel
    @6431nnel 7 ปีที่แล้ว +2

    Maybe you could use a genetic algorithm to help choose the fitness function ;-)

  • @arslane1972
    @arslane1972 4 ปีที่แล้ว

    Thank you for this channel,
    I have a strong problem concerning optimization by genetic algorithm, can you help me? Because no one that I know can solve this problem.
    Rgrds.

  • @dineshsharma-rn4yi
    @dineshsharma-rn4yi 6 ปีที่แล้ว

    You are the best. Is there anything related to Honeybee mating optimization?

  • @dysh-tyc-edu-tw
    @dysh-tyc-edu-tw 3 ปีที่แล้ว

    machine learning use about softmax, Can use it to Fitness function?

  • @Ensivion
    @Ensivion 7 ปีที่แล้ว

    I know this might be nitpicky, but technically any fitness function that has a power in it could be called polynomial and it might make more sense. The 2^N function would be exponential, although exponentials can be represented as polynomial functions (a pretty example is of course www.wolframalpha.com/input/?i=e%5Ex+expansion) these are only approximations that take infinitely many polynomials to converge. I'm new to these kind of algorithms so take that lightly. Also a question: is it possible that a higher order (polynomial, exponential) functions negatively effect the genetic algorithm's speed? My guess is that there is a point that the function jumps too quickly and the variation of mutations becomes a limiting factor.

    • @TheCodingTrain
      @TheCodingTrain  7 ปีที่แล้ว

      Not nitpicky at all, important and helpful clarification! (If you have a minute to see how it is described in natureofcode.com chapter 10 and file any corrections here github.com/shiffman/The-Nature-of-Code/issues I'd love that!)

  • @nurafezaajirah4450
    @nurafezaajirah4450 7 ปีที่แล้ว

    i have problem in generating my fitness function using both PSNR and NCC parameter. The aim is to find the most optimize or best solution for my image watermarking scaling factor (using genetic algorithm)
    Hopefully, you guys can help me. Thank you

  • @kapilverma2668
    @kapilverma2668 6 ปีที่แล้ว +1

    The matingPool Algorithm is good but when I am selecting the top 2 fittest and mating them population.length times that is giving me results better than the Shakespeare Example of yours

    • @finally-a-girl-is-noone
      @finally-a-girl-is-noone 3 ปีที่แล้ว

      If the top two dont have some sequence of characters by chance then its better to include other low scoring members than letting mutation fix it right?

  • @finally-a-girl-is-noone
    @finally-a-girl-is-noone 3 ปีที่แล้ว

    Why does the average fitness go down when we use an exponential fitness function?

  • @fasligand7034
    @fasligand7034 7 ปีที่แล้ว +7

    it's just a higher degree polynomial fitness function, not an exponential one

    • @finally-a-girl-is-noone
      @finally-a-girl-is-noone 3 ปีที่แล้ว

      A higher degree polynomial is closer to an exponential fn than a linear fn in this case. The goal is to have a function that increases more steeply as we go to the right...

  • @mayurlahane9707
    @mayurlahane9707 7 ปีที่แล้ว

    Sir,according to you is macbook air 2016 good for developing games mostly in unity,unreal engine4 & cryengine

    • @memorablename5187
      @memorablename5187 7 ปีที่แล้ว

      not really.... you will need a decent gpu for that stuff

  • @dhaouadibadreddine4483
    @dhaouadibadreddine4483 7 ปีที่แล้ว +1

    genetic algorithm for hardware software partitioning??

  • @panjersonten7610
    @panjersonten7610 6 ปีที่แล้ว

    forecasting with GA is it possible ?

  • @a19905
    @a19905 7 ปีที่แล้ว +1

    could you provide the source code for this example .. I couldn't find it in your repo. I am interested in understanding how the code works

  • @emmettdja
    @emmettdja 3 ปีที่แล้ว +1

    What is the reason for why you don't just pick the two best children from the previous generation to be the parents of the new generation?

  • @SuperVini16
    @SuperVini16 7 ปีที่แล้ว

    Could one use this technique to solve RSA?

  • @nicvermeeren3011
    @nicvermeeren3011 8 ปีที่แล้ว +2

    Why don't you just take the fitness to a power of lets say 20?
    Are there some consequences?

    • @JS-ct1uo
      @JS-ct1uo 8 ปีที่แล้ว +14

      As you increase the power, you are effectively just increasing the chances of choosing the elements with the higher fitness. In the end you rapidly approach what is effectively choosing only the best element of the population to populate the next generation. This can lead to problems in the populations variation; if say one element has a large part of the solution while another has a smaller different part of the solution, it would result in the 2nd element being discarded. This means you can quickly be reduced to an algorithm which takes the best element of a generation and simply tries to improve on that single element through only mutations in its DNA i.e. in the video's example it would take the best phrase then swaps some letters randomly in the next generation. While not as slow as simple random guessing it can lead to many more generations required till the solution is found when compared to the standard genetic algorithm.

    • @TheCodingTrain
      @TheCodingTrain  8 ปีที่แล้ว +7

      +Joshua Spaul such a great explanation thank you!!!

  • @nitintripathi8165
    @nitintripathi8165 8 ปีที่แล้ว

    how ur typing speed is so good??
    .
    plz give some tips.
    .
    I am saying this after watching snake video game
    ( may u not reply it so 1st comment)

  • @TheHpsh
    @TheHpsh 7 ปีที่แล้ว +1

    pretty much faster then my algoritme, i used 11 hour for "hello world, and the rest of the universe"
    but was a pretty simple algoritme.

  • @cykablyat9333
    @cykablyat9333 2 ปีที่แล้ว

    i fucking hate this. why the fuck did i pick this module holy shit i made a mistake

  • @JazevoAudiosurf
    @JazevoAudiosurf 7 ปีที่แล้ว +1

    somewhat annoying that hes constantly on speed

    • @albertdadzie4567
      @albertdadzie4567 7 ปีที่แล้ว +4

      What will it cost you to say Thank you. Ingratitude.