Gamified challenge · Reinforcement learning
A robot has nStates rooms and nActions moves. experiences[k] = [s, a, r, next] says that in room s move a earned reward r (an integer) and led to room next, or ended the episode if next = -1. Start with every Q[s][a] = 0 and replay the experiences once, in order. Q values are kept in hundredths of a point, as integers:
best = 0 if next == -1 else max(Q[next]), target = 100·r + ⌊gammaPct · best / 100⌋, then Q[s][a] += ⌊alphaPct · (target − Q[s][a]) / 100⌋, where ⌊ ⌋ rounds down (toward −∞: // in Python, Math.floorDiv in Java).
Write greedyPolicy(nStates, nActions, experiences, alphaPct, gammaPct) returning, for every room, the move with the largest Q (ties go to the lowest action, so an untouched room answers 0). Example: [[0,1,0,1],[1,1,10,-1],[0,1,0,1]] with 2 rooms, 2 moves, α = 50, γ = 90 gives Q(1,1) = 500 then Q(0,1) = 225, so the answer is [1, 1].
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google