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

In this video I look at strategies for improving the genetic algorithm’s fitness function to improve efficiency and accuracy.

Support this channel on Patreon:

Send me your questions and coding challenges!:


Source Code for the Video Lessons:


For More Genetic Algorithm videos:

For More Nature of Code videos:

Help us caption & translate this video!






21 responses to “9.6: Genetic Algorithm: Improved Fitness Function – The Nature of Code”

  1. SuperVini16 Avatar

    Could one use this technique to solve RSA?

  2. Epper Marshall Avatar

    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.

  3. Albert Dadze Avatar

    Thank you. Genetic Algorithm understood for my next project.

  4. Justin Lennox Avatar

    Maybe you could use a genetic algorithm to help choose the fitness function 😉

  5. Dhaouadi Badreddine Avatar

    genetic algorithm for hardware software partitioning??

  6. JazevoAudiosurf Avatar

    somewhat annoying that hes constantly on speed

  7. nurafeza ajirah Avatar

    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

  8. Pedro Ferreira Avatar

    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!

  9. Tum Voodoo Avatar

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

  10. Charlie McGuire Avatar

    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 http://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.

  11. Aman Ag Avatar

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

  12. Mayur Lahane Avatar

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

  13. Michał Szczuryk vel Szczerba Avatar

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

  14. Hans PS Hansen Avatar

    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.

  15. Gowtham Javvadi Avatar

    Sir,this is j.gowtham Doing project on" FRACTIONAL ORDER PID CONTROLLER FOR AN AVR SYSTEM" my Question is How we can apply Fitness function for an fractional order system?
    please sent my information that how we can select for a fractional order transfer function
    please sent to my mail gowthamsreeram@gmail.com
    thank you sir,

    with regards,

  16. Dezzles Avatar

    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

  17. ايمن الاشول Avatar

    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

  18. Bryan Garcia Avatar

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

  19. San Coca Avatar

    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

  20. nic v. Avatar

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

  21. Nitin Tripathi Avatar

    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)

Leave a Reply

Your email address will not be published. Required fields are marked *