liveBook · Manning

Discount factor

As explained in Optimization Algorithms: AI techniques for design, planning, and control problems

A discount factor is a scalar between zero and one that determines how strongly future rewards contribute to an action value.

The discount factor, γ, controls how much future rewards count when an agent evaluates a state or action. It is typically between 0 and 1. A value close to 0 favors immediate rewards; a value close to 1 gives more weight to rewards that arrive later. section 12.1.2

Discounting is part of expected cumulative reward. A state-value function V(s) estimates that reward from a state while following a policy; an action-value function Q(s, a) estimates it after taking a particular action. Changing γ therefore changes how strongly those estimates value future rewards. section 12.1.2

CartPole advantage calculation

In a CartPole A2C implementation, γ is set to 0.99. The advantage calculation combines the current reward with γ times the critic’s estimate of the next state, then subtracts the critic’s estimate of the current state. The next-state term is omitted when the episode is done. This is where the preference for future reward enters the training update. section 12.3

advantage = reward + (1-
 done)*gamma*critic(torch.from_numpy(next_state).float()) - 
    critic(torch.from_numpy(state).float())       #1
  
total_reward += reward                              #2
state = next_state                                  #3
#1 Compute the advantage function.
#2 Update the total reward.
#3 Move to the next state.

Inspect the advantage expression to see where gamma scales the next-state value and how the done flag removes that term. section 12.3

How Optimization Algorithms: AI techniques for design, planning, and control problems covers it

How deep it goes
Defines the near-zero versus near-one trade-off and shows gamma in code, without deriving a tuning rule.
Examples
Uses a CartPole A2C implementation with gamma set to 0.99 and applied to the next-state critic estimate.
What it assumes
Introduces state- and action-value functions before applying discounting in code that uses an actor and critic.
What you can do after
Build it from scratch into the shown CartPole A2C advantage calculation by setting gamma and weighting the next-state value.
How it connects
Connects discounted reward to state-value functions, action-value functions, policies, critics, and advantage functions.

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 Optimization Algorithms: AI techniques for design, planning, and control problems. The section links point to the parts of the book it draws on.