B AYESIAN E XPLORATION FOR L IFELONG R EINFORCEMENT L EARNING
Anonymous authors
Paper under double-blind review
A BSTRACT
A central question in reinforcement learning (RL) is how to leverage prior knowledge to accelerate learning in new tasks.
We propose a Bayesian exploration method for lifelong reinforcement learning (BLRL) that aims to learn a Bayesian posterior that distills the common structure shared across different tasks.
We further derive a sample complexity analysis of BLRL in the ﬁnite MDP setting.
To scale our approach, we propose a variational Bayesian Lifelong Learning (VBLRL) algorithm that is based on Bayesian neural networks, can be combined with recent model-based RL methods and exhibits backward transfer.
Experimental results on three challenging domains show that our algorithms adapt to new tasks faster than state-of-the-art lifelong RL methods.
I NTRODUCTION
Reinforcement-learning (RL) methods (Sutton & Barto, 1998;
Kaelbling et al., 1996) have been successfully applied to solve challenging individual tasks such as learning robotic control (Duan et al., 2016) and playing expert-level Go (Silver et al., 2017).
However, in the real world, a robot usually experiences a collection of distinct tasks that arrive sequentially throughout its operational lifetime; learning each new task from scratch is infeasible, but treating them all as a single task will fail.
Therefore, recent research has focused on algorithms that enable agents to learn across multiple, sequentially posed tasks, leveraging past knowledge from previous tasks to accelerate the learning of new tasks.
This problem setting is known as lifelong reinforcement learning (Brunskill & Li, 2014;
Wilson et al., 2007b; Isele et al., 2016b).
The key questions in lifelong RL research are: How can an algorithm exploit knowledge gained from past tasks to improve performance in new tasks (forward transfer), and how can data from new tasks help the agent to perform better on previously learned tasks (backward transfer)?
To answer these two questions, ﬁrst consider a simple problem, which is to ﬁnd different items in different houses.
Here, a single task corresponds to ﬁnding items in a speciﬁc house.
Although items may be stored in different locations in different houses, there still exists some shared information that connects all houses.
For instance, a toothbrush is more likely to be found in a bathroom than a kitchen, and a room without a window is more likely to be a bathroom than a living room.
Such information can signiﬁcantly accelerate the search for items in newly encountered houses.
We propose that extracting the common structure existing in previously encountered tasks can help the agent quickly learn the dynamics of the new tasks.
Speciﬁcally, this paper considers lifelong RL problems that can be modeled as hidden-parameter MDPs or HiP-MDPs (Doshi-Velez & Konidaris, 2016;
Killian et al., 2017), where variations among the true task dynamics can be described by a set of hidden parameters.
We model two main categories of learning across multiple tasks: the world-model distribution, which describes the probability distribution over tasks, and the task-speciﬁc model, that deﬁnes the (stochastic) dynamics within a single task.
To enable more accurate sequential knowledge transfer, we separate the learning process for these two quantities and maintain a hierarchical Bayesian posterior to approximate them.
The world-model posterior is designed to manage the uncertainty in the world-model distribution, while the task-speciﬁc posterior handles the uncertainty from the data collected from only the current task.
We propose a Bayesian exploration method for lifelong RL (BLRL) that learns a Bayesian worldmodel posterior that distills the common structure of previous tasks, and then uses it as a prior to learn a task-speciﬁc model in each subsequent task.
For the discrete case, we derive an explicit performance bound that shows that the task-speciﬁc model requires fewer samples to become accurate as the world-model posterior approaches the true underlying world-model distribution.
We further develop VBLRL, a more scalable version of BLRL that uses variational inference to approximate the world-model distribution and leverages Bayesian Neural Networks (BNNs) to build the hierarchical
Bayesian posterior.
Our experimental results on a set of challenging domains show that our algorithms achieve better forward and backward transfer performance than state-of-the-art lifelong RL algorithms within limited samples for each task.
B ACKGROUND
RL is the problem of maximizing the long-term expected reward of an agent interacting with an environment (Sutton & Barto, 1998).
We usually model the environment as a Markov Decision
Process or MDP (Puterman, 1994), described by a ﬁve tuple: (cid:104) S, A, R, T, γ (cid:105) , where S is a ﬁnite set of states; A is a ﬁnite set of actions; R : S × A (cid:55)→ [0 , 1] is a reward function, with a lower and upper bound 0 and 1 ; T : S × A (cid:55)→
Pr( S ) is a transition function, with T ( s (cid:48) | s, a ) denoting the probability of arriving in state s (cid:48) ∈ S after executing action a ∈ A in state s ; and γ ∈ [0 , 1) is a discount factor, expressing the agent’s preference for delayed over immediate rewards.
An MDP is a suitable model for the task facing a single agent.
In the lifelong RL setting, the agent instead faces a series of tasks τ 1 , ..., τ n , each of which can be modeled as an MDP: (cid:104) S ( i ) , A ( i ) , R ( i ) , T ( i ) , γ ( i ) (cid:105) .
A key question is how these task MDPs are related; we model the collection of tasks as a HiP-MDP (Doshi-Velez & Konidaris, 2016; Killian et al., 2017), where a family of tasks is generated by varying a latent task parameter ω drawn for each task according to the world-model distribution P Ω .
Each setting of ω speciﬁes a unique MDP, but the agent neither observes ω nor has access to the function that generates the task family.
Formally, then, the dynamics
T ( s (cid:48) | s, a ; ω i ) and reward function R ( r | s, a ; ω i ) for task i depend on ω i ∈ Ω , which is ﬁxed for the duration of the task.
For lifelong RL problems, the performance of a speciﬁc algorithm is usually evaluated based on both forward transfer and backward transfer results (Lopez-Paz & Ranzato, 2017):
• Forward transfer : the inﬂuence that learning task t has on the
performance in future
task k
(cid:31)
t
• Backward transfer : the inﬂuence that
learning
task t has on
the performance in earlier
tasks k ≺ t
B AYESIAN EXPLORATION FOR L IFELONG R EINFORCEMENT L EARNING
[Figure]
for the BLRL approach.
τ j denotes trajectory { s, a, r, s (cid:48) } j .
There are K different tasks and the agent samples R trajectories from each task.
The key component of our approach is a hierarchical Bayesian posterior over task MDPs controlled by the hidden parameter ω .
Intuitively, we maintain probability distributions that separately capture two categories of uncertainty within lifelong learning tasks: the world-model posterior captures the epistemic uncertainty of the world-model distribution over different tasks controlled by the hidden parameter.
As the learner is exposed to more and more tasks, this posterior should converge to the world-model distribution
P Ω .
The task-speciﬁc posterior captures the epistemic uncertainty of the current task m .
As the learner is exposed to more and more transitions within the task, this posterior should approach m , leaving only the aleatoric uncertainty of transitions within the task, which is independent of other tasks.
By sampling from the worldmodel posterior, an agent can learn new tasks faster by exploiting knowledge common to previous tasks, thus exhibiting positive forward transfer.
We ﬁrst consider the ﬁnite MDP setting.
Concretely, we use a hierarchical Bayesian model to represent the distribution over MDPs.
Figure 1 shows our generative model in plate notation.
Ψ is the parameter set that represents distribution P Ω .
It functions as the world-model posterior that aims to capture the common structure across different tasks.
The resulting MDP m i is created based on ω i , which is one hidden parameter sampled from Ψ .
We can sample from our approximation of Ψ to create and solve possible MDPs.
The proposed BLRL approach is formalized in Algorithm 3 in the appendix.
Initially, before any
MDPs are experienced, the world-model posterior q e ( ·| s t , a t ) is initialized to an uniformed prior.
For each new task m i , we ﬁrst initialize the task-speciﬁc posterior q m i θ ( ·| s t , a t ) with the parameter values from the current world-model posterior, and then, for each timestep, select actions using a Bayesian exploration algorithm based on sampling from this posterior (Thompson, 1933; Asmuth et al., 2009).
A set of sampled MDPs drawn from q m i θ is a concrete representation of the uncertainty within the current task.
BLRL samples K models from the task-speciﬁc posterior whenever the number of transitions from a state–action pair has reached threshold B .
Analogously to RMAX (Brafman &
Tennenholtz, 2003) and BOSS (Asmuth et al., 2009), we call a state–action pair known whenever it has been observed N s t ,a t = B times.
For each state–action pair, if it is known , we use the taskspeciﬁc posterior to sample the model.
If it is unknown , we instead sample from the world-model posterior.
These models are combined into a merged MDP m # i and BLRL solves m # i to get a policy π ∗ m # i .
This approach is adopted from BOSS (best of sampled set) to create optimism in the face of uncertainty, and thereby drive exploration.
The new policy π ∗ m # i will be used to interact with the environment until a new state–action pair reaches the sampling threshold.
The collected transitions from this task will be used to update the task-speciﬁc posterior immediately, while the world-model posterior will be updated using transitions from all the previous tasks at a slower pace.
For simple ﬁnite MDP problems in practice, we use the Dirichlet distribution (the conjugate for the multinomial) to represent the Bayesian posterior.
Thus, the updating process for the posterior is straightforward to compute.
Intuitively, BLRL is able to rapidly adapt to new tasks as long as the prior of the task-speciﬁc model (that is, the world-model posterior) is close to the true underlying model and captures the uncertainty of the common structure of a set of tasks.
3. S AMPLE C OMPLEXITY A NALYSIS
We now provide a simple theoretical analysis of BLRL.
First, we use the setting and results of Zhang (2006) to describe the properties of the Bayesian prior and how it relates to the sample complexity for the concentration of the Bayesian posterior.
Lemma 1.
Let π ( ω ) denote the prior distribution on the parameter space Γ .
We consider a set of transition-probability densities p ( ·| ω ) indexed by ω , and the true underlying density q .
Deﬁne the prior-mass radius of the transition-probability densities as:
[Equation]
Intuitively, this quantity measures the distance between the Bayesian prior we use to initialize the posterior and the true underlying distribution.
Then, ∀ ρ ∈ (0 , 1) and η ≥ 1 , let
[Equation]
where ε upper,n is the critical upper-bracketing radius (Zhang, 2006).
The decay rate of ε upper,n controls the consistency of the Bayesian posterior distribution (Asmuth et al., 2009).
Let ρ = 12 , we have for all t ≥ 0 and δ ∈ (0 , 1) , with probability at least 1 − δ ,
[Equation]
Proof (sketch).
The proof is similar to that of Corollary 5.2 of Zhang (2006)
(see Appendix A.5).
Instead of using the critical prior-mass radius ε π,n to describe certain characteristics of the Bayesian prior, we deﬁne and use the prior-mass radius d π , which is independent of the sample size n and measures the distance between the prior and true distribution.
Similar to BOSS, for a new MDP m ∼ M with hidden parameters ω m , we can deﬁne the Bayesian concentration sample complexity for the task-speciﬁc posterior: f ( s, a, (cid:15) 0 , δ 0 , ρ 0 ) , as the minimum number c such that, if c IID transitions from ( s, a ) are observed, then, with probability at least 1 − δ 0 ,
[Equation]
Lemma 2.
Assume the posterior is consistent (that is, ε upper,n = o (1) ) and set η = 2 , then the Bayesian concentration sample complexity for the task-speciﬁc posterior f ( s, a, (cid:15), δ, ρ ) =
O (cid:16) d π +ln 1 ρ (cid:15) 2 δ − d π (cid:17) .
Proof (sketch).
This bound can be derived by directly combining Lemma 1 and Equation 4.
The above lemma suggests an upper bound of the Bayesian concentration sample complexity using the prior-mass radius.
We can further combine this result with PAC-MDP theory (Strehl et al., 2006) and derive the sample complexity of the algorithm for each new task.
Theorem 1.
For each new task, set the sample size
K =
Θ( S 2 Aδ ln SAδ ) and the parameters (cid:15)
= (cid:15) (1 − γ ) 2 , δ
=
δSA , ρ 0 = δ S
A 2 K , then, with probability at least 1 − 4 δ , V A t ( s t ) ≥ V ∗ ( s t ) − 4 (cid:15)in all but ˜
O
( S 2 A 2 d π δ(cid:15) 3 (1 − γ ) 6 ) steps, where ˜ O ( · ) suppresses logarithmic dependence.
Proof (sketch).
The proof is based on the PAC-MDP theorem (Strehl et al., 2009) combined with the new bound for the Bayesian concentration sample complexity we derived in Lemma 2.
In general, we use the same process in BOSS to verify the three required properties of PAC-MDP: optimism, accuracy and learning complexity.
For each new task, the main difference between BLRL and BOSS is that we use the world-model posterior to initialize the task-speciﬁc posterior, which results in a new sample complexity bound based on the prior-mass radius.
The result formalizes the intuition that, if we put a larger prior mass at a density that is close to the true q such that d π is small, the sample complexity of our algorithm will be lower.
In the meantime, the sample complexity is bounded by polynomial functions of the relevant quantities, showing that our training strategy preserves the properties required by PAC-MDP algorithms (Strehl et al., 2009).
S CALING U P : V ARIATIONAL B AYESIAN L IFELONG RL
Directly computing the exact posterior is typically not possible for large scale problems.
Instead, we propose a practical approximate algorithm, VBLRL, that uses neural networks and variational inference (Hinton & van Camp, 1993a).
We model the posterior via the transition dynamics using p ( s t +1 , r t | s t , a t ; θ ) , θ ∈ Θ .
The posterior, given a new state–action pair, can be rewritten via Bayes’ rule:
[Equation]
where D t is the agent’s history with all the experienced tasks up until time step t .
As representing the posterior p ( θ | D ) is intractable, we approximate it through an alternative distribution q ( θ ; φ ) by minimizing D KL [ q ( θ ; φ ) ||
p ( θ | D )] , leveraging variational lower bounds (Hinton & van Camp, 1993b;
Houthooft et al., 2016).
We choose Bayesian neural networks (BNN) to approximate the posterior.
The intuition is that, in the context of stochastic outputs, BNNs naturally approximate the hierarchical Bayesian model since they also maintain a learnable distribution over their weights and biases (Graves, 2011; Houthooft et al., 2016).
We expect the uncertainty embedded in the weights and biases of networks can capture the epistemic uncertainty introduced by hidden parameters of different tasks, while we also set the outputs of the neural networks to be stochastic to capture the aleatoric uncertainty within each speciﬁc task.
In our case, the BNN weights and biases distribution q ( θ ; φ ) can be modeled as fully factorized
Gaussian distributions (Blundell et al., 2015):
[Equation]
where φ = { µ, σ } , and µ is the Gaussian’s mean vector while σ is the covariance matrix diagonal.
Then, the posterior distribution over the model parameters can be computed through:
[Equation]
where p ( θ ) represents the ﬁxed prior distribution of θ .
The second term on the right hand side can be approximated through 1 N (cid:80) Ni =1 log p ( s t +1 , r t | D t , a t ; θ i ) with N samples from θ i ∼ q ( φ ) .
This optimization can be performed in parallel for each s , keeping φ t − 1 ﬁxed.
[Equation]
⋯ ⋯ ⋯ 𝜇𝜇 𝑑
[Equation]
⋮ ⋮ ⋮ ⋮ 𝑺
[Equation]
⋯ ⋯ ⋯
[Equation]
𝜎
[Equation]
⋮
[Equation]
⋮ ⋮ [Equation] [Figure] We provide the intuition of how our design capture the uncertainties of lifelong RL in Figure 2 and summarize the method in Algorithm 1.
The left side of the ﬁgure shows the process of how transitions are generated from the environment’s true distribution, while the other parts show how our models generate transition predictions and how they separately estimate different uncertainties generating from approximating the true underlying distribution.
We employ our posterior knowledge models in the context of a model-based RL method.
When encountering a new task, VBLRL ﬁrst uses the model parameters (that is, { µ, σ } of weights and biases of BNN) from the general knowledge model to initialize the task-speciﬁc posterior network.
The task-speciﬁc model outputs the predicted next state and reward given a state–action pair.
Then, we use model-predictive control (Garcia et al., 1989) to select actions based on the generated transitions.
For planning, at each step, we begin by creating P particles from the current state s pτ =
t =
s t ∀ p .
Then we sample N candidate action sequences a t : t + T from a learnable distribution.
We propagate the state-action pairs using the learned task-speciﬁc model p
m i ( ·| s, a ) (BNN) and use the cross entropy method (Botev et al., 2013) to update the sampling distribution to make the sampled action sequences close to previous action sequences that achieved high reward.
We further calculate the cumulative reward estimated (via the learned model) for previously sampled sequences and use the mean of that distribution to select the current action.
The task-speciﬁc posterior is updated using the data collected from only the current task.
The world-model posterior is updated after a few more steps with the collected transitions from all the visited tasks.
The intuition is to guide the two posteriors to separately learn two categories of uncertainty within lifelong learning tasks.
Note that other CEM-based model-based RL algorithms like PETS (Chua et al., 2018) usually maintain a set of neural networks using the same training data, and sample action sequences from each of the neural nets to achieve randomness in transitions.
Besides the problem of requiring special training tricks, it is unrealistic to maintain ( ≥ 30 ) models for each task in lifelong RL settings.
Our usage of BNNs avoids such problems as we only have to train one neural network using the same data for each task, and we can sample an unlimited number of different action sequences to cover more possibilities as needed.
In PETS, the epistemic uncertainty is estimated via the variance of the output mean of different neural networks, while in VBLRL, it is estimated via the variance of the weights and biases distribution of BNN during training.
This is implied as the objective function we use to update φ t is from minimizing D KL [ q ( θ ; φ )
|| p ( θ | D )] .
Initialize general knowledge model p wm ( ·| s, a ; θ wm ) , replay buffer D m 1 , · · · , D m M for each task m i from i = 1 , 2 , 3 , · · · , M do
Initialize task-speciﬁc model
p
m i ( ·| s, a ; θ m i ) with general knowledge model p wm for each episode do for Time t = 0 to TaskHorizon do
Sample Actions a t : t + T ∼ CEM( · )
Propagate state particles s pτ with p m i ( s (cid:48) | s, a )
Evaluate actions as (cid:80) t + T τ = t 1 P (cid:80)
Pp =1 p m i ( r | s, a )
Update CEM( · ) distribution.
Execute optimal actions a ∗ t : t + T end
Add transitions to replay buffer D
m i
Update task-speciﬁc model according to Equation (7) given D
m i
Update general knowledge model according to Equation (7) given { D m 1 , · · · , D m i } end end
4. B ACKWARD T RANSFER OF V ARIATIONAL B AYESIAN L IFELONG RL
In our lifelong RL setting, the agent interacts with each task for only a limited number of episodes and the task-speciﬁc model stops learning when the next task is initiated.
As a result, there may exist portions of the transition dynamics in which model uncertainty remains high.
However, as the world-model posterior continues to train on new tasks, it gathers more experience in the whole state space and can provide improvements in its guesses concerning the “unknown” transition dynamics, even for previously encountered tasks.
Intuitively, the performance of an agent on one task has the potential to be further improved (positive backward transfer) if there exists a sufﬁciently large set of state–action transition pairs of which the task-speciﬁc model’s predictions are not conﬁdent due to lack of data.
This type of model uncertainty is sometimes called epistemic uncertainty (Kiureghian & Ditlevsen, 2009; Ciosek et al., 2020).
In our algorithm, the aleatory variability (irreducible chance in the outcome) is measured by the output variance of the prediction { σ r pτ , σ s pτ } , and the epistemic uncertainty (due to lack of experience) corresponds to the uncertainty of the output mean and variance (see Deﬁnition 1 below).
Thus, a straightforward method to improve a previously learned task-speciﬁc model is to ﬁnd the predictions it needs to make that have high epistemic uncertainty, and replace them with the predictions from the world-model posterior, which has lower epistemic uncertainty.
If we only consider reward prediction, the conditions for measuring whether a task-speciﬁc model is sufﬁciently conﬁdent are as follows.
Deﬁnition 1.
Assume there exist known constants δ µ r , δ σ r .
For a given state–action pair ( s, a ) , the task-speciﬁc model (reward) is proclaimed conﬁdent when the following conditions are satisﬁed:
[Equation]
where P is the number of particles.
Similar deﬁnition applies to the task-speciﬁc model’s next-state prediction.
Intuitively, δ µ r and δ σ r function as the threshold to judge whether the uncertainty of the output mean or variance for each dynamic prediction is too high to be called as a conﬁdent prediction.
The detailed backward transfer testing algorithm can be found in the appendix.
In practice, it is often hard to ﬁnd speciﬁc conﬁdence thresholds ( δ µ s , δ µ r , δ σ s , δ σ r ) that are effective.
Instead, we implement a simpler approach: During planning, for each prediction, we compare the uncertainty of the output mean and variance of the world model and the task-speciﬁc model, and then choose the one with lower values, which indicates higher conﬁdence level.
E XPERIMENTS 5. G RID -W ORLD I TEM S EARCHING
We ﬁrst evaluate BLRL in a simple Grid-World domain.
Our testbed consists of a collection of houses, each of which has four rooms.
The goal of each task is to ﬁnd a speciﬁc object (blue, green or purple) in the current house.
The type of each room is sampled based on an underlying distribution given by the environment.
Each room type has a corresponding probability distribution of which kind of objects can be found in rooms of this type.
Different tasks/houses vary in terms of which rooms are which types and precisely where objects are located in the room (the task’s hidden parameters).
To simplify the problem, instead of modeling the whole MDP distribution, we use BLRL to model the object distribution as the Bayesian posterior and sample MDPs from the distribution.
We use
BOSS with a ﬁxed prior (no intertask transfer) as our baseline.
The average training performance of all 300 tasks are shown in Figure 3 top right.
Each task consists of 10 epochs, with 21 sample steps for each epoch.
Within the limited steps allotted for each task, BLRL is able to discover and transfer the common knowledge and helps the agent quickly adapt to new tasks as the training goes on.
In comparison, running BOSS with a ﬁxed prior is able to ﬁnd the optimal policy eventually but needs more sample steps and learns more slowly than BLRL.
5. B OX -J UMPING T ASK
We use a simpliﬁed version of the jumping task (des Combes et al., 2018) as a testbed for the proposed algorithm VBLRL.
As shown in Figure 3 bottom left, the goal of the agent is to reach the right side of the screen by jumping over the obstacle.
The agent can only choose from two actions: jump and right.
It will hit the obstacle unless the jump action is chosen at precisely the right time.
We set different obstacle positions as different tasks, constituting the HiP-MDP hidden parameters.
The 4-element state vector describes the ( x, y ) coordinates of the agent’s current position, and its velocity in the x and y directions.
Figure 3 bottom right presents the average performance during training across all 300 tasks.
Each task is run for 30 episodes.
We compare VBLRL against state-of-the-art lifelong RL methods LPGFTW (Mendez et al., 2020) from the multi-model category, EWC (Kirkpatrick et al., 2016) from the single-model category, singel-task model-base RL baseline (using the same BNN structure and planning procedures) as well as a HiP-MDP baseline (Killian et al., 2017).
For a fair comparison, we further replace the DDQN algorithm (van Hasselt et al., 2016) used in Killian et al.
’s paper with CEM planning, and let the transition model also predict the reward for each state–action pair.
This modiﬁed baseline is similar to the single-model version of VBLRL (i.e., only using the world-model posterior).
VBLRL clearly learns faster than the HiP-MDP baseline and reaches better ﬁnal performance.
Thus, in the lifelong RL setting, separating the updating processes of the world-model posterior and the task-speciﬁc posterior can lead to better learning efﬁciency.
5. O PEN AI G YM M U J O C O D OMAINS
We evaluate the performance of VBLRL on HiP-MDP versions of several continuous control tasks from the Mujoco physics simulator (Todorov et al., 2012), HalfCheetah-gravity, HalfCheetahbodyparts, Hopper-gravity, Hopper-bodyparts, Walker-gravity, Walker-bodyparts , all of which are lifelong-RL benchmarks used in prior work 1 (Mendez et al., 2020).
For each of six different domains, the task-speciﬁc hidden parameters correspond to different gravity values or different sizes and masses of the simulated body parts.
More details can be found in the appendix.
Compared with prior work, we substantially reduced the number of iterations that the agent can sample and train on ( iterations for each task and a horizon of 100/200 for each iteration).
We used such settings to increase the difﬁculty of lifelong learning and ensure that no learning-from-scratch algorithm could obtain a good policy in the available training time.
[Table]
The results are shown in Table 1.
We compare our algorithm against the three algorithms described in
Section 5.2.
For all six domains, we report the average performance of all the tasks at the beginning of training ( Start ) and after all training for each new task ( Train ), as well as the average performance for all previous tasks after training for a given number of tasks
[Table]
which is the backward transfer test ( Back ).
As shown in the results, our method VBLRL shows better performance on all three test stages of the HalfCheetah domain and Walker domain, as well as better backward transfer performance on
Hopper-gravity and Hopper-bodyparts than the other three algorithms.
LPG-FTW exhibits better forward training performance in the Hopper domain
[Table]
but still shows some signs of catastrophic forgetting as there is a huge gap between its training performance and backward performance.
EWC fails in most of the tasks as the tasks are diverse and we set very limited sample steps for each task, which means it is hard to directly learn a single shared policy that achieves good performance.
The
HiP-MDP baseline shows good results on some of the tasks because it is more sample-efﬁcient to learn a shared model across all the tasks and easier to capture the world-model uncertainty.
However, it cannot achieve as good performance as VBLRL as it is hard to model the task-speciﬁc uncertainty using only one model across all tasks, which also leads to the negative backward transfer performance on Cheetah-Gravity.
Comparing VBLRL’s performance on the Train stage and Back stage, we also ﬁnd that it shows positive backward transfer results on most of the tasks, without showing patterns of catastrophic forgetting.
Overall, VBLRL’s world-model posterior contributes to better forward transfer performance ( Start ), the learning of task-speciﬁc posterior contributes to better forward transfer training for each new task ( Train ), and the combination of these two posteriors guides the agent to achieve better backward transfer performance ( Back ).
R ELATED WORK
HiP-MDPs (Doshi-Velez & Konidaris, 2016) provide a framework for studying lifelong RL.
Published
HiP-MDP methods use Gaussian Processes (Doshi-Velez & Konidaris, 2016) or Bayesian neural networks (Killian et al., 2017) to ﬁnd a single model that works for all tasks, which may trigger catastrophic forgetting .
Other single-model lifelong RL algorithms encourage transfer across tasks by modifying objective functions.
EWC (Kirkpatrick et al., 2016) imposes a quadratic penalty that pulls each weight back towards its old values by an amount proportional to its importance for performance on previously-learned tasks to avoid forgetting.
There are several extensions of this work based on the core idea of modifying the form of the penalty (Li & Hoiem, 2017; Zenke et al., 2017;
Nguyen et al., 2018).
Another category of lifelong RL methods uses multiple models with shared parameters and task-speciﬁc parameters to avoid or alleviate the catastrophic problem (Bou-Ammar et al., 2014; Isele et al., 2016a; Mendez et al., 2020).
The drawback of this method is that it is hard to incorporate the knowledge learned from previous tasks during initial training on a new task (Mendez et al., 2020).Nagabandi et al.
(2019) introduce a model-based continual learning framework based on MAML, but they focus on discovering when new tasks were encountered without access to task indicators.
Research in Meta-RL (Wang et al., 2016;
Finn et al., 2017) and multi-task RL (Parisotto et al., 2016;
Teh et al., 2017) settings also attempts to ﬁnd ways to accelerate learning by transferring knowledge from different tasks.
Some work employs the MAML framework with Bayesian methods to learn a stochastic distribution over initial parameter (Yoon et al., 2018; Grant et al., 2018; Finn et al., 2018).
Other work uses the collected trajectories to infer the hidden parameter, which is taken as an additional input when computing the policy (Rakelly et al., 2019; Zintgraf et al., 2020; Fu et al., 2021).
Our method, however, focuses on problems where the tasks arrive sequentially instead of having a large number of tasks available at the beginning of training.
This sequential setting makes it hard to accurately infer the hidden parameters, but opens the door for algorithms that support backward transfer.
Further, our method approximates the true HiP-MDP model by learning the
Bayesian posterior over past tasks and uses it to initialize a model for each new task, encouraging the agent to explore places where the epistemic uncertainty of the world model is high.
Some prior work uses Bayesian methods in RL to quantify uncertainty over initial MDP models (Ghavamzadeh et al., 2015; Asmuth & Littman, 2011; Guez et al., 2012).
Several algorithms start from the idea of sampling from a posterior over MDPs for Bayesian RL, maintaining Bayesian posteriors and sampling one complete MDP (Strens, 2000; Wilson et al., 2007a) or multiple MDPs from this distribution (Asmuth et al., 2009).
Instead of focusing on single-task RL, our algorithm aims to ﬁnd a posterior over the common structure among multiple tasks.
Wilson et al.
(2007a) uses a hierarchical Bayesian inﬁnite mixture model to learn a strong prior that allows the agent to rapidly infer the characteristics of new environment based on previous tasks.
However, it only infers the category label of a new MDP and uses that information to ﬁnd parameter values.
Moreover, their method only works in discrete settings and cannot be applied to the kind of continuous problems we included in our evaluation.
Lifelong learning has also been widely studied within the supervised learning domain with explicit performance bounds (Baxter, 2000; Pentina & Lampert, 2014).
Our work is one of the ﬁrst papers to give explicit sample complexity bounds for lifelong reinforcement learning algorithm, where data efﬁciency is essentially important.
C ONCLUSION
To address the lifelong RL problems, our work proposed to distill the shared knowledge from similar
MDPs and maintain a Bayesian posterior to approximate the distribution derived from that knowledge.
We gave a sample complexity analysis of the algorithm in the ﬁnite MDP setting.
Then, we extended our method to use variational inference, which scales better and supports both backward and forward transfer.
Our experimental results show that the proposed algorithms enables faster training on new tasks through collecting and transferring the knowledge learned from preceding tasks.
A
B ACKWARD T RANSFER
We take backward transfer to be the inﬂuence of subsequent learning on the agent’s performance of a previous task.
Negative backward transfer, which is also known as catastrophic forgetting , describes the scenario in which the agent’s progress on a task is erased after learning new tasks (French, 1993;
Carpenter & Grossberg, 1988; Robins, 1995).
Our algorithm avoids catastrophic forgetting as it maintains a separate task-speciﬁc model for each task.
In the mean time, there are circumstances in which VBLRL exhibits positive backwards transfer as introduced in the main text.
input : Test task m i , model uncertainty thresholds δ µ s , δ µ r , δ σ s , δ σ r for Time t = 0 to TaskHorizon do for Trial k = 1 to K do
Sample Actions a t : t + T ∼ CEM( · ) for each action do
Propagate state particles s pτ and reward r pτ with T
m i ( s (cid:48) , r | s, a ) if T m i ( s (cid:48) , r | s, a ) is not conﬁdent ( Deﬁnition 1 ) then
Repropagate state particles s pτ and reward r pτ with T e ( s (cid:48) , r | s, a ) end end
Evaluate actions as (cid:80) t + T τ = t 1 P (cid:80)
Pp =1 T m i ( r | s, a )
Update CEM( · ) distribution.
end
Execute optimal actions a ∗ t : t + T end
The difference between the backward transfer version and the forward training version is that, when we do predictions for the state particles, each time we will also calculate the conﬁdence level (Deﬁnition 1) of the task-speciﬁc model for this particular transition.
If the task-speciﬁc model is not conﬁdent enough for this state–action pair, we will use the world-model instead and recalculate the prediction value.
In practice, it is often hard to ﬁnd speciﬁc conﬁdence thresholds ( δ µ s , δ µ r , δ σ s , δ σ r ) that are effective.
Instead, we implement a simpler approach: During planning, for each prediction, we compare the uncertainty of the output mean and variance of the world model and the task-speciﬁc model, and then choose the one with lower values, which indicates higher conﬁdence level.
Here is a link to the learned behaviors of VBLRL https://youtu.be/I7RAT6g9v5w .
The video shows the agent trained by our algorithm learns some meaningful behaviors at the current setting within limited steps, and performs better compared with the behaviors learned by other baseline algorithms.
A. BNN MODEL
As we model the transition models as Gaussian distributions:
[Equation]
The function f θ represented as a Bayesian neural network parameterized by θ , which is further modeled as the posterior distribution parameterized by φ , predicts the mean µ s , µ r and variance σ s , σ r given current state and action s, a .
To make it clearer, we can view the BNN model in VBLRL as an inﬁnite neural network ensemble by integrating out its parameters:
[Equation]
Compared to previous model-based algorithms that use ﬁnite number of neural network ensembles (e.g. PETS), our choice of BNN is more suitable for lifelong RL as we only need to maintain one neural network for each task, and we can sample an unlimited number of predictions from it which better estimates the uncertainty and is essential in our setting where both dynamic function and reward function are not given unlike prior model-based RL methods.
input : K , B initialize MDP set, the world-model posterior q e ( s t +1 , r t | s t , a t ) ; for each MDP m i do N s,a ← 0 , ∀ s, a do sample ← TRUE ; initialize the task-speciﬁc posterior q m i θ ( s t +1 , r t | s t , a t ) ← q e ( s t +1 , r t | s t , a t ) ; for all timesteps t = 1 , 2 , 3 , ... do if do sample then
Sample K models m i 1 , m i 2 ,···, m i K from the task-speciﬁc posterior q m i θ ( s t +1 , r t | s t , a t ) .
Merge the models into the mixed MDP m # i ;
Solve m # i to obtain π ∗ m # i ; do sample ← FALSE end
Use π ∗ m # i for action selection: a t ← π m # i ( s t ) and observe reward r t and next state s t +1 ;
N s t ,a t ← N s t ,a t + 1 ; Update the task-speciﬁc posterior distribution q m i θ ( s t +1 , r t | s t , a t ) for the current MDP; if N s t ,a t =
B then Update the world-model posterior distribution q e ( s t +1 , r t | s t , a t ) with the collected transitions; do sample ← TRUE end end end
A. E XPERIMENTAL S ETTING A.4. G RID -W ORLD I TEM S EARCHING
Our testbed consists of a collection of houses, each of which has four rooms.
The goal of each task is to ﬁnd a speciﬁc object (blue, green or purple) in the current house.
The type of each room is sampled based on an underlying distribution given by the environment.
Each room type has a corresponding probability distribution of which kind of objects can be found in rooms of this type.
Different tasks/houses vary in terms of which rooms are which types and precisely where objects are located in the room (the task’s hidden parameters).
Room types are sampled from a joint distribution.
[Table]
A.4. B OX - JUMPING T ASK
We use a simpliﬁed version of jumping task (des Combes et al., 2018) as a simple testbed for the proposed algorithm VBLRL.
We select a random position of obstacle between 15 ∼ 33 for each task.
The 4-element state vector describes the ( x, y ) coordinates of the agent’s current position, and its velocity in the x and y directions.
The agent can choose from two actions: jump and right.
The reward function for this box-jumping task is:
R t =
I { s t reach the right wall } − I { s t +1 hit the obstacle } + ˙ x t · I { s t +1 not hit the obstacle } (11)
[Table]
[Figure]
Similar to (Mendez et al., 2020), we evaluated on the HalfCheetah, Hopper, and Walker-2D environments.
For the gravity domain, we select a random gravity value between 0 .
5 g and 1 .
5 g for each task.
For the body-parts domain, we set the size and mass of each of the four parts of the body (head, torso, thigh, and leg) to a random value between 0 .
5 × and 1 .
5 × its nominal value.
As shown in Appendix
C of (Mendez et al., 2020), these changes lead to highly diverse tasks for lifelong RL.
Further, as required by model-based deep RL methods, we change the environment settings for Hopper and
Walker following (Wang et al., 2019).
When implementing VBLRL, we found that in the ﬁrst few
[Table]
episodes of each new tasks, the agent hasn’t collected enough samples of the new task, which results in overﬁtting problems when training the task-speciﬁc.
Thus, we use the world-model posterior instead to do the ﬁrst few rounds of predictions and let the task-speciﬁc model begin training after collecting enough samples.
The world-model has lower possibility of overﬁtting as its training data comes from all the previous tasks and has much larger quantity.
We list the other implementation details below.
The planning horizons are selected from values suggested by previous model-based
RL papers (Chua et al., 2018; Wang et al., 2019).
For LPG-FTW and EWC, we use the original source code 2 with parameters and model architectures suggested in the original paper.
Speciﬁcally, we select step size from { 0 . 005 , 0 . 05 , 0 . 5 } .
For LPGFTW, e use λ = 1 e − 5 , µ = 1 e − 5 and select k from 3,5,10.
For EWC, we select λ from { 1 e − 6 , 1 e − 7 , 1 e − 4 } .
For HiP-MDP baseline, we modify the original algorithm for a fair comparison.
We replace the DDQN algorithm used in Killian et al.
’s paper with the exact same CEM planning method we used in VBLRL as well as the same parameters.
And we use the same model architecture of Bayesian Neural network by modifying the baseline algorithm to also predict reward for each state-action pair (the original method only considers next-state prediction).
[Table]
For BOSS and BLRL, we set the number of sampled models K = 5 , and γ = 0 .
95 , ∆ = 0 .
01 for value iteration.
A. D ETAILED PROOF FOR LEMMA
Following the same settings introduced in section 5 of (Zhang, 2006), we deﬁne the resolvability of standard Bayesian posterior as:
[Equation]
We refer the readers to Zhang’s paper for further explanation of the denotations.
Intuitively, the
Bayesian resolvability controls the complexity of the density estimation process.
Based on this deﬁnition and our previous deﬁnitions of d π , we can derive a simple and intuitive estimate of the standard Bayesian resolvability.
Lemma 3.
The resolvability of standard Bayesian posterior deﬁned in (12) can be bounded as
[Equation]
proof.
For all d > 0 , we have
[Equation]
This bound links the Bayesian resolvability to the number of samples n and prior-mass radius d π which is a ﬁxed property of the density given a speciﬁc prior and the true underlying density.
Intuitively, the Bayesian posterior is better behaved when the Bayesian prior is closer to the true distribution ( d π is smaller) and more samples are used (n is larger).
Now we can prove the main theorem of Lemma 1.
Let ρ = 12 , (cid:15) t = 2 ε n +(4 η − 2) t δ/, deﬁne Γ
= { p ∈ Γ : D Reρ ( q || p ) <
(cid:15) t } and Γ 2 = { p ∈ : D Reρ ( q || p ) ≥ (cid:15) t } .
We let a = e − nt and deﬁne π (cid:48)
( θ ) =
aπ ( θ ) C when θ ∈ Γ 1 and π (cid:48) ( θ ) C when θ ∈ Γ 2 , where the normalization constant
C =
( aπ (Γ 1 ) + π (Γ 2 ))
− 1 ∈ [1 , 1 /a ] .
Firstly,
[Equation]
according to the Markov inequality (with probability at least 1 − δ ) and Pinsker’s inequality.
Then according to Theorem 5.2 and Proposition 5.2 in Zhang’s paper,
[Equation]
Then, using the deﬁnitions of d π , we further obtain
E X π
[Equation]
(Γ 2 | X ) (cid:15) t
[Equation]
We use η instead of γ which is used in the original paper to avoid confusion with the discount factor.
Then we further divide both sides by (cid:15) t and obtain π (cid:48)
(Γ | X ) ≤ 0 .
Then by deﬁnition,
[Equation]
Thus, we get the desired bound.
A. D ETAILED PROOF FOR T HEOREM
Theorem 2.
(Full version of the bound in Theorem 1)
For each new task, set the sample size
K =
Θ( S 2 Aδ ln SAδ ) and the parameters (cid:15)
= (cid:15) (1 − γ ) 2 , δ
=
δSA , ρ 0 = δ S
A 2 K , then, with probability at least 1 − 4 δ , V A t ( s t ) ≥ V ∗ ( s t ) − 4 (cid:15) in all
but O ( S
A 2 ( d π +ln S 2 A 2 K δ ) δ(cid:15)
[Equation]
1 − γ ) ) steps.
First, we would like to introduce two lemma from BOSS (Asmuth et al., 2009):
Lemma 4.
The sample size K =
Θ( S
Aδ ln SAδ ) sufﬁces to guarantee V ∗ m ( s ) ≥ V ∗ ( s ) for all s during the entire learning process with probability at least 1 − δ .
Lemma 5.
If the knownness parameter B = max s,a f ( s, a, (cid:15), δSA , ρ S 2 A 2 K ) , then the transition function of all the sampled models are (cid:15) -close (in the l 1 sense) to the true transition function for all the known state-action pairs during the entire learning process with probability at least 1 − δ − ρ .
proof.
Given discrete state and action spaces, the proof that BLRL on each new task is PAC-MDP depends on three main assumptions, following a general PAC-MDP theorem from (Strehl et al., 2006):
Learning complexity condition.
In our settings, a state-action pair is claimed to be known after being visited for B times.
In the meantime, there are SA unknown state-action pairs in total at the beginning of each task, so the bounded discoveries condition is guaranteed.
Optimism.
This is guaranteed by Lemma 3.
We construct a new hyper-model each time a discovery event occurs.
The values for each unknown state in every hyper-model are optimistic.
Accuracy.
For each new task, since the prior π has bounded sample complexity of B for δ 0 and (cid:15) 0 , a known state-action pair will be locally (cid:15) 0 - accurate with probability at least 1 − δ 0 .
Given the deﬁnition of Bayesian concentration sample complexity and Lemma 4, (cid:15)
= (cid:15) (1 − γ ) 2 translates into an (cid:15) error bound in the value function (Asmuth et al., 2009).
Finally, given Lemma 2, we know f ( s, a, (cid:15) 0 , δ 0 , ρ 0 )
=
O (cid:18)
d π +ln
[Table]
(cid:15)
δ 0 − d π (cid:19) , let (cid:15)
= (cid:15) (1 − γ ) 2 , δ
=
δSA , ρ 0 = δ S
A 2 K , we can get f ( s, a, (cid:15) 0 , δ 0 , ρ 0 )
=
O (cid:18) SA ( d π +ln S
A 2 K δ ) δ(cid:15) 2 (1 − γ )(cid:19) .
We can get the ﬁnal form of the bound by replacing B with these quantities.
A. A DDITIONAL EXPLANATION OF THE ALGORITHM
Here we ﬁrst provide an example to help the readers better understand our plate notation.
In our
Gridworld Item Searching case, Ψ represents the parameters of P Ω , which is the room-type and object distribution.
For each task, the environment samples a hidden parameter ω , which is the actual room and object layout of this house, from this distribution P Ω .
The sampled ω then will result in an
MDP m and let the agent interact with it
. A.7. PLANNING ALGORITHM
With the transition dynamics and reward functions, a planning algorithm like CEM is not the only way to solve the MDP to get an optimal policy.
Another option would be using other Deep RL algorithms like Soft actor-critic (Haarnoja et al., 2018) with data generated from the model.
However, in this case, incorporating a deep RL algorithm means that we need to introduce additional neural networks (that is, policy/value networks) for each task.
The update signal from the RL loss is usually stochastic and weak, which is even worse in this case when our model is still far from accurate.
So, here we assume applying a planning algorithm is a better way to get the policy.
A. C OIN E XAMPLE
Consider a coin-ﬂipping environment.
We want to ﬁnd the sample complexity of the unbiased coin (i.e. How many times we need to ﬂip this coin such that our posterior samples are accurate.).
Consider a Dirichlet prior, α
=
( n 1 , n 2 ) and θ
= ( 12 , 12 ) .
We want to ﬁnd sample complexity B such that the posterior likelihood for a coin with heads likelihood in [0 .
5 − (cid:15), 0 .
5 + (cid:15) ] is at least 1 − δ .
Note that the Dirichlet distribution on the two-dimensional simplex is the Beta distribution.
The
Multinomial distribution with two outcomes is the Binomial distribution.
That is, given the process
[Equation] [Equation]
choose a value B such that
[Equation] [Equation]
Here, n 1 and n 2 capture the prior.
The smallest B that satisﬁes Equation 16 can be found numerically.
We set (cid:15) = 0 .
1 and δ = 0 .
Here are the results of sample complexity B given different values of n 1 , n 2 :
We ﬁx the sum of ( n 1 , n 2 ) as 10 .
As shown in the results, the value of sample complexity B becomes lower as we use a more accurate prior (from (10 , 0) to (5 , 5) ).
( n 1 , n 2 ) lowest B (0,10) (1,9) (2,8) (3,7) (4,6) (5,5) (6,4) (7,3) (8,2) (9,1) (10,0)
In general, for the task-speciﬁc posterior, we can relate B, (cid:15) and δ with the following equation:
[Equation]
For the world model posterior:
[Equation]
For each task, ﬁrst we pick a true model P
according to the true distribution and initialize the task-speciﬁc prior Φ old =
Φ w .
Then, we make some observations from the world.
Once we have the true model and the observations, we can calculate how many models are (cid:15) -close to the true model, weighted according to their posterior likelihood.