2
$\begingroup$

I want to apply Deep Q Learning to a problem, which has a clear finite horizon definition, like:

$$V(s) = \mathbb{E}[r_1 + r_2]$$

Since the horizon is finite, I do not use reward discounting. My action spaces at the time steps 1 and 2 do change and also the policies are therefore clearly not stationary as well. But the state and reward transitions are deterministic as: $r_i(s_i,a_i)$ and $s_{i+1}(s_i,a_i)$. The state space is also very large, so tabular methods are out of question. So the value function can be defined as:

$$V(s) = \sum_{a_1}\sum_{a_2}\left(r_1 + r_2\right)\pi_1(a_1|s_1=s)\pi_2(a_2|s_2(s_1=s,a_1))$$

since the only randomness comes from the policy distributions. (I dropped the reward functions' depedency on the states and actions for clarity). My question is, would Deep Q Learning work for such a finite horizon case? I plan to use two separate MLPs for the Q functions at time steps 1 and 2. I know that the Bellman Optimality can be shown both for the finite and infinite cases; in the finite case, it does not even need the stationarity of the distributions. But all examples on DQNs I came accross during my research solves problems with the infitine horizon assumption. So I just wanted ask for some insight there.

$\endgroup$
0

1 Answer 1

1
$\begingroup$

DQN solves optimal control problems for maximising average reward. Although it typically uses discounted reward, the discount factor is not part of the setting - instead it is part of the solution hyperparameters, and usually set quite high e.g. 0.99 - when using function approximators.

The TD target used in DQN is a problem for you:

$$G_{t:t+1} = R_{t+1} + \gamma \text{max}_{a'}Q(S_{t+1},a')$$

as it relies on a Bellman equation that no longer holds for the given value functions. In your case, there does not seem to be any way to express the TD target for time $t$ by referencing other Q values, as you would need to then subtract future rewards, which is very ungainly. Instead, you could use a simple truncated Monte Carlo return

$$G_{t:t+3} = R_{t+1} + R_{t+2} + R_{t+3}$$

There are a few different ways you could do this, but the simplest and closest to DQN would IMO be to:

  • Store trajectories in order in the experience replay table
  • For each item in the training mini-batch:
    • Pick a start state/action pair to assess $s_t, a_t$ randomly from replay table
    • Check that $a_{t+1}$ and $a_{t+2}$ are maximising actions in your current target policy for $s_{t+1}$ and $s_{t+2}$, reject the sample if not (note you don't need to check or reject $a_t$, and that is how your code learns about exploratory actions)
    • Calculate the TD target, $g_t = r_{t+1} + r_{t+2} + r_{t+3}$
    • Your training data for that example is $s_t, a_t, g_t$

The checking for maximising action parts could be quite slow, so you might prefer to simplify the approach and not use off-policy. Alternatively, if $epsilon$ is low enough you could just store the three step returns directly in the experience replay table (wait until you have the data from $t+3$ before storing data for $t$) and ignore the fact that some returns are from exploratory actions, thus noisy/biased . . . this approach is used in n-step returns in DQN "Rainbow" version and works well enough in practice on the Atari problems despite being on shaky theoretical ground.


Note I am using the convention $s_t, a_t, r_{t+1}, s_{t+1}$ to represent a step in the trajectory, whilst in the question you appear to be using $s_t, a_t, r_t, s_{t+1}$ with a different reward index. You will need to convert back if you want to stick with your convention.

$\endgroup$
7
  • $\begingroup$ Many thanks for the detailed answer. Is the main problem in my case that the Bellman equation does not hold for me right? Is it only valid for problems with infinite time steps? I didn't exactly get what violates the Bellman equation in my case. $\endgroup$ Commented Dec 27, 2019 at 11:07
  • 1
    $\begingroup$ I think that there are Bellman equations that could be applied. However, the Bellman equations that are used for Q learning and relate value functions between time steps become much more cumbersome as you need to remove the reward beyond the horizon, so you end up with awkward sums like $v(s) = \mathbb{E}_{\pi}[R_{t+1} + v(S_{t+1}) - R_{t+4} |S_t = s]$ $\endgroup$ Commented Dec 27, 2019 at 12:22
  • $\begingroup$ Oh, so I see that Q learning assumptions are about an infinte horizon case. Would policy gradients help me then? I think it is possible to maximize $V_2(s)$ wrt $\pi_2$ and then using them, frozen, for maximizing $V_1(s)$ wrt $\pi_1, as proposed here: rll.berkeley.edu/deeprlcoursesp17/docs/lec1.pdf $\endgroup$ Commented Dec 27, 2019 at 12:41
  • 1
    $\begingroup$ @UfukCanBicici: Policy gradient methods should work, but any Actor-Critic variant will suffer a similar problem for estimating values. This answer would apply to those too - you could use a truncated Monte Carlo return in place of bootstrapping between value functions on different time steps. $\endgroup$ Commented Dec 27, 2019 at 13:07
  • 1
    $\begingroup$ @UfukCanBicici: I cannot really tell how that would work from your comment. Are you suggesting having sub-optimisers that work with time horizon of 2 and 1, then using the 2-horizon value function to bootstrap the 3-horizon value function, and the 1-horizon function to bootstrap the 2-horizon one? Seems odd, but cannot think of a reason off top of my head why it would not work. I suspect it would not be very efficient and there may be a better way that i don't know however. Perhaps ask another question on the site? $\endgroup$ Commented Dec 28, 2019 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.