Тёмный

Genetic Algorithm C# - Generic Implementation 

Kryzarel
Подписаться 7 тыс.
Просмотров 60 тыс.
50% 1

Implementation of a Genetic Algorithm in C#, using the Unity game engine to demonstrate the algorithm in action. In this video we cover the base implementation of the algorithm.
Source Code: bitbucket.org/kryzarel/generi...
Genetic Algorithm in depth (The Coding Train): • 9.1: Genetic Algorithm...
C# Generics: www.tutorialspoint.com/csharp...
Algorithm for choosing parents: stackoverflow.com/questions/5...
Part 1 | Base Implementation: [current video]
Part 2 | Fitness Function & Generating Genes: • Genetic Algorithm C# (...
Part 3 | Adding Individuals on New Generations: • Genetic Algorithm C# (...
Part 4 | Serialization, Saving & Loading: • Genetic Algorithm C# (...
Music by TeknoAXE:
00:00 Figuring it All Out ( • Figuring it All Out --... )
04:14 Nevermind the Ether ( • Nevermind the Ether --... )
09:13 Europa ( • Europa -- Background/D... )
14:16 The Infinite ( • The Infinite -- Sounds... )
18:05 Nevermind the Ether (again)
22:57 Burnt to a Crisp or Bloody as Hell ( • Burnt to a Crisp or Bl... )

Наука

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

 

26 июл 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 58   
@wwendrom
@wwendrom 7 лет назад
i'm not the greatest fan of programming, but with your voice i saw the whole video without getting bored! keep it up!
@nacs
@nacs 5 лет назад
You're awesome for making and sharing not only these videos but the source as well! Thank you @Kryzarel!
@benjaminmcintosh6380
@benjaminmcintosh6380 3 года назад
I just kinda scrolled through the programming playlist and, yeah, you don't have everything I'm looking for, but there's a ton of great content here. Keep up the good work.
@AEvans853
@AEvans853 6 лет назад
Thank you so much! That was just one beautiful explanation. Also like that ambient music in the background...
@Kryzarel
@Kryzarel 6 лет назад
Thank you! I'm glad you enjoyed it :D
@geotyper
@geotyper 6 лет назад
Nice and clear to understand. Thanks
@josefprochazka5852
@josefprochazka5852 6 лет назад
Thank you for your time!
@scheiepfostierer4652
@scheiepfostierer4652 6 лет назад
Awesome video! Thank you so much!
@HenkvanAlphen
@HenkvanAlphen 7 лет назад
Great :-) Can't wait for next episode
@Kryzarel
@Kryzarel 7 лет назад
Next episode is out! :D
@yanniskramer8805
@yanniskramer8805 6 лет назад
Nice video and thx for the code. I will use it as a template for my projects. Info: This code is for callByValue-types (string, char, int, double, etc.), not for classes with properties from different types. For that, you have to rewrite the code for your needs. Greetings
@TrifectaMonkey
@TrifectaMonkey 3 года назад
Thanks for this, very helpful.
@lilbabushka7298
@lilbabushka7298 5 лет назад
Man makes computer .Man uses computer and creates code. Man uses computers code to make software. Man uses coding software to make project. Man plays video game.
@KlesierTheSurvivor
@KlesierTheSurvivor 7 лет назад
damn dude, i'm researching right now about deep leaning and more specifically genetic algorithms and this was in perfect timing! will there a second video with the uses of it?
@Kryzarel
@Kryzarel 7 лет назад
Yes sir! Planning to make the followup video this week or the next :) Oh, and if you want to go more in depth into the theory of genetic algorithms, I highly recommend checking out the playlist I linked in the description. It's from a channel called "The Coding Train", I thought he did an excellent job explaining it.
@user-bp1tj7pu6m
@user-bp1tj7pu6m 6 лет назад
This video is perfect since i really wanted to learn Genetic Algorithm in unity,!!!!!!
@Kryzarel
@Kryzarel 6 лет назад
Thank you!
@user-bp1tj7pu6m
@user-bp1tj7pu6m 6 лет назад
Kryzarel thank you!!!!
@MQNGameDev
@MQNGameDev 4 года назад
Very interesting stuff. I am already seeing a ton of practical applications for this. Thanks
@TheJackACID
@TheJackACID 7 лет назад
I believe you defined the fitnessFunction delegate to wrong way. It should take an int and return a float, not the other way around. Thank you for the video. It's a really interesting subject. Looking forward to more :)
@Kryzarel
@Kryzarel 7 лет назад
Oh crap, you're right, I've fixed the code in the repository and I'll mention it in the next video. Nice catch!
@yanniskramer8805
@yanniskramer8805 6 лет назад
Hello man, I looked deeper into the algorithm and found out, that when you remove this line in the fitness function: score /= targetString.Length; He finds the solution way faster. So don't take the relative score, take the absolut one. I can't explain why, but try it.
@Kryzarel
@Kryzarel 6 лет назад
It should certainly stop faster, but are you sure it finds the correct answer?
@valakiaki3663
@valakiaki3663 6 лет назад
Hello sir, awesome video. I just want to ask how can i start it in my visual studio? (Download from link in description)
@Kryzarel
@Kryzarel 6 лет назад
You need only the DNA.cs and GeneticAlgorithm.cs classes. Create any type of Visual Studio project you wish and then just copy paste those files in there :)
@samirakercash1845
@samirakercash1845 6 лет назад
hi Kryzarel how can i use genetic algrithm in university class schedule ''timetable '' in c#
@Kryzarel
@Kryzarel 6 лет назад
For sure, use it for whatever you like!
@samirakercash1845
@samirakercash1845 6 лет назад
will you make video how is it please
@Kryzarel
@Kryzarel 6 лет назад
Probably Not. I'd prefer if you *suggest* videos and not *ask* for them. You would have to be a lot more specific in your request anyway. If this sounds rude at all I apologize, that is not my intention, I just like being straightforward.
@ergeorgiev
@ergeorgiev 6 лет назад
Thank you. I had a hard time understanding how ChooseParent works though. It seems a bit too random to me, I am guessing you are planning to change it in the next video... or maybe I am wrong in my assumption and it is ideal for the job.
@Kryzarel
@Kryzarel 6 лет назад
Check out the link in the description for better understanding of how we're choosing parents. It's using a weighted random choice :)
@infernape28
@infernape28 3 года назад
@@Kryzarel I checked the link. I remember seeing this vid when it first game out and I'm just now coming back with a better understanding of programing. This part is still throwing me for a loop. I still don't quite understand why you're multiplying the rand.
@markfeltner8260
@markfeltner8260 3 года назад
can you do a series on a breeding system for games similar as dragon quest monsters tem tem pokemon or monster crown? monster taming games are becoming more and more popular and i think alot of people would like to see it as theres not much info on it. i dont see it being much different than a crafting system.
@aikou2886
@aikou2886 3 года назад
I still don't quite get a few concepts from monster raising games and even if I did I'm still learning how to code so I 100% support this. His voice is pretty calm and his tutorials are really nice.
@VidimusWolf
@VidimusWolf 6 лет назад
Is there a reason as to why you need to take a Random type object as a parameter through the constructor, instead of just declaring and initializing it in the DNA Class itself?
@Kryzarel
@Kryzarel 6 лет назад
Just thought it would be better to let users have control over when and how they allocate the random objects. Maybe could have added an optional constructor that creates it if the user doesn't want to suppy one.
@VidimusWolf
@VidimusWolf 6 лет назад
Thanks :)
@Un4GivNX
@Un4GivNX 7 лет назад
Would you please add your TestShakespeare.cs script to the source repo? :) Or the unity project itself. It would be really appreciated!
@Kryzarel
@Kryzarel 7 лет назад
We'll be messing with that script in the next video, I'll probably add the Unity project to the repository when that video goes live :)
@Nytrox3000
@Nytrox3000 6 лет назад
Can someone explain the ChooseParent function? I don't understand the logic behind it. :S
@Kryzarel
@Kryzarel 6 лет назад
Explained in this stack overflow answer: stackoverflow.com/questions/56692/random-weighted-choice It's an algorithm for choosing weighted random elements from a list. Link also in the description ;)
@Nytrox3000
@Nytrox3000 6 лет назад
Thank you, I couldn't really understand why you were multiplying the fitnessSum with random.NextDouble() but after watching some videos I understand now.
@stanixdor
@stanixdor 6 лет назад
Hello. I ported your project into C++. Results are very strange. If I just leave the code as it is, it never finds the correct answer, it stays at 0.90 fitness maximum. But if I remove: score /= targetString.Length; It almost insta finds it. Any ideas? (I think my port to C++ is 100% correct)
@Kryzarel
@Kryzarel 6 лет назад
And does it actually find the right answer or it just stops really fast with a random one? Could it be something to do with float/int conversions? The score variable is a float while targetString.Length is an int. Try casting targetString.Length to a float and see if it makes a difference. Also check if dna.Genes.Length == targetString.Length
@stanixdor
@stanixdor 6 лет назад
It stops after a long time, finding a wrong answer. I checked everything you said. Still the same result. My only solution is to pow the score. for example, i get the score and i return 2^score as the final score. Then it works pretty well.
@Kryzarel
@Kryzarel 6 лет назад
That seems quite weird. So the basic idea is to add 1 point to the score for each character that it gets right. If the target phrase is 10 characters long, then having a score of 10 means we have a phrase that has 10 characters right, meaning we got to the correct solution. To make it more generic I decided to divide that score by the length and get the percentage of "correctness" instead. If we had 5 characters right we'd get 5/10 = 0.5 so 50% correct, 10 characters right 10/10 = 1 so 100% correct. And after that there's yet another layer, where we use some exponents to make it so that having 6 characters correct is not just 10% better than 5 characters correct, but a bunch more. With this in mind I suggest you try to debug your code, maybe using breakpoints, and checking where in that process the calculations stop making sense. You can probably delete or comment out the last layer with the exponents to make the process simpler. If you don't mind sharing your code somehow, I'm also open to take a look at it.
@stanixdor
@stanixdor 6 лет назад
I uploaded the code into a github repo if u wanna have a look: github.com/stanixdor/KryzarelGeneticAlgorithm
@Kryzarel
@Kryzarel 6 лет назад
I took a look at the code and could not find anything obvious for what the issue might be. Other than this line ´if (score == 134)´, which I'm assuming is for debug purposes, everything seems to be alright. Strongly recommend you try to step through the code using breakpoints to try and figure out where the math stops making sense.
@zarrexx
@zarrexx 5 лет назад
Is this a type of Neural Network or its own entity?
@Kryzarel
@Kryzarel 5 лет назад
This is something different. I believe they both fall under the category of "Evolutionary Programming", but they are in fact two different algorithms. Sometimes they are used in tandem to improve each other, but still two different algorithms XD
@VidimusWolf
@VidimusWolf 6 лет назад
I also don't understand how the ChooseParent function works. Why are we subtracting every time? With what logic is it exactly choosing a parent? To me it just seems random o_O
@Kryzarel
@Kryzarel 6 лет назад
It is based on this algorithm: stackoverflow.com/questions/56692/random-weighted-choice Should have had this as a link in the video, updating it now :P
@agentarachnid2009
@agentarachnid2009 5 лет назад
Could this be used in c++?
@sacredgeometry
@sacredgeometry 3 года назад
Of course but I wouldn't write it like this. It's not written all that well.
@bhavin716
@bhavin716 Год назад
Hii Kryzarel I am working in similar test case of genetic algorithm in c# which has Fitness function below private static Func Fitness(string goal) { return new Func(chromosome => { double total = 0; for (int i = 0; i < goal.Length; i++) { if (goal[i] != chromosome[i]) { total++; } } return 1.0 / (total + 1); }); } I need to complete a function which Find Binary Genetic String which accepts above function parameter as input also other parameter is probMutation and probCrossover are provided floating point numbers that represent the chance of their respective modification occuring. public static string FindBinaryGeneticString(Func fitness, int length, double probCrossover, double probMutation) { //need to complete logic here } Above function should return a binary string of '0' and '1' of chromosome Length that has a fitness score of 1 as computed by getFitness. Can you help me to iterate over this function logic.
@fabiorangel9187
@fabiorangel9187 5 лет назад
zoom it in very hard next videos...
Далее
C# Generics - The complete guide
18:43
Просмотров 39 тыс.
This Stop Motion is Insane
00:39
Просмотров 8 млн
Новые iPhone 16 и 16 Pro Max
00:42
Просмотров 1,2 млн
How I created an evolving neural network ecosystem
10:09
Why all your classes should be sealed by default in C#
11:43
AI Learns to Speedrun Mario
8:07
Просмотров 723 тыс.
Elon Musk fires employees in twitter meeting DUB
1:58
Deep Learning Cars
3:19
Просмотров 10 млн
Reproduce image with genetic algorithm
1:47
Просмотров 436 тыс.
C# in 100 Seconds
2:27
Просмотров 2 млн
Телефон-електрошокер
0:43
Просмотров 1,3 млн
iPhone 15 Pro в реальной жизни
24:07
Просмотров 443 тыс.