Medicine Computer Science
Computer Science-2021.gz:143474
Computer Science
dcb6fa098b20efd1e6a9f40fc34ffff1d2bba889
Complex Robotic Manipulation via Graph-Based Hindsight Goal Generation

Reinforcement learning algorithms such as hindsight experience replay (HER) and hindsight goal generation (HGG) have been able to solve challenging robotic manipulation tasks in multi-goal settings with sparse rewards. HER achieves its training success through hindsight replays of past experience with heuristic goals, but under-performs in challenging tasks in which goals are difficult to explore. HGG enhances HER by selecting intermediate goals that are easy to achieve in the short term and promising to lead to target goals in the long term. This guided exploration makes HGG applicable to tasks in which target goals are far away from the object's initial position. However, HGG is not applicable to manipulation tasks with obstacles because the euclidean metric used for HGG is not an accurate distance metric in such environments. In this paper, we propose graph-based hindsight goal generation (G-HGG), an extension of HGG selecting hindsight goals based on shortest distances in an obstacle-avoiding graph, which is a discrete representation of the environment. We evaluated G-HGG on four challenging manipulation tasks with obstacles, where significant enhancements in both sample efficiency and overall success rate are shown over HGG and HER. Videos can be viewed at https://sites.google.com/view/demos-g-hgg/.


Introduction
In recent years, deep reinforcement learning (RL) has made significant progress, with RL concepts being successfully applied to decision-making problems in robotics, which include, but not limited to, helicopter control [19], hitting a baseball [22], door opening [5], screwing a cap onto a bottle [17], and object manipulation [1]. To train a meaningful policy for such tasks, neural networks are used as function approximators for learning a value function to optimize a long-term expected return. Estimation of the expected return is based on a reward function, which is highly associated with the tasks and therefore must be thoroughly shaped for policy optimization.
In most real-world applications, where a concrete representation of efficient or even admissible behavior is unknown, the design of a reward function is challenging and time-consuming, thereby hindering the wide applications of RL. Consequently, algorithms that can support learning from sparse rewards are highly desirable, e.g., a binary signal indicating successful task completion; since sparse rewards are easy to derive from the task definition without further engineering. Andrychowicz et al. [1] introduced an algorithm called " hindsight experience replay (HER)", which improves the success of off-policy RL algorithms in multi-goal RL problems with sparse rewards. The concept behind HER is to first learn with hand-crafted heuristic intermediate goals that are easy to achieve, and then continue with more difficult goals. Precisely, HER constructs hindsight goals from previously achieved states, replays known trajectories with these hindsight goals, and trains the goal-dependent value function based on the results. While HER has proven to work efficiently in environments where goals can be easily reached through random explorations [23], it fails to reach goals that are far away from initial states and hard to reach. Due to random exploration and the heuristic choice of hindsight goals from achieved states, hindsight goals keep being distributed around the initial state, far away from the target goals, which will never be reached since no reward signal is obtained.
Hindsight goal generation (HGG) [24] tackles the aforementioned problem by using intermediate hindsight goals as an implicit curriculum to guide exploration towards target goals. HGG aims at choosing hindsight goals that are both easy to achieve and challenging enough to help the function approximator learn how to achieve the target goals eventually. In HGG, the choice of hindsight goals is based on two criteria: the current value function (as much knowledge as possible about how to reach the hindsight goals) and the Wasserstein distance between the target goal distribution and the distribution of potential hindsight goals (goals as close as possible to the target goal distribution). The resulting Wasserstein-Barycenter problem is discretely solved using the euclidean distance metric between two goals sampled from the potential hindsight goal distribution and the target goal distribution. While HGG demonstrates higher sample efficiency than HER in environments where the euclidean metric is applicable, it fails in environments with obstacles, where the shortest obstacle-avoiding distance between two goals cannot be computed with the euclidean metric.
In this paper, we introduce graph-based hindsight goal generation (G-HGG), an extension of HGG, designed for sparse-reward RL in robotic object manipulation environments with obstacles. To make G-HGG applicable to environments with obstacles, the euclidean metric is replaced by a graph-based distance metric: the environment's goal space is represented by a graph consisting of discrete goals as vertices and obstacle-avoiding connections between the vertices as edges. The distance between two goals are then approximated by the shortest path on the graph between the two vertices that are closest to the two goals. For verification, we evaluated G-HGG on four different challenging object manipulation environments. With the graph-based distance metric, a significant enhancement in both sample efficiency and overall success rate is demonstrated over HGG and HER. Ablation studies in the appendix (See supplementary material) show the robustness of G-HGG in terms of discretization density.

Background
Goal-Conditioned RL In goal-conditioned RL, an agent interacts with its environment to reach some goals, which can be modeled as a goal-conditioned Markov decision process (MDP) with a state space S, an action space A, a goal space G, a probabilistic transition function P : S × A → S, a reward function r g : S × A → R, and a discount factor γ. At every time step t, the agent's behavior a t is defined by a probabilistic policy π(s t ||g), given by the current state s t and the goal g (we use || as a symbol for concatenation into S × G). The task is to find an optimal policy that can maximize the expected curriculum reward starting from the initial state sampled from the initial state distribution s ∈ S 0 , which is defined as Hindsight goal generation HGG [24] is an extension of HER [1] to scenarios in which the target goal distribution differs a lot from the initial state distribution. HGG can be briefly explained as follows. A value function of a policy π for a specific goal g is assumed to have some generalizability to another goal g ′ close to g [2,18]. This assumption is mathematically characterized via Lipschitz continuity as where d(s||g, s ′ ||g ′ ) is a metric defined by d((s||g), (s ′ ||g ′ )) = c||m(s) − m(s ′ )|| 2 + ||g − g ′ || 2 .
Γ(T (1) , T (2) ) denotes the collection of all joint distributions µ(s 0 ||g (2) ), the marginal probabilities of which are T (1) and T (2) . With T * denoting the joint distribution over initial state s 0 and goal g, the agent tries to find a policy π maximizing the expectation of the discounted cumulative reward based on the state value function defined in (1): From (4), it can be derived that optimizing this expected cumulative reward defined in (6) can be relaxed into the surrogate problem of finding Joint optimization of π and T (7) is solved in a two-stage iterative algorithm. First, standard policy optimization maximizes the value function V π based on experience generated from the intermediate task set T . Second, the intermediate task set T is optimized while the policy π is kept constant. The second step is a variant of the Wasserstein Barycenter problem with the value function as a bias term for each initial state-goal pair, which can be solved as a bipartite matching problem [8].
For this to work, T * is approximated by by K initial state-goal pairs sampled from it, resulting in The Lipschitz constant L is treated as a hyper-parameter. These K trajectories τ i minimize the sum Finally, from each of the K selected trajectories τ i , the hindsight goal g i is selected from the state s i t ∈ τ i , that minimized (8). More formally, Combined with the idea of HER [1] and replacing (s 0 , g) with (ŝ i 0 , g i ), the generated hindsight transition (s t ||g, a t , r t , s t+1 ||g) can be then stored in the replay buffer for training the policy. To this end, HGG is able to generate a curriculum of meaningful hindsight goals rather than hand-crafted heuristic goals from HER, guiding exploration towards target goals.

Methodology
Problem Statement: In this paper, we focus on solving robotic object manipulation tasks with sparse rewards, where the goal is to move an object to a certain point in 3D space with a robotic gripper arm. Even though the general principle of HGG is applicable, there is one major limitation. Solving the Wasserstein Barycenter problem in HGG consists of the computation of the distance between a goal g ∈ G and the goal representation m(s) of state s ∈ S. However, in 3D space with obstacles, the euclidean metric used in HGG is generally not applicable. To illustrate this point, we consider an example, where the goal is to pick up an object with a robotic arm, lift it over an obstacle (blue box), and place it at the target goal. Let us consider two cases: A (Figures 1a and  1c) and B (Figures 1b and 1d), where goals g 1 and g 2 are marked in green. In Figures 1a and 1b, the euclidean metric calculates the distance, d euc = ||g 2 − g 1 ||, which is marked with red lines. If the task is completed in an environment without obstacles, this is an accurate distance metric, and the task can be solved using HGG. In environments with obstacles, however, the object cannot go through these obstacles, which means the euclidean metric is not a suitable distance metric. Then, a suitable shortest-path based distance measure similar to the ones in Figures 1c and 1d is required in such a scenario.
The problem of finding the shortest path between two points without intersecting an obstacle is known as the euclidean shortest path problem. In this paper, we propose an algorithm called graphbased hindsight goal generation (G-HGG), in which approximate shortest distances from discrete points in 3D space are pre-computed and used to compare distances between potential hindsight goals.

G-HGG
G-HGG is an extension of HGG to environments with obstacles, where the euclidean metric is not applicable as a distance metric. Hence, we reformulate (8) and (10), replacing the euclidean metric with the graph-based distance metric d G .
With the new formulation, for every (ŝ i 0 ,ĝ i ) ∈T * , we can find a trajectory from the replay buffer where all these variables have the same meanings as in (8). Altogether, these K trajectories τ i minimize the sum Finally, from each of the K selected trajectories τ i , the hindsight goal g i is selected from the state s i t ∈ τ i , that minimizes (11): The distance metric d G is based on shortest paths in a graph with a discrete representation of the goal space as vertices. The computation of shortest path distances is done pre-training and consists of creating a graph representing the environment and pre-computing shortest distances among vertices.

Graph Construction
Let us consider an unbounded goal space G with an infinite number of goals; let us further define a continuous but bounded subset of the goal space, the accessible goal space G A ⊂ G. G A contains all potential goals that the object can reach. We then establish a representation of the accessible goal space G A with an undirected graph. A graph G = (P, E) consists of a set of vertices P with a set of weighted edges E, and an assigned weight w.
where p 1 and p 2 are two possible vertices. In environments with obstacles, goals g obs ∈ G lying within an obstacle that are blocked from being reached are not elements of the accessible goal space g obs / ∈ G A . Since G A is bounded, it can be enclosed in a parallelepipedic bounding box defined by values x min , x max , y min , y max , z min , z max ∈ R, describing the span of this box in each coordinate direction. We then use this box to generate a finite set of verticesP spatially arranged as an orthorhombic lattice.P is defined by the total number of vertices n = n x · n y · n z , with n x , n y , n z ∈ N in each coordinate direction of G A , or alternatively by the distance between two adjacent grid-points in each coordinate direction given by Finally, we define the set of vertices as P =P ∩ G A , wherê A set of vertices in a demo environment with an obstacle is illustrated in Figure 2a, G A is defined as the cuboid space marked by the blue balls, in which the obstacle is depicted by the blue box. n x = n y = n z = 4. All the vertices are evenly distributed in G A and no one lies inside the obstacle.    As a next step, we connect two adjacent vertices p 1 = (x 1 ,ŷ 1 ,ẑ 1 ) ∈ P, p 2 = (x 2 ,ŷ 2 ,ẑ 2 ) ∈ P with an edge of weight w considering the following: with w := (x 2 −x 1 ) 2 + (ŷ 2 −ŷ 1 ) 2 + ·(ẑ 2 −ẑ 1 ) 2 .  In environments with obstacles, it is important to make sure that no edge in the graph cuts through an obstacle. It should be noted that, for convex obstacles, we simply replace them with a minimal axis-aligned cuboid that can enclose the obstacle. We then remove this cuboid from G A ; for a nonconvex obstacle, we decompose it into several convex obstacles and then replace each of them with Algorithm 1 Graph-Based Hindsight Goal Generation (G-HGG) 1: Given: off-policy algorithm A, sampling strategy S, reward function r g : S × A → R 2: Construct a graph G = (V, E) as a discrete representation of G ⊲ section 3.1 3: Pre-compute shortest distancesd G between every pair of vertices (p 1 , p 2 ) ∈ P 2 with Dijkstra 4: Initialize A and replay buffer R 5: for iteration do 6: (13) ⊲ based on d G ≈d G 7: for episode = 1, M do 8: hindsight goal-oriented exploration 9: for t = 0, T − 1 do 10: Sample an action a t using the policy from A with noise: a t ← π(s t ||g) + N t

11:
Execute the action a t and observe a new state s t+1

12:
for t = 0, T − 1 do 13: r t := r g (s t , a t ); Store transition (s t ||g, a t , r t , s t+1 ||g) in R; ⊲ experience replay 14: Sample a set of additional goals for replay G := S(current episode) 15: for g ′ ∈ G do 16: r ′ := r g ′ (s t , a t ); Store the transition (s t ||g ′ , a t , r ′ , s t+1 ||g ′ ) in R; ⊲ HER 17: for t = 1, N do 18: Sample a minibatch B from the replay buffer R ⊲ HER or EBP 19: Perform one step of optimization using A and minibatch B using DDPG a minimal axis-aligned cuboid that can enclose the convex obstacle. Consequently, we require every convex sub-obstacle to be detected by at least one potential vertex v ∈P but v / ∈ G A . Let us define the space of one of the cuboid with its edges α, β, γ. Thus, the graph must satisfy the graph density criterion (18) for every convex sub-obstacle, i.e., continuous set goals not included in G A : ∆ x < α obs min ; ∆ y < β obs min ; ∆ z < γ obs min , where α obs min , β obs min , γ obs min ∈ R, describing the infimum length of edges of all the convex sub-obstacle. When vertices are connected according to (17), every vertex is connected to at most 26 adjacent vertices (as illustrated in Figure 2b). However, an edge only exists as long as the adjacent vertex is contained in G A , thus, in case of an environment with obstacles, there is never an edge cutting through an obstacle as long as the graph density criterion (18) is satisfied. Figure 2c illustrates the final graph consisting of edges and vertices in our demo environment.
Shorted Distance Computation Considering the created graph that represents the environment, we can employ a shortest path algorithm such as Dijkstra's algorithm [7] to calculate shortest paths and shortest distancesd G between every possible pair of vertices (p 1 , p 2 ) = ((x 1 ,ŷ 1 ,ẑ 1 ), (x 2 ,ŷ 2 ,ẑ 2 )) ∈ P 2 in a graph G = (P, E). All possible combinations of the resulting shortest distance functiond G can be efficiently pre-computed with Dijkstra and stored in an n × n table, where n denotes the number of vertices in P . An ablation study of n can be found in the Appendix ??.
Given two goals g 1 = (x 1 , y 1 , z 1 ) ∈ G, g 2 = (x 2 , y 2 , z 2 ) ∈ G and a graph G = (P, E) with representing the approximate goal space G A ⊂ G with x min , x max , y min , y max , z min , z max , ∆ x , ∆ y , and ∆ z , the graph-based distance d : G 2 → R is defined such that where ν : G A → P maps goals in G A to the closest vertex in P : ⌊a⌉ rounds any a ∈ R to the closest integer value. Figure 3 illustrates a visualization of graph-based goal distance computation between goals g 1 ∈ G A , g 2 ∈ G A . In both Cases A (Figure 3a) and B (Figure 3b), both goals are contained in the accessible goal space G A . Therefore, the graph-based distance is approximated by the shortest distance between the two vertices ν(g 1 ) and ν(g 2 ) that are closest to the goals g 1 and g 2 , respectively. Mathematically, d(g 1 , g 2 ) =d G (ν(g 1 ), ν(g 2 )).

Algorithm and Stop Condition:
The overall G-HGG algorithm is provided as Algorithm 1. The main differences between HGG and G-HGG are in steps 2,3 and 6.
Step 2 (graph construction) and step 3 (shortest distance computation) are performed pre-training. The pre-computed table of shortest distancesd G is used in step 6. G-HGG guides exploration by hindsight goals. This is especially useful at the beginning of training, where hindsight goals are far from the target goals G T . When training progresses and a certain fraction δ stop ∈ [0, 1] of the hindsight goal candidates are very close to sampled target goals, stopping HGG and continuing with vanilla HER will lead to faster learning and higher success rates. Because of the page limit, we include the ablation study on δ stop in Appendix ??.

Experiments
To demonstrate the advantages of G-HGG over HGG and vanilla HER, we create new experimental environments based on the standard robotic manipulation environments from OpenAI Gym [23].
• FetchPushLabyrinth (Figure 4a): the goal is to push the cube from its initial position around the blue obstacles (labyrinth) to a target goal. The gripper remains permanently closed. • FetchPickObstacle (Figure 4b): the goal is to pick up the cube from its initial position, lift it over the obstacle, and place it at a target goal position. Gripper control is enabled. • FetchPickNoObstacle (Figure 4c): the goal is to pick up the cube from its initial position, lift it up, and place it at a target goal position. No obstacle is present in this scenario, but the target goals are located in the air. Gripper control is enabled. • FetchPickAndThrow (Figure 4d): the goal is to pick up the cube from its initial position, lift it up, and throw it into one of the eight boxes (obstacles). Gripper control is enabled. Robotic manipulation environments. We tested G-HGG on the four environments to compare its performance to HGG and HER. Since we know from [32] and [24] that energy-based prioritization (EBP) [32] significantly enhances the performance of both HER and HGG, we used EBP in all our trainings of HER, HGG, and G-HGG. The results clearly show that G-HGG outperforms HGG by far in environments with obstacles, both in terms of sample efficiency and maximum success rate. In the environment without obstacles, the performance of G-HGG was still comparable to HGG in terms of sample efficiency and maximum success rate. distance metric used in G-HGG leads to a choice of hindsight goals guiding the agent around the obstacle towards the target goals , HGG repeatedly uses goals that are closest to the target goals with respect to the euclidean metric. Since this euclidean metric based shortest path is blocked by an obstacle, the agent gets stuck trying to reach the hindsight goals (pushing the object against the obstacle), never achieving more promising goals, and thus, never reaching the target goals.
In the FetchPickObstacle environment, G-HGG outperforms HGG in terms of sample efficiency, due to graph-based distances supporting goals that avoid the obstacle. Since the euclidean distance metric is at least partly (in x and y direction) valid, HGG eventually achieves a notable success rate as well. However, the plots show that there is a large variance within the HGG trainings, emphasizing the disadvantage of random exploration in HGG with non-meaningful hindsight goals over guided exploration in G-HGG. Vanilla HER cannot solve the task.
FetchPickNoObstacle is an environment where G-HGG has no advantage over HGG. As no obstacle is present, the euclidean metric is applicable to compare distances, allowing HGG to perform well.
Since the euclidean metric used in HGG is more exact than the graph-based distances in G-HGG, it is not surprising that HGG yields slightly better training results. However, the similarity of the curves shows that G-HGG's performance is comparable to HGG in terms of sample efficiency and success rate even in environments without obstacles. Overall, we assume that G-HGG is generally applicable to all environments where HGG yields good training results. HER still fails to reach the target goals. FetchPickAndThrow is a difficult task, since target goals are not uniformly sampled from a continuous target goal distribution, but from a discrete set of eight goals. G-HGG yields better results than HGG in terms of success rate after 600 iterations and is clearly more sample efficient. Both HGG and G-HGG cannot achieve success rates above 60% due to the difficulty of the task, involving picking the object, lifting it up, and dropping it while giving it a well-dosed push in the desired direction.
Since the final policy trained to achieve the task results from guided, but still random exploration, it is no surprise that the agent cannot develop a perfect throwing motion from sparse rewards.

Related Work
Informative and effective explorations are essential for solving goal-conditioned RL tasks with sparse rewards. An amount of research has emerged and we briefly discuss them from three main ideas.
Prioritized Experience Replay One major drawback of HER has been its inefficient random replay of experience. Research has shown that prioritized sampling of transitions from the replay buffer significantly increases sample efficiency. Prioritized sampling can be based on the TD-error [27], reward-weighted entropy [31], transition energy [32], and density of achieved goals [33]. Curriculum Learning Another way to tackle the exploration problem in sparse-reward multi-goal RL is curriculum learning (CL) [25], which presents problems in a favorable order, the so-called curriculum. One CL approach to improve exploration is augmenting the sparse learning problem with basic, easy-to-learn auxiliary tasks [25,9]. In the absence of extrinsic motivation due to the sparsity of external rewards, intrinsic motivation can be used to create a curriculum for improved exploration [28,20,14,21,30,6,3]. Another way of constructing a meaningful curriculum is to predict high-reward states and generate goals close to these meaningful states [16,12,13,11]. Representation Learning [4] is a promising framework to solve goal-conditioned RL tasks, in which representative abstractions are interpreted from high-dimensional observations to lowdimensional latent states. With the representations as a planner, model-free RL algorithms are able to perform control tasks. Some work showed that learned representations can be used to solve navigation and goal-reaching tasks for mobile agents. Robotic manipulations tasks were implemented but limited to 2D space because most representations were learned from images [29,15,10].

Conclusion
We proposed a novel automatic hindsight goal generation algorithm G-HGG on the basis of the HGG for robotic object manipulation in environments with obstacles, by which the selection of valuable hindsight goals is generated with a graph-based distance metric. We formulated our solution as a graph construction and shortest distance computation process as pre-training steps. Experiments on four different challenging object manipulation tasks demonstrated superior performance of G-HGG over HGG and HER in terms of both maximum success rate and sample efficiency. Future research could concentrate on improvement, extension, and real-world deployment of G-HGG.
Broader Impact