Factored Adaptation for Non-stationary Reinforcement Learning
Abstract
Dealing with non-stationarity in environments (e.g., in the transition dynamics) and objectives (e.g., in the reward functions) is a challenging problem that is crucial in real-world applications of reinforcement learning (RL).
While most current approaches model the changes as a single shared embedding vector, we leverage insights from the recent causality literature to model non-stationarity in terms of individual latent change factors, and causal graphs across different environments.
In particular, we propose Factored Adaptation for Non-Stationary RL (FANS-RL), a factored adaption approach that learns jointly both the causal structure in terms of a factored MDP, and a factored representation of the individual time-varying change factors.
We prove that under standard assumptions, we can completely recover the causal graph representing the factored transition and reward function, as well as a partial structure between the individual change factors and the state components.
Through our general framework, we can consider general non-stationary scenarios with different function types and changing frequency, including changes across episodes and within episodes.
Experimental results demonstrate that FANS-RL outperforms existing approaches in terms of return, compactness of the latent state representation, and robustness to varying degrees of non-stationarity.
Introduction
Learning a stable policy under non-stationary environments is a long-standing challenge in Reinforcement learning (RL) [1, 2, 3].
While most RL approaches assume stationarity, in many real-world applications of RL there can be changes in the dynamics or the reward function, both across different episodes and within each episode.
Recently, several works adapted Meta-RL methods to learn sequences of non-stationary tasks [4, 5].
However, the continuous MAML [6] adaptation for non-stationary RL [4] does not explicitly model temporal changing components, while TRIO [5] needs to meta-train the model on a set of non-stationary tasks.
LILAC [7] and ZeUS [8] leverage latent variable models to directly model the change factors in the environment in a shared embedding space.
In particular, they consider families of MDPs indexed by a single latent parameter.
In this paper, we argue that disentangling the changes as separate latent parameters and modeling the process with a factored representation improves the efficiency of adapting to non-stationarity.
In particular, we leverage insights from the causality literature [9, 10] that model non-stationarity in terms of individual latent change factors and causal graphs across different environments.
We propose
Factored Adaptation for Non-Stationary RL (FANS-RL), a factored adaptation framework that jointly learns the causal structure of the MDP and a factored representation of the individual change factors, allowing for changes at discrete timepoints and continuously varying environments.
While we provide a specific architecture (FN-VAE), the theoretical framework of FANS-RL can be implemented with different architectures and combined with various RL algorithms.
We formalize our setting as a
Factored Non-stationary MDP (FN-MDP), which combines a Factored-MDP [11, 12, 13] with latent change factors that evolve in time following a Markov process.
We build upon the AdaRL framework [14], a recently proposed fast adaptation approach.
AdaRL learns a factored representation that explicitly models changes (i.e., domain-specific components) in observation, dynamics and reward functions across a set of source domains.
An optimal policy learnt on the source domains can then be adapted to a new target domain simply by identifying a low-dimensional change factor, without any additional finetuning.
FANS-RL extends AdaRL from the stationary case with constant change factors to a general non-stationary framework.
Specifically,
FANS-RL learns the low-dimensional and time-evolving representations θ st and θ rt that fully capture the non-stationarity of dynamics and rewards, allowing for continuous and discrete changing functions, both within-episode and across-episode .
Our main contributions can be summarized as:
• We formalize FN-MDPs, a unified factored framework that can handle many non-stationary settings, including discrete and continuous changes, both within and across episodes.
We prove that, under standard assumptions, the causal graph of the transition and reward function is identifiable, while we can recover a partial structure for the change factors.
• We introduce Factored Adaptation for Non-Stationary RL (FANS-RL), a general nonstationary RL approach that interleaves model estimation of an FN-MDP and policy optimization.
We also describe FN-VAE, an example architecture for learning FN-MDPs.
• We evaluate FANS-RL on simulated benchmarks for continuous control and robotic manipulation tasks and show it outperforms the state of the art on the return, compactness of the latent space representation and robustness to varying degrees of non-stationarity.
Factored Non-stationary MDPs
To model different types of non-stationarity in a unified and factored way, we propose Factored
Non-stationary Markov Decision Processes (FN-MDPs).
FN-MDPs are an augmented form of a factored MDPs [11, 12, 13] with latent change factors that evolve over time following a Markov process.
Since the change factors are latent, FN-MDPs are partially observed.
We define them as:
Definition 1.
A Factored Non-stationary Markov Decision Process (FN-MDP) is a tuple ( S , A , Θ s , Θ r , γ, G , P s , R , , P θ r , P θ s ) , where S is the state space, A the action space, Θ s the space of the change factors for the dynamics, Θ r the space of the reward change factors and γ the discount factor.
We assume G is a Dynamic Bayesian Network over { s 1 ,t , ... , s d,t , a 1 ,t , ... , a m,t , r t , θ s 1 ,t , ... , θ s p,t , θ r 1 ,t , ... , θ rq,t } , where d , m , p , and q are the dimensions of states, action, change factors on dynamics and reward, respectively.
We define the factored state transition distribution
P s as:
[Equation]
where pa ( s i,t ) denotes the causal parents of s i,t in G , which are a subset of the dimensions of s t − 1 , a t − 1 and θ s t .
Note that the action a t − 1 is a vector of m dimensions in our setting.
We assume a given initial state distribution P s ( s 0 ) .
Similarly, we define the reward function R as a function of the parents of r t in G , i.e., R ( s t , a t , θ r t ) =
R ( pa ( r t )) , where pa ( r t ) are a subset of dimensions of s t , a t , and θ r t .
We define the factored latent change factors transition distributions P θ s and P θ r as:
[Equation]
where pa ( θ sj,t ) are a subset of the dimensions of θ s t − 1 , while pa ( θ rk,t ) are a subset of dimensions of θ r t − 1 .
We assume the initial distributions P θ s ( θ s 0 ) and P θ r ( θ r 0 ) are given.
We show an example DBN representing the graph G of an FN-MDP in Fig. 1(a).
Since we are interested in learning the graphical structure of the FN-MDP, as well as identifying the values of the latent change factors from data, we describe a generative process of an FN-MDP environment.
In particular, we assume that the graph G is time-invariant throughout the non-stationarity, and there are no unobserved confounders and instantaneous causal effects in the system.
We will learn a set of binary masks c · (cid:41) · and C · (cid:41) · that are the indicators for edges in G .
s 1, t − a 1, t − r t θ s 1, t s 2, t − s 3, t − a 2, t − s 1, t s 2, t s 3, t θ s 2, t θ r 1, t θ r 2, t a 1, t a 2, t
θ s 1, t
+ θ s 2, t
+ θ r 1, t + θ r 2, t + (a) (b)
CF inference network CF dynamics network Transition decoder Reward decoder s t a t r t q sϕ h s t θ rt p α̂ s t + ̂ r t +1 p
β̂ r t p βp γ s p γ r s t a t ̂
s t p α 1 a t − s t
C θ s →
θ s C θ r
→ θ r c s → r c a → r s t +1 a t + a t s t −
C s → s C a → s C θ s → s θ s t q rϕ s t +1 a t +1 r t + q sϕ a t +1 s t +1 θ rt + p α̂ s t + ̂ r t +
p β̂ r t +1 p βp
α 1 s t a t
C s → s C a → s C θ s → s c s → r c a → r s t +2 a t + s t +1 a t + ̂ s t
+ θ s t +1 q rϕ h rt
Generative environment model.
We adapt the generative model in AdaRL [14] across k different domains to a time-varying setting on a single domain.
We assume the generative process of the environment at timestep t in terms of the transition function for each dimension i = 1 , ... , d of s t is:
[Equation]
where ⊙ is the element-wise product, f i are non-linear functions and ϵ si,t is an i.i.d.
random noise.
The binary mask c s (cid:41) s i ∈ { 0 , 1 } d represents which state components s j,t − 1 are used in the transition function of s i,t .
Similarly, c a (cid:41) s i ∈ { 0 , 1 }
m indicates whether the action directly affects s i,t .
The change factor θ s t ∈ R p encodes any change in the dynamics.
The binary mask c θ t (cid:41) s i ∈ { 0 , 1 } p represents which of the components of θ s
t influence s i,t .
We model the reward function as:
[Equation]
where c s (cid:41) r ∈ { 0 , 1 } d , c a (cid:41) s ∈ { 0 , 1 } m , and ϵ rt is an i.i.d.
random noise.
The change factor θ rt ∈ R q encodes any change in the reward function.
The binary masks c · (cid:41) · can be seen as indicators of edges in the DBN G .
In AdaRL, all change factors are assumed to be constant in each domain.
Since in this paper we allow the change parameters to evolve in time, we introduce two additional equations:
[Equation]
[Equation]
for i = 1 , ... , d , j = 1 , ... , p , k = 1 , ... , q , and g s , and g r are non-linear functions.
We assume the binary masks c · (cid:41) · are stationary across timesteps and so are the ϵ si,t , ϵ rt , ϵ θ s t and ϵ θ r t , the i.i.d.
random noises.
Although c · (cid:41) · and ϵ are stationary, we model the changes in the functions and some changes in the graph structure through θ .
For example a certain value of θ rt can switch off the contribution of some of the state or action dimensions in the reward function, or in other words nullify the effect of some edges in G .
Similarly the contribution of the noise distribution to each function can be modulated via the change factors.
On the other hand, this setup does not allow adding edges that are not captured by the binary masks c · (cid:41) · .
We group the binary masks in the matrices C s (cid:41) s :=
[ c s (cid:41) s i ] di =1 ,
C θ s (cid:41) s :=
[ c θ s (cid:41) s i ]
d i =1 , and C a (cid:41) s :=
[ c a (cid:41) s i ]
d i =1 .
Similarly, we also group the binary vectors in the dynamics of the latent change factors in matrices C θ s (cid:41) θ s :=
[ c θ s (cid:41) θ s j ] pj =1 and C θ r (cid:41) θ r :=
[ c θ r (cid:41) θ r k ] qk =1 .
Since latent change factors θ s and θ r follow a Markov process based on g s and g r , we can consider different types of changes by varying the form of g s and g r , generalizing the approaches in literature.
We can also model concurrent changes in dynamics and reward, including different types of changes, e.g. a continuous g s and a piecewise-constant g r .
Compact representations.
Huang et al.
[14] show that the only dimensions of the state and change factors useful for policy learning are those that eventually affect the reward.
These dimensions are called compact representations and are defined as the dimensions of the state and change factors with a path (i.e. a sequence of edges → ) to the present or future reward r t + τ for τ ≥ 0 in the DBN G : s i,t ∈ s min ⇐⇒ s i,t → ...
→ r t + τ for τ ≥ 0 , and θ i ∈ θ min ⇐⇒ θ i → ... → r t + τ for τ ≥
Continuous changes.
If g s and g r are continuous, then they can model smooth changes in the environment, including across episodes.
While the functions in Eq.
1-3 allow us to model withinepisode changes, i.e. changes that can happen only before t
= H where H is the horizon, we also want to model across-episode changes.
We use a separate time index ˜ t that models the agent’s lifetime.
Initially ˜ t = t for t ≤ H , but while we reset t = 0 afterwards, ˜ t continues to grow indefinitely.
Discrete changes.
We assume discrete changes happen at specific timesteps and can be represented with a piecewise constant function.
In particular we denote change timesteps as ˜ t =
(˜ t 1 , . .
. , ˜ t M ) where ˜ t i describes a specific timepoint in the agent’s lifetime time index ˜ t .
This allows us to model within-episode changes .
In this case, we assume that the change happens always at the same steps ( t 1 , ... , t m ) in each episode, i.e., we assume that ˜ t
= ( t 1 , ... , t m , H + t 1 , ... , H + t m , 2 H + t 1 , ... , 2 H + t m , ... ) , where H is the horizon.
We can also model across-episode changes , when we assume the change points only occur at the end of each episode, i.e., ˜ t
= ( H, 2 H, 3 H, ... ) .
We extend the result on identifiability of factored MDPs in AdaRL [14] to non-stationary environments.
We first assume that we observe the change factors and show we can identify the true causal graph G :
Proposition 1 (Full identifiability with observed change factors) .
Suppose the generative process follows Eq.
1-3 and all change factors θ s t and θ r t are observed, i.e., Eq. 1-3 is an MDP.
Under the Markov and faithfulness assumptions, i.e. conditional independences correspond exactly to d-separations, all binary masks C · (cid:41) · are identifiable, i.e., we can fully recover the causal graph G .
We provide all proofs and a detailed explanation in Appendix B. If we do not observe the change factors θ s t and θ r t , we cannot identify their dimensions, and we cannot fully recover the causal graph
G .
On the other hand, we can still identify the partial causal graph over the state variables s t , reward variable r t , and action variable a t .
We can also identify which dimensions in s i,t have changes, i.e., we can identify C θ s (cid:41) s .
We formalize this idea in the following (proof in Appendix B):
Proposition 2 (Partial Identifiability with latent change factors) .
Suppose the generative process follows Eq.
1-3 and the change factors θ s t and θ r t are unobserved.
Under the Markov and faithfulness assumptions, the binary masks C s (cid:41) s , C a (cid:41) s , c s (cid:41) r and c a (cid:41) r are identifiable.
Moreover, we can identify which state dimensions are affected by θ s t and whether the reward function changes.
This means that even in the most general case, we can learn most of the true causal graph G in an
FN-MDP, with the exception of the transition structure of the latent change factors.
In the following, we show a variational autoencoder setup to learn the generative process in FN-MDPs.
Learning the Generative Process in FN-MDPs
There are many possible architectures to learn FN-MDPs through Eq.
We propose FN-VAE , a variational autoencoder architecture described in Fig. 1(b).
In FN-VAE, we jointly learn the structural relationships, state transition function, reward function, and transition function of the latent change factors, as described in detail in Appendix Alg.
A1.
An FN-VAE has four types of components: change factor (CF) inference networks that reconstruct the latent change factors, change factor (CF) dynamics networks that model their dynamics with an LSTM [15], transition decoders that reconstruct the state dynamics at the time t and predict one step further at t + 1 , and reward decoders that reconstruct the reward at t and predict the future reward at t
+ 1 .
We now describe them in detail.
CF inference networks (blue boxes in Fig. 1(b)).
The two inference models for latent change factors q ϕ s ( θ st | s t , a t ) and q ϕ r ( θ rt | s t , a t , r t ) are parameterised by ϕ s and ϕ r , respectively.
To model the time-dependence of θ st and θ rt , we use LSTMs [15] as inference networks.
At timestep t , the dynamics change factor LSTM infers q ϕ s (cid:0)
θ st | s t , a t , r t , h st − 1 (cid:1) , where h st − 1 ∈ R L is the hidden state in the LSTM.
Thus we can obtain µ ϕ s ( τ 0: t ) and σ 2 ϕ s ( τ 0: t ) using q ϕ s , and sample the latent changing factor θ s t ∼ N ( µ ϕ s ( τ 0: t ) , σ 2 ϕ s ( τ 0: t )) , where τ 0:
t = ( s 0 , a 0 , r 0 , s 1 , a 1 , r 2 , . . .
, s t , a t , r t ) .
Similarly, the reward change factor LSTM infers q ϕ r ( θ rt | s t , a t , r t , h rt − 1 ) , where h rt − 1 ∈ R L is the hidden state, such that we can sample θ rt ∼ N ( µ ϕ r ( τ 0: t ) , σ 2 ϕ r ( τ 0: t )) .
CF dynamics network (orange boxes in Fig. 1(b)).
We model the dynamics of latent change factors with p γ s (cid:0) θ s t +1 | θ s t , C θ s (cid:41) θ s (cid:1) and p γ r (cid:0) θ r t +1 | θ r t , C θ r (cid:41) θ r (cid:1) .
To ensure the Markovianity of θ st and θ rt , we define a loss L KL that helps minimize the KL-divergence between q ϕ and p γ .
[Equation]
If we assume that the change between θ s t and θ s t +1 , and similarly θ r t , is smooth, we can add a smoothness loss L smooth .
We provide a smooth loss for discrete changes in Appendix D.2.
[Equation]
Transition decoders (purple boxes in Fig. 1(b)).
We learn an approximation of the transition dynamics in Eq.
1 by learning a reconstruction, parameterized by α 1 , and a prediction encoder, parametrized by α 2 .
To simplify the formulas, we define C · (cid:41) s :=
( C s (cid:41) s , C a (cid:41) s ,
C θ s (cid:41) s ) .
At timestep t , the reconstruction encoder p α 1 ( s t | s t − 1 , a t − 1 , θ st ; C · (cid:41) s ) reconstructs the state from current state s t with sampled θ s t .
The one-step prediction encoder p α 2 ( s t +1 | s t , a t , θ s t ) instead tries to approximate the next state s t +1 .
We do not use the prediction loss, when the one-step prediction is not smooth.
In particular, we do not use it for the last time-step in episode i if there is a change happening at the first step in episode ( i + 1) , since the states in new episodes will be randomly initiated.
We also do not use it in the case of discrete changes at the timesteps (˜ t 1 − 1 , . . .
, ˜ t M − 1) .
The loss functions are:
[Equation]
Reward decoders (green boxes in Fig. 1(b)).
Similarly, we use a reconstruction encoder p β 1 ( r t | s t , a t , θ rt , c s (cid:41) r , c a (cid:41) r ) , parameterized by β 1 , and a one-step prediction encoder p β 2 ( r t +1 | s t +1 , a t +1 , θ rt ) , parametrized by β 2 , to approximate the reward function.
Similarly to transition decoders, we do not use the one-step prediction loss, if it is not smooth.
The losses are:
[Equation]
Sparsity loss.
We encourage sparsity in the binary masks C · (cid:41) · to improve identifiability, by using following loss with adjustable hyperparameters ( w 1 , ... , w 7 ) , which we learn through grid search.
[Equation]
[Equation] The total loss is L vae = k [Equation] L
[Equation] , where ( k 1 , ... , k 5 ) : hyper-parameters, which we learn with an automatic weighting method [16].
Learning from raw pixels.
Our framework can be easily extended to image inputs by adding an encoder ϕ o to learn the latent state variables from pixels, similar to other works [17, 18, 14].
In this case, our identifiability results do not hold anymore, since we cannot guarantee that we identify the true causal variables.
We describe this component in Appendix D.3.
do 8:
10: θ s ← θ s θ old 11:
12: θ s ← θ st − θ r ← θ rt − 1 13: end
14: for j = s, r do 15:
Infer mean µ γ j ( θ j ) and variance σ j ( of the parameter jt via p j 16:
Sample θ jt ∼ N (cid:16) µ γ j ( θ j ) , σ 2 γ j ( θ j ) (cid:17) 17: end for 18: if t = H − 1 then 19: θ s old ← θ st and θ r old ← θ st ; 20: end if 21:
Generate a t ∼ π ψ ( a t | s mint , θ mint and receive reward r n,t from Add s to
D ; 23: Extract a
Alg.
Sample a batch of data from ; 26: end for 27: end for
FANS-RL: Online Model Estimation and Policy Optimization
We propose Factored Adaptation for Non-Stationary RL (FANS-RL), a general algorithm that interleaves model estimation and policy optimization, as shown in Alg. 1.
After we estimate the initial FN-MDP with the FN-VAE, we can identify compact representations s min and θ min following
AdaRL [14].
In particular, the only dimensions of the state and change factors that are useful for policy learning are those that have a directed path to the reward in the graph G .
The online policy π ψ (cid:0) a t | s mint , q ϕ ( θ mint | τ 0: t ) (cid:1) can be learned end-to-end, including learning the FN-VAE, as shown in Alg.
We use SAC [19] as our policy learning model, so the policy parameters are ψ = ( π, Q ) .
Continuous changes.
In Alg.
1 we describe our framework in case of continuous changes that can span across episodes.
We start by collecting a few trajectories τ
and then learn our initial FN-VAE (Lines 3-4).
We can use the graphical structure of the initial FN-VAE to identify the compact representations (Line 5).
During the online model estimation and policy learning stage, we estimate the latent change factors θ st and θ rt using the CF dynamics networks γ s and γ r (Lines 8-20).
Since in this case, we assume the dynamics of the change factors are smooth across episodes, at time t
=we will use the last timestep ( H − 1) of the previous episode as a prior on the change factors (Line 10).
Otherwise, we will estimate the change factors using their values in the previous timestep t − 1 .
We use the estimated latent factors θ t and observed state s t to generate a t using π ψ and receive a reward r t (Line 21).
We add ( s t , a t , r t , θ st , θ rt ) to the replay buffer (Line 22).
We now update our estimation of the FN-VAE, but we keep the graph G fixed (Lines 23-24).
Finally, we sample a batch of trajectories in the replay buffer and update the policy network ψ (Line 25).
Discrete changes. Since we assume discrete changes happen at specific timestep ˜ t = (˜ t 1 , . . . , ˜ t M ) , we can easily modify Alg.
1 for discrete changes, both within-episode and across-episode, by changing
Lines 9-20 to only update the change parameters at the timesteps in ˜t , as shown in Appendix Alg.
A2.
[Figure]
LILAC
TRIO
[Figure]
[Table]
[Figure]
[Table]
R+2D) 0 .0 .0 .1 .
R e w a r d s
Oursw/ostructure w/osmooth w/ominsets w/osparsity w/orewardpred w/ostatepred w/odisentangled
Evaluation
We evaluate our approach on four well-established benchmarks, including Half-Cheetah-V3 from
MuJoCo [20, 21], Sawyer-Reaching and Sawyer-Peg from Sawyer [22, 18] and Minitaur [23].
We modified these tasks to test several non-stationary RL scenarios with continuous and discrete changes.
The results suggest that FANS-RL can (1) obtain high rewards, (2) learn meaningful mappings to the change factors with compact latent vectors and (3) be robust to different non-stationary levels, different functional forms (e.g. piecewise linear, sine, damped sine) and multiple concurrent changes.
For space limits, we only highlight a subset of results, and report the full results in Appendix C.4.
The implementation will be open-sourced at https://bit.ly/3erKoWm .
Half-Cheetah-v3 in MuJoCo.
In this task, the agent is moving forward using the joint legs and the objective is to achieve the target velocity v g .
We consider both the changes in the dynamics (change of the wind forces f w , change of gravity) and reward functions (change of target velocity v g ).
We also consider changes on the agent’s mechanism, where one random joint is disabled.
The reward function is r t = − ∥ v ot − v gt ∥ 2 − 0 .
∥ a t ∥ 2 , where v o and a t are the agent’s velocity and action, respectively, at timestep t .
The number of time steps in each episode is 50 .
For dynamics, we change the wind forces f w in the environment.
Moreover, in terms of the reward functions, we change the target velocity v g to be a time-dependent variable.
The change function in the dynamics f w can be either continuous or discrete, and discrete changes can happen both within and across episodes.
[Table] Similarly to LILAC [7], we choose different functions (piecewise linear, sine and damped sine), besides allowing the change at specified intervals, we also allow it to change smoothly.
The change in the reward function v g is not generally stable in the continuous case, so we only consider the discrete and across episode change functions v g for the reward.
We also design a scenario where dynamic and reward functions change concurrently.
We report all equations for g s and g r in Appendix C.1.
Sawyer.
We consider two robotic manipulation tasks, Sawyer-Reaching and Sawyer-Peg.
We describe the non-stationary settings in Appendix C.2.
In Sawyer-Reaching, the sawyer arm is trained to reach a target position s g .
The reward r t is the difference between the current position s t and the target position r t = − ∥ s t − s g ∥ 2 .
In this task, we cannot directly modify the dynamics in the simulator, so consider a reward-varying scenario, where the target location changes across each episode following a periodic function.
In Sawyer-Peg, the robot arm is trained to insert a peg into a designed target location s g .
In this task, following [8], we consider a reward-varying scenario, where the target location changes across each episode following a periodic function.
In order to compare with similar approaches, e.g., ZeUS [8],
CADM [24], Hyperdynamics [25]and Meld [18], we evaluate our method on raw pixels.
Following [8], we consider discrete across-episode changes, where the target location can change in each episode, and is randomly sampled from a small interval.
Minitaur.
A minitaur robot is a simulated quadruped robot with eight direct-drive actuators.
The minitaur is trained to move at the target speed s t,v .
The reward is r t = 0 .
3 − | 0 .
3 − s t,v | − 0 .
01 · ∥ [Equation] + a [Equation]
∥ 1 .
We modify (1) the mass m (dynamics) and (2) target speed s t,v (reward) of the minitaur.
We consider continuous, discrete across-episode and discrete within-episode changes for the dynamics, and across-episode changes for the reward.
We describe the settings in Appendix C.3.
Baselines.
We compare our approach with a meta-RL approach for stationary RL, VariBAD [26], a meta-RL approach for non-stationary RL, TRIO [5], as well as with two representative task embedding approaches, LILAC [7] and ZeUS [8].
The details on the meta-learning setups are given in Appendix D.4.
We also compare with stationary RL method, SAC [19], which will be our lowerbound, and compare with an oracle agent that has access to the full information of non-stationarity (e.g., the wind forces) and can use it to learn a policy, which will be our upper-bound.
For all baselines, we use SAC for policy learning.
We compare with the baselines on average return and the compactness of the latent space in varying degrees and functional forms of non-stationarity.
Experimental results.
Fig.
2(a)-(c) shows the smoothed curves of average return across timesteps in a subsection of Half-Cheetah, Sawyer-Reaching, and Minitaur experiments.
Smoothed curves of other experiments are given in Appendix Fig.
A2 and A3.
For continuous changes, we only compare with
LILAC [7] since other approaches are not applicable.
We smooth the learning curves by uniformly selecting a few data points for readability.
Table 1 shows the results on Sawyer-Peg experiments using raw pixels as input, based on the reported results in [8].
The learning curve is given in Appendix
Fig.
A9.
For a fair comparison, we indicate the best and final average return for each baseline in
Fig.
A9.
Full quantitative results of all experiemnts are given in Appendix C.4, including significance tests for Wilcoxon signed-rank test at α = 0 .
05 showing that FANS-RL is significantly better than baselines.
Finally, we conduct ablation studies on each component of FANS-RL and report some key results in Fig. 2(d).
Full results are in Appendix C.4.
Ablation studies.
The ablation studies verify the effectiveness of all components, including binary masks/structure, smoothness loss, sparsity loss, reward prediction or state prediction.
The results show that the largest gain is provided by the factored representation , validating our original hypothesis, followed by state prediction.
As expected, reward prediction is also important when there is a nonstationary reward, while smoothness is important for within-episode changes.
The disentangled design of CF inference networks is valuable when there are changes on both dynamics and reward functions.
Full results are in Appendix C.5.
Visualization on the learned θ .
To verify that the learned θ can capture the true change factors, we compute the pairwise distance between learned θ r at different time steps.
We randomly sample 10 time steps from the Half-Cheetah experiment with across-episode changes on reward functions.
Fig. 2(e) gives the pairwise distance of θ r among 5 time steps (from episode 148 , 279 , 155 , 159 , 230 ) with different target speed values ( 0 . 04 , 0 . 48 , 0 . 89 , 2 . 06 , 2 . 85 ), respectively.
We can find that there is a positive correlation between the distance of learned θ r and values of change factors.
Meanwhile, we also sample 5 time steps from episodes 31 , 188 , 234 , 408 with target values around 1 . 67 .
Fig. 2(f) shows that the distance of θ r among these 5 time steps is very small, indicating that the learned θ r are almost the same for the similar values of change factors at different time steps.
The visualization suggests that the learned θ can capture meaningful mappings from the time-varying factors.
Varying latent dimensions, non-stationary levels and functional forms.
Fig. 2(g) shows the normalized averaged return versus the number of two latent features on Half-Cheetah.
Our framework can learn a better policy with relatively smaller feature dimensions in the latent space than other approaches.
As we show in Appendix C.4, Saywer and Minitaur have the similar trend, where we learn a better policy than the baselines with fewer latent features.
We also vary the non-stationary levels in Half-Cheetah with discrete across-episode changes on both dynamics and rewards.
A higher non-stationary degree indicates a faster change rate.
Fig. 2(h) shows that FANS-RL achieves the highest return across all tested non-stationary degrees and that the gap increases with the nonstationarity.
We also test FANS-RL together with all baselines on different non-stationary functions, including piecewise linear, damping-like and sinusoid waves.
Fig.
2(i) displays the results, which indicate that FANS-RL can generally outperform the baselines on diverse non-stationary function forms.
Detailed function equations and experimental setups can be referred to Appendix C.
Multiple change factors We consider different numbers and types of changes to verify the benefits from the factored structure in FANS-RL.
We conduct experiments with 1) only change wind forces (1D); 2) change wind forces and gravity concurrently (2D); 3) change wind force and target speed (1D+1R); and 4) change wind force, gravity, and target speed together (2D+1R) in an across-episode way in Half-Cheetah.
From Fig. 2(j), we find that, thanks to the factored representation, FANS-RL performs better in those more complicated scenarios with multiple numbers and types of changes.
Related Work
Non-stationary RL.
Early works in non-stationary RL [27, 28] only detect changes that have already happened instead of anticipating them.
If the evolution of non-stationary environments is a (Semi)-Markov chain, one can deal with non-stationarity with HM-MDPs [29] or HS3MDPs [30].
Several methods learn to anticipate changes in non-stationary deep RL.
Chandak et al.
[31] propose to maximize future rewards without explicitly modeling non-stationary environments.
MBCD [32] uses change-point detection to decide if the agent should learn a novel policy or reuse previously trained policies.
Al-Shedivat et al.
[4] extend MAML [6] for the non-stationary setting, but do not explicitly model the temporal changes.
TRIO [5] tracks the non-stationarity by inferring the evolution of latent parameters, which captures the temporal change factors during the meta-testing phase.
ReBAL and
GrBAL [33] meta-train the dynamic prior, which adapts to the local contexts efficiently.
However, these methods have to meta-train the model on a set of non-stationary tasks, which may not be accessible in real-world applications.
Another line of research directly learns the latent representation to capture the non-stationary components.
In particular, LILAC [7] and ZeUS [8] leverage latent variable models to directly model the change factors in environments, and Guo et al.
[34] estimate latent vectors that describe the non-stationary or variable part of the dynamics.
Our approach fits in this line of work; however, as opposed to these methods, which model all temporal changes using a shared embedding space or a mixture models of dynamics, we use a factored representation.
Factored MDPs.
Among works on factored representations in stationary settings, Hallak et al.
[35] learn factored MDPs [11, 12, 13] to improve sample efficiency in model-based off-policy RL.
Balaji et al.
[36] employ known factored MDP to improve both model-free and model-based RL algorithms.
Working memory graphs [37] learn the factored observation space using Transformers.
NeverNet [38] factorizes the state-action space through graph neural networks.
Zholus et al.
[39] factorize the visual states into actor-related, object of manipulation, and the latent influence factor between these two states to achieve sparse interaction in robotic control tasks.
Differently from methods modeling the factored dynamics and rewards only, Zhou et al.
[40] and Tang et al.
[41] explore factored entities and actions, respectively.
Zhou et al.
[40] extend the factored MDP to the multi-entity environments, learning the compositional structure in tasks with multiple entities involved.
Tang et al.
[41] leverage the factored action space to improve the sample efficiency in healthcare applications.
However, the factored structures in these two works are derived from inductive bias or domain experts.
Factored MDPs, causality and multiple environments.
Several works leverage factored MDPs to improve the sample efficiency and generalization of RL.
Most of these works focus on learning an invariant (e.g. causal) representation that fits all environments and do not support learning latent change factors.
For example, AFaR [42] learns factored value functions via attention modules to improve sample efficiency and generalization across tasks.
Mutti et al.
[43] learn a causal structure that can generalize across a family of MDPs under different environments, assuming that there are no latent causal factors.
Similarly, Wang et al.
[44] propose to learn the factored and causal dynamics in model-based RL, in which the learned causal structure is assumed to generalize to unseen states.
By deriving the state abstraction based on the causal graph, it can improve both the sample efficiency and generalizability of policy learning of MBRL.
While most of the previous works focus on learning a causal structure that is time-invariant, Pitis et al.
[45] learn a locally causal dynamics that can vary at each timestep and use it to generate counterfactual dynamics transitions in RL.
While the previously described methods focus on a domain or time-invariant representations, in our work we also focus on modelling domain or time-specific factors in the form of latent change factors.
A related work,
AdaRL [14] learns the factored representation and the model change factors under heterogeneous domains with varying dynamics or reward functions.
However, AdaRL is designed only for the domain adaptation setting and constant change factors without considering non-stationarity.
Independent causal mechanisms.
Another related line of work is based on independent causal mechanisms [46, 47].
Recurrent independent mechanisms (RIMs) [48] learn the independent transition dynamics in RL with sparse communication among the latent states.
Meta-RIMs [49] leverage meta-learning and soft attention to learn a set of RIMs with competition and communication.
As opposed to these works, we do not assume that the mechanisms are independent and we learn the factored structure among all components in MDPs with a DBN.
Conclusions, Limitations and Future Work
We describe Factored Adaptation for Non-Stationary RL (FANS-RL), a framework that learns a factored representation for non-stationarity that can be combined with any RL algorithm.
We formalize our problem as a Factored Non-stationary MDP (FN-MDP), augmenting a factored MDP with latent change factors evolving as a Markov process.
FN-MDPs do not model a family of MDPs, but instead include the dynamics of change factors analogously to the dynamics of the states.
This allows us to capture different non-stationarities, e.g., continuous and discrete changes, both within and across different episodes.
To learn FN-MDPs we propose FN-VAEs, which we integrated in
FANS-RL, an online model estimation and policy evaluation approach.
We evaluate FANS-RL on benchmarks for continuous control and robotic manipulation, also with pixel inputs, and show it outperforms the state of the art on rewards and robustness to varying degrees of non-stationarity.
Learning the graph in model estimation is computationally expensive, which limits the scalability of our approach.
In future work, we plan to meta-learn the graphs among different tasks to improve the scalability of our approach and its applicability to complex RL problems, e.g., multi-agent RL.
Acknowledgments
FF would like to acknowledge the CityU High-Performance Computing (HPC) resources in Hong
Kong SAR and LISA HPC from the SURF.nl.
SM was supported by the MIT-IBM Watson AI Lab and the Air Force Office of Scientific Research under award number FA8655-22-1-7155.
BH would like to acknowledge the support of Apple Scholarship.
KZ was partially supported by the National
Institutes of Health (NIH) under Contract R01HL159805, by the NSF-Convergence Accelerator
Track-D award #2134901, by a grant from Apple Inc., and by a grant from KDDI Research Inc.
Appendix for Factored Adaptation for Non-Stationary Reinforcement Learning A Broader Impact
Our work is a first exploration in leveraging factored representations for non-stationary RL in order to improve adaptation.
One of the limitations of our current approach, and similarly to a few other non-stationary RL approaches, is that we do not provide theoretical guarantees in terms of adapting to non-stationarity.
This limits the applicability of these approaches in safety-critical applications, e.g. self-driving cars, or in adversarial environment.
One of the future directions of this work would be to provide theoretical guarantees under reasonable assumptions, similarly to generalization bounds for factored representations for fast domain adaptation [14].
Based on the application, there might be different assumptions or inductive biases that might be considered reasonable.
Since our work leverages insights from recent causality literature [9], we also inherit the same inductive bias in terms of assuming there is an underlying causal structure that is time-invariant throughout the non-stationarity.
In our current method, this causal structure is estimated in the model estimation phase as one of the first steps of the algorithm.
After this estimation, there can still be changes in the functional dependencies between the various components, but we assume there are no new edges/causal relations between components that were previously disconnected, or new forms of non-stationarity, in terms of connections between the change factor components and the state dimensions or reward.
For example, if we consider Halfcheetah-v3 with a change in gravity and estimate a model that can handle this type of non-stationarity, our method will not be able to perform well under a new type of non-stationarity (e.g. change of wind forces) that was not observed during model estimation.
An interesting extension of our work would be designing ways to efficiently detect changes in the causal structure and adapt the model.
As is the case with other works in causal discovery, we also make some standard assumptions to recover the causal graph from time series observational data.
In particular, we assume that there are no other unobserved confounders, except for the change factors, and that there are no instantaneous causal effects between the state components, which is implied by our definition of an FN-MDP and its Dynamic Bayesian Network.
In practical applications, this means that we are able to measure all the relevant causal variables and we are measuring them at a rate that is faster than their interaction.
Additionally, in our identifiability proofs, we assume the causal Markov and faithfulness assumptions [50], which provide a correspondence between conditional independences and d-separations in the graph.
The faithfulness assumption can be violated for example in case of deterministic relations, thus requiring a careful modelling of the system.
In general, if these assumptions are violated, the causal structure we learn might be incorrect, and therefore the factored representation might not be beneficial to adapt to non-stationarity.
A future direction would be to relax some of the current assumptions to provide a more realistic and flexible framework for factored non-stationary RL.
B Proofs and Causality Background B.1 Preliminaries B.1.1 Dynamic Bayesian networks
Dynamic Bayesian networks (DBNs) [51] are the extensions of Bayesian networks (BN), which model the time-dependent relationship between nodes (See an example in Fig.
A1(b)).
The unfolded
DBNs can be represented as BNs.
The variables in DBNs are in discrete time slices and dependent on variables from the same and previous time slices.
Hence, the DBNs can model the stationary process repeated over the discrete time slices.
xx
[Equation]
x
[Equation]
x
[Equation]
x t − x t − x t − x t − x tx tx tx t
[Figure]
B.1.2 Markov and faithfulness assumptions
Given a directed acyclic graph G =
( V , E ) , where V is the set of nodes and E is the set of directed edges, we can define a graphical criterion that expresses a set of conditions on the paths.
Definition 2 (d-separation
A path p is said to be blocked by a set of nodes
Z ⊆ V if and
only if (1) p contains a chain i → m → j or a fork i ← m → j such that the middle node m is in Z , or (2) p contains a collider i → m ← j such that the middle node m is not in Z and such that no descendant of m is in Z .
Let X , Y , and Z be disjunct sets of nodes.
Z is said to d-separate X from Y (denoted as X ⊥ d Y | Z ) if and only if Z blocks every path from a node in X to a node in Y .
Definition 3 (Global Markov Condition [50, 52]) .
A distribution P over V satisfies the global
Markov condition on graph G if for any partition ( X, Z, Y ) such that X is d-separated from Y given
Z , i.e. X ⊥ d Y | Z the distribution factorizes as:
[Equation]
In other words, X is conditionally independent of Y given Z , which we denote as X ⊥⊥ Y | Z .
Definition 4 (Faithfulness Assumption [50, 52]) .
There are no independencies between variables that are not entailed by the Markov Condition.
If we assume both of these assumptions, then we can use d-separation as a criterion to read all of the conditional independences from a given DAG G .
In particular, for any disjoint subset of nodes
[Equation]
B.2 AdaRL summary
Our work extends the factored representation for fast policy adaptation across domains introduced in
AdaRL [14], which we summarize here.
While Huang et al.
[14] propose a general framework that can be applied to both MDPs and POMDPs, in this work we focus on MDPs, so we only present the simplified version of AdaRL for MDPs.
The simplified AdaRL setting considers n source domains and n ′ target domains.
The state at time t is represented as s t =
( s 1 ,t , · · · , s d,t ) ⊤ ∈ S d , while a t ∈ A m is the executed action and r t ∈ R is the reward signal.
The generative process of the environment in the k -th domain with k = 1 , ... , n + n ′ can be described in terms of the transition function for each dimension i = 1 , ... , d of s t as:
[Equation]
where ⊙ denotes the element-wise product.
The binary mask c s (cid:41) s i ∈ { 0 , 1 } d represents which of the state components s j,t − 1 are used in the transition function of s i,t .
Similarly, c a (cid:41) s i ∈ { 0 , 1 } m is a mask that indicates whether the action directly affects s i,t .
The change factor θ s k ∈ R p is the only parameter that depends on the domain k in Eq.
and it encodes any change across domains in the dynamics.
The binary mask c θ k (cid:41) s i ∈ { 0 , 1 } p represents which of the θ s k components influence the s i,t .
Finally, ϵ si,t is an i.i.d.
random noise.
Similarly the reward function is modeled as:
[Equation]
where c s (cid:41) r i ∈ { 0 , 1 } d , c a
[Equation]
s i ∈ { 0 , 1 } m , and ϵ rt is an i.i.d.
random noise.
The change factor θ rk ∈ R q is the only parameter that depends on the domain k in Eq.
A2 and it encodes any change in the reward function.
In this simplified setting, the binary masks c · (cid:41) · can be seen as indicators of edges in a
Dynamic Bayesian Network (DBN).
Under Markov and faithfulness assumptions, i.e., assuming the conditional independences in the data and d-separations in the true underlying graph coincide, the edges in the graph can be uniquely identified.
This means one can learn the true causal graph representing jointly all of the environments, even if the change parameters are latent.
In the general AdaRL framework, the representation is learned via a combination of a state prediction network (to estimate the various f i ) and a reward prediction network (to estimate h ).
All binary masks c · (cid:41) · and change factors θ · k are trainable parameters.
All change factors θ · k are assumed to be constant in each domain k .
If the inputs are pixels, another encoder is added to infer the symbolic states, forming a Multi-model Structured Sequential Variational Auto-Encoder (MiSS-VAE) .
MiSS-VAE leverages the generative modeling to learn the data generation process in RL system with multiple domains.
All change factors in MiSS-VAE are modeled by constants in each domain.
This setting is not suitable for non-stationary RL where the change factors evolve over time.
In general, not all of the dimensions of the learned state and change factor vectors are useful in policy learning.
Huang et al.
[14] select a subsection of dimensions which are essential for policy optimization.
Leveraging the learned representation as a DBN, we can select compact states and CFs as having a directed path to a reward:
[Equation]
B.3 Proofs
Proposition 3 (Identifiability with observed change factors) .
Suppose all the change factors θ s t and θ r t are observed, i.e., Eq. 1-3) is an MDP.
Under the Markov and faithfulness assumptions, all the binary masks C · (cid:41) · are identifiable.
Proof.
We construct the graph in the Factored Non-stationary MDP as a dynamic Bayesian network (DBN) G over the variables
V MDP
=
{ s 1 ,t − 1 , . . .
, s d,t − 1 , s 1 ,t , . . . , s d,t , a 1 ,t − 1 , . .
. , a m,t − 1 , r t − 1 } , and the change factors V
[Equation]
In this setting, we can always the correct causal graph under the Markov and faithfulness assumptions.
We rewrite the time index of r t − 1 as r t .
We could rewrite also the change factors time indices by shifting them back in time by one step, i.e. t → t − 1 , and this would allow us to model the whole setup as a Markov DBN without any instantaneous effect.
In this setup, we can leverage existing results to show that the true causal graph is asymptotically identifiable from conditional independences in a time-series without any unobserved confounders or instantaneous effects [53].
In order to make our proof clearer, we instead show step by step how we can recover the parts of the graph related to V MDP , to V θ and finally the connections between them.
In this setting, there are no instantaneous effects except for the change factors, and the only causal parents for a variable that is not a change factor at time t can be in the previous time-step t − 1 .
In particular, as in usual MDPs, these are the only allowed edges:
state dimension s i,t − 1 at time t − 1 to state dimension s j,t at time t , for i, j ∈ { 1 , . . .
, d } (this includes the case in which i = j ); 2.
action dimension a k,t − 1 at time t − 1 to state dimension a j,t at time t , for j ∈ { 1 , . . .
, d } , k ∈ { 1 , . . .
, m } ; 3.
state dimension s i,t − 1 at time t − 1 to reward r t at time t , for i ∈ { 1 , . . .
, d } , k ∈ { 1 , . . .
, m } ;
action dimension a k,t − 1 at time t − 1 to reward r t at time t , for k ∈ { 1 , . . .
, m } ;
and in addition we have some extra knowledge about the allowed edges to and from change factors, as expressed in our generative model in Equations (1-3):
transition change factor dimension θ si,t at time t to state dimension s j,t at time t , for i ∈ { 1 , . .
. , p } , j ∈ { 1 , . .
, d } ; 2.
transition change factor dimension θ si ,t at time t to transition change factor dimension θ sj,t + at time t + 1 , for i, j ∈ { 1 , . .
. , p } ; 3.
reward change factor dimension θ ri ,t at time t to reward change factor dimension θ rj,t +1 at time t + 1 , for i, j ∈ { 1 , . .
. , q } ;
For the reward change factors, we assume they are fully connected to the reward, as shown in Eq.
Using this background knowledge, we can learn the edges from any other variable V i,t − 1 → V j,t , for V i,t − 1 , V j,t ∈ V MDP , just by checking if V i,t − 1 ̸⊥⊥ V i,t | θ rt , θ st , s t − 2 , a t − 2 .
This dependence implies that the variables are d-connected, under the Markov and faithfulness assumptions.
Except for a direct edge, there is no other possible path through the graph unrolled in time, since we have blocked all influence of time-step t − 2 and earlier, and the paths through future time-steps contain colliders.
So this means that V i,t − 1 and V j,t are adjacent, and in particular the edge follows the arrow of time, from t − 1 to t .
In our setting, we do not model the actions at time t , since we assume they are not caused by any other variable.
We also never need to condition on the reward to check if two variables are adjacent, since it’s always on a collider path.
This means we are able to learn the following binary masks:
state dimensions to state dimensions C s (cid:41) s ; 2. action dimensions to state dimensions C a (cid:41) s ; 3.
state dimensions to reward c s (cid:41) r 4.
action dimensions to reward c a (cid:41) r ;
To learn the edges between any change factor component to another change factor component, i.e.,
V i,t − 1 → V j,t for V
i,t − 1 , V j,t ∈ V θ , we can just check if V i,t − 1 ̸⊥⊥ V i,t | θ rt − 2 , θ st − 2 , since states, actions and rewards can never be parents of the change factors, so we do not need to condition on them to close any path through the earlier time-steps.
We also assumed that change factor components follow a Markov process, so they do not have instantaneous effects towards each other.
This means we are able to learn the following masks:
transition change factor dimensions to transition change factor dimensions C θ s (cid:41) θ s ; 2.
reward change factor dimensions to reward change factor dimensions C θ r (cid:41) θ r ;
Finally to learn the edges between the change factors V i,t ∈ V θ
and the other variables V j,t ∈ V MDP , we can just check if V i,
[Equation]
̸⊥⊥ V j,
[Equation]
| s
[Equation]
, a
[Equation]
1 , θ rt − 1 , θ st
[Equation]
1 and if this is true we can learn the edge V i,t → V j,t .
This means we are able to learn the mask:
transition change factor dimensions to state dimensions
C θ s (cid:41) s ;
All of these results together show that if we have the Markov and faithfulness assumption, i.e. the conditional independence tests return the true d-separations in the graph, and we observe the change factors, we are able to completely identify the graph of the FN-MDP represented by the binary masks.
Proposition 4 (Partial Identifiability with latent change factors) .
Suppose the generative process follows Eq.
1-3 and the change factors θ s t and θ r t are unobserved.
Under the Markov and faithfulness assumptions, the binary masks C s (cid:41) s , C a (cid:41) s , c s (cid:41) r and c a (cid:41) r .
Moreover, we can identify which state dimensions are affected by θ s t and if the reward function changes.
Proof.
In this case, the MDP is non-stationary, since we cannot observe the latent change factors.
We assume that we can represent the latent change factors as a smooth function of the observed time index t .
This assumption is called pseudo-causal sufficiency in previous work [9].
We can then use the time index t as a surrogate variable to characterize the unobserved change factors, since at each time-step their value will be fixed.
We again consider a
[Equation]
over the variables
[Equation]
and the time index t .
We rewrite the time index of r t − 1 as r t .
Note that we do not represent the change factors in this DBN, but we can capture their effect through t since they are assumed to be deterministic smooth functions of the time index.
We can then reuse the results by Huang et al.
[9] (Theorem 1) in which under the pseudo-causal sufficiency (Assumption 1 in that paper) and the Markov and faithfulness assumption (Assumption 2), one can asymptotically identify the true causal skeleton (i.e. the adjacencies) in the graph G MDP ∪{ t } ) through conditional independence tests.
In particular for any V i , V j ∈ V MDP ∪ { t } , V i and V j are not adjacent if there exists a subset of the unrolled graph V k of V MDP ∪{ t } \ { V i , V j } in G MDP ∪{ t } such that V
i ⊥⊥ V j | V k .
In particular, we can also focus on the tests that were used for the proof of the previous Proposition, by just substituting the change factors with the time index t .
The skeleton is the undirected version of the causal graph, so this result only tells us that can asymptotically get the correct undirected edges, but not their orientations.
Fortunately, in our setting we have some additional background knowledge that allows us to orient all the existing edges.
In particular, as in usual MDPs, these are the only allowed edges:
state dimension s i,t − 1 at time t − 1 to state dimension s j,t at time t , for i, j ∈ { 1 , . . .
, d } (this includes the case
in
which i = j ); 2.
action dimension a k,t − 1 at time t − 1 to state dimension a j,t at time t , for j ∈ { 1 , . . .
, d } , k ∈ { 1 , . . .
, m } ; 3.
state dimension s i,t − 1 at time t − 1 to reward r t at time t , for i ∈ { 1 , . . .
, d } , k ∈ { 1 , . . .
, m } ; 4.
action dimension a k,t − 1 at time t − 1 to reward r t at time t , for k ∈ { 1 , . . .
, m } ;
This means that, for example, we cannot have a variable at time t causing a variable at time t − 1 .
Therefore if two variables V i,t − 1 and V j,t are adjacent, we already know that the direction of that edge will be V i,t − 1 → V j,t .
This also implies that the following binary masks are identifiable (i.e. no edge remains unoriented):
state dimensions to state dimensions C s (cid:41) s ; 2. action dimensions to state dimensions C a (cid:41) s ; 3.
state dimensions to reward c s (cid:41) r 4.
action dimensions to reward c a (cid:41) r ;
These represent all of the edges in G MDP .
We can also learn the edges from t to V MDP (by construction we assume the opposite direction is not possible), which will represent the effect of the change factors, as we show in the following.
Since t inherits all of the children of the latent change factors in G , we can further show that if s i,t ⊥⊥ t | s t − 1 , a t − 1 in G , then none of the latent change factor dimensions θ sj,t affect s i,t , i.e.,
[Equation]
= 0 .
Intuitively, this means that the distribution of s i,t only depends on s t − 1 and a t − 1 , and not on the timestep t , or in other words, this distribution is stationary.
Under the same principle, if r t ⊥⊥ t | s t , a t , then the reward is stationary.
C Details on Experimental Designs and Results
C.1 MuJoCo
We modify the Half-Cheetah environment into a variety of non-stationary settings.
Details on the change factors are given as below.
Changes on dynamics.
We change the wind forces f w in the environment.
We consider the changing functions can be both continuous and discrete.
• Continuous changes: f wt = 10 + 10 sin(0 .
005 · t ) , where t is the timestep index; • Discrete changes: (1) Across-episode: a. Sine function: f w = 10 + 10 sin(0 .
5 · i )
b. Damping-like function: f w = 10 + 3 · (1 . 01) −⌈ i/ 10 ⌉ sin(0 .
5 · i )
c. Piecewise linear function f w = 5 + 0 .
02 · ∥ i − 1500 ∥ ; , where i is the episode index.
(2) Within-episode: f w = 10 + 10 sin(0 .·
⌊ t/ 10 ⌋ ) , where t is the timestep index.
We also consider a special case where the agent’s mechanism is changing over time.
Specifically, the one random joint is disabled at the beginning of each episode.
Changes on reward functions.
To introduce non-stationarity in the rewards, we change the target speed v g in each episode.
To make the learning process stable, we only consider the discrete changes and the change points are located at the beginning of each episode.
The changing function is v g = 1 .
5 + 1 . 5 sin(0 .
2 · i ) , where i denotes the episode index.
Changes on both dynamics and rewards.
We consider a more general but challenging scenario, where the changes on dynamics and rewards can happen concurrently during the lifetime of the agents.
We change the wind forces and target speed at the beginning of each episode.
At episode i , the dynamics and reward functions are:
[Equation]
Here, w is the non-stationary degree.
We consider multiple values of w in our experiments.
In
Fig. 2(d), w = 0 .
In Fig. 2(h), w is the value of non-stationary degree.
C.2 Sawyer benchmarks
In Sawyer-Reaching, the sawyer arm is trained to reach a target position s gt .
The reward r t is the difference between the current position s t and the target position r t = − ∥ s t − s g ∥ 2 .
In this task, we cannot directly modify the dynamics in the simulator, so consider a reward-varying scenario, where the target location changes across each episode following a periodic function.
In Sawyer-Peg, the robot arm is trained to insert a peg into a designed target location s g .
The reward function is r t
= I ( ∥ s t − s g ∥ 2 ≤ 0 . 05) .
We change the target location in Sawyer reaching task.
The target location s gt is given as below:
[Equation] [Equation]
cos
[Equation]
2 · i )
[Equation] [Equation]
sin
[Equation] [Equation]
where i is the episode index.
For Sawyer-Peg task, the target location s g changes at each episode.
The parameters in each dimension of s g is randomly sampled at episode i as below:
• x_range_1: (0 . 44 , 0 . 45) ; • x_range_2: (0 . 6 , 0 . 61) ; • y_range_1: ( − 0 .
08 , − 0 .
; • y_range_2: (0 . 07 , 0 . 08) ;
C.3 Minitaur benchmarks
We consider both the changes on dynamics and reward functions.
Changes on dynamics.
We change the mass of taur m in the environment.
Specifically, we consider both the continuous and discrete changes.
• Continuous changes: m t = 1 .
+ 0 .
75 sin(0 .
005 · t ) ; • Discrete and within-episode changes: m t = 1 .
+ 0 .
75 sin(0 .
3 · ⌊ t/ 20 ⌋ )
Changes on both dynamics and reward functions.
We also consider a case where both the dynamics and reward functions change at the beginning of each episode.
We change the target speed of minitaur to introduce the non-stationarity of reward functions.
The change functions are given below:
[Equation]
C.4 Full results
Fig.
A2 and A3 give the smoothed learning curves on average return over 10 runs versus timesteps in Half-Cheetah and Minitaur experiments.
Table C.4 shows the average final return over 10 runs for all experiments.
Fig.
A4 demonstrates the return on Half-Cheetah with different non-stationary degrees on multi-factor changing scenario.
Fig.
A5 gives average return on different benchmarks with varying numbers of latent features with all evaluated approaches.
[Figure] [Figure]
[Figure] [Figure]
Steps (
[Figure]
n
[Figure] [Figure]
[Table]
Nonstationary degrees 0 .0 .0 .1 .
R e
[Figure]
Latent features 0 .0 .0 .0 .1 .
R e w a r d s     #.
Latent features 0 .0 .0 .0 .1 .
R e w a r d s     #.
Latent features 0 .0 .0 .1 .
R e w a r d s (a) (b) (c)     #.
Latent features 0 .0 .0 .1 .
R e w a r d s     #.
Latent features 0 .0 .0 .0 .1 .
R e w a r d s   #.
Latent features 0 .0 .0 .1 .
R e w a r d s (d) (e) (f)    #.
Latent features 0 .0 .1 .
R e w a r d s    #.
Latent features 0 .0 .0 .0 .1 .
R e w a r d s    #.
Latent features 0 .0 .0 .1 .
R e w a r d s (g) (h) (i)
Ours
LILAC
VariBAD
TRIO #.
Latent features #. Latent features #.
Latent features #. Latent features #.
Latent features #. Latent features #.
Latent features #. Latent features #.
Latent features
R e
[Table]
u r n
[Table]
R e t u r n
R
[Table]
u r n
R e t u r n R e t u r n
R e t u r n R e t u r n
[Figure]
To verify the effectiveness of each component in our proposed framework
[Figure]
we consider the following ablation studies:
• Without smoothness loss ( L smooth ); • Without structural relationships ( C · (cid:41) · ); • Without compact representations ( s min , θ min );
• Without sparsity losses ( L sparse ); • Without reward or state prediction losses ( L pred-rw , L pred-dyn ); • Without the disentangled design of CF inference networks for dynamics ( q sϕ ) and rewards ( q rϕ ).
Specifically
[Table]
we use one CF inference encoder and the mixed latent space of θ s and θ r in this setting.
As shown in Fig.
A
[Table]
all the studied components benefit the performance.
Furthermore, FANS-RL can still outperform the strong baselines even without some of the components.
We also test different smoothness losses, including the moving average (MA) L smooth
[Equation]
) and exponential moving average
(EMA) L
[Equation]
1 ) , where v t = βθ t
+ (1 − β ) v t − 1 and v 0 is a zero vector.
Table C.5 shows the normalized final results of using different smoothness losses.
We can find that different smoothness losses have comparable performances.
[Table]
C.6 Visualization on the learned change factors
Fig.
A7 gives the visualization on the learned θ in Half-Cheetah.
Fig.
A7(a-b) show the pairwise
Euclidean distance between learned θ r and the axes denote the values of change factors on rewards.
Similarly, Fig.
A7(c-d) displays the Euclidean distance between learned θ s and the values of change factors on dynamics.
The results suggest that there is a positive correlation between the distance of learned θ versus the true change factors.
This can verify that θ can capture the change factors in the system.
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
D Details on the Factored Adaptation Framework
D.1 Algorithm pipelines of FN-VAE Alg.
A1 gives the full pipeline of FN-VAE.
D.
The framework dealing with discrete and across-episode changes
Input
Output:
, α α β β 2 , γ for i = 1 , 2 , . .
, E do
Randomly sample a batch of trajectories τ 0: k in τ # Infer the latent change factors for j = s, r do
Infer µ ϕ j ( τ 0: k ) and σ 2 ϕ j ( τ 0: k ) using q ϕ j
Infer µ γ j ( θ j 0: k ) and σ 2 γ j ( θ j 0: k ) using p γ j
Sample θ j 0: k ∼ N (cid:16) µ ϕ j ( τ 0: k ) , σ 2 ϕ j ( τ 0: k ) (cid:17) end for
Reconstruct and predict ˆ s 0: k , ˆ s 1: k , ˆ r 0: k , ˆ r 1: k using p α 1 , p α 2 , p β 1 , and p β 2 # Update the FN-VAE model
[Equation]
[Equation] [Equation]
← α − λ
[Equation]
∇
[Equation]
( L
[Equation]
+ L
[Equation]
β ← β − λ β ∇ β ( L rec-rw + L pred-rw ) if updateG then
G ← G − λ G ∇ G ( L rec-dyn + L rec-rw + L KL + L sparse ) end if end for
Alg.
A2 gives the extended framework for handling both across- and within-episode changes in non-stationary RL, respectively.
The major difference between Alg. A2 and Alg. 1 is that we only infer θ using via CF dynamics networks at change points.
Furthermore, we also adjust the objective functions of FN-VAE to fit the discrete changes.
At timestep t in episode n , where t m ≤ (cid:0) ( n − 1) · H + t (cid:1) <
t m +1 , we have:
• Prediction and reconstruction losses:
[Equation]
• KL loss:
[Equation]
• Sparsity loss:
[Equation]
1: Init: Env; VAE parameters: ϕ = ( ϕ s , ϕ r ) , α = ( α 1 , α 2 ) , β = ( β 1 , β 2 ) ,
; Mask matrices: C
Policy parameters: ψ ; replay buffer: D ; Number of episodes: N ; Episode horizon: H ; Change index ˜ t
= { t 1 , . . .
, t M } ; m = 0 .
2: Output: ϕ , α 1 , α 2 , β 1 , β 2 , γ , ψ 3: # Model initialization 4: Collect multiple trajectories τ = { τ 10: k , τ 20: k , . . .
} with policy π ψ from Env; 5: Learn an initial VAE model on τ (Alg.
A1) 6:
Identify the compact representations s min and change factors θ min based on C · (cid:41) · 7:
# Model estimation & policy learning
8: for n = 0 , . . .
, N − 1 do 9: for t = 0 , . . .
, H − 1 do 10:
Observe s t from Env; 11:
# Estimating
latent change factors
12: if n · ( H − 1) + t ∈ ˜ t then 13: m ← m + 1 14: for j = s, r do 15:
Infer µ γ j ( θ jt m − 1 ) and σ 2 γ j ( θ jt m − 1 ) via p γ j 16:
Sample θ jt m ∼ N (cid:16) µ γ j ( θ jt m
[Equation]
1 ) , σ 2 γ j ( θ jt m − 1 ) (cid:17) 17: end for 18: end if 19:
Generate a t ∼ π ψ ( a t
| s mint , θ mint m ) 20:
Receive r n,t from Env 21:
Add ( s t , a t , r t , θ st m , θ rt m ) to replay buffer D ; 22:
Extract a trajectory with length k from D ; 23:
Learn VAE (Alg. A1) with updateG=
False; 24:
Sample a batch of data from D
Update policy network parameters ψ 26: end for 27: end for
• Smoothness loss:
[Equation]
The total loss L vae = k 1 L rec + k 2 L pred − k 3 L KL − k 4 L sparse − k 5 L smooth , where k 1 , k 2 , k 3 , k 4 , and k 5 are adjustable hyper-parameters to balance the objective functions.
D.3 The framework dealing with raw pixels
We augment the generative process in Eq.
1-3 with the generative process of observation.
[Equation]
where u is a non-linear function and i = 1 , .
, d .
c s
[Equation]
o :=
[ c s
[Equation]
o i ] di =1 .
ϵ ot is an i.i.d.
random noise.
To learn the u i , we model the states as the latent variables in FN-VAE.
Fig.
A8 gives the modified
FN-VAE dealing with raw pixels, where the states are also in the latent space.
Different from the original FN-VAE, we incorporate state inference networks and state dynamics networks.
Moreover, we reconstruct and predict the current and future observations using the observation decoder.
Detailed objective functions are given below.
• Prediction and reconstruction losses
c s → r c a → r θ rt p α̂ o t + ̂ r t +1 p β̂ r t p βp γ s ̂ o t p α
C θ r → θ r a t + c s → o θ s t
C θ s → θ s s t θ rt + p
α̂ o t + ̂ r t +2 p
β̂
r t +1 p βp αc s → o c s → r c a → r a t + a t + ̂ o t + θ s t
+1 s t
+ p γ r
C s → s , θ s t , a t p γ o a t q sϕ h s t o t a t r t q rϕ h rt q oϕ o t +1 a t +1 r t + q sϕ q rϕ q oϕ h o t
[Figure]
[Equation]
(A10)
KL loss
[Equation]
where τ 0: t = { o 0 , r 0 , o 1 , r 1 , . . .
, o t , r t } .
• Sparsity loss
[Equation]
• Smooth loss
[Equation]
Steps (M) °°°
R e w a r d s
Ours
ZeUS (best)
ZeUS ( ﬁ nal)
Meld (best)
Meld ( ﬁ nal)
CaDM (best)
CaDM ( ﬁ nal)
HyperDynamics (best)
HyperDynamics ( ﬁ nal)
R e t u r n #.
Steps (M)
D.4 Hyper-parameter selection D.4.1 Factored model estimation
Input with symbolic states.
In Half-Cheetah, Sawyer-Reaching, and Minitaur the symbolic states are observable.
For the CF dynamic networks, we use 2 -layer fully connected networks.
The number of neurons is 512 .
For CF inference networks, we use 2 -layer fully connected networks, where the number of neurons is 256 , followed by the LSTM networks with 256 hidden units.
The initial learning rates for all losses are set to be 0 .
1 with a decay rate 0 .
The batch size is 256 and the length of time steps is equal to the horizon in each task.
The number of RNN cells is 256 .
The decoder networks are 2 -layer fully connected networks.
The number of neurons is 512 .
Input with raw pixels.
In Saywer-Peg, we directly learn and adapt in non-stationary environments with raw pixels observed.
Different from other experiments, we use the architecture described in
Fig.
A8.
At timestep t , we stack 4 frames as the input o t .
A 5 -layer convolutional networks is used to extract the features of the trajectories of observations and rewards.
The layers have 32 , 64 , 128 , 256 , and 256 filters.
And the corresponding filter sizes are 5 , 3 , 3 , 3 , 4 .
The observation decoders are the transpose of the convolutional networks.
Then the extracted features are used as the input of LSTM networks in state inference networks.
The state inference networks and state dynamic networks share the same architectures with the CF inference and dynamics networks, respectively.
We use the same CF inference networks, CF dynamics networks, and reward decoders with those in cases with symbolic states as input.
The number of latent features is 40 .
Balancing parameters in losses For all experiments:
• All w · are set to be 0 . 1 ; • Weights of the reconstruction loss: k 1 = 0 . 8 ; • Weights of the prediction loss: k 2 = 0 . 8 ; • Weights of KL loss: k 3 = 0 . 5 ; • Weights of sparsity loss: k 4 = 0 . 1 ;
• Weights of smooth loss: k 5 = 0 .
We use the automatic weighting method in [16] to learn the weights for k 1 , . .
, K 5 and grid search for w 1 , . .
w 7 .
Model initialization.
Table A3, A4, and A5 provide the settings of learning the model initialization.
[Table] [Table]
[Table]
D.4.2 Policy learning
In the Half-Cheetah, Sawyer-Reaching, and Minitaur experiments, we follow the learning rates selection for policy networks in [7].
In Sawyer-Peg, for both actor and critic networks, we use 2 -layer fully-connected networks.
The number of neurons is 256 .
For all experiments, we use standard
Gaussian to initialize the parameters of policy networks.
The learning rate is 3 e − 4 .
The relay buffer capacity is 50 , 000 .
The number of batch size is 256 .
Details on TRIO and VariBAD.
For TRIO and VariBAD, we meta-train the models (batch size: 5000, # epochs: 2 for all experiments) and show the learning curves of meta-testing.
The tasks parameters for meta-training are uniformly sampled from a Gaussian distribution.
For all approaches, we use the same set of hyper-parameters for policy optimization modules (i.e., SAC).
For the latent parameters in TRIO, we follow the original paper where the latent space from the inference network is projected to a higher dimension.
The number of latent parameters for TRIO is the same as those in other approaches (Half-Cheetah and Minitaur: 40 , Sawyer-Reaching: 20 ).
We compared with
TS-TRIO, with the kernels set as in the original implementation.
E Experimental Platforms and Licenses E.1 Platforms
All methods are implemented on 8 Intel Xeon Gold 5220R and 4 NVidia V100 GPUs.
E.2 Licenses
In our code, we have used the following libraries which are covered by the corresponding licenses:
• Tensorflow (Apache License 2.0), • Pytorch (BSD 3-Clause "New" or "Revised" License), • OpenAI Gym (MIT License), • OpenCV (Apache 2 License), • Numpy (BSD 3-Clause "New" or "Revised" License) • Keras (Apache License).