title
9.4: Genetic Algorithm: Looking at Code - The Nature of Code
description
In part 4 of the series on Genetic Algorithm, I finally look at code! Using p5.js (and Processing / Java in the addendum), I implement the Shakespeare Monkey genetic algorithm example in JavaScript. https://thecodingtrain.com/more/archive/nature-of-code/9-genetic-algorithms/9.4-looking-at-code.html
đšī¸ p5.js Web Editor Sketch: https://editor.p5js.org/codingtrain/sketches/PqRSmKLQU
đĨ Previous video: https://youtu.be/nrKjSeoc7fc?list=RxTfc4JLYKs&list=PLRqwX-V7Uu6bJM3VgzjNV5YxVxUwzALHV
đĨ Next video: https://youtu.be/_of6UVV4HGo?list=RxTfc4JLYKs&list=PLRqwX-V7Uu6bJM3VgzjNV5YxVxUwzALHV
đĨ All videos: https://www.youtube.com/playlist?list=RxTfc4JLYKs&list=PLRqwX-V7Uu6bJM3VgzjNV5YxVxUwzALHV
Links discussed in this video:
đ Nature of Code Book: https://natureofcode.com/
đ ASCII Table: https://www.asciitable.com/
Timestamps:
0:00 Welcome!
1:14 How do I have the code organized?
2:41 Explore! Creating the population.
5:54 Explore! Calculate fitness.
8:40 Explain! How am I picking the parents?
12:58 Explore! How I am making a matting pool.
15:45 Explore! How am I making a new generation?
17:15 Explore! Crossover and mutation.
19:09 That's everything.
20:27 Ideas! What could you create?
21:30 Addendum! Processing code!
đ Website: http://thecodingtrain.com/
đž Share Your Creation! https://thecodingtrain.com/Guides/community-contribution-guide.html
đŠ Suggest Topics: https://github.com/CodingTrain/Rainbow-Topics
đĄ GitHub: https://github.com/CodingTrain
đŦ Discord: https://discord.gg/hPuGy2g
đ Membership: http://youtube.com/thecodingtrain/join
đ Store: https://standard.tv/codingtrain
đ Books: https://www.amazon.com/shop/thecodingtrain
đī¸ 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
detail
{'title': '9.4: Genetic Algorithm: Looking at Code - The Nature of Code', 'heatmap': [{'end': 208.496, 'start': 162.745, 'weight': 1}], 'summary': 'Delves into the genetic algorithm code, covering steps like population initialization, fitness calculation, selection, crossover, and mutation to understand the implementation and functionality of the algorithm, with a fitness score of 90% for 9 out of 10 correct characters, and demonstrations of reproduction, selection, and mutation to generate a new population.', 'chapters': [{'end': 69.379, 'segs': [{'end': 83.484, 'src': 'embed', 'start': 54.882, 'weight': 0, 'content': [{'end': 56.404, 'text': 'How do you write the algorithm for crossover?', 'start': 54.882, 'duration': 1.522}, {'end': 62.612, 'text': 'How do you write the algorithm for mutation and then have this new population that you then make the current population repeat over and over again?', 'start': 56.605, 'duration': 6.007}, {'end': 67.218, 'text': 'So I want to look at every single one of these steps and find in the code where those steps happen.', 'start': 62.832, 'duration': 4.386}, {'end': 69.379, 'text': "So Let's just start doing that.", 'start': 67.578, 'duration': 1.801}, {'end': 76.061, 'text': 'Actually, before I do that though, let me at least open up this directory here and show you how I have the code organized.', 'start': 69.659, 'duration': 6.402}, {'end': 77.402, 'text': 'So I have the code organized.', 'start': 76.302, 'duration': 1.1}, {'end': 81.103, 'text': "There's the libraries folder for the p5.js JavaScript library I'm using.", 'start': 77.642, 'duration': 3.461}, {'end': 83.484, 'text': "There's the HTML file which references the JavaScript files.", 'start': 81.123, 'duration': 2.361}], 'summary': 'Reviewing algorithm implementation and code organization for genetic algorithm.', 'duration': 28.602, 'max_score': 54.882, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc54882.jpg'}], 'start': 0.453, 'title': 'Genetic algorithms code analysis', 'summary': 'Covers an in-depth analysis of genetic algorithm code, exploring each step such as population initialization, fitness calculation, selection, crossover, and mutation, aiming to understand the implementation and functionality of the algorithm.', 'chapters': [{'end': 69.379, 'start': 0.453, 'title': 'Genetic algorithms code analysis', 'summary': 'Covers an in-depth analysis of the genetic algorithm code, exploring each step such as population initialization, fitness calculation, selection, crossover, and mutation, aiming to understand the implementation and functionality of the algorithm.', 'duration': 68.926, 'highlights': ['The chapter delves into an in-depth analysis of the genetic algorithm code, exploring each step such as population initialization, fitness calculation, selection, crossover, and mutation, aiming to understand the implementation and functionality of the algorithm.', "The video series is focused on dissecting a pre-made code example from 'The Nature of Code, chapter 9', providing a detailed understanding of the genetic algorithm implementation.", "The analysis aims to comprehend the code's functionality, addressing various aspects such as population initialization, fitness calculation, selection, crossover, and mutation, enabling a comprehensive understanding of the algorithm's implementation."]}], 'duration': 68.926, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc453.jpg', 'highlights': ['The chapter delves into an in-depth analysis of the genetic algorithm code, exploring each step such as population initialization, fitness calculation, selection, crossover, and mutation, aiming to understand the implementation and functionality of the algorithm.', "The video series is focused on dissecting a pre-made code example from 'The Nature of Code, chapter 9', providing a detailed understanding of the genetic algorithm implementation.", "The analysis aims to comprehend the code's functionality, addressing various aspects such as population initialization, fitness calculation, selection, crossover, and mutation, enabling a comprehensive understanding of the algorithm's implementation."]}, {'end': 350.403, 'segs': [{'end': 130.104, 'src': 'embed', 'start': 103.632, 'weight': 0, 'content': [{'end': 110.615, 'text': "so there's functions for calculating the fitness values there, there's functions for doing the selection there, and then there's the dna.js file.", 'start': 103.632, 'duration': 6.983}, {'end': 116.157, 'text': 'this is a really important file, because this file is actually this object, this DNA object.', 'start': 110.615, 'duration': 5.542}, {'end': 123.801, 'text': 'as I look at more sophisticated examples in future videos, The code in dna.js will actually be present in almost all of them.', 'start': 116.157, 'duration': 7.644}, {'end': 130.104, 'text': "so a lot of what's great, even though this example is kind of completely trivial example, because again I could just type to be or not to be.", 'start': 123.801, 'duration': 6.303}], 'summary': 'The dna.js file contains crucial code for fitness calculation and selection, and will be present in many future examples.', 'duration': 26.472, 'max_score': 103.632, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc103632.jpg'}, {'end': 208.496, 'src': 'heatmap', 'start': 162.745, 'weight': 1, 'content': [{'end': 165.867, 'text': 'And where this happens is actually in population.js.', 'start': 162.745, 'duration': 3.122}, {'end': 168.329, 'text': 'And we can actually see this happen right here.', 'start': 165.907, 'duration': 2.422}, {'end': 171.811, 'text': 'I say create population equals a new population.', 'start': 168.909, 'duration': 2.902}, {'end': 174.793, 'text': 'So the population is made with three arguments.', 'start': 172.072, 'duration': 2.721}, {'end': 178.836, 'text': 'A target, which is the target phrase, to be or not to be, which I could change.', 'start': 174.974, 'duration': 3.862}, {'end': 181.518, 'text': 'A mutation rate and a population max.', 'start': 179.176, 'duration': 2.342}, {'end': 185, 'text': 'So those values are sort of stored also in that population object.', 'start': 181.558, 'duration': 3.442}, {'end': 192.598, 'text': 'And in the population object itself, This is the kind of key variable, this.population.', 'start': 185.44, 'duration': 7.158}, {'end': 194.18, 'text': 'Oh, no.', 'start': 192.618, 'duration': 1.562}, {'end': 198.228, 'text': "Don't forget.", 'start': 197.566, 'duration': 0.662}, {'end': 201.753, 'text': "don't forget this dot.", 'start': 200.632, 'duration': 1.121}, {'end': 208.496, 'text': 'so variables that are part of that object itself are attached to it by saying this dot population.', 'start': 201.753, 'duration': 6.743}], 'summary': 'In population.js, a new population is created with a target phrase, mutation rate, and population max.', 'duration': 45.751, 'max_score': 162.745, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc162745.jpg'}, {'end': 312.579, 'src': 'embed', 'start': 282.807, 'weight': 4, 'content': [{'end': 283.387, 'text': 'Think I broke.', 'start': 282.807, 'duration': 0.58}, {'end': 284.328, 'text': "no, I didn't break this anyway.", 'start': 283.387, 'duration': 0.941}, {'end': 285.009, 'text': 'that light went off.', 'start': 284.328, 'duration': 0.681}, {'end': 288.211, 'text': 'this might be a little bit darker for a second.', 'start': 285.009, 'duration': 3.202}, {'end': 290.854, 'text': 'Okay, the fan is blowing at my legs.', 'start': 288.211, 'duration': 2.643}, {'end': 293.176, 'text': 'So this is the population array.', 'start': 290.854, 'duration': 2.322}, {'end': 300.342, 'text': 'each element of the array is a phrase which is actually a DNA object, which itself is an array,', 'start': 293.176, 'duration': 7.166}, {'end': 304.606, 'text': 'and each element of that array being a single character.', 'start': 300.342, 'duration': 4.264}, {'end': 307.176, 'text': "okay, so that's how.", 'start': 305.635, 'duration': 1.541}, {'end': 310.258, 'text': 'each element of the population is an array of elements.', 'start': 307.176, 'duration': 3.082}, {'end': 312.579, 'text': 'each element is an array of characters.', 'start': 310.258, 'duration': 2.321}], 'summary': 'Describing a population array of dna objects with single characters.', 'duration': 29.772, 'max_score': 282.807, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc282807.jpg'}, {'end': 359.018, 'src': 'embed', 'start': 331.77, 'weight': 2, 'content': [{'end': 336.133, 'text': 'there might be an easier way to do this in JavaScript, but I really just want random characters.', 'start': 331.77, 'duration': 4.363}, {'end': 338.274, 'text': "I'm using that sort of ASCII table here.", 'start': 336.133, 'duration': 2.141}, {'end': 347.261, 'text': "so I'm picking a random number between 63 and 122 and then converting those from that number to a string using its character code.", 'start': 338.274, 'duration': 8.987}, {'end': 350.403, 'text': "so like using the ASCII table, and if you're not sure what the ASCII table is,", 'start': 347.261, 'duration': 3.142}, {'end': 355.126, 'text': "I'll try to include a reference link in this video's description to that.", 'start': 350.403, 'duration': 4.723}, {'end': 359.018, 'text': 'so that is step one initialize.', 'start': 355.126, 'duration': 3.892}], 'summary': 'Using javascript to generate random characters within ascii table range 63-122.', 'duration': 27.248, 'max_score': 331.77, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc331770.jpg'}], 'start': 69.659, 'title': 'Organizing and implementing genetic algorithm code', 'summary': 'Covers organizing the genetic algorithm code, discussing file structure, main program in sketch.js, population.js object, and dna.js file. it also explains implementing dna.js in a different scenario, focusing on dna object, mutation function, creating a population, and storing values in the population object.', 'chapters': [{'end': 141.242, 'start': 69.659, 'title': 'Organizing genetic algorithm code', 'summary': 'Discusses the organization of the code for a genetic algorithm, including the file structure, the main program in sketch.js, the population.js object managing the population, and the dna.js file as the key object for future examples.', 'duration': 71.583, 'highlights': ['The dna.js file is crucial as it contains the DNA object, which will be present in almost all future examples, making it a key component for building genetic algorithms.', 'The population.js file manages the array of all the elements of the population, including functions for calculating fitness values and selection.', 'The HTML file references the JavaScript files, while the libraries folder contains the p5.js JavaScript library used in the code organization.']}, {'end': 214.599, 'start': 141.242, 'title': 'Implementing dna.js in a different scenario', 'summary': 'Discusses implementing dna.js in a different scenario, focusing on the dna object, mutation function, creating a population, and storing values in the population object.', 'duration': 73.357, 'highlights': ['The DNA.js has a DNA object with a function for mutation and it stores characters for each phrase and individual elements of the population.', 'The population is created with a target phrase, mutation rate, and population max, and these values are stored in the population object.', 'The population object is a constructor function creating a JavaScript object and it is made as an empty array.']}, {'end': 350.403, 'start': 214.599, 'title': 'Creating dna objects for population', 'summary': 'Explains the process of creating a population array of dna objects, with each element being an array of characters, and the method of generating random characters using the ascii table.', 'duration': 135.804, 'highlights': ['The population object is a big array of n elements, with each element being a random phrase.', 'Each element of the population is an array of elements, and each element is an array of characters.', 'The method of generating random characters involves picking a random number between 63 and 122 and converting it to a string using its character code from the ASCII table.']}], 'duration': 280.744, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc69659.jpg', 'highlights': ['The dna.js file is crucial as it contains the DNA object, which will be present in almost all future examples, making it a key component for building genetic algorithms.', 'The population.js file manages the array of all the elements of the population, including functions for calculating fitness values and selection.', 'The DNA.js has a DNA object with a function for mutation and it stores characters for each phrase and individual elements of the population.', 'The population is created with a target phrase, mutation rate, and population max, and these values are stored in the population object.', 'The population object is a big array of n elements, with each element being a random phrase.']}, {'end': 509.902, 'segs': [{'end': 376.428, 'src': 'embed', 'start': 350.403, 'weight': 1, 'content': [{'end': 355.126, 'text': "I'll try to include a reference link in this video's description to that.", 'start': 350.403, 'duration': 4.723}, {'end': 359.018, 'text': 'so that is step one initialize.', 'start': 355.126, 'duration': 3.892}, {'end': 362.22, 'text': 'Step two being selection.', 'start': 360.879, 'duration': 1.341}, {'end': 366.922, 'text': 'Now we need to evaluate the fitness of every element of the population.', 'start': 362.62, 'duration': 4.302}, {'end': 374.687, 'text': 'So where does that happen? So one thing, by the way, that I think is worth looking at is this main program.', 'start': 367.182, 'duration': 7.505}, {'end': 376.428, 'text': 'So draw, by the way, look at this.', 'start': 374.967, 'duration': 1.461}], 'summary': 'Video will include a reference link; initializing, selecting, and evaluating population fitness are steps to consider.', 'duration': 26.025, 'max_score': 350.403, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc350403.jpg'}, {'end': 519.953, 'src': 'embed', 'start': 492.534, 'weight': 0, 'content': [{'end': 495.955, 'text': 'And the fitness is the score divided by the total length.', 'start': 492.534, 'duration': 3.421}, {'end': 499.957, 'text': 'So the number of characters correct divided by the total length gives you a percentage.', 'start': 496.215, 'duration': 3.742}, {'end': 503.659, 'text': 'I got nine out of 10 characters correct, a fitness score of 90%.', 'start': 499.977, 'duration': 3.682}, {'end': 505.16, 'text': "So you can see that's what's happening.", 'start': 503.659, 'duration': 1.501}, {'end': 509.902, 'text': "And so that's step two selection, calculate fitness.", 'start': 505.38, 'duration': 4.522}, {'end': 519.953, 'text': 'initialize, generate 200 random DNA objects, step to calculate the fitness for those random DNA objects.', 'start': 510.925, 'duration': 9.028}], 'summary': 'Fitness score is 90% based on 9 out of 10 correct characters in dna objects.', 'duration': 27.419, 'max_score': 492.534, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc492534.jpg'}], 'start': 350.403, 'title': 'Genetic algorithm: selection and fitness evaluation', 'summary': 'Elaborates on the steps of genetic algorithm, including fitness evaluation and selection, resulting in a fitness score of 90% for 9 out of 10 correct characters.', 'chapters': [{'end': 509.902, 'start': 350.403, 'title': 'Genetic algorithm: selection and fitness evaluation', 'summary': 'Elaborates on the steps of genetic algorithm, including fitness evaluation and selection, through functions like calculatefitness and calcfitness, resulting in a fitness score of 90% for 9 out of 10 correct characters.', 'duration': 159.499, 'highlights': ['The fitness function calculates the score by iterating over each character in the phrase and comparing it with the target phrase, resulting in a fitness score of 90% for 9 out of 10 correct characters.', 'The population object contains specific functions for the algorithm steps, such as calculating fitness for every element, performing natural selection, and generating the next population.', 'The calculateFitness function loops through every member of the population and calls another function, calcFitness, to check the fitness against the target phrase.']}], 'duration': 159.499, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc350403.jpg', 'highlights': ['The fitness function calculates the score by iterating over each character in the phrase and comparing it with the target phrase, resulting in a fitness score of 90% for 9 out of 10 correct characters.', 'The population object contains specific functions for the algorithm steps, such as calculating fitness for every element, performing natural selection, and generating the next population.', 'The calculateFitness function loops through every member of the population and calls another function, calcFitness, to check the fitness against the target phrase.']}, {'end': 779.447, 'segs': [{'end': 583.222, 'src': 'embed', 'start': 559.895, 'weight': 0, 'content': [{'end': 568.417, 'text': 'Well, you know, I could actually build in the code like this sort of physics simulation of a spinning wheel, but that would be a little bit overkill.', 'start': 559.895, 'duration': 8.522}, {'end': 576.88, 'text': 'There are a lot of different techniques of picking random elements from an array based on probabilities.', 'start': 568.597, 'duration': 8.283}, {'end': 581.301, 'text': "There's a technique where I can pick two random numbers, a kind of qualifying random number.", 'start': 576.9, 'duration': 4.401}, {'end': 583.222, 'text': 'I forget what I called it.', 'start': 582.361, 'duration': 0.861}], 'summary': 'Discussion on techniques for picking random elements from an array and the consideration of building a physics simulation in code.', 'duration': 23.327, 'max_score': 559.895, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc559895.jpg'}], 'start': 510.925, 'title': 'Genetic algorithm reproduction process and picking random elements based on probabilities', 'summary': 'Introduces the process of genetic algorithm reproduction, including generating 200 random dna objects, calculating fitness, and using a spinning wheel selection method to pick parents based on their fitness. it also explains a technique for picking random elements from an array based on probabilities, with a having a 40% chance, b 20%, c 10%, and d 30%, and demonstrates how to adjust the probability in the array to increase the likelihood of being picked, using a fitness-based approach.', 'chapters': [{'end': 559.095, 'start': 510.925, 'title': 'Genetic algorithm reproduction process', 'summary': 'Introduces the process of genetic algorithm reproduction, including generating 200 random dna objects, calculating fitness, and using a spinning wheel selection method to pick parents based on their fitness.', 'duration': 48.17, 'highlights': ['The process involves initializing and generating 200 random DNA objects.', 'Calculating the fitness for these random DNA objects is a crucial step in the process.', "A spinning wheel selection method is used to pick parents based on their fitness, with fitter individuals receiving a larger slice of the 'wheel of fortune'."]}, {'end': 779.447, 'start': 559.895, 'title': 'Picking random elements based on probabilities', 'summary': 'Explains a technique for picking random elements from an array based on probabilities, with a having a 40% chance, b 20%, c 10%, and d 30%, and demonstrates how to adjust the probability in the array to increase the likelihood of being picked, using a fitness-based approach.', 'duration': 219.552, 'highlights': ['A has a 40% chance of being picked, B 20%, C 10%, and D 30% The chapter outlines the percentage chance of each element being picked, with quantifiable data.', 'Demonstrates adjusting the probability in the array to increase the likelihood of being picked The chapter explains a technique for adjusting the probability in the array to increase the likelihood of being picked, with a fitness-based approach.', 'Technique for picking random elements from an array based on probabilities The chapter introduces a technique for picking random elements from an array based on probabilities, demonstrating a method to adjust the probability to increase the likelihood of being picked.']}], 'duration': 268.522, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc510925.jpg', 'highlights': ["A spinning wheel selection method is used to pick parents based on their fitness, with fitter individuals receiving a larger slice of the 'wheel of fortune'.", 'Calculating the fitness for these random DNA objects is a crucial step in the process.', 'The process involves initializing and generating 200 random DNA objects.', 'Demonstrates adjusting the probability in the array to increase the likelihood of being picked The chapter explains a technique for adjusting the probability in the array to increase the likelihood of being picked, with a fitness-based approach.', 'Technique for picking random elements from an array based on probabilities The chapter introduces a technique for picking random elements from an array based on probabilities, demonstrating a method to adjust the probability to increase the likelihood of being picked.', 'A has a 40% chance of being picked, B 20%, C 10%, and D 30% The chapter outlines the percentage chance of each element being picked, with quantifiable data.']}, {'end': 1234.805, 'segs': [{'end': 904.085, 'src': 'embed', 'start': 876.044, 'weight': 4, 'content': [{'end': 878.665, 'text': 'So actually, the range is between 0 and 100.', 'start': 876.044, 'duration': 2.621}, {'end': 882.566, 'text': "And you could see that's what's happening right here.", 'start': 878.665, 'duration': 3.901}, {'end': 888.619, 'text': 'I do that mapping, then oops, I lost my.', 'start': 883.717, 'duration': 4.902}, {'end': 895.402, 'text': "oh I sorry, I lost control of my computer and then I multiply that value by a hundred and that's n.", 'start': 888.619, 'duration': 6.783}, {'end': 899.744, 'text': "that's how many times those elements are in the mating pool itself.", 'start': 895.402, 'duration': 4.342}, {'end': 904.085, 'text': "so if I were to just do something which I'm a little bit afraid to do, but I'm going to say console,", 'start': 899.744, 'duration': 4.341}], 'summary': 'The range is 0-100, multiplied by 100 for elements in mating pool.', 'duration': 28.041, 'max_score': 876.044, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc876044.jpg'}, {'end': 1024.448, 'src': 'embed', 'start': 993.385, 'weight': 6, 'content': [{'end': 993.806, 'text': 'Big deal.', 'start': 993.385, 'duration': 0.421}, {'end': 995.007, 'text': 'So I have two parents.', 'start': 994.026, 'duration': 0.981}, {'end': 998.248, 'text': 'Parent, or I play a partner a and partner B.', 'start': 995.427, 'duration': 2.821}, {'end': 1003.47, 'text': 'both of those are DNA objects that come from the mating pool, And then I simply call crossover.', 'start': 998.248, 'duration': 5.222}, {'end': 1008.313, 'text': 'I take partner, a crossover with partner B, And that is a new child element.', 'start': 1003.47, 'duration': 4.843}, {'end': 1013.895, 'text': 'and then child I call mutate for the mutation rate, And then I have that new member of the population.', 'start': 1008.313, 'duration': 5.582}, {'end': 1015.836, 'text': 'so this happens end times.', 'start': 1013.895, 'duration': 1.941}, {'end': 1024.448, 'text': "I just say I have the mating pool, give me two parents and cross them over, apply mutation, here's the new child, it goes into the population.", 'start': 1015.836, 'duration': 8.612}], 'summary': 'Genetic algorithm creates new child from two parents using crossover and mutation.', 'duration': 31.063, 'max_score': 993.385, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc993385.jpg'}, {'end': 1200.759, 'src': 'embed', 'start': 1160.462, 'weight': 0, 'content': [{'end': 1168.007, 'text': 'then I create a new population object and then I just walk through the algorithm itself calculate the fitness, build the mating pool,', 'start': 1160.462, 'duration': 7.545}, {'end': 1169.248, 'text': 'generate the next population.', 'start': 1168.007, 'duration': 1.241}, {'end': 1172.171, 'text': 'Evaluate is just checking to see how everything did at the end.', 'start': 1169.608, 'duration': 2.563}, {'end': 1179.419, 'text': "And then there's some other code for sort of displaying all the information using DOM elements and that sort of thing.", 'start': 1172.651, 'duration': 6.768}, {'end': 1181.06, 'text': 'But this is the key algorithm.', 'start': 1179.659, 'duration': 1.401}, {'end': 1182.302, 'text': "It's all in separate functions.", 'start': 1181.08, 'duration': 1.222}, {'end': 1189.99, 'text': 'And each one of these functions, calculate the fitness, natural selection, and generation, simply iterates over that entire population.', 'start': 1182.662, 'duration': 7.328}, {'end': 1195.416, 'text': 'right. the population object has a population array.', 'start': 1191.673, 'duration': 3.743}, {'end': 1200.759, 'text': "I'm always iterating over that population array, calculating the fitness for every element of that array,", 'start': 1195.416, 'duration': 5.343}], 'summary': 'Algorithm iterates through population, calculates fitness, and generates next population.', 'duration': 40.297, 'max_score': 1160.462, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc1160462.jpg'}], 'start': 779.447, 'title': 'Genetic algorithm process', 'summary': 'Explains the genetic algorithm process, including creating a mating pool, conducting natural selection, reproduction, crossover, and mutation to generate a new population with a mating pool normalized between 0 and 1 and multiplied by 100.', 'chapters': [{'end': 876.044, 'start': 779.447, 'title': 'Genetic algorithm: mating pool and fitness normalization', 'summary': 'Discusses the process of generating a mating pool by normalizing fitness values between 0 and 1 and then multiplying by 100, and determining the number of times each member of the population is added to the mating pool based on their fitness.', 'duration': 96.597, 'highlights': ['The process involves normalizing fitness values between 0 and 1, subsequently multiplying by 100 to obtain a range within 0 to 100.', 'The code determines the number of times each member of the population is added to the mating pool based on their fitness value, enabling a balanced representation in the mating pool.', 'The chapter emphasizes the importance of refining the process to determine the number of times each member should be added to the mating pool, allowing for various approaches for optimization.']}, {'end': 1234.805, 'start': 876.044, 'title': 'Genetic algorithm process', 'summary': 'Explains the genetic algorithm process, including creating a mating pool with a significantly larger array than the population size, conducting natural selection, reproduction, crossover, and mutation to generate a new population.', 'duration': 358.761, 'highlights': ['The mating pool is significantly larger than the population size, ranging from 15,000 to 20,000, compared to the population of just 200, due to the fitness-based selection process. The mating pool size is much larger than the population, ranging from 15,000 to 20,000, while the population itself is just 200, as a result of fitness-based selection.', 'The process involves generating a new population by picking two parents from the mating pool, performing crossover, applying mutation, and adding the new child to the population, iterating this process multiple times. The algorithm involves generating a new population by selecting two parents from the mating pool, performing crossover, applying mutation, and adding the new child to the population, repeating this process multiple times.', 'The crossover step involves combining genetic information from two parents, using a random midpoint to determine which genes come from each parent and creating a new DNA object for the child. The crossover step combines genetic information from two parents using a random midpoint to determine gene inheritance, resulting in a new DNA object for the child.', 'Mutation is applied by randomly changing genetic characters based on a specified mutation rate, resulting in the creation of a new child DNA object. Mutation involves randomly changing genetic characters based on a specified mutation rate, leading to the creation of a new child DNA object.']}], 'duration': 455.358, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc779447.jpg', 'highlights': ['The process involves normalizing fitness values between 0 and 1, subsequently multiplying by 100 to obtain a range within 0 to 100.', 'The code determines the number of times each member of the population is added to the mating pool based on their fitness value, enabling a balanced representation in the mating pool.', 'The chapter emphasizes the importance of refining the process to determine the number of times each member should be added to the mating pool, allowing for various approaches for optimization.', 'The mating pool is significantly larger than the population size, ranging from 15,000 to 20,000, compared to the population of just 200, due to the fitness-based selection process.', 'The process involves generating a new population by picking two parents from the mating pool, performing crossover, applying mutation, and adding the new child to the population, iterating this process multiple times.', 'The crossover step involves combining genetic information from two parents, using a random midpoint to determine which genes come from each parent and creating a new DNA object for the child.', 'Mutation is applied by randomly changing genetic characters based on a specified mutation rate, resulting in the creation of a new child DNA object.']}, {'end': 1364.908, 'segs': [{'end': 1283.699, 'src': 'embed', 'start': 1255.299, 'weight': 1, 'content': [{'end': 1257.962, 'text': 'how could this algorithm apply to your scenario??', 'start': 1255.299, 'duration': 2.663}, {'end': 1259.983, 'text': 'What might be the genetic information?', 'start': 1258.282, 'duration': 1.701}, {'end': 1266.209, 'text': 'How is I just made this weird closing my one eye thing expression at you?', 'start': 1260.324, 'duration': 5.885}, {'end': 1266.809, 'text': "I don't know why.", 'start': 1266.209, 'duration': 0.6}, {'end': 1275.794, 'text': 'How can you apply this sort of algorithm and idea to your particular creative project?', 'start': 1269.871, 'duration': 5.923}, {'end': 1277.495, 'text': "And that's what I'm going to start to get to.", 'start': 1276.114, 'duration': 1.381}, {'end': 1283.699, 'text': 'as I look at, a few more advanced or advanced is the wrong word but really more sophisticated examples of applying this.', 'start': 1277.495, 'duration': 6.204}], 'summary': 'Applying algorithms to creative projects, exploring advanced examples.', 'duration': 28.4, 'max_score': 1255.299, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc1255299.jpg'}, {'end': 1319.861, 'src': 'embed', 'start': 1294.405, 'weight': 0, 'content': [{'end': 1299.368, 'text': 'the code for this example is also available in the processing programming environment,', 'start': 1294.405, 'duration': 4.963}, {'end': 1303.931, 'text': 'which is a creative coding environment built on top of the Java programming language.', 'start': 1299.368, 'duration': 4.563}, {'end': 1308.073, 'text': "so if you're looking for Java classes to do genetic algorithm, you can find those as well.", 'start': 1303.931, 'duration': 4.142}, {'end': 1310.795, 'text': "And really, ultimately, it's all kind of the same.", 'start': 1308.353, 'duration': 2.442}, {'end': 1312.556, 'text': "There's some, you know little differences.", 'start': 1310.855, 'duration': 1.701}, {'end': 1319.861, 'text': "You know we've got this sort of more classical, object oriented programming, where I have a DNA class and a population class.", 'start': 1313.276, 'duration': 6.585}], 'summary': 'Java code for genetic algorithm available in processing environment.', 'duration': 25.456, 'max_score': 1294.405, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc1294405.jpg'}], 'start': 1235.045, 'title': 'Genetic algorithms in creative coding', 'summary': 'Discusses the application of genetic algorithms in creative projects, exploring the evolution of design and animation behavior, with a focus on using genetic information and code examples in the processing programming environment.', 'chapters': [{'end': 1364.908, 'start': 1235.045, 'title': 'Genetic algorithms in creative coding', 'summary': 'Discusses the application of genetic algorithms in creative projects, exploring the evolution of design and animation behavior, with a focus on using genetic information and code examples in the processing programming environment.', 'duration': 129.863, 'highlights': ['The chapter explores the application of genetic algorithms in creative projects, focusing on evolving design and animation behavior.', 'The speaker emphasizes the use of genetic information and algorithms in creative projects, providing code examples in the processing programming environment.', 'The discussion includes the comparison between JavaScript arrays and Java array list in the context of genetic algorithms implementation.', 'The speaker provides insights into the implementation of genetic algorithms in Java, with a focus on the creation of population objects and various functions for natural selection and fitness calculation.']}], 'duration': 129.863, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-jv3CgDN9sc/pics/-jv3CgDN9sc1235045.jpg', 'highlights': ['The chapter explores the application of genetic algorithms in creative projects, focusing on evolving design and animation behavior.', 'The speaker emphasizes the use of genetic information and algorithms in creative projects, providing code examples in the processing programming environment.', 'The speaker provides insights into the implementation of genetic algorithms in Java, with a focus on the creation of population objects and various functions for natural selection and fitness calculation.', 'The discussion includes the comparison between JavaScript arrays and Java array list in the context of genetic algorithms implementation.']}], 'highlights': ['The fitness function calculates the score by iterating over each character in the phrase and comparing it with the target phrase, resulting in a fitness score of 90% for 9 out of 10 correct characters.', 'The process involves normalizing fitness values between 0 and 1, subsequently multiplying by 100 to obtain a range within 0 to 100.', 'The process involves generating a new population by picking two parents from the mating pool, performing crossover, applying mutation, and adding the new child to the population, iterating this process multiple times.', 'The chapter delves into an in-depth analysis of the genetic algorithm code, exploring each step such as population initialization, fitness calculation, selection, crossover, and mutation, aiming to understand the implementation and functionality of the algorithm.', "The video series is focused on dissecting a pre-made code example from 'The Nature of Code, chapter 9', providing a detailed understanding of the genetic algorithm implementation.", "The analysis aims to comprehend the code's functionality, addressing various aspects such as population initialization, fitness calculation, selection, crossover, and mutation, enabling a comprehensive understanding of the algorithm's implementation.", 'The dna.js file is crucial as it contains the DNA object, which will be present in almost all future examples, making it a key component for building genetic algorithms.', 'The population.js file manages the array of all the elements of the population, including functions for calculating fitness values and selection.', 'The process involves initializing and generating 200 random DNA objects.', 'The population object is a big array of n elements, with each element being a random phrase.', 'The process involves adjusting the probability in the array to increase the likelihood of being picked, with a fitness-based approach.', 'The chapter introduces a technique for picking random elements from an array based on probabilities, demonstrating a method to adjust the probability to increase the likelihood of being picked, with quantifiable data.', 'The process involves initializing and generating 200 random DNA objects.', 'The process involves adjusting the probability in the array to increase the likelihood of being picked The chapter explains a technique for adjusting the probability in the array to increase the likelihood of being picked, with a fitness-based approach.', 'The process involves normalizing fitness values between 0 and 1, subsequently multiplying by 100 to obtain a range within 0 to 100.', 'The code determines the number of times each member of the population is added to the mating pool based on their fitness value, enabling a balanced representation in the mating pool.', 'The chapter emphasizes the importance of refining the process to determine the number of times each member should be added to the mating pool, allowing for various approaches for optimization.', 'The mating pool is significantly larger than the population size, ranging from 15,000 to 20,000, compared to the population of just 200, due to the fitness-based selection process.', 'The crossover step involves combining genetic information from two parents, using a random midpoint to determine which genes come from each parent and creating a new DNA object for the child.', 'Mutation is applied by randomly changing genetic characters based on a specified mutation rate, resulting in the creation of a new child DNA object.', 'The chapter explores the application of genetic algorithms in creative projects, focusing on evolving design and animation behavior.', 'The speaker emphasizes the use of genetic information and algorithms in creative projects, providing code examples in the processing programming environment.', 'The speaker provides insights into the implementation of genetic algorithms in Java, with a focus on the creation of population objects and various functions for natural selection and fitness calculation.', 'The discussion includes the comparison between JavaScript arrays and Java array list in the context of genetic algorithms implementation.']}