C-L EARNING : H ORIZON -A WARE C UMULATIVE A CCESSIBILITY E STIMATION
A BSTRACT
Multi goal reaching is an important problem in reinforcement learning needed to achieve algorithmic generalization.
Despite recent advances in this ﬁeld , current algorithms suffer from three major challenges: high sample complexity, learning only a single way of reaching the goals and difﬁculties in solving complex motion planning tasks.
In order to address these limitations, we introduce the concept of cumulative accessibility functions which measure the reachability of a goal from a given state within a speciﬁed horizon.
We show that these functions obey a recurrence relation, which enables learning from ofﬂine interactions.
We also prove that optimal cumulative accessibility functions are monotonic in the planning horizon.
Additionally, our method can trade off speed and reliability in goal-reaching by suggesting multiple paths to a single goal depending on the provided horizon.
We evaluate our approach on a set of multi-goal discrete and continuous control tasks.
We show that our method outperforms state-of-the-art goal-reaching algorithms in success rate, sample complexity and path optimality.
Our code is available at https://github.com/layer6ai-labs/CAE and additional visualizations can be found at https://sites.google.com/view/ learning cae
I NTRODUCTION
Multi-goal reinforcement learning tackles the challenging problem of reaching multiple goals, and as a result, is an ideal framework for real-world agents that solve a diverse set of tasks.
Despite progress in this ﬁeld (Kaelbling, 1993; Schaul et al., 2015; Andrychowicz et al., 2017; Ghosh et al., 2019), current algorithms suffer from a set of limitations: an inability to ﬁnd multiple paths to a goal, high sample complexity, and poor results in complex motion planning tasks.
In this paper we propose C -learning, a method which addresses all of these shortcomings.
Many multi-goal reinforcement learning algorithms are limited by learning only a single policy π ( a | s, g ) over actions a to reach goal g from state s .
There is an unexplored trade-off between reaching the goal reliably and reaching it quickly.
We illustrate this shortcoming in Figure 1a, which represents an environment where an agent must reach a goal on the opposite side of some predator.
Shorter paths can reach the goal faster at the cost of a higher probability of being eaten.
Existing algorithms do not allow a dynamic choice of whether to act safely or quickly at test time.
The second limitation is sample complexity.
Despite signiﬁcant improvements (Andrychowicz et al., 2017; Ghosh et al., 2019), multi-goal reaching still requires a very large amount of environment interactions for effective learning.
We argue that the optimal Q -function must be learned to high accuracy for the agent to achieve reasonable performance, and this leads to sample inefﬁciency.
The same drawback of optimal Q -functions often causes agents to learn sub-optimal ways of reaching the intended goal.
This issue is particularly true for motion planning tasks (Qureshi et al., 2020), where current algorithms struggle. [Figure]
We propose to address these limitations by learning horizon-aware policies π ( a | s, g, h ) , which should be followed to reach goal g from state s in at most h steps.
The introduction of a time horizon h naturally allows us to tune the speed/reliability trade-off, as an agent wishing to reach the goal faster should select a policy with a suitably small h value.
To learn these policies, we introduce the optimal cumulative accessibility function C ∗ ( s, a, g, h ) .
This is a generalization of the state-action value function and corresponds to the probability of reaching goal g from state s after at most h steps if action a is taken, and the agent acts optimally thereafter.
Intuitively it is similar to the optimal Q -function, but Q -functions rarely correspond to probabilities, whereas the C ∗ -function does so by construction.
We derive Bellman backup update rules for C ∗ , which allow it to be learned via minimization of unbiased estimates of the cross-entropy loss – this is in contrast to Q -learning, which optimizes biased estimates of the squared error.
Policies π ( a | s, g, h ) can then be recovered from the C ∗ function.
We call our method cumulative accessibility estimation, or Clearning .
Pong et al.
(2018) proposed TDMs, a method involving horizon-aware policies.
We point out that their method is roughly related to a non-cumulative version of ours with a different loss that does not enable the speed/reliability trade-off and is ill-suited for sparse rewards.
We include a detailed discussion of TDMs in section 4.
One might expect that adding an extra dimension to the learning task, namely h , would increase the difﬁculty - as C ∗ effectively contains the information of several optimal Q -functions for different discount factors.
However, we argue that C ∗ does not need to be learned to the same degree of accuracy as the optimal Q -function for the agent to solve the task.
As a result, learning C ∗ is more efﬁcient, and converges in fewer environmental interactions.
This property, combined with our proposed goal sampling technique and replay buffer used during training, provides empirical improvements over Q -function based methods.
In addition to these advantages, learning C ∗ is itself useful, containing information that the horizonaware policies do not.
It estimates whether a goal g is reachable from the current state s within h steps.
In contrast, π ( a | s, g, h ) simply returns some action, even for unreachable goals.
We show that C ∗ can be used to determine reachability with examples in a nonholonomic environment.
Summary of contributions : ( i ) introducing C -functions and cumulative accessibility estimation for both discrete and continuous action spaces; ( ii ) highlighting the importance of the speed vs reliability trade-off in ﬁnite horizon reinforcement learning; ( iii ) introducing a novel replay buffer specially tailored for learning C ∗ which builds on HER (Andrychowicz et al., 2017); and ( iv ) empirically showing the effectiveness of our method for goal-reaching as compared to existing alternatives, particularly in the context of complex motion planning tasks.
B ACKGROUND AND RELATED WORK
Let us extend the Markov Decision Process (MDP) formalism (Sutton et al., 1998) for goal-reaching.
We consider a set of actions A , a state space S , and a goal set G .
We assume access to a goal checking function G : S × G → { 0 , 1 } such that G ( s, g )
=
if and only if state s achieves goal g .
For example, achieving the goal could mean exactly reaching a certain state, in which case G = S and
G ( s, g ) =
1 ( s = g ) .
For many continuous state-spaces, hitting a state exactly has zero probability.
Here we can still take G = S , but let G ( s, g )
=
1 ( d ( s, g ) ≤ (cid:15) ) for some radius (cid:15) and metric d .
More general choices are possible.
For example, in the Dubins’ Car environment which we describe in more detail later, the state consists of both the location and orientation of the car: S =
R 2 × S 1 .
We take G = R 2 , and G ( s, g ) checks that the location of the car is within some small radius of g , ignoring the direction entirely.
For a ﬁxed g , G ( s, g ) can be thought of as a sparse reward function.
In the goal-reaching setting, a policy π : S×G → P ( A ) , where P ( A ) denotes the set of distributions over A , maps state-goal pairs to an action distribution.
The environment dynamics are given by a starting distribution p ( s 0 , g ) , usually taken as p ( s 0 ) p ( g ) , and transition probabilities p ( s t +1 | s t , a t ) .
States for which G ( s, g ) = 1 are considered terminal.
Q-Learning: A Q -function (Watkins & Dayan, 1992) for multi-goal reaching, Q π : S×G×A → R , is deﬁned by Q π ( s t , g, a t ) =
E π [ (cid:80) ∞
i =
t γ i [Equation] G ( s t , g ) | s t , a t ] , where γ ∈ [0 , 1] is a discount factor and the expectation is with respect to state-action trajectories obtained by using π ( a | s i , g ) .
If π ∗ is an optimal policy in the sense that Q π ∗ ( s, g, a ) ≥ Q π ( s, g, a ) for every π and ( s, g, a ) ∈ S ×G ×A , then Q π ∗ matches the optimal Q -function, Q ∗ , which obeys the Bellman equation:
[Equation]
In deep Q -learning (Mnih et al., 2015), Q ∗ is parameterized with a neural network and learning is achieved by enforcing the relationship from equation 1.
This is done by minimizing (cid:80)
i L ( Q ∗ ( s i , g i , a i ) , y i ) , where y i corresponds to the expectation in equation 1 and is estimated using a replay buffer of stored tuples ( s i , a i , g i , s (cid:48) i ) .
Note that s (cid:48)
i is the state the environment transitioned to after taking action a i from state s i , and determines the value of y i .
Typically
L is chosen as a squared error loss, and the dependency of y i on Q ∗ is ignored for backpropagation in order to stabilize training.
Once Q ∗ is learned, the optimal policy is recovered by
[Equation]
There is ample work extending and improving upon deep Q -learning (Haarnoja et al., 2018).
For example, Lillicrap et al.
(2015) extend it to the continuous action space setting, and Fujimoto et al.
(2018) further stabilize training.
These improvements are fully compatible with goal-reaching (Pong et al., 2019; Bharadhwaj et al., 2020a; Ghosh et al., 2019).
Andrychowicz et al.
(2017) proposed
Hindsight Experience Replay (HER), which relabels past experience as achieved goals, and allows sample efﬁcient learning from sparse rewards (Nachum et al., 2018).
C UMULATIVE ACCESSIBILITY FUNCTIONS
We now consider horizon-aware policies π : S × G × N → P ( A ) , and deﬁne the cumulative accessibility function C π ( s, a, g, h ) , or C -function, as the probability of reaching goal g from state s in at most h steps by taking action a and following the policy π thereafter.
By “following the policy π thereafter” we mean that after a , the next action a 1 is sampled from π ( ·| s 1 , g, h − 1) , a 2 is sampled from π ( ·| s 2 , g, h − 2) and so on.
See Figure 2 for a graphical model depiction of how these trajectories are obtained.
Importantly, an agent need not always act the same way at a particular state in order to reach a particular goal, thanks to horizon-awareness.
We use P π ( ·|· ,g,h ) ( ·| s
=
s, a 0 = a ) to denote probabilities in which actions are drawn in this manner and transitions are drawn according to the environment p
( s t +1 | s t , a ) .
More formally, C π is given by:
[Equation]
Proposition 1 : C π can be framed as a Q -function within the MDP formalism, and if π ∗ is optimal in the sense that C π ∗ ( s, a, g, h ) ≥ C π ( s, a, g, h ) for every π and ( s, a, g, h ) ∈ S
×
A × G × N , then
C π ∗ matches the optimal C -function, C ∗ , which obeys the following equation:
[Equation]
See appendix A for a detailed mathematical proof of this proposition.
The proof proceeds by ﬁrst deriving a recurrence relationship that holds for any C π .
In an analogous manner to the Bellman equation in Q -learning, this recurrence involves an expectation over π ( ·| s (cid:48) , g, h − 1) , which, when replaced by a max returns the recursion for C ∗ .
Proposition 1 is relevant as it allows us to learn C ∗ , enabling goal-reaching policies to be recovered:
[Equation]
C ∗ itself is useful for determining reachability.
After maximizing over actions, it estimates whether a given goal is reachable from a state within some horizon.
Comparing these probabilities for different horizons allows us to make a speed / reliability trade-off for reaching goals.
We observe that an optimal C ∗ -function is non-decreasing in h , but this does not necessarily hold for non-optimal C -functions.
For example, a horizon-aware policy could actively try to avoid the goal for high values of h , and the C π -function constructed from it would show lower probabilities of success for larger h .
See appendix A for a concrete example of this counter-intuitive behavior.
Proposition 2 : C ∗ is non-decreasing in h .
See appendix A for a detailed mathematical proof.
Intuitively, the proof consists of showing that an optimal policy can not exhibit the pathology mentioned above.
Given an optimal policy π ∗ ( a | s, g, h ) for a ﬁxed horizon h
we construct a policy ˜ π for h + 1 which always performs better, and lower bounds the performance of π ∗ ( a | s, g, h + 1) .
In addition to being an elegant theoretical property, proposition 2 suggests that there is additional structure in a C ∗ function which mitigates the added complexity from using horizon-aware policies.
Indeed, in our preliminary experiments we used a non-cumulative version of C -functions (see section 3.3) and obtained signiﬁcantly improved performance upon changing to C -functions.
Moreover, monotonicity in h could be encoded in the architecture of C ∗ (Sill, 1998; Wehenkel & Louppe, 2019).
However, we found that actively doing so hurt empirical performance (appendix F).
3. S HORTCOMINGS OF Q - LEARNING
Before describing our method for learning C ∗ , we highlight a shortcoming of Q -learning.
Consider a 2D navigation environment where an agent can move deterministically in the cardinal directions, and ﬁx s and g .
For an optimal action a ∗ , the optimal Q function will achieve some value Q ∗ ( s, g, a ∗ ) ∈ [0 , 1] in the sparse reward setting.
Taking a sub-optimal action a − initially results in the agent taking two extra steps to reach the intended goal, given that the agent acts optimally after the ﬁrst action, so that Q ∗ ( s, g, a − ) =
γ 2 Q ∗ ( s, g, a ∗ ) .
The value of γ is typically chosen close to 1 , for example 0 .
99 , to ensure that future rewards are not too heavily discounted.
As a consequence γ 2 ≈ 1 and thus the value of Q ∗ at the optimal action is very close to its value at a sub-optimal action.
We illustrate this issue in Figure 1b.
In this scenario, recovering an optimal policy requires that the error between the learned Q -function and Q ∗ should be at most (1 − γ 2 ) / 2 ; this is reﬂected empirically by Q -learning having high sample complexity and learning sub-optimal paths.
This shortcoming surfaces in any environment where taking a sub-optimal action results in a slightly longer path than an optimal one, as in e.g. motion planning tasks.
The C ∗ function does not have this shortcoming.
Consider the same 2D navigation example, and let h ∗ be the smallest horizon for which g can be reached from s .
h ∗ can be easily obtained from C ∗ as the smallest h such that max a C ∗ ( s, a, g, h ) = 1 .
Again, denoting a ∗ as an optimal action and a − as a sub-optimal one, we have that C ∗ ( s, a ∗ , g, h ∗ ) =
whereas C ∗ ( s, a − , g, h ∗ ) = 0 , which is illustrated in Figure 1b.
Therefore, the threshold for error is much higher when learning the C ∗ function.
This property results in fewer interactions with the environment needed to learn C ∗ and more efﬁcient solutions.
3. H ORIZON - INDEPENDENT POLICIES
Given a C ∗ -function, equation 4 lets us recover a horizon-aware policy.
At test time, using small values of h can achieve goals faster, while large values of h will result in safe policies.
However, a natural question arises: how small is small and how large is large?
In this section we develop a method to quantitatively recover reasonable values of h which adequately balance the speed/reliability tradeoff.
First, a safety threshold α ∈ (0 , 1] is chosen, which indicates the percentage of the maximum value of C ∗ we are willing to accept as safe enough.
Smaller values of α will thus result in quicker policies, while larger values will result in safer ones.
Then we consider a range of viable horizons, H , and ﬁnd the maximal C ∗ value, M ( s, g [Equation] =
[Equation]
h
[Equation]
,a ∈A C ∗ [Equation] s, a, g, h ) . We then compute:
[Equation]
and take π ∗ α ( a | s, g )
= 1 ( a = arg max a [Equation] C ∗
[Equation] s, [Equation] , g, h α ( s, g ))) .
This procedure also allows us to recover horizon-independent policies from C ∗ by using a ﬁxed value of α , which makes comparing against horizon-unaware methods straightforward.
We used horizon-unaware policies with added randomness as the behaviour policy when interacting with the environment for exploration.
3. A LTERNATIVE RECURSIONS
One could consider deﬁning a non-cumulative version of the C -function, which we call an Afunction for “accessibility” ( not for “advantage”), yielding the probability of reaching a goal in exactly h steps.
However, this version is more susceptible to pathological behaviors that hinder learning for certain environments.
For illustration, consider an agent that must move one step at a time in the cardinal directions on a checkerboard.
Starting on a dark square, the probability of reaching a light square in an even number of steps is always zero, but may be non-zero for odd numbers.
An optimal A -function would ﬂuctuate wildly as the step horizon h is increased, resulting in a harder target to learn.
Nonetheless, A -functions admit a similar recursion to equation 18, which we include in appendix C for completeness.
In any case, the C -function provides a notion of reachability which is more closely tied to related work (Savinov et al., 2018; Venkattaramanujam et al., 2019; Ghosh et al., 2018; Bharadhwaj et al., 2020a).
In Q -learning, discount factors close to 1 encourage safe policies, while discount factors close to 0 encourage fast policies.
One could then also consider discount-conditioned policies π ( a | s, g, γ ) as a way to achieve horizon-awareness.
In appendix D we introduce D -functions (for “discount”),
D ( s, a, g, γ ) , which allow recovery of discount-conditioned policies.
However D -functions suffer from the same limitation as Q -functions in that they need to be learned to a high degree of accuracy.
C UMULATIVE ACCESSIBILITY ESTIMATION
Our training algorithm, which we call cumulative accessibility estimation (CAE), or C -learning, is detailed in algorithm 1.
Similarly to Q -learning, the C ∗ function can be modelled as a neural network with parameters θ , denoted C ∗ θ , which can be learned by minimizing:
[Equation]
where y i corresponds to a stochastic estimate of the right hand side of equation 18.
The sum is over tuples ( s i , a i , s (cid:48)
i , g i , h i ) drawn from a replay buffer which we specially tailor to successfully learn
C ∗ .
Since C ∗ corresponds to a probability, we change the usual squared loss to be the binary cross entropy loss.
Note that even if the targets y i are not necessarily binary, the use of binary cross entropy is still justiﬁed as it is equivalent to minimizing the KL divergence between Bernoulli distributions with parameters
y i and C ∗
θ ( s i , a i , g i , h i )
(Bellemare et al., 2017).
Since the targets used do not correspond to the right-hand side of equation 18 but to a stochastic estimate (through s (cid:48) i ) of it, using this loss instead of the square loss results in an unbiased estimate of (cid:80) i
L ( C ∗ θ ( s i , a i , g i , h i ) , y true i ) , where y true i corresponds to the right-hand side of equation 18 at ( s i , a i , g i , h i ) (see appendix B for a detailed explanation).
This confers another beneﬁt of C -learning over Q -learning, as passing a stochastic estimate of equation 1 through the typical squared loss results in biased estimators.
As in Double Q -learning (Van Hasselt et al., 2015), we use a second network C ∗ θ (cid:48) to compute the y i targets, and do not minimize equation 6 with respect to θ (cid:48) .
We periodically update θ (cid:48) to match θ .
We now explain our algorithmic details.
Parameter: N explore : Number of random exploration episodes
Parameter: N GD : Number of goal-directed episodes
Parameter: N train : Number of batches to train on per goal-directed episode
Parameter: N copy : Number of batches between target network updates
Parameter: α : Learning rate 1 θ ← Initial weights for C ∗ θ 2 θ (cid:48) ← θ //
Copy weights to target network 3 D ← [] // Initialize experience replay buffer 4 n b ←// Counter for training batches 5 repeat N explore times E ← get rollout ( π random ) //
Do a random rollout
D . append ( E ) // Save the rollout to the buffer 8 repeat N GD times g ← goal sample ( n b ) //
Sample a goal
E ← get rollout ( π behavior ) //
Try to reach the goal
D . append ( E ) // Save the rollout {+repeat N train times if n b mod N copy = 
 then θ (cid:48) ← θ //+}
Copy weights periodically B := { s i , a i , s (cid:48)
i , g i , h i } |B| i =1 ← sample batch ( D ) //
Sample a batch { y i } |B| i =1 ← get targets ( B , θ (cid:48) ) //
Estimate RHS of equation ˆ L ← − 1 |B| (cid:80) |B| i = y i log C ∗
θ ( s i , a i , g i , h i )
+ (1 − y i ) log (1 − C ∗
θ ( s i , a i , g i , h i ))
θ ← θ − α ∇ θ ˆ L // Update weights n b ← n b +//
Trained one batch
Reachability-guided sampling : When sampling a batch (line 15 of algorithm 1), for each
i we ﬁrst sample an episode from D , and then a transition ( s i , a i , s (cid:48) i ) from that episode.
We sample h i favoring smaller h ’s at the beginning of training.
We achieve this by selecting h i
= h with probability proportional to h − κn GD /N GD , where n GD is the current episode number, N GD the total number of episodes, and κ is a hyperparameter.
For deterministic environments, we follow HER (Andrychowicz et al., 2017) and select g i uniformly at random from the states observed in the episode after s i . For stochastic environments we use a slightly modiﬁed version, which addresses the bias incurred by HER (Matthias et al., 2018) in the presence of stochasticity. All details are included in appendix G. Extension to continuous action spaces : Note that constructing the targets y i requires taking a maximum over the action space.
While this is straightforward in discrete action spaces, it is not so for continuous actions.
Lillicrap et al.
(2015) proposed DDPG, a method enabling deep Q -learning in continuous action spaces.
Similarly, Fujimoto et al.
(2018) proposed TD3, a method for further stabilizing Q -learning.
We note that C -learning is compatible with the ideas underpinning both of these methods.
We present a TD3 version of C -learning in appendix E.
We ﬁnish this section by highlighting differences between C -learning and related work.
Ghosh et al.
(2019) proposed GCSL, a method for goal-reaching inspired by supervised learning.
In their derivations, they also include a horizon h which their policies can depend on, but they drop this dependence in their experiments as they did not see a practical beneﬁt by including h .
We ﬁnd the opposite for C -learning.
TDMs (Pong et al., 2018) use horizon-aware policies and a similar recursion to ours.
In practice they use a negative L 1 distance reward, which signiﬁcantly differs from our goal-reaching indicators.
This is an important difference as TDMs operate under dense rewards, while we use sparse rewards, making the problem signiﬁcantly more challenging.
Additionally, distance between states in nonholonomic environments is very poorly described by L 1 distance, resulting in TDMs being ill-suited for motion planning tasks.
We also highlight that even if the reward in TDMs was swapped with our goal checking function G , the resulting objective would be much closer to the non-cumulative version of C -learning presented in appendix C. TDMs recover policies from their horizon-aware Q -function in a different manner to ours, not allowing a speed vs reliability trade-off.
The recursion presented for TDMs is used by deﬁnition, whereas we have provided a mathematical derivation of the Bellman equation for C -functions along with proofs of additional structure.
As a result of the C -function being a probability we use a different loss function (binary cross-entropy) which results in unbiased estimates of the objective’s gradients.
Finally, we point out that TDMs sample horizons uniformly at random, which differs from our speciﬁcally tailored replay buffer.
E XPERIMENTS 5. S ETUP
Our experiments are designed to show that ( i ) C -learning enables the speed vs reliability trade-off, ( ii ) the C ∗ function recovered through C -learning meaningfully matches reachability in nonholonomic environments, and ( iii ) C -learning scales to complex and high-dimensional motion planning tasks, resulting in improved sample complexity and goal-reaching.
We use success rate (percentage of trajectories which reach the goal) and path length (average, over trajectories and goals, number of steps needed to achieve the goal among successful trajectories) as metrics.
We compare C -learning against GCSL (Ghosh et al., 2019) (for discrete action states only) and deep Q -learning with HER (Andrychowicz et al., 2017) across several environments, which are depicted in Figure 3.
All experimental details and hyperparameters are given in appendix G. We also provide ablations, and comparisons against TDMs and the alternative recursions from section 3.3 in appendix F. We evaluate C -learning on the following domains:
Frozen lake is a 2D navigation environment where the agent must navigate without falling in the holes (dark blue).
Both the state space ( 7 × 5 grid, with two 3 × 1 holes) and the action state are discrete.
Falling in a hole terminates an episode.
The agent’s actions correspond to intended directions.
The agent moves in the intended direction with probability 0 . 8 , and in perpendicular directions with probabilities 0 . 1 each.
Moving against the boundaries of the environment has no effect.
We take G = S and G ( s, g )
= 1 ( g = s ) .
Dubins’ car is a more challenging deterministic 2D navigation environment, where the agent drives a car which cannot turn by more than 10 ◦ .
The states, with spatial coordinates in [0 , 15] 2 , are continuous and include the direction of the car.
There are 7 actions: the 6 combinations of { left 10 ◦ , straight , right 10 ◦ } × { forward 1 , reverse 1 } , and the option to not move.
As such, the set of reachable states is not simply a ball around the current state.
The environment also has walls through which the car cannot drive.
We take G =
[0 , 15] 2 and the goal is considered to be reached when the car is within an L ∞ distance of 0 .
5 from the goal, regardless of its orientation.
FetchPickAndPlace-v1 (Brockman et al., 2016) is a complex, higher-dimensional environment in which a robotic arm needs to pick up a block and move it to the goal location.
Goals are deﬁned by their 3-dimensional coordinates.
The state space is 25 -dimensional, and the action space is continuous and 4 -dimensional.
HandManipulatePenFull-v0 (Brockman et al., 2016) is a realistic environment known the be a difﬁcult goal-reaching problem, where deep Q-learning with HER shows very limited success (Plappert et al., 2018).
The environment has a continuous action space of dimension 20 , a 63 -dimensional state space, and 7 -dimensional goals.
Note that we are considering the more challenging version of the environment where both target location and orientation are chosen randomly. [Figure]
5. R ESULTS
Speed vs reliability trade-off : We use frozen lake to illustrate this trade-off.
At test time, we set the starting state and goal as shown in Figure 4a.
Notice that, given enough time, an agent can reach the goal with near certainty by going around the holes on the right side of the lake.
However, if the agent is time-constrained, the optimal policy must accept the risk of falling in a hole.
We see that C -learning does indeed learn both the risky and safe policies.
Other methods, as previously explained, can only learn one.
To avoid re-plotting the environment for every horizon, we have plotted arrows in Figure 4a corresponding to arg max a π ∗ ( a | s 0 , g, h ) , arg max a π ∗ ( a | s 1 , g, h − 1) , arg max a π ∗ ( a | s 2 , g, h − 2) and so on, where s t +1 is obtained from the previous state and action while ignoring the randomness in the environment (i.e. s t +1 =
arg max s p ( s | s t , a t ) ).
In other words, we are plotting the most likely trajectory of the agent.
When given the minimal amount of time to reach the goal ( h = 6 ), the CAE agent learns correctly to accept the risk of falling in a hole by taking the direct path.
When given four times as long ( h = 24 ), the agent takes a safer path by going around the hole.
Notice that the agent makes a single mistake at the upper right corner, which is quickly corrected when the value of h is decreased.
On the other hand, we can see on the bottom panel that both GCSL and HER recover a single policy, thus not enabling the speed vs reliability trade-off.
Surprisingly, GCSL learns to take the high-risk path, despite Ghosh et al.
(2019)’s intention to incentivize paths that are guaranteed to reach the goal.
Reachability learning : To demonstrate that we are adequately learning reachability, we removed the walls from Dubins’ car and further restricted the turning angles to 5 ◦ , thus making the dumbbell shape of the true reachable region more extreme.
In Figure 4b, we show that our learned C ∗ function correctly learns which goals are reachable from which states for different time horizons in Dubins’ car: not only is the learned C ∗ function increasing in h , but the shapes are as expected.
None of the competing alternatives recover this information in any way, and thus comparisons are not available.
As previously mentioned, the optimal C ∗ -function in this task is not trivial.
Reachability is deﬁned by the “geodesics” in S =
[0 , 15] 2 × S 1 that are constrained by the ﬁnite turning radius, and thus follow a more intricate structure than a ball in R 2 . [Table]
Motion planning and goal-reaching : For a qualitative comparison of performance for goalreaching, Figure 4c shows trajectories for C -learning and competing alternatives for Dubins’ car.
We can see that C -learning ﬁnds the optimal route, which is a combination of forward and backward movement, while other methods ﬁnd inefﬁcient paths.
We also evaluated our method on challenging goal reaching environments, and observed that C -learning achieves state-of-the-art results both in sample complexity and success rate.
Figure 4d shows that C -learning is able to learn considerably faster in the FetchPickAndPlace-v1 environment.
More importantly, C -learning achieves an absolute 20% improvement in its success rate over the current state-of-the-art algorithm HER (TD3) in the HandManipulatePenFull-v0 environment.
Quantitative results are shown in Table 1.
On Dubins’ car, we also note that C -learning ends up with a smaller ﬁnal L ∞ distance to the goal: 0 .
93 ± 0 .vs.
28 ± 0 .
51 for GCSL.
D ISCUSSION
We have shown that C -learning enables simultaneous learning of how to reach goals quickly and how to reach them safely, which current methods cannot do.
We point out that reaching the goal safely in our setting means doing so at test time, and is different to what is usually considered in the safety literature where safe exploration is desired (Chow et al., 2018; Bharadhwaj et al., 2020b).
Additionally, learning C ∗ effectively learns reachability within an environment, and could thus naturally lends itself to incorporation into other frameworks, for example, in goal setting for hierarchical RL tasks (Nachum et al., 2018) where intermediate, reachable goals need to be selected sequentially.
We believe further investigations on using C -functions on safety-critical environments requiring adaptation (Peng et al., 2018; Zhang et al., 2020), or for hierarchical RL, are promising directions for further research.
We have also argued that C -functions are more tolerant of errors during learning than Q -functions which increases sample efﬁciency.
This is veriﬁed empirically in that C -learning is able to solve goal-reaching tasks earlier on in training than Q -learning.
We ﬁnish by noticing a parallel between C -learning and the options framework (Sutton et al., 1999;
Bacon et al., 2017), which introduces temporal abstraction and allows agents to not always follow the same policy when at a given state s .
However, our work does not ﬁt within this framework, as options evolve stochastically and new options are selected according only to the current state, while horizons evolve deterministically and depend on the previous horizon only, not the state.
Additionally, and unlike C -learning, nothing encourages different options to learn safe or quick policies, and there is no reachability information contained in options.
C ONCLUSIONS
In this paper we introduced C -learning, a Q -learning-inspired method for goal-reaching.
Unlike previous approaches, we propose the use of horizon-aware policies, and show that not only can these policies be tuned to reach the goal faster or more reliably, but they also outperform horizonunaware approaches for goal-reaching on complex motion planning tasks.
We hope our method will inspire further research into horizon-aware policies and their beneﬁts.
A P ROOFS OF PROPOSITIONS
Proposition 1 : C π can be framed as a Q -function within the MDP formalism, and if π ∗ is optimal in the sense that C π ∗ ( s, a, g, h ) ≥ C π ( s, a, g, h ) for every π and ( s, a, g, h ) ∈ S
×
A × G × N , then
C π ∗ matches the optimal C -function, C ∗ , which obeys the following equation:
[Equation]
Proof : First, we frame C -functions within the MDP formalism.
Consider a state space given by
S (cid:48)
=
S × G × N , where states corresponding to reached goals (i.e. G ( s, g ) = 1 ) or with last coordinate equal to 0 (i.e. h = 0 ) are considered terminal.
The dynamics in this environment are given by:
[Equation]
That is, states evolve according to the original dynamics, while goals remain unchanged and horizons decrease by one at every step.
The initial distribution is given by:
[Equation]
where p ( s 0 ) corresponds to the original starting distribution and p ( g 0 , h 0 | s 0 ) needs to be speciﬁed beforehand.
Together, the initial distribution and the dynamics, along with a policy π ( a | s, g, h ) properly deﬁne a distribution over trajectories, and again, we use P π ( ·|· ,g,h ) to denote probabilities with respect to this distribution.
The reward function r : S (cid:48)
×
A → R is given by:
[Equation]
By taking the discount factor to be 1 , and since we take states for which G ( s, g ) = 1 to be terminal, the return (sum of rewards) over a trajectory ( s 0 , s 1 , . . . )
with h
= h is given by:
[Equation]
For notational simplicity we take G ( s t , g ) =
whenever t is greater than the length of the trajectory to properly account for terminal states.
Since the return is binary, its expectation matches its probability of being equal to 1 , so that indeed, the Q -functions in this MDP correspond to C π :
[Equation]
Now, we derive the Bellman equation for our C -functions.
Trivially:
[Equation]
whenever G ( s, g ) = 1 or h = 0 .
For the rest of the derivation, we assume that G ( s, g ) =
and h ≥ 1 .
We note that the probability of reaching g from s in at most h steps is given by the probability of reaching it in exactly one step, plus the probability of not reaching it in the ﬁrst step and reaching it in at most h − 1 steps thereafter.
Formally:
[Equation] [Equation]
where the last equality follows from the fact that C π ( s (cid:48) , a (cid:48) , g, h − 1)
=
whenever G ( s (cid:48) , g )
= 1 .
Putting everything together
[Equation]
we obtain the Bellman equation for C π :
[Equation]
otherwise .
Recall that the optimal policy is deﬁned by the fact that C ∗ ≥ C π for any arguments and for any policy π .
We can by maximizing equation 13 that, given the C ∗ ( · , · , · , h − 1) values, the optimal policy values at horizon h − 1 must be π ∗ ( a | s, g, h − 1) = 1 ( a = arg max a (cid:48)
C ∗ ( s, a, g, h − 1)) .
We thus we obtain:
[Equation]
if G ( s, g ) = [-
-]0 and h ≥ 1 ,
G
[Equation]
s, g
[Equation]
otherwise .
Note that, as in Q -learning, the Bellman equation for the optimal policy has been obtained by replacing the expectation with respect to a (cid:48) with a max .
Proposition 2 : C ∗ is non-decreasing in h .
As mentioned in the main manuscript, one might naively think that this monotonicity property should hold for C π for any π .
However this is not quite the case, as π depends on h and a perverse policy may actively avoid the goal for large values of h .
Restricting to optimal C ∗ -functions, such pathologies are avoided.
As an example, consider an environment with three states, { 0 , 1 , 2 } , and two actions {− 1 , +1 } .
The transition rule is s t +1 = max(0 , min(2 , s t + a t )) , that is, the agent moves deterministically in the direction of the action unless doing so would move it out of the domain.
Goals are deﬁned as states.
Let π be such that π ( a | s = 1 , g = 2 , h = 1) =
1 ( a = 1) and π ( a | s = 1 , g = 2 , h = 2)
= 1 ( a = − 1) .
While clearly a terrible policy, π is such that
C π ( s = 0 , a = 1 , g = 2 , h = 2) =
1 and C π ( s = 0 , a = 1 , g = 2 , h = 3) = 0 , so that C π can decrease with h .
Proof : Fix a distribution p on the action space.
For any policy π ( a | s, g, h ) , we deﬁne a new policy ˜ π as:
[Equation]
The new policy ˜ π acts the same as π for the ﬁrst h steps and on the last step it samples an action from the ﬁxed distribution p .
The ﬁnal step can only increase the cumulative probability of reaching the goal, therefore:
[Equation]
Since equation 15 holds for all policies π , taking the maximum over policies gives:
[Equation]
B U NBIASEDNESS OF THE CROSS ENTROPY LOSS
For given s i , a i , g i and h i from the replay buffer, we denote the right-hand side of equation 2 as y truei :
[Equation]
Note that y truei cannot be evaluated exactly, as the expectation over s (cid:48) would require knowledge of the environment dynamics to compute in closed form.
However, using s (cid:48)
i , the next state after s i in the replay buffer, we can obtain a single-sample Monte Carlo estimate of y truei , y i as:
[Equation]
otherwise .
[Equation]
Clearly y i is an unbiased estimate of y truei .
However, the optimization objective is given by:
[Equation]
where the sum is over tuples in the replay buffer and L is the loss being used.
Simply replacing y truei with its estimate y i , while commonly done in Q -learning, will in general result in a biased estimate of the loss:
[Equation]
since in general the expectation of a function need not match the function of the expectation.
In other words, pulling the expectation with respect to s (cid:48)
i outside of the loss will in general incur in bias.
However, if L is linear in its second argument, as is the case with binary cross entropy but not with the squared loss, then one indeed recovers:
[Equation]
so that replacing y truei with y i does indeed recover an unbiased estimate of the loss.
C N ON - CUMULATIVE CASE
We originally considered a non-cumulative version of the C -function, giving the probability of reaching the goal in exactly h steps.
We call this function the accessibility function, A π (despite our notation, this is unrelated to the commonly used advantage function), deﬁned by:
[Equation]
Here the trivial case is only when h = 0 , where we have:
[Equation]
[Equation]
If h ≥ 1 , we can obtain a similar recursion to that of the C -functions.
Here we no longer assume that states which reach the goal are terminal.
The probability of reaching the goal in exactly h steps is equal to the probability of reaching it in h − 1 steps after taking the ﬁrst step.
After the ﬁrst action a , subsequent actions are sampled from the policy π :
[Equation] [Equation]
By the same argument we employed in proposition [Equation] the recursion for the optimal A -function, A ∗ , is obtained by replacing the expectation with respect to a (cid:48) with max .
Putting this together with the base case, we have:
[Equation]
Note that this recursion is extremely similar to that of C ∗ , and differs only in the base cases for the recursion.
The difference is empirically relevant however for the two reasons that make C ∗ easier to learn: C ∗ is monotonic in h , and the cumulative probability is more well-behaved generally.
D D ISCOUNTED CASE
Another approach which would allow a test-time trade-off between speed and reliability is to learn the following D -function ( D standing for “discounted accessibility”).
[Equation]
26) where the random variable T is the smallest positive number such that G ( s T , g ) = 1 .
If no such state occurs during an episode then γ T − 1 is interpreted as zero.
This is the discounted future return of an environment in which satisfying the goal returns a reward of 1 and terminates the episode.
We may derive a recursion relation for this formalism too
[Equation]
By the same argument as employed for the C and A functions
[Equation]
the D -function of the optimal policy is obtained by replacing the expectation over actions with a max , giving
[Equation] [Equation]
Learning such a D -function would allow a test time trade-off between speed and reliability [Equation] and might well be more efﬁcient than training independent models for different values of γ .
We did not pursue this experimentally for two reasons.
Firstly, our initial motivation was to allow some higher-level operator (either human or a controlling program) to trade off speed for reliability, and a hard horizon is usually more interpretable than a discounting factor.
Secondly, we noticed that
C -learning performs strongly at goal-reaching in deterministic environments, and we attribute this to the hard horizon allowing the optimal policy to be executed even with signiﬁcant errors in the
C -value.
Conversely, Q -learning can typically only tolerate small errors before the actions selected become sub-optimal.
D -learning would suffer from the same issue.
E C ONTINUOUS ACTION SPACE CASE
As mentioned in the main manuscript, C -learning is compatible with the ideas that underpin DDPG and TD3 (Lillicrap et al., 2015; Fujimoto et al., 2018), allowing it to be used in continuous action spaces.
This requires the introduction of another neural network approximating a deterministic policy, µ φ : S ×G × N
→ A , which is intended to return µ ( s, g, h ) =
arg max a C ∗ ( s, a, g, h ) .
This network is trained alongside C ∗ θ as detailed in Algorithm 2.
We do point out that the procedure to obtain a horizon-agnostic policy, and thus π behavior , is also modiﬁed from the discrete version.
Here, M ( s, g ) = max h ∈H C ∗ ( s, µ ( s, g, h ) , g, h ) , and:
[Equation]
s
[Equation]
s [Equation] 29) where we now take π ∗ γ ( a | s, g ) as a point mass at µ ( s, g, h γ ( s, g )) .
F A DDITIONAL EXPERIMENTS
In this section we study the performance of C -learning across different types of goals.
We ﬁrst evaluate C -learning for the Mini maze and Dubins’ car environments, and partition their goal space into easy, medium and hard as shown in Figure 5.
We run experiments for 3 (Mini maze) or(Dubins’ car) choices of random seed and take the average for each metric and goal stratiﬁcation, plus/minus the standard deviation across runs. The Mini maze results are shown in Table 2. We see that C -learning beats GCSL on success rate, although only marginally, with the bulk of the improvement observed on the reaching of hard goals. Both methods handily beat HER on success rate, and note that the path length results in the HER section are unreliable because very few runs reach the goal.
The Dubins’ car results are shown in Table 3.
We see that C -learning is the clear winner here across the board, with GCSL achieving a somewhat close success rate, and HER ending up with paths which are almost as efﬁcient. Note that this result is the quantitative counterpart to the qualitative trajectory visualizations from Figure 4c. As mentioned in the main manuscript, we also tried explicitly enforcing monotonicity of our C -functions using the method of Sill (1998), but we obtained success rates below 50% in Dubins’ car when doing so. We also compare C -learning to naive horizon-aware Q -learning, where instead of sampling h as in C -learning, where consider it as part of the state space and thus sample it along the state in the replay buffer.
Results are shown in the left panel of Figure 6.
We can see that our sampling of h achieves the same performance in roughly half the time.
Additionally, we compare against sampling h uniformly in the right panel of Figure 6, and observe similar results. Parameter: N explore : Number of random exploration episodes Parameter: N GD : Number of goal-directed episodes Parameter: N train : Number of batches to train on per goal-directed episode
Parameter: N copy : Number of batches between target network updates
Parameter: α : Learning rate 1 θ 1 , θ
[Table]
← Initial weights for C
[Table] 1 , C [Table] 2 θ (cid:48) 1 , θ (cid:48) 2 ← θ 1 , θ// Copy weights to target network 3 φ ← Initial weights for µ φ 4 D ← [] // Initialize experience replay buffer 5 n b ←// Counter for training batches 6 repeat N explore times
E ← get rollout ( π random ) //
Do a random rollout
D .
append ( E ) //
Save the rollout to the buffer 9 repeat N GD times g ← goal sample ( n b ) //
Sample a goal
E ← get rollout ( π behavior ) //
Try to reach the goal
D .
append ( E ) //
Save the rollout repeat N train times
B := { s i , a i , s (cid:48)
i , g i , h i } |B| i =1 ← sample batch ( D ) //
Sample a batch { y i } |B| i =1 ← get targets ( B , θ (cid:48) ) //
Estimate RHS of equation
[Table] [Figure]
// Update weights
[Figure]
// Update weights [Figure]
if n b mod policy delay = 0 then
[Figure]
// Update actor weight
[Figure]
// Update target networks
[Figure]
// Trained one batch
[Table]
[Table]
We also compare C -learning against TDMs Pong et al.
(2018) for motion planning tasks.
Results are in Figure 7.
As mentioned in the main manuscript, TDMs assume a dense reward function, which C -learning does not have access to.
In spite of this, C -learning signiﬁcantly outperforms TDMs.
Finally, we also compare against the non-cumulative version of C -learning ( A -learning), and the discount-based recursion ( D -learning) in Dubins’ car. For D -learning, we selected γ uniformly at random in [0 , 1] . Results are shown in table 4. We can see that indeed, C -learning outperforms both alternatives.
Curiously, while underperformant, A -learning and D -learning seem to obtain shorter paths among successful trials.
G E XPERIMENTAL DETAILS
C-learning for stochastic environments : As mentioned in the main manuscript, we modify the replay buffer in order to avoid the bias incurred by HER sampling (Matthias et al., 2018) in nondeterministic environments.
We sample goals independently from the chosen episode.
We sample g i to be a potentially reachable goal from s i in h i steps.
For example, if given access to a distance d between states and goals such that the distance can be decreased at most by 1 unit after a single step, we sample g i from the set of g ’s such that d ( s i , g ) ≤ h i .
Moreover, when constructing y i (line 16 of algorithm 1), if we know for a fact that g i cannot be reached from s (cid:48)
i in h
i − 1 steps, we output 0 instead of max a (cid:48)
C ∗ θ (cid:48)
( s (cid:48)
i , a (cid:48) , g i , h i − 1) .
For example, d ( s (cid:48)
i , g i ) >
h i − 1 allows us to set y i = 0 .
We found this practice, combined with the sampling of g i described above, to signiﬁcantly improve performance.
While this requires some knowledge of the environment, for example a metric over states, this knowledge is often available in many environments.
For frozen lake, we use the L 1 metric to determine if a goal is not reachable from a state, while ignoring the holes in the environment so as to not use too much information about the environment. [Table]
G. F ROZEN LAKE
For all methods
[Table] we train for 300 episodes, each one of maximal length 50 steps, we use a learning rate 10 − 3 , a batch size of size [Table] and train for 64 gradient steps per episode.
We use a 0 .
1 -greedy for the behavior policy.
We use a neural network with two hidden layers of respective sizes 60 and 40 with ReLU activations.
We use 15 fully random exploration episodes before we start training.
We take p ( s 0 ) as uniform among non-hole states during training [Table] and set it as a point mass at (1 , 0) for testing.
We set p ( g ) as uniform among states during training [Table] and we evaluate at every goal during testing.
For C -learning, we use κ = 3 , and copy the target network every 10 steps.
We take the metric d to be the L 1 norm, completely ignoring the holes so as to not use too much environment information.
For the horizon-independent policy, we used H = { 1 , 2 , . . .
, 50 } and α = 0 .
We do point out that, while C -learning did manage to recover the safe path for large h , it did not do always do so: we suspect that the policy of going directly up is more likely to be explored.
However, we never observed GCSL taking the safe path.
G. M INI MAZE
We again train for 3000 episodes, now of maximal length 200 .
We train 32 gradient steps per episode, and additionally decay the exploration noise of the C -learning behavior policy throughout training according to (cid:15) = 0 .
5 / (1 + n GD / 1000) .
The network we used has two hidden layers of size 200 and 100 with ReLU activations, respectively.
While the environment is deterministic, we use the same replay buffer as for frozen lake, and take the metric d to be the L 1 norm, completely ignoring walls.
We found this helped improve performance and allowed C -learning to still learn to reach far away goals.
We also deﬁne H ( s, g ) :
= {(cid:107) s − g (cid:107) 1 , (cid:107) s − g (cid:107)
+ 1 , . .
, h max } , with h max := 50 , as the set of horizons over which we will check when rolling out the policies.
We take p ( s 0 ) as a point mass both for training and testing.
We use p ( g ) during training as speciﬁed in Algorithm 1, and evaluate all the methods on a ﬁxed set of goals.
Additionally, we lower the learning rate by a factor of 10 after 2000 episodes.
All the other hyperparameters are as in frozen lake.
Figure 5 shows the split between easy, medium, and hard goals.
G. D UBINS ’ CAR
We train for 4500 episodes, each one with a maximal length of 100 steps and using 80 gradient steps per episode.
We use a neural network with two hidden layers of respective sizes 400 and 300 with
ReLU activations.
We take the metric d to be the L ∞ norm, completely ignoring walls, which we only use to decide whether or not we have reached the goal.
We take p ( s 0 ) as a point mass both for training and testing.
We use p ( g ) during training as speciﬁed in Algorithm 1, and evaluate all the methods on a ﬁxed set of goals.
All other hyperparameters are as in frozen lake.
The partition of goals into easy, medium and hard is speciﬁed in Figure 5, where the agent always starts at the upper left corner.
G. F ETCH P ICK A ND P LACE - V
We train with a learning rate of 0.0001 and batch size of 256.
We take 64 gradient steps per episode, and only update φ with half the frequency of θ .
We use 40000 episodes for FetchPickAndPlace-v1.
All the other hyperparameters are as in Dubins’ car.
G. H AND M ANIPULATE P EN F ULL - V
We train with a learning rate of 0.0001 and batch size of 256.
We take 80 gradient steps per episode, and only update φ with half the frequency of θ .
We use 60000 episodes for HandManipulatePenFullv0.
All the other hyperparameters are as in Dubins’ car.