Self-parking Car in 500 Lines of Code
trekhleb.dev
trekhleb.dev
Consider: if you were given a freeze-frame view of the car in the exact right spot, what controls would you send it to keep it there? It'd be impossible to say without knowing the car's velocity - if the car was in the process of reversing, it should apply forwards acceleration to come to a stop, but if it was in the process of going forwards it should apply reverse acceleration.
The solution is to add Derivative control. This would look like a second set of inputs to the system comprised of the difference between the current measurements and the prior ones.
When this happened on my job, I was very surprised that I hadn’t heard of PID controllers in CS school. They’re standard in other kinds of engineering.
There are often better variants and alternatives to a basic PID controller, but I’m quite partial to the core idea - the three terms in the PID controller are analogous to car/bike suspensions. It’s a unitless suspension system for sensors & data. Spring rate is like your proportional term, and compression damping and rebound damping are like the derivative and integral terms. This analogy ain’t perfect, but I dig the concept.
My concentration was embedded systems but the majority of the class were just regular CS students.
But yes, I couldn’t imagine a CS education without controls. My intro CS class in college explored controls in some depth and I took a follow up class. Some of the most incredible things I’ve created were control systems, and it’s one of the primary classes I think of when people ask about the merits of a college education.
https://codesandbox.io/embed/rocket-sim-final-with-position-...
There are supposed to be better controllers but dang PID just work.
Usually better to design the process to be controlled by a PID than the other way around.
In this case, the mapping of a complicated multi-step process involving external constraints to a "gene" is going to be a hack, no matter what you do.
I think calling it a "hack" misses the nuance: mapping the physical metrics and telemetry into a genome is nontrivial.
Plus 40 generations is no where NEAR enough. A GA needs millions (or billions) of generations to avoid local minima/maxima. Especially given the size of the input vector. His vector is what, 2^100 states?
> I think calling it a "hack" misses the nuance: mapping the physical metrics and telemetry into a genome is nontrivial.
Well, that's definitely what I was trying to say, so we're agreed.
I actually don't think GA a great fit for this problem as parking a car is a time- and circumstance-dependent process, and a fixed gene is...not. But that's a guess.
To give a silly example, Monte Carlo is like trying to guess the surface area of a dartboard by throwing darts at it and counting how many hit it, while gradient descent is like throwing darts at the board until you hit the center (or something you think is the center).
Oh definitely not! :)
Assuming you can actually detect success, that's not really that big of a problem. You can do it in 11 lines by appending:
for(i in 1e7){g=do-generation(g);if(worksp(g)) return g}
It'll take while, but the claim is that it optimises on lines, not on runtime.Does this evolution park a car only if all the other cars are in those precise spots?
[1] https://www.npr.org/templates/story/story.php?storyId=122880...
I'm all about using the right tool for the job. In this case, I'd say algebra, if the job is "park the car." If the job is "teach genetic algorithms with a simple example," no complaints except for the headline.
I downvoted because I thought that the comment's dismissive tone is not helpful, and doesn't encourage the sort of content I like to see on Hacker News. I like it when enthusiastic people make cool stuff that explains an idea well. I don't like it when commenters are incredulous that others aren't doing something the same way they would, or generally are cruel and condescending about someone else's enthusiasm. "Not impressive" is just such an unhelpful thing to say, and not what I come here for, so I downvoted.
This comment in particular seems to be a great example of "middlebrow dismissal" in the original sense from pg.
> I downvoted because I thought that the comment's dismissive tone is not helpful
I can't help but notice though that you initially had a rather dismissive comment, which I tried to reply to so I could ask for clarity, but you had deleted it by the time I hit submit. My comment that you are responding to was initially for you.
Can you shed more light on how this dichotomy exists? Generally, if you don't care for those types of comments, you'd also not make them, which even now in your second content is somewhat derisive with the "middlebrow dismissal" even if it is a quote from pg.
Anyway, I deleted it because I can't really defend that tone myself, and think that a downvote says enough.
I don't really understand the rest of your comment. What dichotomy are you talking about?