Coding Challenge #29: Smart Rockets in p5.js

preview_player
Показать описание


Videos:

Related Coding Challenges:

Timestamps:
0:00 Introduction
3:10 Rocket object
7:07 Population object
10:48 DNA object
15:09 Add target
17:24 Evaluate function
19:35 Mating pool
23:26 Selection function
25:36 Crossover function
33:56 Is the genetic algorithm working?
35:50 Check if rocket has reached target
38:05 Mutation function
40:17 Add obstacle
43:34 Check if rocket hits canvas edges
46:55 Conclusion and possible improvements

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

#geneticalgorithm #dna #evolutionaryalgorithm #p5js #javascript
Рекомендации по теме
Комментарии
Автор

A smart rocket walks into a bar. Daniel resets the simulation with a whole new population and tries again.

kevnar
Автор

coding challenges in the past: i will give myself 10 minutes
Looks at run time: 48:16
Oh boy, this must have been a good one

LoganLovell
Автор

I love how enthusiastic you are in these videos. You're a great teacher!

mouse
Автор

This video got me really interested in genetic algorithms, thanks.

Salva
Автор

I made an email signature for my boss using HTML. Changed the color and size of font, etc. I felt accomplished.

ScubzMcTalBowling
Автор

This was interesting. Understood about 80% of it.

batfan
Автор

Hey Dan, thanks for taking the time to do it from scratch! I think it really helps learn the subject but also helps with some of the syntax and tricks you can do with p5js. Keep up the awesome work!

bsizzbs
Автор

oh god... my smart rockets developed sentience... now they are questioning why they were made on the endless task of seeking for the target... never ceasing, always trying to get more fit

noonecares
Автор

I’ve lost a couple hours on the library error. I’m trying to learn, but if I could edit libraries or describe their cross functionality with various APIs I would not need a tutorial. Aside from the problem with the library and/or text editor/browser issue, the content and enthusiasm is top notch. I’m a 42 year old guy in the throws of a career change in which I’m already behind, and the train is accelerating! Fortunately, dedication counts for a great deal.

chrisjones
Автор

An interesting thing happened when I added time to the fitness value ((1/count) * 100 added to the fitness value before the 10 times multiplier whenever a rocket has reached the target).

After about 15 generations, the average fitness keeps bouncing between 1700 and 2100. The top fitness is 4010, but this is unattainable, as it would require the rocket to take less than a single frame to get from start to target. The top achievable right now (as far as I could tell) is 4006.7, with the record I've seen over a few hundred generations is 4006.66.

It's like when you add a second quality to fitness, it tries to incorporate that so hard that it will pick the faster rockets over the more accurate ones, until it notices that the faster ones miss the target, but those that hit the target are slower so they won't be picked as often. That drags the average down, as most rockets will miss the target, but those that hit will have a higher breeding chance as their score is more than 10 times those that miss (~380 compared to over 4000). So the more accurate ones are picked again, but the faster ones score slightly higher now, so they will start getting picked, reducing accuracy and so on and so forth in infinitum.

So past gen 15, I ended up every single time with about half the rockets hitting but slowly and half missing, but they shoot off quite quick. The mutation kicks in some times, creating a rocket that goes way off course, then that one is removed from the gene pool thanks to the evolution thing.

morphman
Автор

The ending has me getting all philosophical. Like what if one side were a bit shorter, but all the rockets went around the other side anyway, and kept doing that because it was what worked first, even though there was a better way.

CaptainAardvaark
Автор

And this, kids, is what a real programmer is. Using his knowledge in science to simulate the existing world, then pushing further in order to solve problems. (Here it's Physics mixed with Genetics, could also be applied with knowledge and problems in Economics, Sociology, and so on...)
Subscribed.

MrKraignos
Автор

if you calculate d with "1/(distance+1)", you will get a normalized exponential fitness range and eliminate divide by 0 posibility. which is great and easy

sayochikun
Автор

Rocket flies through rocket
Ah yes the physics system is done

flamexode
Автор

I think a big reason they were all loving crashing was because the value was set to 1 for crashing, which about as good as if they got within a pixel of the target.

samfrostinjapan
Автор

He forgot to revisit the other website to see how the rockets evolved ^^

JinTsen
Автор

please please please make this project an ongoing series. it would be awesome to refine it over time and maybe end up with a population that can navigate a maze or something.

divadbate
Автор

You genuinely seem like a good person, I love your enthusiasm. Keep it up!

heruka
Автор

this was my first ever introduction to machine learning back in the day

Timotheeee
Автор

Daniel you are amazing And it helps my son out a lot. Thanks man.

sumanpahari