Explore Library
Code QuizIntermediate

Greedy Policy Extraction

Find why extracting a greedy policy from Q-values picks the wrong action.

Codejavascript
function extractGreedyPolicy(Q) {
  const policy = [];
  for (let s = 0; s < Q.length; s++) {
    let bestAction = 0;
    for (let a = 1; a < Q[s].length; a++) {
      if (Q[s][a] < Q[s][bestAction]) bestAction = a;
    }
    policy[s] = bestAction;
  }
  return policy;
}

What is the bug in this greedy policy extraction?