Комментарии:
Subscribe for more
ОтветитьIt would great to show the different parts of a GA, variation, fitness, etc.
ОтветитьWow, could you make it any slower?
ОтветитьJava was my first language and the lack of types in Python is making my head hurt 😂
ОтветитьCan I get the code
Ответитьwhat if i want to do this for any variable type function
...i m havung problem in substiting the variables in the funtion.
finally, something I can understand
ОтветитьThank you! It helped me a ton!
ОтветитьThanks for the video, helping me through my AI assignments. A little trick I found is to make the mutation rate adjust depending on fitness, if fitness was exponential, and mutation rate being the inverse (of course capped at 0.02 though) It helps with being super precise
ОтветитьThe reason you didn't get a result close to 0 at the end was merely due to the fact that you forgot to subtract 25.
ОтветитьSir how to implement multiple traveling salesman problem using NSGA-2 in python.
ОтветитьLine 29 print (f"=== Gen..........).
The world f not declared. How this is working !?
Thank you
Use a list comprehension rather than that for loop.
ОтветитьI subscribed cause you teach clearly and do not step out of anything. Thank you, sir.
ОтветитьAm I missing something, why loop 10000 in line 21, when in line 16 you only loop 1000 to make 1000 random solutions?
ОтветитьCan I know how to use GA for optimising an array? Example of given an array of [1, 2, 3, 5, 7, 9] and partition it into two. So my objective is to minimise the difference between these two…
ОтветитьWhy didn't you write like this? (I'm not good at ENG)
At first, I thought this is better than your code. Because my code can distinguish x, y, z. but it wasn't better than yours. I wonder why.
(my guess is that: In my code, difference between x, y, z are large. So it is hard to reach to appropriate value. But in your code, x, y and z are almost same. So it's easy to x,y,z to reach to appropriate value.)
elements1 = []
elements2 = []
elements3 = []
for s in bestsolutions:
elements1.append(s[1][0])
elements2.append(s[1][1])
elements3.append(s[1][2])
newGen = []
for _ in range(1000):
e1 = random.choice(elements1) * random.uniform(0.99, 1.01)
e2 = random.choice(elements2) * random.uniform(0.99, 1.01)
e3 = random.choice(elements3) * random.uniform(0.99, 1.01)
this was so confusing
ОтветитьThanks for the video.
Please, how can one optimize the coefficients of a Logistic Regression Model using a Genetic Algorithm?
Hello! I want to use multi-objective genetic algorithm for data imputation. How can I do it? Can you help me with the code?
ОтветитьCode:
import random
def foo(x, y, z):
return 6*x**3 + 9*y**2 + 90*z - 25
def fitness(x,y,z):
ans = foo(x,y,z)
if ans == 0:
return 99999
else:
return abs(1/ans)
solutions = []
for s in range(1000):
solutions.append( (random.uniform(0, 10000), random.uniform(0, 10000), random.uniform(0, 10000)))
for i in range(10000):
rankedsolutions = []
for s in solutions:
rankedsolutions.append( (fitness(s[0], s[1], s[2]), s) )
rankedsolutions.sort()
rankedsolutions.reverse()
print(f'=== Gen {i} best solutions ===')
print(rankedsolutions[0])
if rankedsolutions[0][0] > 999:
break
bestsolutions = rankedsolutions[:100]
elements = []
for s in bestsolutions:
elements.append(s[1][0])
elements.append(s[1][1])
elements.append(s[1][2])
newGen = []
for _ in range(1000):
e1 = random.choice(elements) * random.uniform(0.99, 1.01)
e2 = random.choice(elements) * random.uniform(0.99, 1.01)
e3 = random.choice(elements) * random.uniform(0.99, 1.01)
newGen.append((e1, e2, e3))
solutions = newGen
I found an improvement that made it literally 100 times faster. There, in line 34, when you append all three elements to the same group you're mixing the x, y and z elements. So when you use these elements to create new tupple most of the newGen solutions are mixed, using a good y as x, a good x as z and so on. To fix it, instead of just one group "elements" create three groups ("elements_0", "elements_1" and "elements_2"). Then instead of "elements.append(s[1][0])" type "elements_0.append(s[1][0])", "elements_1.append(s[1][1])" and "elements_2.append(s[1][2])". Finally, when creating the newGen, comand "e1 = random.choice(elemets_0)" and the same for the other two groups. This way you're always taking a good x as x, y as y and z as z, no more scrumble. Congrats for the nice class Top Shelf, the best I could find so far!
Ответитьsource code>
ОтветитьI think you rushed in the explanation too much in the important part, which is at the end when the new contestants mutate from the previous bests. Still it is a really good example and without pedantic, too complex, paraphernalic, stack overflowish code, and I respect that.
ОтветитьI am fairly new to GA, and was able to kind of grasp the whole. So the first part is the choice of the fittest solutions (first 100). Then comes the crossover, which is randomly choosing from the pool of fittest solutions (please correct me if I am wrong). Then comes the multiplication by a random probability range, which is where I am confused a little. I would like to know why a multiplication by a random probability is a mutation in this scenario; specifically why do you multiply the chosen elements to obtain a mutation ? In the classical scenario, a mutation would be the swapping of 1 to 0 or 0 to 1 and I would like to know why in this case it represents multiplication.
ОтветитьNice Video.
Small tip: you can sort a list in descending order by using the parameter 'reverse' (like: list.sort(reverse=True)) instead of sorting and then reversing the list.
Excellent! very informative and understandable.
ОтветитьSuperb video, thank you very much! If I need x to be in a certain range, how could I define that in the code?
Ответитьone in c++ please...
ОтветитьIs this really genetic algorithm. Where is selection, mutation and crossover implemented in this code? This is just generation some random numbers and iterating to get the result.
ОтветитьI feel like the intent behind this video is good, but you should know the basics by hearth before trying to teach genetic algos and stuff. Also, the production quality is.....mediocre at best.
ОтветитьGood evening, thank you for this video. I'm trying to reproduce this code to solve a second equation at the same time with 3 unknowns (6 unknowns to be determined) and I'm having a bit of trouble, do you have any advice?
ОтветитьIt's just sorting and taking the first 100 ?
Did I missed anything ?
thanks sir! the best yet simple explanation for AG ive seen so far... more power!
ОтветитьHey thanks for posting this! I couldn't solve my previous issue; that line just prints scrolling numbers and generations; so I wrote my own code to do that - works just as well, looks even better.
I am able to follow the code through, but I couldn't have written it myself from scratch (yet); the narrator seemed to be blowing it off the top of his head on the fly - I got a long way to go before I am that proficient!
I have adapted it to solve other math problems. You get a different (still correct) answer each time! I suppose there is a way to calculate exactly how many solutions there are to equations like that, or maybe if you are shooting for a "close, good enough" solution, there may be an infinite number, depending on how close you set the break-out. I don't know.
It uses MUTATION, and I found by increasing from 2%->10% it solves much quicker and shorter!
Also, as I study the theory of GA, there is something called "crossover". I know what it is, but I don't see it.
Is that used here? Or am I missing it? (be gentle, I am a newbie with GA).
When I get to the line: print(f"=== Gen {i} best solutions === ") I get a "invalid syntax" error, and the cursor is placed between the final ") characters, suggesting the problem is there. Anyone else get this? I am using python 3.5.4 in Fedora Linux.
Ответитьwould be amazing if you could do an implementation of the ES Hyperneat algorithm, but not using the typical google enviroments
Ответитьthank you for your amazing video , I have question about how we can save best result (last ranked solutions ) in a list?
ОтветитьThank you
ОтветитьIn line10 you should change the returned value from an arbitrarily large value to 1/ machine epsilon. Your currently selected value is too small, and there is no way for a computer to determine the difference between zero and zero +- anything smaller than machine epsilon.
ОтветитьI just can't understand the need to evaluate the cells as you do. Why bother the if ==0 and the 1/ans ? Instead of just ranking the evaluation the other way around ?
ОтветитьAwesome video man! Your good in explainning! The end of the video is so funny :-D
ОтветитьIdea great, but this is not how you write python :D
ОтветитьGreat great vídeo, i have a question.
Suppose You have polynomial roots ( -4,-2,-3,-1,4) and You are asked to find the 6 coeffients
How would You do it ?
Thank You!
ОтветитьThis is really great, easy to follow
ОтветитьGreat video! Thank you very much
ОтветитьI did the same thing as you did but didn't get any output. I am always getting error at sort() and reverse().
Ответить