title
9.2: Genetic Algorithm: How it works - The Nature of Code

description
In part 2 of this genetic algorithm series, I explain how the concepts behind Darwinian Natural Selection are applied to a computational evolutionary algorithm. Code: https://thecodingtrain.com/tracks/the-nature-of-code-2/noc/9-genetic-algorithms/2-how-it-works 🎥 Previous: https://youtu.be/9zfeTw-uFCw?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM 🎥 Next: https://youtu.be/nrKjSeoc7fc?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM 🎥 All: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM References: 🔗 Nature of Code: https://nature-of-code-2nd-edition.netlify.app/ Timestamps: 0:00 Hello! Let's talk about genetic algorithms. 2:05 Principals of Darwinian natural selection 7:08 Creating a random population 10:35 Calculating the fitness 12:52 Reproduction/Selection 14:05 Picking the parents 17:00 Making a new element 18:05 Crossover 20:10 Mutation 23:07 Review the algorithm Editing by Mathieu Blanchette Animations by Jason Heglund Music from Epidemic Sound 🚂 Website: https://thecodingtrain.com/ 👾 Share Your Creation! https://thecodingtrain.com/guides/passenger-showcase-guide 🚩 Suggest Topics: https://github.com/CodingTrain/Suggestion-Box 💡 GitHub: https://github.com/CodingTrain 💬 Discord: https://thecodingtrain.com/discord 💖 Membership: http://youtube.com/thecodingtrain/join 🛒 Store: https://standard.tv/codingtrain 🖋️ Twitter: https://twitter.com/thecodingtrain 📸 Instagram: https://www.instagram.com/the.coding.train/ 🎥 Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH 🎥 Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA 🔗 p5.js: https://p5js.org 🔗 p5.js Web Editor: https://editor.p5js.org/ 🔗 Processing: https://processing.org 📄 Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/thecodingtrain.com/issues/new #darwinianselection #geneticalgorithm #p5js

detail
{'title': '9.2: Genetic Algorithm: How it works - The Nature of Code', 'heatmap': [{'end': 1191.978, 'start': 1172.564, 'weight': 1}], 'summary': "Explores genetic algorithms, demonstrating their ability to find the phrase 'to be or not to be' in 5 to 10 seconds and outlines the three key principles of evolution - heredity, variation, and selection - highlighting their application in creative software projects.", 'chapters': [{'end': 97.069, 'segs': [{'end': 54.205, 'src': 'embed', 'start': 23.551, 'weight': 2, 'content': [{'end': 28.212, 'text': 'that is the question in a sea of random, to be or not random phrases.', 'start': 23.551, 'duration': 4.661}, {'end': 30.353, 'text': 'So, to demonstrate this idea,', 'start': 28.553, 'duration': 1.8}, {'end': 36.514, 'text': "I have this particular P5 sketch running in the browser and it's just generating random phrases over and over again randomly.", 'start': 30.353, 'duration': 6.161}, {'end': 42.956, 'text': 'Now, at some point after some gajillion, jillion, jillion, gajillion amount of years, we might, I mean, it could happen right now.', 'start': 36.734, 'duration': 6.222}, {'end': 48.217, 'text': 'This could be the moment where we could be so unbelievably lucky and we would just all go buy our Powerball tickets.', 'start': 43.176, 'duration': 5.041}, {'end': 54.205, 'text': "where to be or not to be actually appears right here, but I'm pretty sure that it's not going to.", 'start': 48.217, 'duration': 5.988}], 'summary': "A p5 sketch generates random phrases, hoping to find 'to be or not to be', but chances are slim.", 'duration': 30.654, 'max_score': 23.551, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs23551.jpg'}, {'end': 90.942, 'src': 'embed', 'start': 62.646, 'weight': 0, 'content': [{'end': 66.627, 'text': "And you can see that this is now the example that I'm going to get to of the genetic algorithm running.", 'start': 62.646, 'duration': 3.981}, {'end': 72.169, 'text': 'And you can see it took a matter of 5 to 10 seconds to find this phrase, to be or not to be.', 'start': 66.887, 'duration': 5.282}, {'end': 73.169, 'text': 'And that is the question.', 'start': 72.449, 'duration': 0.72}, {'end': 74.57, 'text': 'It took a number of generations.', 'start': 73.249, 'duration': 1.321}, {'end': 76.39, 'text': "There's this concept of fitness.", 'start': 74.89, 'duration': 1.5}, {'end': 77.891, 'text': "There's this idea of a population.", 'start': 76.57, 'duration': 1.321}, {'end': 79.271, 'text': "There's this thing called a mutation rate.", 'start': 77.911, 'duration': 1.36}, {'end': 80.952, 'text': 'So this is what I need to cover.', 'start': 79.511, 'duration': 1.441}, {'end': 83.234, 'text': 'What are all the pieces of the genetic algorithm?', 'start': 81.352, 'duration': 1.882}, {'end': 84.215, 'text': 'How do they work??', 'start': 83.555, 'duration': 0.66}, {'end': 86.177, 'text': 'What is the order in which they happen?', 'start': 84.496, 'duration': 1.681}, {'end': 90.942, 'text': "And then, after I do that, we'll start looking at how all those things are implemented in actual code.", 'start': 86.498, 'duration': 4.444}], 'summary': "Genetic algorithm took 5 to 10 seconds to find 'to be or not to be' phrase.", 'duration': 28.296, 'max_score': 62.646, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs62646.jpg'}], 'start': 0.486, 'title': 'Genetic algorithms', 'summary': "Explores genetic algorithms, showcasing their ability to find the phrase 'to be or not to be' in 5 to 10 seconds through fitness, population, and mutation rate concepts.", 'chapters': [{'end': 97.069, 'start': 0.486, 'title': "Genetic algorithms: solving the 'to be or not to be' problem", 'summary': "Explores the concept of genetic algorithms and their application in finding the phrase 'to be or not to be' within a sea of random phrases, demonstrating the algorithm's ability to achieve the desired result in 5 to 10 seconds, using the concept of fitness, population, and mutation rate.", 'duration': 96.583, 'highlights': ["The genetic algorithm successfully finds the phrase 'to be or not to be' in 5 to 10 seconds The genetic algorithm demonstrates its efficiency by finding the phrase 'to be or not to be' within 5 to 10 seconds, showcasing its practical application.", "The demonstration involves finding the phrase 'to be or not to be' within a sea of random phrases The specific problem of finding the phrase 'to be or not to be' among random phrases is used as a demonstration of the genetic algorithm's capabilities.", 'The algorithm employs the concepts of fitness, population, and mutation rate The genetic algorithm utilizes the concepts of fitness, population, and mutation rate, showcasing its adaptability and effectiveness in solving complex problems.']}], 'duration': 96.583, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs486.jpg', 'highlights': ["The genetic algorithm successfully finds the phrase 'to be or not to be' in 5 to 10 seconds", 'The algorithm employs the concepts of fitness, population, and mutation rate', "The demonstration involves finding the phrase 'to be or not to be' within a sea of random phrases"]}, {'end': 418.696, 'segs': [{'end': 126.669, 'src': 'embed', 'start': 97.469, 'weight': 3, 'content': [{'end': 100.931, 'text': 'Okay, so coming back to the algorithm.', 'start': 97.469, 'duration': 3.462}, {'end': 102.613, 'text': "Oh, let's check out our car by the way.", 'start': 100.971, 'duration': 1.642}, {'end': 104.714, 'text': "So this by the way I'm just letting this run in the background.", 'start': 102.793, 'duration': 1.921}, {'end': 109.177, 'text': 'You can see that these cars from Boxcar2D are really evolving quite nicely.', 'start': 104.874, 'duration': 4.303}, {'end': 112.479, 'text': 'I want to credit whoever made Boxcar2D because I really love this project.', 'start': 109.237, 'duration': 3.242}, {'end': 114.26, 'text': "So I don't know it off the top of my head.", 'start': 112.759, 'duration': 1.501}, {'end': 117.262, 'text': "So I'll mention it in a future video and I'll make sure that it's in the description of this video.", 'start': 114.28, 'duration': 2.982}, {'end': 119.324, 'text': "But you're going to have to go to the website itself and find it.", 'start': 117.282, 'duration': 2.042}, {'end': 121.905, 'text': "Okay, so we'll check back in on our cars in a little bit.", 'start': 119.664, 'duration': 2.241}, {'end': 122.506, 'text': 'Our cars.', 'start': 122.065, 'duration': 0.441}, {'end': 126.669, 'text': 'But right now I want to go back to this kind of presentation.', 'start': 123.506, 'duration': 3.163}], 'summary': 'Boxcar2d cars are evolving nicely, credit to the project creator.', 'duration': 29.2, 'max_score': 97.469, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs97469.jpg'}, {'end': 189.438, 'src': 'embed', 'start': 164.17, 'weight': 1, 'content': [{'end': 176.253, 'text': "rigorous scientist who's trying to do a formal experiment about evolution and model evolutionary processes precisely in software to study some type of actual biological process.", 'start': 164.17, 'duration': 12.083}, {'end': 182.234, 'text': 'The idea of a genetic algorithm is simply like this idea of inspired by actual events, based on a true story.', 'start': 176.513, 'duration': 5.721}, {'end': 189.438, 'text': 'This genetic algorithm takes ideas from actual biological evolution and applies them in software.', 'start': 183.474, 'duration': 5.964}], 'summary': 'Scientist uses genetic algorithm to model evolutionary processes in software.', 'duration': 25.268, 'max_score': 164.17, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs164170.jpg'}, {'end': 297.699, 'src': 'embed', 'start': 269.502, 'weight': 0, 'content': [{'end': 273.146, 'text': "And what's the mechanism in order for there to be a variety of traits,", 'start': 269.502, 'duration': 3.644}, {'end': 276.69, 'text': 'either in the population when it starts or as the population? Evolves over time?', 'start': 273.146, 'duration': 3.544}, {'end': 280.114, 'text': "so that's another key principle variation.", 'start': 276.69, 'duration': 3.424}, {'end': 286.796, 'text': 'the last principle which must be present in the genetic algorithm is selection, selection.', 'start': 280.114, 'duration': 6.682}, {'end': 289.357, 'text': "there has to be some way of saying here's my.", 'start': 286.796, 'duration': 2.561}, {'end': 291.558, 'text': "I can't believe I'm using whiteboard markers.", 'start': 289.357, 'duration': 2.201}, {'end': 294.599, 'text': 'I should have thought about this in advance and brought some like stuff.', 'start': 291.558, 'duration': 3.041}, {'end': 295.759, 'text': 'stuffed animals would have been great.', 'start': 294.599, 'duration': 1.16}, {'end': 297.699, 'text': 'I brought some stuff that would have also been weird.', 'start': 295.759, 'duration': 1.94}], 'summary': 'Genetic algorithms require variation and selection for evolution.', 'duration': 28.197, 'max_score': 269.502, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs269502.jpg'}], 'start': 97.469, 'title': 'Algorithm evolution and genetic principles', 'summary': 'Delves into the evolving cars in boxcar2d algorithm and outlines the three key principles of evolution - heredity, variation, and selection - highlighting their application in genetic algorithms for creative software projects.', 'chapters': [{'end': 126.669, 'start': 97.469, 'title': 'Algorithm evolution in boxcar2d', 'summary': 'Discusses the evolving cars in boxcar2d algorithm, crediting the project and promising to provide more details in a future video or the description.', 'duration': 29.2, 'highlights': ['The cars from Boxcar2D are really evolving quite nicely.', 'The speaker credits Boxcar2D project for the evolving cars.', 'The speaker promises to provide more details about Boxcar2D in a future video or the description.']}, {'end': 418.696, 'start': 127.969, 'title': 'Genetic algorithm principles', 'summary': 'Discusses the three key principles of evolution - heredity, variation, and selection - and their application in genetic algorithms, emphasizing the need for these principles in creating compelling and unique creative projects in software.', 'duration': 290.727, 'highlights': ['The three key principles of evolution - heredity, variation, and selection - are essential in the genetic algorithm demonstrated, ensuring the passing of data from one generation to another, introducing variation in traits, and implementing a mechanism for selection based on fitness. The genetic algorithm applies the principles of heredity, variation, and selection to pass data from one generation to another, introduce trait variation, and implement selection based on fitness.', 'The genetic algorithm aims to approximate the processes of genetics and evolution in software to create compelling and unique creative projects, emphasizing the inspiration drawn from actual biological evolution. The genetic algorithm aims to approximate genetics and evolution processes in software to create compelling and unique creative projects, drawing inspiration from actual biological evolution.', 'The need for variation in traits is emphasized, highlighting the importance of having a mechanism to introduce a variety of traits within the population. Emphasizing the importance of introducing variation in traits within the population, requiring a mechanism to introduce a variety of traits.']}], 'duration': 321.227, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs97469.jpg', 'highlights': ['The three key principles of evolution - heredity, variation, and selection - are essential in the genetic algorithm demonstrated, ensuring the passing of data from one generation to another, introducing variation in traits, and implementing a mechanism for selection based on fitness.', 'The genetic algorithm aims to approximate the processes of genetics and evolution in software to create compelling and unique creative projects, emphasizing the inspiration drawn from actual biological evolution.', 'The need for variation in traits is emphasized, highlighting the importance of having a mechanism to introduce a variety of traits within the population.', 'The cars from Boxcar2D are really evolving quite nicely.', 'The speaker credits Boxcar2D project for the evolving cars.', 'The speaker promises to provide more details about Boxcar2D in a future video or the description.']}, {'end': 617.054, 'segs': [{'end': 474.504, 'src': 'embed', 'start': 441.793, 'weight': 0, 'content': [{'end': 444.074, 'text': "I could use rainbow, by the way, but I'm going to use unicorn.", 'start': 441.793, 'duration': 2.281}, {'end': 453.492, 'text': "I want to evolve the phrase unicorn out of every single it's not really a phrase the word, the sequence of characters,", 'start': 445.908, 'duration': 7.584}, {'end': 458.355, 'text': 'unicorn out of every single possible random sequence of characters.', 'start': 453.492, 'duration': 4.863}, {'end': 466.159, 'text': "So the very first thing that I must do in a genetic algorithm, in the traditional computer science genetic algorithm, I don't know.", 'start': 458.655, 'duration': 7.504}, {'end': 467.16, 'text': 'I just said computer science.', 'start': 466.159, 'duration': 1.001}, {'end': 474.504, 'text': 'I have to put like a quarter in my computer science jar.', 'start': 472.283, 'duration': 2.221}], 'summary': "Using a genetic algorithm to evolve the word 'unicorn' out of random character sequences.", 'duration': 32.711, 'max_score': 441.793, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs441793.jpg'}, {'end': 551.77, 'src': 'embed', 'start': 504.093, 'weight': 3, 'content': [{'end': 505.334, 'text': 'what are those three principles?', 'start': 504.093, 'duration': 1.241}, {'end': 515.562, 'text': 'I must have heredity, I must have a variation and I must have selection.', 'start': 505.334, 'duration': 10.228}, {'end': 517.222, 'text': "I'm disappointed with myself.", 'start': 515.562, 'duration': 1.66}, {'end': 522.947, 'text': 'I wish I had written variation first in this order, because ultimately this is where we get in this step.', 'start': 517.222, 'duration': 5.725}, {'end': 524.649, 'text': 'we get our first principle variation.', 'start': 522.947, 'duration': 1.702}, {'end': 528.372, 'text': 'now, the way I wrote this create a population of n elements.', 'start': 524.649, 'duration': 3.723}, {'end': 530.473, 'text': "I don't necessarily have variation there.", 'start': 528.372, 'duration': 2.101}, {'end': 538.119, 'text': 'yet I really should say create a, you know, random, and I think this might be cut off at the top, but I just wrote the word random there.', 'start': 530.473, 'duration': 7.646}, {'end': 542.062, 'text': "create a random population of n elements, and really I didn't write that very well.", 'start': 538.119, 'duration': 3.943}, {'end': 547.206, 'text': 'I should say create a population of n elements with random genetic material.', 'start': 542.062, 'duration': 5.144}, {'end': 549.328, 'text': 'now, what is this genetic material?', 'start': 547.206, 'duration': 2.122}, {'end': 551.77, 'text': 'this idea of like sort of virtual DNA, digital DNA.', 'start': 549.328, 'duration': 2.442}], 'summary': 'Three principles: heredity, variation, selection. create a population with random genetic material.', 'duration': 47.677, 'max_score': 504.093, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs504093.jpg'}, {'end': 629.139, 'src': 'embed', 'start': 601.503, 'weight': 5, 'content': [{'end': 606.587, 'text': 'I have uni here, I have a c here, but I have nothing with an o in this spot, nothing with an r.', 'start': 601.503, 'duration': 5.084}, {'end': 608.828, 'text': 'Oh, maybe I do have an r, nothing with an n in that last spot.', 'start': 606.587, 'duration': 2.241}, {'end': 615.573, 'text': "So there's more to variation than just that initial population, which I'll get to, but that's sort of a key principle.", 'start': 609.108, 'duration': 6.465}, {'end': 617.054, 'text': "Okay, so that's step number one.", 'start': 615.633, 'duration': 1.421}, {'end': 625.698, 'text': 'Great And actually you can think of this in the sort of p5.js and processing world of we have a sort of initialization and then a forever loop.', 'start': 617.614, 'duration': 8.084}, {'end': 629.139, 'text': 'This step one is actually the setup function.', 'start': 626.138, 'duration': 3.001}], 'summary': 'Variation in population is more than initial composition. step one: setup function in p5.js and processing world.', 'duration': 27.636, 'max_score': 601.503, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs601503.jpg'}], 'start': 419.056, 'title': 'Genetic and evolutionary algorithms', 'summary': "Discusses the use of genetic algorithms to evolve the word 'unicorn' and the creation of a population for an evolutionary algorithm, emphasizing the importance of variation and natural selection in achieving specific goals.", 'chapters': [{'end': 466.159, 'start': 419.056, 'title': 'Genetic algorithm for phrase evolution', 'summary': "Presents the use of a genetic algorithm to evolve the word 'unicorn' from random sequences of characters, aiming to achieve a simpler phrase, with the initial focus on natural selection and the challenge of evolving specific words.", 'duration': 47.103, 'highlights': ["The initial focus is on using natural selection to evolve the word 'unicorn' from random sequences of characters.", "The challenge involves evolving a specific word, 'unicorn', from random sequences, aiming to achieve a simpler phrase.", "The speaker discusses the consideration of using 'rainbow' but ultimately decides to focus on evolving the word 'unicorn'.", "The speaker mentions the intention to use a genetic algorithm to achieve the evolution of the word 'unicorn' from random sequences of characters."]}, {'end': 617.054, 'start': 466.159, 'title': 'Evolutionary algorithm: creating population', 'summary': 'Covers the creation of a population for an evolutionary algorithm, emphasizing the importance of variation and random genetic material, and the need for sufficient variation in the initial population for successful evolution.', 'duration': 150.895, 'highlights': ['The key principles of creating a population for an evolutionary algorithm are heredity, variation, and selection, with emphasis on the importance of variation.', 'It is essential to create a population of n elements with random genetic material, representing virtual DNA, to ensure variation and diversity.', 'The initial population should have sufficient variation to enable successful evolution, demonstrated through examples of seven-character words with random characters.']}], 'duration': 197.998, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs419056.jpg', 'highlights': ["The speaker mentions the intention to use a genetic algorithm to achieve the evolution of the word 'unicorn' from random sequences of characters.", "The initial focus is on using natural selection to evolve the word 'unicorn' from random sequences of characters.", "The challenge involves evolving a specific word, 'unicorn', from random sequences, aiming to achieve a simpler phrase.", 'The key principles of creating a population for an evolutionary algorithm are heredity, variation, and selection, with emphasis on the importance of variation.', 'It is essential to create a population of n elements with random genetic material, representing virtual DNA, to ensure variation and diversity.', 'The initial population should have sufficient variation to enable successful evolution, demonstrated through examples of seven-character words with random characters.', "The speaker discusses the consideration of using 'rainbow' but ultimately decides to focus on evolving the word 'unicorn'."]}, {'end': 1003.782, 'segs': [{'end': 690.131, 'src': 'embed', 'start': 617.614, 'weight': 0, 'content': [{'end': 625.698, 'text': 'Great And actually you can think of this in the sort of p5.js and processing world of we have a sort of initialization and then a forever loop.', 'start': 617.614, 'duration': 8.084}, {'end': 629.139, 'text': 'This step one is actually the setup function.', 'start': 626.138, 'duration': 3.001}, {'end': 632.02, 'text': 'This is what will happen in the setup function.', 'start': 629.899, 'duration': 2.121}, {'end': 639.964, 'text': "Okay, step two, which I'm going to draw a line here, because this is what's going to happen in the draw function,", 'start': 632.16, 'duration': 7.804}, {'end': 643.325, 'text': 'meaning step two is going to happen over and over and over again.', 'start': 639.964, 'duration': 3.361}, {'end': 647.047, 'text': 'Generation, generation, generation, evolving, evolving, evolving.', 'start': 644.286, 'duration': 2.761}, {'end': 658.485, 'text': 'Step 2a is calculate fitness for you know, n elements.', 'start': 648.419, 'duration': 10.066}, {'end': 664.55, 'text': 'So we want to calculate the fitness of every single member of the population.', 'start': 659.286, 'duration': 5.264}, {'end': 668.573, 'text': 'This, by the way, is playing a role now, this idea of selection.', 'start': 665.23, 'duration': 3.343}, {'end': 670.754, 'text': 'Fitness is going to be a means,', 'start': 669.053, 'duration': 1.701}, {'end': 680.442, 'text': 'a mathematical function to determine which members of the population are more likely to be selected to pass their genetic material down to the next generation.', 'start': 670.754, 'duration': 9.688}, {'end': 683.084, 'text': "so that's this idea of calculating a fitness.", 'start': 680.902, 'duration': 2.182}, {'end': 687.929, 'text': "so there's going to be some sort of loop that will go through all the elements of the population, call a function.", 'start': 683.084, 'duration': 4.845}, {'end': 690.131, 'text': 'that will calculate the fitness and give you some number back.', 'start': 687.929, 'duration': 2.202}], 'summary': 'In p5.js and processing, the setup function initializes while the draw function evolves repeatedly, calculating fitness for n elements to determine selection.', 'duration': 72.517, 'max_score': 617.614, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs617614.jpg'}, {'end': 866.391, 'src': 'embed', 'start': 836.899, 'weight': 2, 'content': [{'end': 841.381, 'text': 'So this reproduction selection step is a multi-step process.', 'start': 836.899, 'duration': 4.482}, {'end': 852.085, 'text': "the first thing that I need to do is pick two and for lack of a better word, I'm going to call them parents, and two is somewhat arbitrary.", 'start': 841.741, 'duration': 10.344}, {'end': 857.127, 'text': "so there's a lot of parts of this genetic algorithm that you can kind of play around with.", 'start': 852.085, 'duration': 5.042}, {'end': 866.391, 'text': 'certainly you could say that the way that reproduction works in your genetic algorithm is a single element just makes an entire copy of itself.', 'start': 857.127, 'duration': 9.264}], 'summary': 'Genetic algorithm reproduction involves selecting two parents and customizing the process.', 'duration': 29.492, 'max_score': 836.899, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs836899.jpg'}, {'end': 902.007, 'src': 'embed', 'start': 876.675, 'weight': 3, 'content': [{'end': 881.718, 'text': 'this is all just sort of made up as an algorithm and you might have to creative takes on this,', 'start': 876.675, 'duration': 5.043}, {'end': 886.92, 'text': 'but the sort of classic genetic algorithm kind of follows this idea of two parents.', 'start': 881.718, 'duration': 5.202}, {'end': 888.941, 'text': 'so how are those two parents picked?', 'start': 886.92, 'duration': 2.021}, {'end': 892.117, 'text': 'Well, this is an interesting thing.', 'start': 890.796, 'duration': 1.321}, {'end': 894.779, 'text': "And by the way, we're really talking about selection here.", 'start': 892.417, 'duration': 2.362}, {'end': 897.06, 'text': "We're now in the third principle here.", 'start': 894.799, 'duration': 2.261}, {'end': 902.007, 'text': "The way that those two parents are picked There's a bunch of different ways, by the way.", 'start': 897.58, 'duration': 4.427}], 'summary': 'Genetic algorithms involve selecting two parents in various ways for the algorithm.', 'duration': 25.332, 'max_score': 876.675, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs876675.jpg'}], 'start': 617.614, 'title': 'Genetic algorithms in p5.js and basics', 'summary': 'Covers the implementation of genetic algorithms in p5.js and processing, including initialization, a forever loop, fitness calculation, and selection, as well as the basics of genetic algorithms, such as the fitness function, reproduction, selection steps, and parent picking based on fitness scores to improve fitness over time.', 'chapters': [{'end': 764.735, 'start': 617.614, 'title': 'Genetic algorithm in p5.js', 'summary': 'Explains the implementation of a genetic algorithm in p5.js and processing, involving initialization, a forever loop, fitness calculation, and selection to pass genetic material down to the next generation.', 'duration': 147.121, 'highlights': ['The steps involved in the genetic algorithm include initialization, a forever loop, fitness calculation, and selection for passing genetic material down to the next generation.', 'The setup function in p5.js is equivalent to the initialization step in the genetic algorithm, while the draw function represents the forever loop.', 'Fitness calculation is a crucial aspect of the genetic algorithm, and it involves determining which members of the population are more likely to be selected based on a fitness function.', 'The fitness function for the particular problem discussed involves calculating the number of characters that match the target phrase for each element of the population, with examples demonstrating fitness scores of 5, 1, 0, and 4.', 'Refinement of fitness and optimization of genetic algorithms can improve their efficiency and performance.']}, {'end': 1003.782, 'start': 764.755, 'title': 'Genetic algorithm basics', 'summary': 'Explains the basics of a genetic algorithm, including the fitness function, reproduction and selection steps, and the process of picking parents based on fitness scores to create a new population, with the ultimate goal of improving fitness scores over time.', 'duration': 239.027, 'highlights': ['The genetic algorithm aims to create a new population of n elements through a multi-step process of reproduction and selection, resulting in higher fitness scores over time.', 'The process of picking parents in the genetic algorithm involves assigning probabilities based on fitness scores, allowing for a more traditional and effective approach compared to solely selecting the top scoring parents.', 'The way parents are picked in a genetic algorithm can be based on assigning probabilities to elements from the entire population, improving the diversity and effectiveness of the selection process.', 'The genetic algorithm involves a fitness function to calculate the fitness of the population, guiding the reproduction and selection steps to create a new population with higher overall fitness scores.']}], 'duration': 386.168, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs617614.jpg', 'highlights': ['The genetic algorithm involves a fitness function to calculate the fitness of the population, guiding the reproduction and selection steps to create a new population with higher overall fitness scores.', 'The steps involved in the genetic algorithm include initialization, a forever loop, fitness calculation, and selection for passing genetic material down to the next generation.', 'The process of picking parents in the genetic algorithm involves assigning probabilities based on fitness scores, allowing for a more traditional and effective approach compared to solely selecting the top scoring parents.', 'The way parents are picked in a genetic algorithm can be based on assigning probabilities to elements from the entire population, improving the diversity and effectiveness of the selection process.', 'The setup function in p5.js is equivalent to the initialization step in the genetic algorithm, while the draw function represents the forever loop.']}, {'end': 1434.805, 'segs': [{'end': 1073.042, 'src': 'embed', 'start': 1003.862, 'weight': 3, 'content': [{'end': 1006.742, 'text': "And most of the time, it's going to land on Unijorm.", 'start': 1003.862, 'duration': 2.88}, {'end': 1009.403, 'text': "Often, it'll also land on popcorn.", 'start': 1008.042, 'duration': 1.361}, {'end': 1011.083, 'text': "But every once in a while, it'll land on pancake.", 'start': 1009.423, 'duration': 1.66}, {'end': 1013.143, 'text': "And that's how I'm going to pick those two parents.", 'start': 1011.383, 'duration': 1.76}, {'end': 1017.444, 'text': 'So the higher the fitness, the more likely that element is to be selected.', 'start': 1013.403, 'duration': 4.041}, {'end': 1019.025, 'text': "So that's step one.", 'start': 1018.004, 'duration': 1.021}, {'end': 1030.329, 'text': "Once I have those two parents, I'm going to make a new, and I'm using the word element just to be a sort of word for a member of the population,", 'start': 1019.785, 'duration': 10.544}, {'end': 1032.531, 'text': 'a creature element thing.', 'start': 1030.329, 'duration': 2.202}, {'end': 1033.891, 'text': "but I'm gonna make a new element.", 'start': 1032.531, 'duration': 1.36}, {'end': 1037.893, 'text': 'And making the new element is a two-step process.', 'start': 1035.112, 'duration': 2.781}, {'end': 1045.396, 'text': 'One step is called crossover, and another step is called mutation.', 'start': 1039.733, 'duration': 5.663}, {'end': 1053.23, 'text': 'And this is, by the way, where we get our last key principle from Darwinian evolution.', 'start': 1046.743, 'duration': 6.487}, {'end': 1057.834, 'text': 'So we had variation because we created an initial population of random elements.', 'start': 1053.51, 'duration': 4.324}, {'end': 1065.479, 'text': 'We have selection in that we calculate the fitness of each element, and we use the fitness as a probability.', 'start': 1058.996, 'duration': 6.483}, {'end': 1068.18, 'text': "It's sort of selection probability.", 'start': 1065.499, 'duration': 2.681}, {'end': 1069.98, 'text': "It's probability of being selected as a parent.", 'start': 1068.22, 'duration': 1.76}, {'end': 1073.042, 'text': 'And now, to make that new element,', 'start': 1070.421, 'duration': 2.621}], 'summary': 'Using fitness to select parents, then crossover and mutation to create new elements in a two-step process inspired by darwinian evolution.', 'duration': 69.18, 'max_score': 1003.862, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs1003862.jpg'}, {'end': 1172.564, 'src': 'embed', 'start': 1139.633, 'weight': 0, 'content': [{'end': 1142.274, 'text': 'you combine those taking two with a high fitness to make a new one.', 'start': 1139.633, 'duration': 2.641}, {'end': 1146.956, 'text': 'you have a good chance of getting a child with an even higher fitness score for that next generation.', 'start': 1142.274, 'duration': 4.682}, {'end': 1147.956, 'text': 'So this is the idea.', 'start': 1147.236, 'duration': 0.72}, {'end': 1150.237, 'text': "Now there's a lot of different ways that you can do crossover.", 'start': 1148.016, 'duration': 2.221}, {'end': 1152.878, 'text': 'You can actually just pick a random midpoint.', 'start': 1151.177, 'duration': 1.701}, {'end': 1158.58, 'text': 'So sometimes you just take one from the other, Six from one or five from one and three from the other.', 'start': 1153.118, 'duration': 5.462}, {'end': 1163.962, 'text': 'you could do something where you like alternate, take you then, oh, then I then see right, or you could flip it.', 'start': 1158.58, 'duration': 5.382}, {'end': 1166.382, 'text': 'you can have a 50% probability for each one.', 'start': 1163.962, 'duration': 2.42}, {'end': 1172.564, 'text': 'you could, you know, you could turn this into binary information and mix up the zeros and the ones and then convert those back into characters.', 'start': 1166.382, 'duration': 6.182}], 'summary': 'Combining high-fitness individuals leads to offspring with higher fitness scores for the next generation, using various crossover techniques.', 'duration': 32.931, 'max_score': 1139.633, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs1139633.jpg'}, {'end': 1192.579, 'src': 'heatmap', 'start': 1166.382, 'weight': 4, 'content': [{'end': 1172.564, 'text': 'you could, you know, you could turn this into binary information and mix up the zeros and the ones and then convert those back into characters.', 'start': 1166.382, 'duration': 6.182}, {'end': 1179.027, 'text': "there's all sorts of ways that you can do crossover, but you'll see what I'm doing in my example, which is kind of a, You know,", 'start': 1172.564, 'duration': 6.463}, {'end': 1184.591, 'text': "conventional way of doing it is picking out midpoint, taking half from one and half from the other, and, as you'll see,", 'start': 1179.027, 'duration': 5.564}, {'end': 1185.992, 'text': 'These characters are stored in an array.', 'start': 1184.591, 'duration': 1.401}, {'end': 1191.978, 'text': "That's what I'm going to get to it soon as soon as we look at the code So that's crossover Now, we could say that I'm done.", 'start': 1186.032, 'duration': 5.946}, {'end': 1192.579, 'text': 'This is it.', 'start': 1192.198, 'duration': 0.381}], 'summary': 'Using crossover in genetic algorithm to mix binary information and characters in an array.', 'duration': 26.197, 'max_score': 1166.382, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs1166382.jpg'}, {'end': 1236.359, 'src': 'embed', 'start': 1203.467, 'weight': 7, 'content': [{'end': 1204.448, 'text': 'Calculate the fitness again.', 'start': 1203.467, 'duration': 0.981}, {'end': 1206.03, 'text': 'Create a new generation with crossover.', 'start': 1204.708, 'duration': 1.322}, {'end': 1207.13, 'text': 'Over and over and over again.', 'start': 1206.17, 'duration': 0.96}, {'end': 1208.412, 'text': 'That could be it.', 'start': 1207.791, 'duration': 0.621}, {'end': 1209.993, 'text': "However, there's a problem.", 'start': 1208.912, 'duration': 1.081}, {'end': 1217.935, 'text': 'In the case of not having enough variation in the initial population, which is quite a reasonable thing to have,', 'start': 1210.693, 'duration': 7.242}, {'end': 1224.336, 'text': 'it is often useful to artificially introduce additional variation into this process.', 'start': 1217.935, 'duration': 6.401}, {'end': 1232.018, 'text': 'So two elements of the population are combined with crossover, but before that child is finished, a mutation is applied.', 'start': 1224.696, 'duration': 7.322}, {'end': 1236.359, 'text': 'And mutation is typically referred to as a sort of percentage rate.', 'start': 1232.298, 'duration': 4.061}], 'summary': 'Iteratively calculate fitness, create new generations with crossover, and introduce mutation to address lack of variation in initial population.', 'duration': 32.892, 'max_score': 1203.467, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs1203467.jpg'}, {'end': 1314.761, 'src': 'embed', 'start': 1265.012, 'weight': 1, 'content': [{'end': 1267.113, 'text': 'And this keeps variation in the system.', 'start': 1265.012, 'duration': 2.101}, {'end': 1276.419, 'text': "This mutation rate, as I'll show you in a little bit when I run the example again, really, really affects how the algorithm behaves.", 'start': 1267.153, 'duration': 9.266}, {'end': 1278.76, 'text': 'Is there a lot of randomness, less randomness, that sort of thing.', 'start': 1276.479, 'duration': 2.281}, {'end': 1281.062, 'text': 'So this really completes the genetic algorithm.', 'start': 1279.041, 'duration': 2.021}, {'end': 1282.463, 'text': 'This is the fold.', 'start': 1281.863, 'duration': 0.6}, {'end': 1284.885, 'text': 'We have heredity as part of crossover.', 'start': 1282.483, 'duration': 2.402}, {'end': 1286.246, 'text': "That's the mechanism for heredity.", 'start': 1284.925, 'duration': 1.321}, {'end': 1293.731, 'text': 'We have variation in the way that we create the initial population and the way that we use mutation as that last step of making the next generation.', 'start': 1286.486, 'duration': 7.245}, {'end': 1301.077, 'text': 'And selection as this way of using a mathematical function to assign a fitness score to each element of the population.', 'start': 1294.172, 'duration': 6.905}, {'end': 1314.761, 'text': 'as well as then using that fitness score as a probability for how that element of the population,', 'start': 1301.657, 'duration': 13.104}], 'summary': 'Genetic algorithm includes heredity, variation, and selection to assign fitness scores.', 'duration': 49.749, 'max_score': 1265.012, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs1265012.jpg'}], 'start': 1003.862, 'title': 'Genetic algorithms', 'summary': 'Delves into the process of genetic algorithms, covering the selection of parents based on fitness, crossover techniques, and the impact of mutation rate and fitness function, providing a comprehensive understanding of genetic algorithm processes.', 'chapters': [{'end': 1073.042, 'start': 1003.862, 'title': 'Genetic algorithm process', 'summary': 'Explains the process of genetic algorithm, which involves selecting parents based on fitness, creating a new element through crossover and mutation, and utilizing principles from darwinian evolution.', 'duration': 69.18, 'highlights': ['The higher the fitness, the more likely that element is to be selected, determining the selection probability of parents based on their fitness.', 'Creating a new element involves a two-step process: crossover and mutation, as part of the genetic algorithm.', 'Utilizing principles from Darwinian evolution, such as variation, selection based on fitness, and the process of creating new elements through crossover and mutation.']}, {'end': 1184.591, 'start': 1073.042, 'title': 'Genetic crossover technique', 'summary': 'Explains the technique of crossover in genetic algorithms, where genetic information from two members of a population is combined to create a new member with potentially higher fitness, with various methods of crossover discussed.', 'duration': 111.549, 'highlights': ["The technique of crossover involves combining genetic information from two members of a population to create a new member with potentially higher fitness, contributing to the advancement of the population's genetic diversity and fitness scores.", 'Various methods of crossover are discussed, including picking a random midpoint, alternating selections, flipping selections, and converting to binary information, providing insights into the diverse approaches available for implementing crossover in genetic algorithms.']}, {'end': 1434.805, 'start': 1184.591, 'title': 'Genetic algorithm explained', 'summary': 'Explains the process of a genetic algorithm, including the steps of creating a random population, applying crossover, mutation, and selection, and how these steps are repeated to create new generations, with a focus on the impact of mutation rate and the role of fitness function in the algorithm.', 'duration': 250.214, 'highlights': ['The genetic algorithm involves creating a random population, applying crossover, mutation, and selection, and repeating these steps to create new generations. The genetic algorithm involves creating a random population, calculating fitness, creating a new generation with crossover, and repeating these steps over and over again.', "The impact of mutation rate on the algorithm's behavior is significant, affecting the level of randomness in the system. The mutation rate significantly affects how the algorithm behaves, influencing the level of randomness in the system.", 'The role of fitness function in evaluating each element of the population and using the fitness score as a probability for selection is crucial in the genetic algorithm. The fitness function plays a crucial role in evaluating each element of the population and using the fitness score as a probability for selection in the genetic algorithm.']}], 'duration': 430.943, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/RxTfc4JLYKs/pics/RxTfc4JLYKs1003862.jpg', 'highlights': ["The technique of crossover involves combining genetic information from two members of a population to create a new member with potentially higher fitness, contributing to the advancement of the population's genetic diversity and fitness scores.", 'The role of fitness function in evaluating each element of the population and using the fitness score as a probability for selection is crucial in the genetic algorithm.', "The impact of mutation rate on the algorithm's behavior is significant, affecting the level of randomness in the system.", 'Utilizing principles from Darwinian evolution, such as variation, selection based on fitness, and the process of creating new elements through crossover and mutation.', 'Various methods of crossover are discussed, including picking a random midpoint, alternating selections, flipping selections, and converting to binary information, providing insights into the diverse approaches available for implementing crossover in genetic algorithms.', 'The higher the fitness, the more likely that element is to be selected, determining the selection probability of parents based on their fitness.', 'Creating a new element involves a two-step process: crossover and mutation, as part of the genetic algorithm.', 'The genetic algorithm involves creating a random population, applying crossover, mutation, and selection, and repeating these steps to create new generations.']}], 'highlights': ["The genetic algorithm successfully finds the phrase 'to be or not to be' in 5 to 10 seconds", 'The algorithm employs the concepts of fitness, population, and mutation rate', "The demonstration involves finding the phrase 'to be or not to be' within a sea of random phrases", 'The three key principles of evolution - heredity, variation, and selection - are essential in the genetic algorithm demonstrated, ensuring the passing of data from one generation to another, introducing variation in traits, and implementing a mechanism for selection based on fitness', 'The genetic algorithm aims to approximate the processes of genetics and evolution in software to create compelling and unique creative projects, emphasizing the inspiration drawn from actual biological evolution', 'The need for variation in traits is emphasized, highlighting the importance of having a mechanism to introduce a variety of traits within the population', "The speaker mentions the intention to use a genetic algorithm to achieve the evolution of the word 'unicorn' from random sequences of characters", "The initial focus is on using natural selection to evolve the word 'unicorn' from random sequences of characters", "The challenge involves evolving a specific word, 'unicorn', from random sequences, aiming to achieve a simpler phrase", 'The genetic algorithm involves a fitness function to calculate the fitness of the population, guiding the reproduction and selection steps to create a new population with higher overall fitness scores', 'The steps involved in the genetic algorithm include initialization, a forever loop, fitness calculation, and selection for passing genetic material down to the next generation', 'The process of picking parents in the genetic algorithm involves assigning probabilities based on fitness scores, allowing for a more traditional and effective approach compared to solely selecting the top scoring parents', 'The way parents are picked in a genetic algorithm can be based on assigning probabilities to elements from the entire population, improving the diversity and effectiveness of the selection process', "The technique of crossover involves combining genetic information from two members of a population to create a new member with potentially higher fitness, contributing to the advancement of the population's genetic diversity and fitness scores", 'The role of fitness function in evaluating each element of the population and using the fitness score as a probability for selection is crucial in the genetic algorithm', "The impact of mutation rate on the algorithm's behavior is significant, affecting the level of randomness in the system", 'Utilizing principles from Darwinian evolution, such as variation, selection based on fitness, and the process of creating new elements through crossover and mutation', 'Various methods of crossover are discussed, including picking a random midpoint, alternating selections, flipping selections, and converting to binary information, providing insights into the diverse approaches available for implementing crossover in genetic algorithms', 'The higher the fitness, the more likely that element is to be selected, determining the selection probability of parents based on their fitness', 'Creating a new element involves a two-step process: crossover and mutation, as part of the genetic algorithm', 'The genetic algorithm involves creating a random population, applying crossover, mutation, and selection, and repeating these steps to create new generations']}