Тёмный

Spawning - Writing your own Genetic Algorithm Part 1 

Tutorials with Gary
Подписаться 3,9 тыс.
Просмотров 17 тыс.
50% 1

Genetic Algorithms are incredibly powerful problem-solving tools. In this video, we will start to solve the travelling salesman problem by writing our very own genetic algorithm by writing a spawn and evaluation method.
0:00 Introduction
0:24 Travelling Salesman Overview
2:27 Project Introduction
2:47 Visual Studio Setup
3:30 Code Overview
5:07 Individual Genome
5:42 Implementing Spawning
8:37 Fitness Calculation Overview
9:12 Implementing Fitness Calculation
10:40 First Visualisation
11:01 Challenge Question & Outro
Links to all the good stuff:
Get the code here!
github.com/Gary-The-Cat/Spawning
Link to Visual Studio Community (It's Free!)
visualstudio.microsoft.com/do...

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

 

12 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 37   
@ianseychell
@ianseychell 4 года назад
Very well constructed video and explanation. Kudos !
@TheMajoris
@TheMajoris 2 года назад
Very clear video on a complicated topic!
@agentvx8320
@agentvx8320 4 года назад
The two ideas that occur to me for optimizing the fitness algorithm are: 1) Create a lookup table for the distance between each pair of towns to avoid running the calculation every time. 2) Choose some cutoff for the total distance such that when a given neighbour's distance total exceeds it, you can break out of the loop and stop spending cycles on an individual with poor fitness.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
Hey, I love the ideas! 1) A map of the distances would certainly speed things up a good deal. -However it would require us to have 10! ~3.6million different distances stored in the dictionary- sorry, I was wrong there, that’s only for the case for the entire paths not the unique pairs, definitely doable for our example! 2) Early exit conditions are always a great way to speed up a system! How would yo go about deciding the value of our threshold?
@agentvx8320
@agentvx8320 4 года назад
@@TutorialsWithGary 1) Wouldn't you only need the square of the number of towns to represent the possible two town pairs? n! would be the number of possible entire paths, right? Just keeping track of pairs would allow you to skip the square root and two multiplication options, making it just addition to find the total. 2) That's of course the tricky part because you wouldn't want to inadvertently chop out all variation. The first idea that occurs to me is to take the best and worst of the previous generation and find some point in the middle. The exact center is one possibility, but making it closer to the most fit would consume less resources while making it closer to the less fit would allow for more variation.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
1 - correct, -the number of unique town pairs in this case is the same as the number of unique paths- sorry misread! Correct the distances between town pairs not total paths would be significantly less and save time! Love it 2 - maintaining variability is a key point when running our GA. I think there is a middle ground solution here that I will cover in my next video - where we will also cover the crossover. Will be out within the week!
@agentvx8320
@agentvx8320 4 года назад
@@TutorialsWithGary Thinking further about the distance lookup table, it seems like its value as an optimization has a lot to do with the ratio of possible stops to the number of individuals in the algorithm. If the number of stops is large and the number of individuals is small, it's probably not worth doing. But if you have a lot of individuals, that's a lot of repeated operations. Particularly if the number of stops is relatively small and the same pairs are more likely to come up repeatedly.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
Agent VX There’s always trade offs when considering designs of your system - and it seems like you are thinking in all the right ways here. Most of the time when using GA’s to solve problems we will want a larger population, but having smarter mutation methods can be equally as important. Perhaps after we have an initial implementation, I can make a video showing the impact tweaking various parameters can have.
@allaboutcomputers9132
@allaboutcomputers9132 4 года назад
well explained
@TutorialsWithGary
@TutorialsWithGary 4 года назад
Thank you
@SolvingOptimizationProblems
@SolvingOptimizationProblems 4 года назад
Very clear and interesting tutorial on genetic algorithm. Thank you. I don't know C# but it looks like python?
@TutorialsWithGary
@TutorialsWithGary 4 года назад
C# is a lovely language, highly recommend giving it a look.
@SolvingOptimizationProblems
@SolvingOptimizationProblems 4 года назад
@@TutorialsWithGary Many thanks, I will try
@martinp.617
@martinp.617 2 года назад
Good day, nice series, keep it up. Looking for the next. Although I have a concern, do you have any recommendation on how to setup the SFML you are using. It's kind a daunting to me because last time I remember when I initiate to use SFML, I installed it and it looks like I messed up regarding the minGW something, thus one of my program (GridLab-D) ended up not working as I expected it to be. I don't know if that's the real reason, though. Thank you in advance.
@TutorialsWithGary
@TutorialsWithGary 2 года назад
Hey, thanks for the kind words. It sounds like you were using SFML with C++, with C# it's a lot simpler. You should be able to download my same project and be up and running without much issue. If you can't get it working, send me a message here and I can provide some help. - Luke
@jeanbaptisteminani9546
@jeanbaptisteminani9546 Год назад
I downloaded it too but SFML probably is causing unexpected behavior. what is the preferred target platform? 64-bit, 32-bit or AnyCPU. in my case, I am selecting AnyCPU.
@mohdmeawad8366
@mohdmeawad8366 Год назад
when I try to modify the reference like in the vid I do not reference paths under properties
@mr.k2201
@mr.k2201 Год назад
hey gary! thanks for defination of genetics algorithm video , do you have any video in this article on python ?
@TutorialsWithGary
@TutorialsWithGary Год назад
Hey mate, I don’t have any videos going through python on my channel other than quite an old one (and that was about creating digital filters). The theory in my videos will work across any language though, so it would be worth watching these and finding a Python tutorial. I’ve found freeCodeCamp to be good, they have a channel here on RU-vid, ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-rfscVS0vtbw.html.
@mr.k2201
@mr.k2201 Год назад
@@TutorialsWithGary I like channel and content, despite it's not python that i need to focus on it, but I'll keep watching, thank you for the link ✌️☺️
@vetirtal1168
@vetirtal1168 4 года назад
Use square distances instead of distances. Larger distances between neighbours will be discouraged. You could then square root the total distance but that is not necessary for a fitness function? I'm wondering if squared distance would not get the best answer because larger and smaller distances will be judged unequally.
@vetirtal1168
@vetirtal1168 4 года назад
If you were trying to find the shortest path between two nodes, the square error may prioritise a large number of small distances rather than a few larger distances.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
That is true! It will also skew the fitness of each of the individuals that will impact the selection behaviour.
@FractAlkemist
@FractAlkemist 2 месяца назад
Possible answer to question at end: First add up all the "x" values. Then add up all the "y" values. Then square them both, add those results. Take the square root of that. .
@repanzar
@repanzar 4 года назад
Another option to reduce computing time is to only work with the squares, ignoring the square root until the very end. For fitness alone, the square root is not needed at all.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
I love it, when we get to parent selection, how wold this impact the fitness of each parent? (Spoiler for the next video)
@repanzar
@repanzar 4 года назад
@@TutorialsWithGary The fitness is then the squared distance between all towns. Can be used for comparison, but can also be easily converted to the real value - e.g. for displaying it in the UI.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
That’s true, good thinking!
@seismograf3908
@seismograf3908 4 года назад
Could you elaborate on how this is a viable option? For N=5, let's assume two sequences of distances, S1 = 2,2,2,2,2; S2 = 3,3,1,1,1. sum(S1) = 10 > 9 = sum(S2) . Yet, sum(2^2 + 2^2 + 2^2 + 2^2 + 2^2) = 20 < 21 = sum(3^2 + 3^2 + 1 + 1 + 1). The ordering is inconsistent, hence neither can you use the sum of squares for comparison nor can you calculate the square root later.
@TutorialsWithGary
@TutorialsWithGary 4 года назад
Seismo Graf you’re completely correct, effectively what I was trying to get at with it impacting the fitness of the individuals - what we covered in the next video. There are a number of times where approximations can be used (as long as the trade off is known) in place of performance. This is most often used when trying to approximate a nonlinear system as linear for use in something like an LP. In this case, storing the distances in a dictionary up front would be a much better way to go. It would be fast, and without having to have considerations.
@KARANAMHEMASUDHADIWAKAR
@KARANAMHEMASUDHADIWAKAR Год назад
Can use Manhattan distance for evaluation
@TutorialsWithGary
@TutorialsWithGary Год назад
Great idea :)
@yvescloutier1580
@yvescloutier1580 3 года назад
I changed the configuration to match my screen: public static float Scale = 1f; public static uint Height = (uint)(1080 * Scale); public static uint Width = (uint)(1920 * Scale); but the picture are too big and zoom out does not work. public static Key ZoomOut => Key.X; I pressed x or X but nothing happened.
@TutorialsWithGary
@TutorialsWithGary 3 года назад
Hey Yves, sorry to hear! The earlier repos in the series didn’t have the ‘camera’ class in them, i think it was introduced in the crossover video. You can either use the smaller window for now, or try to take the camera code out of the later repo
@MrJayC3
@MrJayC3 Год назад
Go to Configuration.cs Edit code line 10 - 12 to: public static uint Height = (uint)(1080 * Scale); public static uint Width = (uint)(1920 * Scale); Then Go to DataStructres/town.cs Edit code line 14 - 19 to: this.Shape = new RectangleShape(new Vector2f(300/2, 300/2)) { Texture = texture, Origin = new Vector2f(150/2, 150/2), Position = position, }; Then go to Helpers/TownHelper.cs Edit code line 11 - 12 to : private const int Linethickness = 4/2; private const int PathOffsetFromTown = 180/2; Edit code line 48 - 57 to: new Vector2f(3060/2, 1300/2), new Vector2f(1050/2, 450/2), new Vector2f(450/2, 750/2), new Vector2f(690/2, 1890/2), new Vector2f(1410/2, 1830/2), new Vector2f(2070/2, 1560/2), new Vector2f(1725/2, 1080/2), new Vector2f(3360/2, 810/2), new Vector2f(3450/2, 1770/2), new Vector2f(2460/2, 240/2),
@Marco_AFC4325
@Marco_AFC4325 Год назад
@@MrJayC3 Thank you
Далее
Selection - Writing your own Genetic Algorithm Part 2
12:34
«K operatsiyasi» davom etadi: Kiyevning rejasi ma'lum
05:07
skibidi toilet 77 (part 1)
03:51
Просмотров 14 млн
Mutation - Writing your own Genetic Algorithm Part 4
17:36
13. Learning: Genetic Algorithms
47:16
Просмотров 520 тыс.
Evolutionary Algorithms
16:56
Просмотров 125 тыс.
Genetic Algorithm In Python Super Basic Example
17:42
Просмотров 123 тыс.