concept

Tabular Q-learning update

One temporal-difference action-value update. Nonterminal transitions need legal next-action values. Terminal transitions have reward-only targets. External truncation alone does not remove bootstrapping.

Formal Syntax & Structure

artificial-intelligence syntaxartificial-intelligence
q_update(old, reward, next_values, alpha, gamma, terminated)

Working Example

Example Snippetartificial-intelligence
def q_update(old, reward, next_values, alpha, gamma, terminated):    if not 0 <= alpha <= 1 or not 0 <= gamma <= 1:        raise ValueError("alpha and gamma must be in [0, 1]")    if not terminated and not next_values:        raise ValueError("nonterminal state requires legal actions")    target = reward if terminated else reward + gamma * max(next_values)    return old + alpha * (target - old)
print(q_update(1, -1, [2, 4], 0.5, 0.5, False))print(q_update(1, 5, [], 0.5, 0.5, True))