Action Guidance: Getting the Best of Sparse Rewards and Shaped Rewards for Real-time Strategy Games

Training agents using Reinforcement Learning with sparse rewards is often difficult ( Pathak et al. , 2017 ) . First , due to the sparsity of the reward , the agent often spends the majority of the training time doing inefficient exploration and sometimes not even reaching the first sparse reward during the entirety of its training . Second , even if the agents have successfully retrieved some sparse rewards , performing proper credit assignment is challenging among complex sequences of actions that have led to theses sparse rewards . Reward shaping ( Ng et al. , 1999 ) is a widely-used technique designed to mitigate this problem . It works by providing intermediate rewards that lead the agent towards the sparse rewards , which are the true objective . For example , the sparse reward for a game of Chess is naturally +1 for winning , -1 for losing , and 0 for drawing , while a possible shaped reward might be +1 for every enemy piece the agent takes . One of the critical drawbacks for reward shaping is that the agent sometimes learns to optimize for the shaped reward instead of the real objective . Using the Chess example , the agent might learn to take as many enemy pieces as possible while still losing the game . A good shaped reward achieves a nice balance between letting the agent find the sparse reward and being too shaped ( so the agent learns to just maximize the shaped reward ) , but this balance can be difficult to find . In this paper , we present a novel technique called action guidance that successfully trains the agent to eventually optimize over sparse rewards while maintaining most of the sample efficiency that comes with reward shaping . It works by constructing a main policy that only learns from the sparse reward function RM and some auxiliary policies that learn from the shaped reward function RA1 , RA2 , . . . , RAn . During training , we use the same rollouts to train the main and auxiliary policies and initially set a high-probability of the main policy to take action guidance from the auxiliary policies , that is , the main policy will execute actions sampled from the auxiliary policies . Then the main policy and auxiliary policies are updated via off-policy policy gradient . As the training goes on , the main policy will get more independent and execute more actions sampled from its own policy . Auxiliary policies learn from shaped rewards and therefore make the training sampleefficient , while the main policy learns from the original sparse reward and therefore makes sure that the agents will eventually optimize over the true objective . We can see action guidance as combining reward shaping to train auxiliary policies interlieaved with a sort of imitation learning to guide the main policy from these auxiliary policies . We examine action guidance in the context of a real-time strategy ( RTS ) game simulator called µRTS for three sparse rewards tasks of varying difficulty . For each task , we compare the performance of training agents with the sparse reward function RM , a shaped reward function RA1 , and action guidance with a singular auxiliary policy learning from RA1 . The main highlights are : Action guidance is sample-efficient . Since the auxiliary policy learns from RA1 and the main policy takes action guidance from the auxiliary policy during the initial stage of training , the main policy is more likely to discover the first sparse reward more quickly and learn more efficiently . Empirically , action guidance reaches almost the same level of sample efficiency as reward shaping in all of the three tasks tested . The true objective is being optimized . During the course of training , the main policy has never seen the shaped rewards . This ensures that the main policy , which is the agent we are really interested in , is always optimizing against the true objective and is less biased by the shaped rewards . As an example , Figure 1 shows that the main policy trained with action guidance eventually learns to win the game as fast as possible , even though it has only learned from the match outcome reward ( +1 for winning , -1 for losing , and 0 for drawing ) . In contrast , the agents trained with reward shaping learn more diverse sets of behaviors which result in high shaped reward . To support further research in this field , we make our source code available at GitHub1 , as well as all the metrics , logs , and recorded videos2 . 1 RELATED WORK . In this section , we briefly summarize the popular techniques proposed to address the challenge of sparse rewards . Reward Shaping . Reward shaping is a common technique where the human designer uses domain knowledge to define additional intermediate rewards for the agents . Ng et al . ( 1999 ) show that a slightly more restricted form of state-based reward shaping has better theoretical properties for preserving the optimal policy . Transfer and Curriculum Learning . Sometimes learning the target tasks with sparse rewards is too challenging , and it is more preferable to learn some easier tasks first . Transfer learning leverages this idea and trains agents with some easier source tasks and then later transfer the knowledge through value function ( Taylor et al. , 2007 ) or reward shaping ( Svetlik et al. , 2017 ) . Curriculum learning further extends transfer learning by automatically designing and choosing a full sequences of source tasks ( i.e . a curriculum ) ( Narvekar & Stone , 2018 ) . Imitation Learning . Alternatively , it is possible to directly provide examples of human demonstration or expert replay for the agents to mimic via Behavior Cloning ( BC ) ( Bain & Sammut , 1995 ) , which uses supervised learning to learn a policy given the state-action pairs from expert replays . Alternatively , Inverse Reinforcement Learning ( IRL ) ( Abbeel & Ng , 2004 ) recovers a reward function from expert demonstrations to be used to train agents . Curiosity-driven Learning . Curiosity driven learning seeks to design intrinsic reward functions ( Burda et al. , 2019 ) using metrics such as prediction errors ( Houthooft et al. , 2016 ) and “ visit counts ” ( Bellemare et al. , 2016 ; Lopes et al. , 2012 ) . These intrinsic rewards encourage the agents to explore unseen states . Goal-oriented Learning . In certain tasks , it is possible to describe a goal state and use it in conjunction with the current state as input ( Schaul et al. , 2015 ) . Hindsight experience replay ( HER ) ( Andrychowicz et al. , 2017 ) develops better utilization of existing data in experience replay by replaying each episode with different goals . HER is shown to be an effective technique in sparse rewards tasks . Hierarchical Reinforcement Learning ( HRL ) . If the target task is difficult to learn directly , it is also possible to hierarchically structure the task using experts ’ knowledge and train hierarchical agents , which generally involves a main policy that learns abstract goals , time , and actions , as well as auxiliary policies that learn primitive actions and specific goals ( Dietterich , 2000 ) . HRL is especially popular in RTS games with combinatorial action spaces ( Pang et al. , 2019 ; Ye et al. , 2020 ) . The most closely related work is perhaps Scheduled Auxiliary Control ( SAC-X ) ( Riedmiller et al. , 2018 ) , which is an HRL algorithm that trains auxiliary policies to perform primitive actions with 1https : //github.com/anonymous-research-code/action-guidance 2Blinded for peer review shaped rewards and a main policy to schedule the use of auxiliary policies with sparse rewards . However , our approach differs in the treatment of the main policy . Instead of learning to schedule auxiliary policies , our main policy learns to act in the entire action space by taking action guidance from the auxiliary policies . There are two intuitive benefits to our approach since our main policy learns in the full action space . First , during policy evaluation our main policy does not have to commit to a particular auxiliary policy to perform actions for a fixed number of time steps like it is usually done in SAC-X . Second , learning in the full action space means the main policy will less likely suffer from the definition of hand-crafted sub-tasks , which could be incomplete or biased . 2 BACKGROUND . We consider the Reinforcement Learning problem in a Markov Decision Process ( MDP ) denoted as ( S , A , P , ρ0 , r , γ , T ) , where S is the state space , A is the discrete action space , P : S×A×S → [ 0 , 1 ] is the state transition probability , ρ0 : S → [ 0 , 1 ] is the the initial state distribution , r : S × A→ R is the reward function , γ is the discount factor , and T is the maximum episode length . A stochastic policy πθ : S ×A→ [ 0 , 1 ] , parameterized by a parameter vector θ , assigns a probability value to an action given a state . The goal is to maximize the expected discounted return of the policy : Eτ [ T−1∑ t=0 γtrt ] , where τ is the trajectory ( s0 , a0 , r0 , s1 , . . . , sT−1 , aT−1 , rT−1 ) and s0 ∼ ρ0 , st ∼ P ( ·|st−1 , at−1 ) , at ∼ πθ ( ·|st ) , rt = r ( st , at ) Policy Gradient Algorithms . The core idea behind policy gradient algorithms is to obtain the policy gradient ∇θJ of the expected discounted return with respect to the policy parameter θ . Doing gradient ascent θ = θ + ∇θJ therefore maximizes the expected discounted reward . Earlier work proposes the following policy gradient estimate to the objective J ( Sutton & Barto , 2018 ) : gpolicy , θ = Eτ∼πθ [ T−1∑ t=0 ∇θ log πθ ( at|st ) Gt ] , where Gt = ∑∞ k=0 γ krt+k denotes the discounted return following time t. This gradient estimate , however , suffers from large variance ( Sutton & Barto , 2018 ) and the following gradient estimate is suggested instead : gpolicy , θ = Eτ [ ∇θ T−1∑ t=0 log πθ ( at|st ) A ( τ , V , t ) ] , where A ( τ , V , t ) is the General Advantage Estimation ( GAE ) ( Schulman et al. , 2015 ) , which measures “ how good is at compared to the usual actions ” , and V : S → R is the state-value function . 3 ACTION GUIDANCE . The key idea behind action guidance is to create a main policy that trains on the sparse rewards , and creating some auxiliary policies that are trained on shaped rewards . During the initial stages of training , the main policy has a high probability to take action guidance from the auxiliary policies , that is , the main policy can execute actions sampled from the auxiliary policies , rather than from its own policy . As the training goes on , this probability decreases , and the main policy executes more actions sampled from its own policy . During training , the main and auxiliary policies are updated via off-policy policy gradient . Our use of auxiliary policies makes the training sample-efficient , and our use of the main policy , who only sees its own sparse reward , makes sure that the agent will eventually optimize over the true objective of sparse rewards . In a way , action guidance can be seen as training agents using shaped rewards , while having the main policy learn by imitating from them . Specifically , let us defineM as the MDP that the main policy learns from andA = { A1 , A2 , ... , Ak } be a set of auxiliary MDPs that the auxiliary policies learn from . In our constructions , M and A share the same state , observation , and action space . However , the reward function forM is RM , which is the sparse reward function , and reward functions for A are RA1 , ... , RAk , which are the shaped reward functions . For each of these MDPs E ∈ S = { M } ∪A above , let us initialize a policy πθE parameterized by parameters θE , respectively . Furthermore , let us use πS = { πθE |E ∈ S } to denote the set of these initialized policies . At each timestep t , let us use some exploration strategy S that selects a policy πb ∈ πS to sample an action at given st. At the end of the episode , each policy πθ ∈ πS can be updated via its off-policy policy gradient ( Degris et al. , 2012 ; Levine et al. , 2020 ) : Eτ∼πθb [ ( T−1∏ t=0 πθ ( at|st ) πθb ( at|st ) ) T−1∑ t=0 ∇θ log πθ ( at|st ) A ( τ , V , t ) ] ( 1 ) When πθ = πθb , the gradient in Equation 1 means on-policy policy gradient update for πθ . Otherwise , the objective means off-policy policy gradient update for πθ .

Summary: The paper introduces an approach for learning policies across multiple MDPs and using those policies to improve learning performance on the task that the agent designer cares about. The approach assumes that a set of MDPs are provided to the learning agent, and that all of the MDPs have the same underlying task but with different reward densities (i.e., some of these MDPs have shaped rewards, and thus are faster to learn from). The approach operates by training the main agent to imitate the actions chosen by the other agents that are trained on the MDPs with shaped reward functions.