liveBook · Manning

Discount factor

As explained in Grokking AI Algorithms, Second Edition

A discount factor is a reinforcement-learning hyperparameter that determines how strongly future rewards contribute to the value of a current decision.

A discount factor controls how much future rewards matter when an agent chooses an action. Think of choosing between one marshmallow now and more marshmallows later: a patient agent is willing to wait, while an impulsive one focuses on what it gets immediately. section 10.6

The setting changes how far ahead the agent values rewards:

  • At 0, only the immediate reward matters. section 10.6
  • At 0.9, future rewards still matter considerably; 0.9 is a typical default. section 10.11
  • At 1, future rewards are not discounted in the delayed-gratification analogy. section 10.6

Updating the value of an eastward move

Suppose moving east gives an immediate reward of +1. In the new state, the highest predicted Q-value is 2.0. With a discount factor of 0.9, the training target is 1 + 0.9 × 2.0 = 2.8. If the network predicted 2.2 for the original move, training uses the squared difference between 2.2 and 2.8 as its loss. The factor lets the move receive credit for both its immediate reward and its promising next state. section 10.11

Future value decays with distance in time. In Q-learning, this encourages the agent to reach a rewarding goal by a shorter route rather than wander before collecting the reward. section 10.6

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines settings intuitively, notes exponential decay, and works through a one-step training target without a theoretical derivation.
Examples
Uses a marshmallow choice and an eastward move with a +1 reward, 2.0 next-state maximum, and 0.9 discount.
What it assumes
Builds intuition from a delayed-gratification choice before using rewards, states, actions, and Q-values in training examples.
What you can do after
Apply it to weight future rewards in Q-learning and calculate a one-step ANN training target.
How it connects
Links Q-learning, Q-tables, Q-values, rewards, and neural-network loss through the value assigned to a next state.

Also explained in

Compare how 4 books explain discount factor →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.