r/ArtificialInteligence
•
u/egehancry
•
Oct 03 '26
•
1
š Tutorial / Guide Explaining How AI Learns to Drive with Evolution
I love making hard things intuitive. I hope you enjoy this one!
This technique is called neuroevolution: training neural networks using evolutionary methods such as selection and mutation, without gradient descent.
Let me know if you have any questions.
Also shared to X: https://x.com/sinaatalay/status/2106270194817789968
89
u/lazo40 Oct 03 '26
Thatās really neat!! But like can the cars race on other tracks too or is it just this one??
37
u/Disastrous-Action897 Oct 03 '26
This is awesome. I teach people about AI, often. This is a great an explanation in an understandable context.
22
u/Fit-Tangerine-6006 Oct 03 '26
Great way to visually learn how AI works, more please!šĀ
13
u/Smittumi Oct 03 '26
How could you make a function to make them want to win, as in improve their position over the other drivers?Ā
It seems like if there was an AI F1 out would be pretty boring if they all just drive in the same perfect pattern.
10
u/Perfect-Escape-3904 Oct 03 '26
You might like this guys videos, heās been doing this with Trackmania for 5 years now.
He even has a similar presentation style to yours
https://youtu.be/a8Bo2DHrrow?si=s1ot9sPaogJhQEzD
3
u/AleksZlovic Oct 03 '26
Adding weights is such a fascinating part of this. Itās still very nebulous to me, however. Any books someone can recommend on RL, BP, weights, and other stuff?
3
u/Tube-Goblin Oct 03 '26
Great video. What breathe two functions? Are you ok to share the maths? Obviously ok if you don't.
3
u/Dany-GG Oct 03 '26
Do I need some crazy specs o my PC to replicate this?
4
u/Practical_Departure8 Oct 03 '26
Neat variation of genetic programming
2
u/Sore6 Oct 03 '26
out of curiosity: instead of letting ai figure it oit completely - could you cut down training time / generations by showing a perfect lap yourself to the ai and learn from that one example so it alternates from there?
2
u/__asm__ Oct 03 '26
Pretty neat. Have you considered benchmarking it against some well-known self-driving 2D racing heuristics like: Vector Field Histogram, Potential Field Method, Follow-the-Gap, or Pure Pursuit?
Would be curious to see how it compares.
2
u/pfunf Oct 03 '26
Great video
2
u/guttanzer Oct 03 '26
Nice work.
For the folks asking about higher-order behaviors like racing strategy and tactics, safety vs speed on varying tracks and so on, implementing those features would require a richer, more complex setup. This one is a great learning tool for its simplicity.
These cars are piloted by a feed-forward NN that is reacting to near-field observations and the most basic car model of a momentum vector. The only āmemoryā in this setup is the momentum vector. The aircraft equivalent is the flight controller in a fly-by-wire aircraft.
Since the system has no memory of the track it reacts its way into turns. It doesnāt anticipate and plan ahead the way a real driver would. So tuning the weights in the NN is equivalent to tuning a F1 car by making tire choices and altering the wing and suspension settings - the evolutionary algorithm is optimizing performance parameters, not performance.
Given this setup, Iād create a few different track styles and compare the optimal car controllers on those. Make one track have only wide, sweeping turns. Make another city-block like, with sharp 90 degree turns. Have another with only increasing radius turns, and another sister track with only decreasing radius turns (equivalently, have them race in different directions on the same wonky track).
I suspect you will find that a car tuned for one track will be slow or unsafe on a different type of track. What you may learn is why.
5
u/Kinu4U Oct 03 '26
You should randomise the track everytime so they "evolve" to be able to race any track. It will take a few billions iterations instead of thousands.
4
u/According_Gift_7095 Oct 03 '26
āNobody taught themā is incorrect, you taught them with specific functions then had a computer calculate at scale all possibilities, removing those that did t work until all worked.
Love this and all computer progress, just take Jaron Lanierās view that we should always think of this as āhuman collaborationā vs some magic black box called āAIā where the spark is coming from somewhere other than us, the creators, designers and input
1
u/TonyDRFT Oct 03 '26
Very interesting! It seems this is not the fastest line though, in racing you want to get as much speed possible at the exit of the corner (so it benefits from this speed the whole straight after the corner), this means sometimes sacrificing the corner entry speed and curve... Then there are several racing and breaking techniques based on physics, like weight transfer and resulting grip... etc
1
u/loftyspy Oct 03 '26
This is genuinely very cool. Could you also link the game for me hehe, kinda a racing fan.
1
u/_ginj_ Oct 03 '26
Whats the compute time for each generation? Hardware?
1
u/Infinite-Month-3454 Oct 03 '26
An elegant exposition of process.
1
u/AppealSame4367 Oct 03 '26
You sound like Mark Zuckerberg :D
1
u/geonber Oct 03 '26
fascinating thanks
1
u/JasonMckin Oct 03 '26
Academic question: does the fact that the steering and gas were not explicitly programmed make it AI? or does the model itself have to evolve for it to be AI?
Because it seems like you could just have just explicitly programmed how steering and gas worked and then it would drive exactly the same.
So the learning was only at development time, not at runtime. At runtime, itās just passively feeding sensor data to the model to get directions on steering and gas.
Does AI require runtime updates to the model or does any non-explicit programming get considered as AI even if there is no ongoing model learning at runtime?
1
u/Impossible_Way7017 Oct 03 '26
How did you decide on the neural net architecture?
1
u/rawbdor Oct 03 '26
Why was a neural network required at all here? What did the neural network do?
Couldn't you just use genetic algortithms without a neural network to discover the optimal function definitions? Ninety percent of your success was based on the genetic nature of the algorithm, seeding the next generation from the prior generation's winners. At what point does the neural network actually come into play, and how?
I did a very similar project decades ago except there was no neural network, just a normal genetic algorithm to find the most efficient and accurate function definitions.
1
u/Tribun4201 Oct 03 '26
If the track doesnt change, isnt this just machine learning instead of AI?
1
u/kidjupiter Oct 03 '26
Great explanation. Now, just add a "pain" factor that each driver experiences when they crash and watch them eventually refuse to race. Then, sit back and watch the AI psychosis backlash to your "cruel" experiments.
1
u/ConcertoInX Oct 04 '26
This is a neat presentation of evolutionary computing! One theory question for further exploration I have is, how confident are you that this process avoids getting stuck at local optima, i.e. might the AI be locking into a driving profile too early? Would some evolutionary processes like including crossover or doing simulated annealing see a more comprehensive search for the "best" driving profile?
1
u/Positive_Method3022 Oct 04 '26
You didn't explain how many layers and how many nodes in each layer in the neural network are chosen. Can you explain that?
3
u/Aggravating-Catch461 Oct 03 '26
if anyone is interested, there is a game on steam on this principle: https://store.steampowered.com/app/3312030/AI_Learns_To_Drive/
3
u/sleo82 Oct 04 '26
If you're curious about this topic, I would recommend looking at this course (the videos are free online). It shows how the real world problems like localization, PID controls, etc are solved in self driving cars. Most of these can be solved without using a neural network. But would be interested to see how your neural network evolves to handle things like sensor errors, changing courses, unknown maps, etc.
https://omscs.gatech.edu/cs-7638-robotics-ai-techniques-course-videos
2
u/New-Ingenuity-5437 Oct 03 '26
What are some good ways to try neural evolution stuff. Iāve seen videos for many years on this stuff and itās always been so cool
2
u/JoseLunaArts Oct 03 '26
Now lets do some drafting.
2
u/fitm3 Oct 03 '26
Now they need to learn to over take and not collide :)
2
u/Cold-Permission-5249 Oct 03 '26
Now give them the goal to win.
2
u/johndsmits Oct 03 '26
You're taking the LOS approach which will get stable quickly. It's how missile ATR systems run (for decades).
Once you get there them tackle vehicle on the track, should end up fairly predictable.
2
u/kgold0 Oct 04 '26
Consider car collision and drag!!! Then start adding different factors to each individual car (engine, tires, aerodynamics, accelerating, braking, handling)!
And maybe have it auto select the parents for the next generation (even have it decide what makes a good parent for the next generation).
2
u/AdAstramentis Oct 04 '26
Next level is to train on incline/decline or curved paths which will cause different physics on trajectories.
2
u/ProbablyCarl Oct 04 '26
Now turn crash physics on.
2
u/Equal_Animator7440 Oct 04 '26
Does System 1 thinking models simplify the whole evaluation?
I imagine the inputs are the distances and the model decides on turn right, turn left, or straight as output.
2
u/molumen Oct 04 '26
Now add car collisions and watch them learn overtaking. That will look like real drivers' behavior.
2
u/Antique-Wonk Oct 04 '26
This is really cool. Need to try for sure.
2
u/Witty-Elk2052 Oct 04 '26
moar evolution š§¬
2
u/6gv5 Oct 04 '26
Interesting, they end up choosing almost the same exact trajectory, which makes sense as all cars are essentially the same and they race on the same track. Might be worth giving each car some slightly different parameters (power/acceleration, max speed, weight, drag, braking, etc) so that they all need to evolve from initial training, possibly ending up developing "personalized" racing styles.
2
u/Massive_Lavishness90 Oct 04 '26
uh dude, have you seen the game "AI learns to drive" on Steam? It's basically this.
2
u/NoMindZen Oct 04 '26
š
2
u/DJ_Flugscham Oct 05 '26
This is great.
2
u/fokac93 Oct 05 '26
Nice. Ai doesnāt even know itās driving it is just calling functions
3
u/SirGelson Oct 03 '26
Overfitted.
1
u/haux_haux Oct 03 '26
Feel bad / feel good?
1
u/smrt_pants Oct 03 '26
Not sure the comment, āno body taught them to driveā is true. You gave it a set of formulas and kept picking the best performance as an input to the start of the next race. You technically taught the model to be better with each iteration, so what did the AI do for itself?
1
u/infamouslycrocodile Oct 05 '26
Amazing video but we should crack down on "nobody taught them to drive". If by "nobody" you mean the environment then that makes sense but like evolution in our plane of existence these car creatures too have been taught by the nature of their existence.
1
u/Historical_Ice_1844 Oct 06 '26
I've built (Claude did with my assistance) something based on your post: credits at bottom
https://neuroevolution.useful-shit.org
1
u/AmphibianTurbulent58 Oct 06 '26
I should have paid more attention in math class, š¤£š¤£ I got the logic tho
1
u/bull_bear25 Oct 06 '26
Looks a bit overfittingĀ
1
u/Popular-Elephant-884 Oct 07 '26
This is so cool. Thank you.
1
u/zulutune Oct 07 '26
To achieve this only in 400 generations is beyond my intuition, I find that miraculous.
I have a question though: when you create these different drivers in each generation, how do you make sure to not randomize too far of the āparentā?
1
u/Prize-Bee9481 Oct 09 '26
For anyone interested there's a whole free course on YouTube where someone builds this using vanilla JavaScript to build the neural network and do all the drawings (in primitives) too. He even visualises the network diagram.
1
u/Current-Elk5185 Oct 12 '26
u/savevideo
1
u/awesam9 Oct 23 '26
You have a repo ?
0
u/Illustrious-Egg5459 Oct 03 '26
how much of this video did AI generate? obviously the script, and the voice. the visuals too?
0
u/Pazienca Oct 03 '26
Anyone else can't stand this AI voice anymore?
-3
u/WillTheyKickMeAgain Oct 03 '26
What does it mean no one taught them to drive? The whole approach, programmed by a human, teaches them to drive. Letās not think this is some sort of magic and forget what weāre doing here.Ā
-6
u/FootballPositive1044 Oct 03 '26
Nothing special, ai slop. There is trackmania based videos that has explored this concept ages ago and much better.Ā
1
u/[deleted] Oct 09 '26
[removed] ā view removed comment