➡️ Part 14 of learning ML code from scratch: Building an algorithm that can escape a maze in under 2…
MachineLearningToGo
Visit on TikTok29K followers
42,200 views #machinelearning #ai #reinforcementlearning
➡️ Part 14 of learning ML code from scratch: Building an algorithm that can escape a maze in under 2 minutes. The game is a maze in five lines of text. S is the start, G is the exit, and every # is a wall. All we need is Python and numpy, and the whole AI is 16 lines of code. How it learns: every step costs one point. Its memory is a score table called Q, with one score for every cell and each of the four moves, 220 scores in total, and all of them start at zero. Zero is the best score there is, so every move it has never tried looks perfect, and it tries them all. At a wall it bumps and stays put. The surprise: one single line does all the learning. The move it just made gets the best score of the cell it landed in, minus one for the step. That is Q-learning. Game 1 takes 148 steps, with 60 bumps into walls and a dead end. When it reaches the exit, the last move learns: one step to go. Game after game this knowledge flows backwards, one cell at a time, until in game 35 the start knows: 18 steps. From game 37 on it takes the shortest way, 18 steps, every single time. Did it really learn, or did it memorize? We gave it a new maze. With its old score table and the learning line switched off, it walks its old way and gets stuck at a new wall two steps before the exit, forever. The same 16 lines with the new maze typed in learn it from scratch: from game 43 on it takes the new shortest way, and all 100 games take 0.057 seconds. We tested 20 more new mazes. The old table got stuck in all 20, and the 16 lines learned all 20. The score table is like a note with the way through one maze. What we built is the skill to write that note. With the same idea, and a neural network in place of the table, computers taught themselves to play video games and Go. #machinelearning #ai #reinforcementlearning #python #coding
Comments
Comments from the original post on TikTok
No comments yet
