Find why this value-iteration Bellman update ignores immediate rewards.
Codejavascript
// One Bellman backup for state s in value iteration
function bellmanUpdate(s, actions, transitions, reward, gamma, V) {
let best = -Infinity;
for (const a of actions) {
let q = 0;
for (const [sp, prob] of transitions(s, a)) {
q += prob * (gamma * V[sp]);
}
best = Math.max(best, q);
}
return best;
}
The value estimates never account for earnings along the way. What is the bug?