Тёмный

Genetic Algorithm from Scratch in Python -- Full Walkthrough 

Cerup
Подписаться 1,2 тыс.
Просмотров 86 тыс.
50% 1

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

 

9 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 104   
@DimitriLeandro
@DimitriLeandro 5 лет назад
Awesome! I'll adapt your code so that I can use it in a Machine Learning class in my college. I won't forget to give you the credits, it helped me a lot. Tkx!
@cerupsly
@cerupsly 5 лет назад
That's awesome, man. Good luck!
@aimastermind_mjr
@aimastermind_mjr 5 лет назад
@@cerupsly hey buddy, I have a hub location problem to solve using GA. but i am creating random population from some data from excel... how can i continue the following steps such as mutation and crossover and till the final steps as shown in your video? how can i adapt your code and replace the initial population using my excel data???can you guide me???
@cerupsly
@cerupsly 5 лет назад
Just save the excel file as .csv and read it in with pandas. pandas.read_csv()
@DimitriLeandro
@DimitriLeandro 5 лет назад
​@@cerupsly Here it is. It's all in Portuguese, but i thought it would be nice to share with you. Thanks again! github.com/DimitriLeandro/SistemasInteligentesUFABC/blob/master/ECs/EC_5.ipynb
@chuckstarwar7890
@chuckstarwar7890 4 года назад
YOU are the best on teaching this topic.
@scottk5083
@scottk5083 4 года назад
I was looking through the map matrix, not sure if it was mentioned or not but theres one point i dont quite get. Lets say, its a 2 by 2 matrix. Row 1 Col 1 reads say 26 and Row 1 Col 2 reads 67. I understand that the respective nodes to go from point A(row 1) to point B(col 2) is 67. However, Row 1 Col 1 reads 26 despite pointing towards the same place and having no arcs. Should it be 0 instead of 67?
@viperaputakeyteaparyou8237
@viperaputakeyteaparyou8237 4 года назад
Thank you so much for this. Crystal clear explanation and you made the code available too! Cheers
@cerupsly
@cerupsly 4 года назад
So nice!
@juleswombat5309
@juleswombat5309 4 года назад
That was kinda cool. And did not mention Genome once ! I was a bit puzzled by some of the seaborne and style of code. But I have played around a bit from your jupyter download to understand some more parts of the code. Thanks so much for sharing. I did note once problem, in that the initialise code, could potentially set up none possible solutions, especially for much smaller maps. (e.g. No Paths from a Node, as probability of a value falls below p_zero threshold.) So may need a fudge that there is at least one path from each node, within initialise_map regardless of p_zero ? - at least from my quick 15 minutes of play.
@benben341
@benben341 5 лет назад
Thank you for this. I like the idea of a grid on connections as this could be a grid of actions/choices for a character in a game ie you cant build army without a barracks so kinda of a tier control thing. Also it would be interesting to instead of random map - draw a circle as we can visually see the optimal route that way. Cheers thanks again.
@curiously-cinnamon
@curiously-cinnamon 3 года назад
I'm getting this error : FileNotFoundError: [Errno 2] No such file or directory: 'images/new1000plot_0.png' I created the image folder. Now where do i get this image from?
@curiously-cinnamon
@curiously-cinnamon 3 года назад
It's working now, my bad
@ice-qf8vz
@ice-qf8vz 3 года назад
Any chance you make another one of these videos with a different example? I follow pretty well except for the map generation and navigation
@MasudRana-cp4lk
@MasudRana-cp4lk 4 года назад
Thank you sop much brother for making the video and it,s totally helpful.
@SrJose41
@SrJose41 2 года назад
Hi I was wondering if you could help me with an optimization process based on the granulometric size of minerals, I’m finishing my ChemE degree and this is my final work, thanks!
@khalidacid
@khalidacid 6 лет назад
awsome video ... but try to increase font size so that code is visible even in low res
@cerupsly
@cerupsly 6 лет назад
The code is all on github. Feel free to go get it. ;)
@cerupsly
@cerupsly 6 лет назад
Good tip though. Next time. ;)
@RaKUen1999
@RaKUen1999 4 года назад
Is this like Travelling Salesman Problem?
@homerlol9058
@homerlol9058 2 года назад
i think it is
@mahdieshraghi
@mahdieshraghi 2 года назад
It's a bit different. Salesmen start and end in the same place but it's start and end aren't same.
@kuldeepkurroliya2555
@kuldeepkurroliya2555 4 года назад
Nice explanation Sir. Thank you very much.
@kuldeepkurroliya2555
@kuldeepkurroliya2555 4 года назад
Sir, can you please tell where we have to fix source and destination between which it is finding a path with minimum no. of edges
@cerupsly
@cerupsly 4 года назад
I’m not sure that I understand what you’re asking
@juane.gonzalez1006
@juane.gonzalez1006 3 года назад
Amazing tutorial! The 'mutate' method is buggy though. As far I could see and test, the "mutated" route is nothing but the original input route with an additional random element appended to it, which makes it senseless, since once you reach the final node, the route should be completed.
@harikhakumaravel8757
@harikhakumaravel8757 4 года назад
Can I have the python code using genetic algorithm for finding shortest path... Please sir... Please... Past 3 months I'm trying but no use... Please help me sir
@cerupsly
@cerupsly 4 года назад
It’s all on github. Feel free to go get it. Link in the description.
@dubem1947
@dubem1947 4 года назад
Thank you for the video, I’m trying to make a program that takes peoples address and finds the best route to pick them up to go hospital , what changes would I have to make to use your genetic algorithm and could using google map api be possible? Thank you
@tusharagarwal2994
@tusharagarwal2994 5 лет назад
FileNotFoundError: [Errno 2] No such file or directory: 'images/new1000plot_0.png' , I am getting this error can you help ?
@cerupsly
@cerupsly 5 лет назад
You need to create the images folder
@curiously-cinnamon
@curiously-cinnamon 3 года назад
@@cerupsly I'm getting the same error. I created the images folder, but now where do i add the images from?
@curiously-cinnamon
@curiously-cinnamon 3 года назад
Tushar kaise theek kiya? What did you do after creating the images folder?
@mjar3799
@mjar3799 5 лет назад
Hi, I have unconstrained multi-objective optimization model and I am not sure if Genetic algorithm works for such kind of problems ??. Could you help me out in this regards Thanks
@mjar3799
@mjar3799 5 лет назад
I should also add that my optimization problem is binary (xij = 0 or 1) (kind of scheduling problem)
@cerupsly
@cerupsly 5 лет назад
Yes I think this could be accomplished. If you can provide more details, I can propose a solution
@MarkovChains223
@MarkovChains223 5 лет назад
Is there any particular reason you wrote this in more of a functional programming style rather than OO? Is there some advantage to that approach for this sort of algorithm, or is that just the style you're used to?
@cerupsly
@cerupsly 5 лет назад
zack budde it’s because I’m not a very good coder. Haha!
@khanduom9341
@khanduom9341 5 лет назад
Sir, Would you mind to share some information how we can use genetic algorithm to shift time for peak load to non peak hours please. Thank You
@mr.comingsoon9873
@mr.comingsoon9873 5 лет назад
hi, thanks for your video. may i know why >> FileNotFoundError: [Errno 2] No such file or directory: 'image/new1000plot_0.png' occurred in my code? got any solution? or i need to add a file?
@cerupsly
@cerupsly 5 лет назад
Does the image directory exist?
@cerupsly
@cerupsly 5 лет назад
If not, you have to create it in the folder that you opened your notebook
@mr.comingsoon9873
@mr.comingsoon9873 5 лет назад
@@cerupsly thx so much for your help. I just found out the problem. may I know why add >>%(iteration_number), dpi=300 behind that?
@cerupsly
@cerupsly 5 лет назад
It’s the file name and the resolution of the image to output
@mr.comingsoon9873
@mr.comingsoon9873 5 лет назад
@@cerupsly thanks so much!!!
@ramdanirizkipratama2273
@ramdanirizkipratama2273 4 года назад
Can anyone help me to solve my Travlling Slaesman Problem with Genetic Algorithm?
@momodoubjallow2585
@momodoubjallow2585 4 года назад
His explanation is quite straightforward just watch it several times and formulate a simple problem then you will be good to go.
@suzanneonaeko9310
@suzanneonaeko9310 5 лет назад
How would you modify this code to help generate a timetable? - Is it possible?
@cerupsly
@cerupsly 5 лет назад
What do you mean by timetable?
@suzanneonaeko9310
@suzanneonaeko9310 5 лет назад
By timetable - I mean a revision kind of timetable where the matrix is basically hour slots in a day and days should be avoided that the user doesn’t want to do work in(constraints). Kind of like an automated timetable where a genetic algorithm is used to determine the best order of specific sessions. Does that kind of make sense?
@cerupsly
@cerupsly 5 лет назад
@@suzanneonaeko9310 Two main changes that you'll have to make. First, you need to figure out a way to encode a solution to the problem as a matrix/vector. Second, you need to adjust the fitness function to calculate the quality of each solution.
@Albert-fe8jx
@Albert-fe8jx 5 лет назад
hi Greg, thank you for posting this. I was interested in knowing if you done comparisons with genetic algorithms and convolutional neural networks or recurrent neural networks for performance and 'best solutions'. Also, is it probable that a potential solution that is terminated early in simulation ultimately may be superior to any future generations? Lastly, you mentioned at 9:00 about 'good' solutions versus 'best' solutions. Isn't the point to produce the best?
@cerupsly
@cerupsly 5 лет назад
Good questions. First, genetic algorithm and neural networks aren’t really comparable because they aren’t in the same category. Genetic algorithm is an optimization scheme, while a neural network is a supervised learning algorithm. You might even use a genetic algorithm to train a neural network (although that isn’t typically how it’s done). Second, usually the best member of the population is carried on to the next generation as a matter of course, so that you don’t lose good solutions. However, it is often helpful to throw out the “best” solution occasionally to avoid being trapped at a local minimum. I would typically do this randomly at some low percentage. Finally, identifying the best solution is the overall goal, but the only way to guarantee that you have found the best solution is to search the entire space. If you have the computational power and sufficient time, then you can definitely do that. Most times, though you’re using the genetic algorithm because you don’t want a full brute force search. Simulated annealing, genetic algorithm, and all the other optimization algorithms are developed to help you get close to the best (and possibly the best) without having to search the entire solution space. Even if you find the best, though, you will never know that for sure. Hope that helps.
@ramyaravichandran5684
@ramyaravichandran5684 5 лет назад
This video was very helpful. Thanks a lot. I am curious about solving any benchmark problems in cultural algorithms. If you could have a tutorial about that in later videos it will be great.
@cerupsly
@cerupsly 5 лет назад
Can you give me an example of the kind of problem that you're thinking about?
@ramyaravichandran5684
@ramyaravichandran5684 5 лет назад
@@cerupsly Like a optimization problem (minimization or maximization) For eg. CEC benchmark problems. For testing our algorithms performance.
@pocketexodial2608
@pocketexodial2608 5 лет назад
averithing works but it never shows the image
@mohammadw2000
@mohammadw2000 5 лет назад
Great work! I am just curious, did you choose this problem just for the sake of explaining it? As far as I know, Dijkstra algorithm can find the shortest path in just a few milliseconds even for a network (map) size like this (1000 nodes). It might be interesting to see if GA will outperform Dijkstra for a very big network size.
@cerupsly
@cerupsly 5 лет назад
oh yeah... this was just an example for the purposes of explanation. I definitely don't think this is the optimal way to solve this problem.
@MikeJans
@MikeJans 6 лет назад
Hi, Thank you very much for the video / and also the new one, could you maybe make 4-6 videos of one of your (fast forwarded) tutorials where you explain it in more detail? maybe just for the next video as sometimes it helps to see the way how you get in to the solution and whats the way you choose as there are many possible ways. Very good edit and thanks again.
@cerupsly
@cerupsly 6 лет назад
Sure. Which one did you want explained in more detail?
@MikeJans
@MikeJans 6 лет назад
I have a dataset that contains 5 columns (about 1GB), each of this rows gets 500'000 features columns that means i would require 500TB diskspace to train it on my model with LSTM. Now my approach that i was thinking about is using a genetic algorythm and generate the 500'000 features on the fly per member. All data inputdata is between 0 and 1. the problem i have or cant think around is how i dynamically assign every member random 400 rows (for example 5000-54000 or 1000-1400....) with the equaling result. Will try to create a github repo with sample data so that i can play with it. I know i would be better off in dividing the data and train a lstm on my dataset, then save the training status, generate the next bunch, train, save, generate the next bunch. It would be much more convenient to use a genetic algorythm in this case.
@cerupsly
@cerupsly 6 лет назад
Sorry I’m not following what you’re trying to do.
@andreacolognese94
@andreacolognese94 5 лет назад
Sorry but I have not clear one thing, The goal is to get to the last node of the matrix?
@cerupsly
@cerupsly 5 лет назад
yes. That's right. In practice you would probably set the start and end points based on where you are and where you're going, but in this case, I just chose two points arbitrarily (the first and the last)
@andreacolognese94
@andreacolognese94 5 лет назад
@@cerupsly thanks, i'm trying to adapt your code to a job scheduling. Thanks for the answer!
@cerupsly
@cerupsly 5 лет назад
@@andreacolognese94 That's so great. Be sure to post and let us know how it goes.
@utubevishnu1189
@utubevishnu1189 4 года назад
Do you have the code uploaded in the net?
@cerupsly
@cerupsly 4 года назад
Link is in the description
@mahdieshraghi
@mahdieshraghi 2 года назад
Thank you for this video. It's very good. My problem is directed graph. It means we can go from node A to B but we can't go from B to A. Could you help me that I solve that problem please?
@cerupsly
@cerupsly 2 года назад
You would just make your adjacency matrix non symmetrical. You can solve this without any code changes.
@mahdieshraghi
@mahdieshraghi 2 года назад
Could you more explain? Actually the problem is maximum flow with genetic algorithm. Usually it solve with fulkerson algorithm but I want to solve it with genetic algorithm.
@cerupsly
@cerupsly 2 года назад
@@mahdieshraghi when you convert the graph into a matrix, for an undirected graph, the matrix is symmetric -- because each half of the adjacency matrix is one direction; i.e., If X is your adjacency matrix, x[i,j] in the matrix is the value of the edge from node i to node j. For an undirected graph, X[i,j] = X[j,i]. For a directed graph this is not true. In this example, I think I used distances as the values of the connections between the nodes and treated "0" as no connection. In your case, you will just need to figure out how to handle the values going in each direction. Does this make sense?
@mahdieshraghi
@mahdieshraghi 2 года назад
@@cerupsly yes it make sense and your explanation is very helpful for me I got it. In my case we want maximum flow with genetic algorithm in directed graph. It name is network flow.
@thevivekmathema
@thevivekmathema 5 лет назад
appreciate it!!
@benjaminfindon6993
@benjaminfindon6993 4 года назад
Love your video! You cool! Please help me ! Could you optimise like 3D CAD designs using this strategy could you tell me how I could lay out the problem so that I could use the genetic algorithm
@cerupsly
@cerupsly 4 года назад
Sure. What makes a drawing good?
@benjaminfindon6993
@benjaminfindon6993 4 года назад
The Real GM when it is fit for purpose. When it handles the environment it’s exposed too aka the forces. So my fitness function will be too do with forces acting on the design ?
@benjaminfindon6993
@benjaminfindon6993 4 года назад
The Real GM so I guess the question is how do I get those forces as data and how do I express the data as fitness value... is that correct ?
@cerupsly
@cerupsly 4 года назад
Yes. That’s it exactly.
@sofianemias
@sofianemias 5 лет назад
Greg, Thank you ever so much for your contribution, is there a way to contact you directly, have some questions please, Thanks.
@cerupsly
@cerupsly 5 лет назад
I can’t find a way for you to do that on here. Just post your question as a comment. I’ll try to answer
@sofianemias
@sofianemias 5 лет назад
Thanks Greg, i have lost you when you said you were minimizing instead of maximizing, and you had to amend that, where was that? Thx
@cerupsly
@cerupsly 5 лет назад
It’s a minimization problem because you’re trying to minimize the travel time/distance.
@cerupsly
@cerupsly 5 лет назад
When you do the crossing over/breeding step, you do so based on the quality of the solution. So lower travel times have a higher chance of being selected.
@sofianemias
@sofianemias 5 лет назад
👍😉👌 thanks, let me know if you do any private lessons ill be more than interested ,
@valeriovergni3339
@valeriovergni3339 3 года назад
ti amo
@jaskarankaur4971
@jaskarankaur4971 3 года назад
Awwwww for your comment on transparency
@nicolahcm
@nicolahcm 3 года назад
thanks!
@leesweets4110
@leesweets4110 Год назад
One of the first things you coded was to import pandas. But you dont know how to make a comment? I still dont know what pandas does.
@jdaniele
@jdaniele 4 года назад
Thanks for your video but you wasted 30% of screen space surroundi your video with bla k bands. More over, try to watch it on a 10" tablet and tell me if you can read what are you coding. Next time, please, change the font size or zoom in. Thanks.
@cerupsly
@cerupsly 4 года назад
Feel free to jump on github and grab the code! Should be very easy to read then!
@cerupsly
@cerupsly 4 года назад
and if you think about it, I really wasted more like 100% of your screen...
@jdaniele
@jdaniele 4 года назад
@@cerupsly Why?
@jdaniele
@jdaniele 4 года назад
@@cerupsly Ok, thanks, i will.
@rohansingh1057
@rohansingh1057 4 года назад
I am not a python programmer. Next Line: Python 2 and 3 are basically the same. Ok I agree with you.
Далее
Bike vs Super Bike Fast Challenge
00:30
Просмотров 18 млн
Они захватят этот мир🗿
00:48
Просмотров 758 тыс.
The Most Elite Chefs Ever!
00:35
Просмотров 6 млн
Reinforcement Learning in Python: getting started
14:17
What are Genetic Algorithms?
12:13
Просмотров 43 тыс.
Mod-01 Lec-38 Genetic Algorithms
54:52
Просмотров 213 тыс.
Genetic Algorithms - Jeremy Fisher
50:07
Просмотров 53 тыс.
How the Best Hackers Learn Their Craft
42:46
Просмотров 2,6 млн
Bike vs Super Bike Fast Challenge
00:30
Просмотров 18 млн