Answers.Body: <p>The motivation for adding the discount factor $\gamma$ is generally, at least initially, based simply in "theoretical convenience". Ideally, we'd like to define the "objective" of an RL agent as maximizing the sum of all the rewards it gathers; its <em>return</em>, defined as:</p>
  
  <p>$$\sum_{t = 0}^{\infty} R_t,$$</p>
  
  <p>where $R_t$ denotes the immediate reward at time $t$. As you also already noted in your question, this is inconvenient from a theoretical point of view, because we can have many different such sums that all end up being equal to $\infty$, and then the objective of "maximizing" that quantity becomes quite meaningless. So, by far the most common solution is to introduce a discount factor $0 \leq \gamma &lt; 1$, and formulate our objective as maximizing the <em>discounted return</em>:</p>
  
  <p>$$\sum_{t = 0}^{\infty} \gamma^t R_t.$$</p>
  
  <p>Now we have an objective that will never be equal to $\infty$, so maximizing that objective always has a well-defined meaning.</p>
  
  <hr>
  
  <p>As far as I am aware, the motivation described above is the <strong>only motivation for a discount factor being strictly necessary / needed</strong>. This is <strong>not related to the problem being stochastic or deterministic</strong>.</p>
  
  <p>If we have a stochastic environment, which is guaranteed to have a finite duration of at most $T$, we can define our objective as maximizing the following quantity:</p>
  
  <p>$$\sum_0^T R_t,$$</p>
  
  <p>where $R_t$ is a random variable drawn from some distribution. <strong>Even in the case of stochastic environments, this is well-defined, we do not strictly need a discount factor</strong>.</p>
  
  <hr>
  
  <p>Above, I addressed the question of whether or not a discount factor is <strong>necessary</strong>. This does not tell the full story though. Even in cases where a discount factor is not strictly <strong>necessary</strong>, it still might be <strong>useful</strong>. </p>
  
  <p>Intuitively, discount factors $\gamma &lt; 1$ tell us that <strong>rewards that are nearby in a temporal sense</strong> (reachable in a low number of time steps) <strong>are more important than rewards that are far away</strong>. In problems with a finite time horizon $T$, this is probably not true, <strong>but it can still be a useful heuristic / rule of thumb</strong>.</p>
  
  <p>Such a rule of thumb is particularly useful in stochastic environments, because <strong>stochasticity can introduce greater variance / uncertainty over long amounts of time than over short amounts of time</strong>. So, even if in an ideal world we'd prefer to maximize our expected sum of undiscounted rewards, <strong>it is often easier to learn how to effectively maximize a discounted sum</strong>; we'll learn behaviour that mitigates uncertainty caused by stochasticity because it prioritizes short-term rewards over long-term rewards.</p>
  
  <p>This rule of thumb especially makes a lot of sense in stochastic environments, but I don't agree with the implication in that book that it would be restricted to stochastic environments. A discount factor $\gamma &lt; 1$ has also often been found to be beneficial for learning performance in deterministic environments, <strong>even if afterwards we evaluate an algorithm's performance according to the undiscounted returns</strong>, likely because it leads to a "simpler" learning problem. In a deterministic environment there may not be any uncertainty / variance that grows over time due to the environment itself, but <strong>during a training process there is still uncertainy / variance in our agent's behaviour</strong> which grows over time. For example, it will often be selecting suboptimal actions for the sake of exploration.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-15T20:23:20.450Z
Answers.Text: Quite elucidating.  Can I ask why t is superscripted with the gamma?
Answers.UserDisplayName: DukeZhou
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-16T08:11:39.813Z
Answers.Text: @DukeZhou It's $\gamma$ raised to the power $t$ (time). Suppose, for example, that $\gamma = 0.9$. Then our first reward ($R_0$) will be multiplied by $0.9^0 = 1$ (fully valued). The second reward ($R_1$) is multiplied by $0.9^1 = 0.9$ (only "90% important"). The third reward is multiplied by $0.9^2 = 0.81$ (only "81% important"), etc. Such a sum can be proven to never reach $\infty$ (assuming that none of the individual rewards $R_t$ are equal to $\infty$)
Answers.UserDisplayName: Dennis Soemers
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-15T17:32:13.997Z
Answers.LastActivityDate: 2018-08-15T17:37:30.380Z
Answers.LastEditDate: 2018-08-15T17:37:30.380Z
Answers.UserDisplayName: Dennis Soemers
Body: <p>I'm now reading a book titled as <em>&quot;Deep Reinforcement Learning Hands-On&quot;</em> and the author said the following on the chapter about AlphaGo Zero:</p>
  <blockquote>
  <p>Self-play</p>
  <p>In AlphaGo Zero, the NN is used to approximate the prior probabilities of the actions and evaluate the position, which is very similar to the Actor-Critic (A2C) two-headed setup. On the input of the network, we pass the current game position (augmented with several previous positions) and return two values. The policy head returns the probability distribution over the actions and the value head estimates the game outcome as seen from the player's perspective. <strong>This value is undiscounted, as moves in Go are deterministic.</strong> Of course, if you have stochasticity in the game, like in backgammon, some discounting should be used.</p>
  </blockquote>
  <p>All the environments that I have seen so far are stochastic environments, and I understand the discount factor is needed in stochastic environment.
  I also understand that the discount factor should be added in infinite environments (no end episode) in order to avoid the infinite calculation.</p>
  <p>But I have never heard (at least so far on my limited learning) that the discount factor is NOT needed in deterministic environment. Is it correct? And if so, why is it NOT needed?</p>
  
Tags: <reinforcement-learning><q-learning><discount-factor>
Title: Is the discount not needed in a deterministic environment for Reinforcement Learning?
UserDisplayName: Blaszard
ThreadText: # Is the discount not needed in a deterministic environment for Reinforcement Learning?
  
  (Asked by: username_0 on 2018-08-15)
  
  I'm now reading a book titled as *"Deep Reinforcement Learning Hands-On"* and the author said the following on the chapter about AlphaGo Zero:
  
  > Self-play
  >
  > In AlphaGo Zero, the NN is used to approximate the prior probabilities of the actions and evaluate the position, which is very similar to the Actor-Critic (A2C) two-headed setup. On the input of the network, we pass the current game position (augmented with several previous positions) and return two values. The policy head returns the probability distribution over the actions and the value head estimates the game outcome as seen from the player's perspective. **This value is undiscounted, as moves in Go are deterministic.** Of course, if you have stochasticity in the game, like in backgammon, some discounting should be used.
  
  All the environments that I have seen so far are stochastic environments, and I understand the discount factor is needed in stochastic environment.
  I also understand that the discount factor should be added in infinite environments (no end episode) in order to avoid the infinite calculation.
  
  But I have never heard (at least so far on my limited learning) that the discount factor is NOT needed in deterministic environment. Is it correct? And if so, why is it NOT needed?
  
  **Tags:** reinforcement-learning, q-learning, discount-factor
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-15. Score: 7 | Accepted answer
  
  The motivation for adding the discount factor $\gamma$ is generally, at least initially, based simply in "theoretical convenience". Ideally, we'd like to define the "objective" of an RL agent as maximizing the sum of all the rewards it gathers; its *return*, defined as:
  
  $$\sum\_{t = 0}^{\infty} R\_t,$$
  
  where $R\_t$ denotes the immediate reward at time $t$. As you also already noted in your question, this is inconvenient from a theoretical point of view, because we can have many different such sums that all end up being equal to $\infty$, and then the objective of "maximizing" that quantity becomes quite meaningless. So, by far the most common solution is to introduce a discount factor $0 \leq \gamma < 1$, and formulate our objective as maximizing the *discounted return*:
  
  $$\sum\_{t = 0}^{\infty} \gamma^t R\_t.$$
  
  Now we have an objective that will never be equal to $\infty$, so maximizing that objective always has a well-defined meaning.
  
  ---
  
  As far as I am aware, the motivation described above is the **only motivation for a discount factor being strictly necessary / needed**. This is **not related to the problem being stochastic or deterministic**.
  
  If we have a stochastic environment, which is guaranteed to have a finite duration of at most $T$, we can define our objective as maximizing the following quantity:
  
  $$\sum\_0^T R\_t,$$
  
  where $R\_t$ is a random variable drawn from some distribution. **Even in the case of stochastic environments, this is well-defined, we do not strictly need a discount factor**.
  
  ---
  
  Above, I addressed the question of whether or not a discount factor is **necessary**. This does not tell the full story though. Even in cases where a discount factor is not strictly **necessary**, it still might be **useful**.
  
  Intuitively, discount factors $\gamma < 1$ tell us that **rewards that are nearby in a temporal sense** (reachable in a low number of time steps) **are more important than rewards that are far away**. In problems with a finite time horizon $T$, this is probably not true, **but it can still be a useful heuristic / rule of thumb**.
  
  Such a rule of thumb is particularly useful in stochastic environments, because **stochasticity can introduce greater variance / uncertainty over long amounts of time than over short amounts of time**. So, even if in an ideal world we'd prefer to maximize our expected sum of undiscounted rewards, **it is often easier to learn how to effectively maximize a discounted sum**; we'll learn behaviour that mitigates uncertainty caused by stochasticity because it prioritizes short-term rewards over long-term rewards.
  
  This rule of thumb especially makes a lot of sense in stochastic environments, but I don't agree with the implication in that book that it would be restricted to stochastic environments. A discount factor $\gamma < 1$ has also often been found to be beneficial for learning performance in deterministic environments, **even if afterwards we evaluate an algorithm's performance according to the undiscounted returns**, likely because it leads to a "simpler" learning problem. In a deterministic environment there may not be any uncertainty / variance that grows over time due to the environment itself, but **during a training process there is still uncertainy / variance in our agent's behaviour** which grows over time. For example, it will often be selecting suboptimal actions for the sake of exploration.
  
  > **Comments:**
  > **username_2**: Quite elucidating.  Can I ask why t is superscripted with the gamma?  
  > **username_1**: @username_2 It's $\gamma$ raised to the power $t$ (time). Suppose, for example, that $\gamma = 0.9$. Then our first reward ($R_0$) will be multiplied by $0.9^0 = 1$ (fully valued). The second reward ($R_1$) is multiplied by $0.9^1 = 0.9$ (only "90% important"). The third reward is multiplied by $0.9^2 = 0.81$ (only "81% important"), etc. Such a sum can be proven to never reach $\infty$ (assuming that none of the individual rewards $R_t$ are equal to $\infty$)  
  
  ---
  
  