Тёмный

9.3: Genetic Algorithm: Shakespeare Monkey Example - The Nature of Code 

The Coding Train
Подписаться 1,7 млн
Просмотров 119 тыс.
50% 1

Опубликовано:

 

9 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 102   
@GaryIV
@GaryIV 7 лет назад
Could you imagine if a genetic algorithm also ran a genetic algorithm inside of it that discovered the most efficient max population as it goes :-*
@juanpabloorlando8300
@juanpabloorlando8300 4 года назад
I think the way you demonstrate how the mutation_rate and population_size affects the algorithm's output is really awesome. Thanks!
@KDChenStudio
@KDChenStudio 7 лет назад
I almost died at the Norwegian part
@Max-bh8tg
@Max-bh8tg 7 лет назад
Yeah me too lol, especially since i am a Norwegian.
@adeelfitness4993
@adeelfitness4993 5 лет назад
I just programmed the same example on my own, after watching this video. I did this in pure javascript... You motivate me a lot 👍
@TheCodingTrain
@TheCodingTrain 5 лет назад
Awesome!
@marklittlewood2418
@marklittlewood2418 7 лет назад
Excellent demo this, really gives students a feel for what the tweek parameters are and what effect they can have
@DrSpooglemon
@DrSpooglemon 4 года назад
I wrote a version of this algorithm in python with the help of these videos and it solves it in around 50 generations. Lightening fast!! I am stoked...
@DrSpooglemon
@DrSpooglemon 4 года назад
That is including punctuation and both upper and lower case chars.
@DrSpooglemon
@DrSpooglemon 4 года назад
I've just done "Where for art thou, Romeo?" in 46 generations. Best yet...
@vtvtify
@vtvtify 5 лет назад
What about adjusting the mutation rate bases upon the fitness score?
@maxinelyu7875
@maxinelyu7875 7 лет назад
man gotta say I really enjoy your style of teaching! so entertaining at the same time insightful XD two thubs up!
@TheCodingTrain
@TheCodingTrain 7 лет назад
So nice to hear, thank you!
@TheSpectron3
@TheSpectron3 8 лет назад
I made a similar GA, But you could type the sentence you wanted, and I used the letter's position in the alphabet to calculate the fitness, and mutated by going up or down, worked pretty well... Good video anyway :)
@TheCodingTrain
@TheCodingTrain 8 лет назад
Oh, cool idea!
@mikkaruru
@mikkaruru 6 лет назад
May I see your code on github please?
@yashsanthalia9561
@yashsanthalia9561 3 года назад
just the best Thank you so much Sir
@oo0O08
@oo0O08 8 лет назад
It was the best of times, it was the blurst of times.
@TheCodingTrain
@TheCodingTrain 8 лет назад
haha
@ispete
@ispete 7 лет назад
Has anyone rewritten this in Python? I've written a few versions. But, my best version still takes thousands of generations to solve "To be or not to be." I don't know what I'm missing. Would love to see others' code.
@MrCmon113
@MrCmon113 6 лет назад
How does your heredity work?
@proloycodes
@proloycodes 3 года назад
Mine takes 50-100 generations
@gabrielpablogonzalezfresar1242
@gabrielpablogonzalezfresar1242 3 года назад
You are the best bro
@orangejuice7234
@orangejuice7234 8 лет назад
Can you make C# tutorials because you make amazing videos.
@TheCodingTrain
@TheCodingTrain 8 лет назад
I don't really do C# but I will consider it.
@wiktorkaczor396
@wiktorkaczor396 8 лет назад
+Daniel Shiffman i second c#
@user-ot8qy7ki5q
@user-ot8qy7ki5q 4 года назад
seriously,much more better than my teacher in SCUT
@kraay89
@kraay89 7 лет назад
Is it safe to say that if your population is (way) bigger than the number of variables in your question you don't need mutation? Your example seemed to indicate that at around 5:00...
@ngroy8636
@ngroy8636 6 лет назад
I see that the mutation rate and the gene pool is important But what can we use math to find the best value for those values ? Like make the variables updatable as one mutate of value is more faster / accurately and approach to the target Like ml in ml?
@kebman
@kebman 7 лет назад
I'm Norwegian. And I'm offended. No I'm not. Hei skål!
@PrebenOlsen90
@PrebenOlsen90 6 лет назад
I was literally going to write just that. Beat me to it. Barely. By 5 months.
@usamatahseenulhaque9125
@usamatahseenulhaque9125 4 года назад
Thanks for the Best explaination
@ARMofficial
@ARMofficial 3 года назад
Hey The Coding Train, first thank you so much for this very clear explanation. I have a quick question though. If we take the example of this or another classic GA : two parents will combine to create one offspring, right ? Could you tell me why and how is it possible that your population stays the same at every iterations ?
@RedsBoneStuff
@RedsBoneStuff 7 лет назад
To be Jr noE tRFbe.
@AgentRex42
@AgentRex42 5 лет назад
Hello, I don't understand how to execute the code. Can you help me ?
@connercampbell456
@connercampbell456 7 лет назад
I open the program in firefox.. & it doesnt show my phrase or my stats below..?? Any help
@otacon1024
@otacon1024 7 лет назад
7:28 The expression you're looking for is "tear the mask off nature and stare at the face of God" :D
@jimmypatrick4409
@jimmypatrick4409 6 лет назад
Does anyone know where the source code is for this video?, I am not able to find it in the github!
@TheCodingTrain
@TheCodingTrain 6 лет назад
Take a look here: github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp10_nn
@Finn-jp6pn
@Finn-jp6pn 5 лет назад
Why does the total population remain constant from one generation to the next? Is it intentional? Because a gradually increasing population would soon become an overhead. Btw, it is always an amazing experience to watch your videos.
@renx99
@renx99 2 года назад
I noticed that this algorithm seems to have issues dealing with words that end with lower case 'z' I set the target to "the bee goes buzz" and it never seems to find it.. it doesn't ever seem to mutate a lower case 'z' although I have seen an upper case 'Z' fly by.. I wonder if we are having an off by one error.. if lower case 'z' is the last character in the list and it never selects it cause it's off by one.. that might explain it.
@renx99
@renx99 2 года назад
found the bug. In DNA.js line 21 change let c = floor(random(63, 122)); to let c = floor(random(63, 123)); It now finds the answer fairly quickly.
@renx99
@renx99 2 года назад
submitted merge request.
@omarelgazzar834
@omarelgazzar834 6 лет назад
Your videos are great, thanks
@skorpion111189
@skorpion111189 5 лет назад
Hello, i have a question. Can i use code from repo on Warsaw school of AI event ? As a part of presenatation about GA ? How need i refer to you ? I made a hyperlink to your stuff and mention your name.
@TheCodingTrain
@TheCodingTrain 5 лет назад
Yes, go right ahead, the example code for my channel is MIT license so free to use!
@FederationStarShip
@FederationStarShip 6 лет назад
I don't understand. How can it be useful if you need to know the answer to assess fitness?
@robin-gu6uy
@robin-gu6uy 5 лет назад
To mess around and test the best settings for an exercise where you wouldn't know the answer
@dejoker9042
@dejoker9042 5 лет назад
The idea is that you know the goal, but you don't know the solution to that specific goal. The fitness is based only by the goal, you can say "The fitness is how close an object is to a target location" then the computer it self finds HOW to get a maximum fitness - Achieving our goal.
@nkemer
@nkemer 5 лет назад
Hello, why link to "Source Code for the Video Lessons" doesn't work. In all videos these links directing to root folder!
@nkemer
@nkemer 5 лет назад
anyone with a direct link?
@DenCato
@DenCato 5 лет назад
@@nkemer Here you go: github.com/nature-of-code/noc-examples-p5.js/tree/master/chp09_ga
@TheCodingTrain
@TheCodingTrain 5 лет назад
Sorry I need to do a better job organizing all of this. . feel free to file a GitHub issue as a reminder!
@kamoroso94
@kamoroso94 8 лет назад
I was inspired by your last video about this and made my own version of this! Then I tried thinking of using this method for solving a nonogram puzzle, but I couldn't figure out what would determine the fitness. Maybe an example with Sudoku would be cool to see.
@TheCodingTrain
@TheCodingTrain 8 лет назад
Would love to see what you make, please share!
@kamoroso94
@kamoroso94 8 лет назад
Well it was the same as your phrase searching algorithm, but you could enter any phrase under 50 characters. I just made a new version that can solve those nonogram puzzles I was talking about. But I don't think I have a good measure on fitness.
@otacon1024
@otacon1024 7 лет назад
As one approach, the base for your fitness could be the number of moves required to solve the thing, a lower value giving a higher fitness score. So say you have a total population of 3 members (A,B,C) that solved the problem in (100, 50, 25) moves respectively. Sum the number of moves for a total of 175, then express the performance of each member as a % of the total. So now we'd have A = 57.14%, B = 28.57%, C = 14.29%. As the final step, since a lower value is better in this case, we'll "invert" the percentages, ie. new % = 100 - current %. So finally, the relative fitness of each member of our population is A = 42.86%, B = 71.43%, C = 85.71%.
@kamoroso94
@kamoroso94 7 лет назад
The Coding Train I went a little further and made a genetic algorithm that finds an optimal mining pattern in Minecraft. You can check it out at kamoroso94.github.io/minecraft-turtle and the GitHub repo of the same name.
@FRlDDY
@FRlDDY 7 лет назад
Where can i find the code he uses?
@mikegleasonjr
@mikegleasonjr 7 лет назад
github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp09_ga
@andrewdavies5722
@andrewdavies5722 4 года назад
I hope this algorithm has a constraint such that when a child is added to the mating pool it cannot mate with the parents... we don't want 'To be or not to be' coming out with webbed letters
@DigitalMonsters
@DigitalMonsters 5 лет назад
6:50 what if you "lock" the things responsible for increasing the fitness score, only mutating things known to be incorrect? idk.. just thinking outloud >_> don't even know if I'm making sense.
@tmhrtly
@tmhrtly 3 года назад
Hi! That's a great idea but in most situations, it wouldn't be clear which parameters were contributing 'positively' and which were contributing 'negatively'. For example, look at the BoxCar example - once you've evolved a super sleek car it's very non-obvious whether making one stick longer or shorter will make it work better or worse here. For that reason you often can't lock off parameters in that way.
@asdfghjkl12904
@asdfghjkl12904 4 года назад
Can you please help us to implement your code in python?
@LuciusTriomphe
@LuciusTriomphe 8 лет назад
Amazing Things.
@matthewse2882
@matthewse2882 8 лет назад
I was thinking, and it would be really meta to make a genetic algorithm which produces the highest average fitness based off of total population and mutation rate. And then do the same thing with the best of that set. Idk, it just made me think.
@matthewse2882
@matthewse2882 8 лет назад
Or for the to be or not to be example, you could switch the average fitness with amount of generations for the case I was talking about
@TheCodingTrain
@TheCodingTrain 8 лет назад
Interesting ideas!
@terozen
@terozen 6 лет назад
I wonder if someone could make a meta-algorithm for this one, that tests out different ranges of population and mutation rates, and assigns fitness level to each iteration based on it's average time spent finding the correct phrase. Eventually, it would settle on a population and mutation rate that gives the correct answer (for phrases of this length) fastest (on average).
@TheCodingTrain
@TheCodingTrain 6 лет назад
Yes, that's a great idea!
@wiktorkaczor396
@wiktorkaczor396 8 лет назад
Nice work
@TheCodingTrain
@TheCodingTrain 8 лет назад
Thanks for watching!
@jackattacker4288
@jackattacker4288 8 лет назад
I LOVE IT!
@TheCodingTrain
@TheCodingTrain 8 лет назад
Thanks for watching!
@halcyon0vds
@halcyon0vds 7 лет назад
What coding language have you used here?
@thegrumpysock6391
@thegrumpysock6391 7 лет назад
He uses p5.js
@thegrumpysock6391
@thegrumpysock6391 7 лет назад
or Processing
@nosuchthing8
@nosuchthing8 Год назад
I wonder what fundamentalists think about all this.
@johnellison1635
@johnellison1635 4 года назад
Isn't this just a bubble up algorithm ?
@eliasjosephsson3994
@eliasjosephsson3994 4 года назад
Couldn't you make an Genetic Algorithm that could play with the variables the way you just did to figure out what would be optimal to get the word you look for the fastest. And compare that with the number of letters in the word, and see if the number e pops up anywhere or something xD
@mrrubixcubeman
@mrrubixcubeman 7 лет назад
Looks exactly like the end of Wargames
@trieulieuf9
@trieulieuf9 6 лет назад
I don't understand, why is that ?
@osaka_phong
@osaka_phong Год назад
3:44 it reproduces with itself
@idontwantmynameinhere
@idontwantmynameinhere 5 лет назад
5:10 yea that'd be pretty efficient 😂
@DerKleineThilo
@DerKleineThilo 6 лет назад
At 3:00 it could have been, that there was enough variation, but it died.
@anonymouxUwu
@anonymouxUwu 7 лет назад
Can we say Genetic Algorithm is artificial intelligence ?
@deyw4786
@deyw4786 7 лет назад
AI is based on GA or so i think
@TheCodingTrain
@TheCodingTrain 7 лет назад
Yes indeed!
@theodorberza9933
@theodorberza9933 7 лет назад
One of the many AI algorithms. There is also neural networks and - the most interesting in my opinion - genetic programming.
@theodorberza9933
@theodorberza9933 7 лет назад
The Coding Train, can you please make a series about genetic programming?
@MrCmon113
@MrCmon113 6 лет назад
Pretty much everything is artificial intelligence. Except us, because we're not artificial (at least according to godless heathens like me).
@Exodia1988
@Exodia1988 Год назад
3:51
@zombiesalad2722
@zombiesalad2722 4 года назад
I will try doing the Navy Seals copypasta to see how long it takes.
@FujihiroCZ
@FujihiroCZ 4 года назад
xDDDDDDDDDDDDDDDDDDDDDDD Norwegian
@michieb1231
@michieb1231 7 лет назад
hey change do what i did and change the code a little bit and make it so it searches for: to be an idiot you must be smart
@Dude7469
@Dude7469 8 лет назад
I think you wanted to get away from that "boring soon-to-be-corpse professor" - kind, but this amount of energy might be a bit too much. You can boost book sales by trying to appeal to masses (find middle ground). Who doesn't want to be successful in their sales? Edit: One way to keep that energy amount but be more appealing is to ask questions enthusiastically. "And as we can see, 100% mutation rate leads to utter garbage. *Why, why does this happen?*". You obviously know the answer, but it's a way to be energetic and try to immense the viewer. After all, we can passively watch these videos without further thinking, but questions promote thinking.
@TheCodingTrain
@TheCodingTrain 8 лет назад
+Dude7469 thanks for the feedback!
@Dude7469
@Dude7469 8 лет назад
Daniel Shiffman Well, my message was intentionally provocative, I edited it a bit..
@johnellison1635
@johnellison1635 4 года назад
Isn't this just a bubble up algorithm ?
@eliasjosephsson3994
@eliasjosephsson3994 4 года назад
Couldn't you make an Genetic Algorithm that could play with the variables the way you just did to figure out what would be optimal to get the word you look for the fastest. And compare that with the number of letters in the word, and see if the number e pops up anywhere or something xD
Далее
Coding Challenge #29: Smart Rockets in p5.js
48:17
Просмотров 404 тыс.
Log4J & JNDI Exploit: Why So Bad? - Computerphile
26:31
Coding Challenge 166: ASCII Text Images
22:42
Просмотров 1,1 млн
SHA: Secure Hashing Algorithm - Computerphile
10:21
Просмотров 1,2 млн