Behavior Alignment via Reward Function Optimization
Dhawal Gupta [∗] Yash Chandak [∗†] Scott M. Jordan [†] University of Massachusetts Stanford University University of Alberta
Philip S. Thomas Bruno Castro da Silva University of Massachusetts University of Massachusetts
Abstract
Designing reward functions for efficiently guiding reinforcement learning (RL) agents toward specific behaviors is a complex task. This is challenging since it requires the identification of reward structures that are not sparse and that avoid inadvertently inducing undesirable behaviors. Naively modifying the reward structure to offer denser and more frequent feedback can lead to unintended outcomes and promote behaviors that are not aligned with the designer’s intended goal. Although potential-based reward shaping is often suggested as a remedy, we systematically investigate settings where deploying it often significantly impairs performance. To address these issues, we introduce a new framework that uses a bi-level objective to learn behavior alignment reward functions . These functions integrate auxiliary rewards reflecting a designer’s heuristics and domain knowledge with the environment’s primary rewards. Our approach automatically determines the most effective way to blend these types of feedback, thereby enhancing robustness against heuristic reward misspecification. Remarkably, it can also adapt an agent’s policy optimization process to mitigate suboptimalities resulting from limitations and biases inherent in the underlying RL algorithms. We evaluate our method’s efficacy on a diverse set of tasks, from small-scale experiments to high-dimensional control challenges. We investigate heuristic auxiliary rewards of varying quality— some of which are beneficial and others detrimental to the learning process. Our results show that our framework offers a robust and principled way to integrate designer-specified heuristics. It not only addresses key shortcomings of existing approaches but also consistently leads to high-performing solutions, even when given misaligned or poorly-specified auxiliary reward functions.
1 Introduction
In this paper, we investigate the challenge of enabling reinforcement learning (RL) practitioners, who may not be experts in the field, to incorporate domain knowledge through heuristic auxiliary reward functions. Our goal is to ensure that such auxiliary rewards not only induce behaviors that align with the designer’s intentions but also allow for faster learning. RL practitioners typically model a given control problem by first designing simple reward functions that directly quantify whether (or how well) an agent completed a task. These could be, for instance, functions assigning a reward of +1 iff the agent reaches a specified goal state, and zero otherwise. However, optimizing a policy based on such a sparse reward function often proves challenging.
∗ Both authors contributed equally to this work. † Work done while at the University of Massachusetts. Corresponding author: Dhawal Gupta (dgupta@cs.umass.edu).
37th Conference on Neural Information Processing Systems (NeurIPS 2023).
Figure 1: Auxiliary rewards can be used to convey to the agent how we (designers) think it should solve the problem. However, if not carefully designed, they can lead to policies that result in undesired behaviors. This figure provides a visual illustration of a toy example depicting how the proposed method works. The star represents the optimal policy, and the red dot represents the fixed point of a policy optimization process under a “sub-optimal” heuristic; i.e., one that, when naively combined with rp, induces behaviors different from those under the optimal policy for rp . (Left) Vector field of a policy optimization process converging to a sub-optimal policy. (Middle and Right) By changing the influence of auxiliary rewards, our method can dynamically correct the entire policy optimization process steering it towards a policy that results in the desired behavior.
To address this issue, designers often introduce auxiliary reward functions that supplement the original rewards. Auxiliary rewards are heuristic guidelines aimed at facilitating and speeding up the learning process. One could, e.g., augment the previously described reward function (which gives a reward of +1 upon reaching a goal state) with an auxiliary reward accounting for the agent’s distance to the goal. However, the effectiveness of using auxiliary reward functions largely depends on the problem’s complexity and the designer’s skill in crafting heuristics that, when combined with the original reward function, do not induce behaviors different than the ones originally intended [26, 27].
Existing methods like potential-based reward shaping [41] aim to incorporate domain knowledge without misaligning the behaviors induced by the resulting combined reward functions. However, as we discuss in Section 3, potential-based shaping has several limitations: (i) it is restricted to state-based functions; (ii) it amounts to a different initialization of the q -function; (iii) it does not alter policy gradients in expectation; and (iv) it can increase the variance in policy gradient methods.
To address these challenges, we introduce a scalable algorithm that empowers RL practitioners to specify potentially imperfect auxiliary reward functions. It ensures that the resulting optimization process will not inadvertently lead to unintended behaviors and that it will allow for faster learning. In particular, this paper addresses the following challenges:
(1) How to incorporate auxiliary reward information: We introduce a novel bi-level objective to analyze and automatically fine-tune designer-created auxiliary reward functions. It ensures they remain aligned with the original reward and do not induce behaviors different from those originally intended by the designer. Additionally, we formulate the problem to shape the optimization landscape, biasing our bi-level optimizer toward auxiliary reward functions that facilitate faster learning.
(2) How to use auxiliary reward to mitigate algorithmic biases: We show that our framework can automatically adjust how primary and auxiliary rewards are blended to mitigate limitations or biases inherent in the underlying RL algorithm (Section 4.1). For instance, many policy-gradient-based RL algorithms are subject to biases due to issues like discounting mismatch [59] or partial off-policy correction [51]. These biases can hinder the algorithm’s ability to identify near-optimal policies.
(3) How to ensure scalability to high-dimensional problems: We introduce an algorithm that employs implicit gradients to automatically adjust primary and auxiliary rewards, ensuring that the combined reward function aligns with the designer’s original expectations (see Figure 1). We evaluate our method’s efficacy across a range of tasks, from small-scale to high-dimensional control settings (see Section 6). In these tasks, we experiment with auxiliary rewards of varying quality; some accelerate learning, while others can be detrimental to finding an optimal policy.
2 Notation
In this paper, we investigate sequential decision-making problems modeled as Markov decision processes (MDPs). An MDP is defined as a tuple ( S, A, p, rp, r aux , γ, d 0), where S is the state set, A is the action set, p is the transition function, rp : S × A → R is the primary reward function, r aux :
2
S × A → R is an optional auxiliary reward function (possibly designed by a non-expert in machine learning, based on domain knowledge), and d 0 is the starting state distribution. Let πθ : S×A → [0 , 1] be any policy parameterized using θ ∈ Θ. For brevity, we will often use πθ and θ interchangeably. Let St and At be the random variables for the state and action observed at the time t . As in the standard RL setting, the performance J ( θ ) of a policy πθ is defined as the expected discounted return with respect to the (primary) reward function, rp ; i.e., J ( θ ) := E π [ [�] [T] t =0 [γ][t][r][p] [(] [S][t][, A][t] [)]][, where] [ T] [ + 1][ is] the episode length. An optimal policy parameter θ [∗] is defined as θ [∗] ∈ arg max θ∈ Θ J ( θ ). A popular technique to search for θ [∗] is based on constructing sample estimates ∆( [ˆ] θ, rp ) of the ( γ -dropped) policy gradient, ∆( θ, rp ), given an agent’s interactions with the environment for one episode [58, 59]. Then, using ψθ ( s, a ) as a shorthand for d ln πθ ( s, a ) / d θ, these quantities are defined as follows:
T
- γ [j][−][t] rp ( Sj, Aj ) . (1)
j = t
- ∆( _θ, rp_ ) = E _πθ_ ˆ∆( _θ, rp_ ) and ˆ∆( _θ, rp_ ) :=
T
- ψθ ( St, At )
t =0
3 Limitations of Potential Based Reward Shaping
When the objective function J ( θ ) is defined with respect to a sparse reward function rp (i.e., a reward function such that rp ( s, a ):= 0 for most s ∈S and a ∈A ), searching for θ [∗] is challenging [24]. A natural way to provide more frequent (i.e., denser) feedback to the agent, in the hope of facilitating learning, is to consider an alternate reward function, ˜ r naive := rp + r aux. However, as discussed earlier, r aux may be a designer-specified auxiliary reward function not perfectly aligned with the objective encoded in rp . In this case, using ˜ r naive may encourage undesired behavior. An alternative way to incorporate domain knowledge to facilitate learning was introduced by Ng et al. [41]. They proposed using a potential function, Φ : S → R (analogous to r aux), to define new reward functions of the form r ˜Φ( St, At, St +1):= rp ( St, At )+ γ Φ( St +1) − Φ( St ). Importantly, they showed that optimal policies with respect to the objective E[ [�] [T] t =0 [γ][t][r] [˜][Φ][(] [S][t][, A][t][, S][t] [+1][)]][ are also optimal with respect to] [ J] [(] [θ] [)][.]
While potential-based reward shaping can partially alleviate some of the difficulties arising from sparse rewards, Wiewiora [64] showed that q -learning using ˜ r Φ produces the exact same sequence of updates as q -learning using rp but with a different initialization of q -values. In what follows, we establish a similar result: we show that performing potential-based reward shaping has no impact on expected policy gradient updates; and that it can, in fact, even increase the variance of the updates.
Property 1. E[ ∆( [ˆ] θ, ˜ r Φ)]= E[ ∆( [ˆ] θ, rp )] and Var( ∆( [ˆ] θ, ˜ r Φ)) can be higher than Var( ∆( [ˆ] θ, rp )) .
All proofs are deferred to Appendix A. The above points highlight some of the limitations of potentialbased shaping for policy gradients and q -learning—both of which form the backbone of the majority of model-free RL algorithms [58]. Furthermore, potential functions Φ cannot depend on actions [41], which restricts the class of eligible auxiliary rewards r aux and heuristics functions that may be used. Finally, notice that Φ is designed independently of the agent’s underlying learning algorithm. As we will show in the next sections, our method can autonomously discover auxiliary reward functions that not only facilitate learning but also help mitigate various types of algorithmic limitations and biases.
4 Behavior Alignment Reward Function
In this section, we introduce an objective function designed to tackle the primary challenge investigated in this paper: how to effectively leverage designer-specified auxiliary reward functions to rapidly induce behaviors envisioned by the designer. The key observation is that naively adding an auxiliary reward function r aux to rp may produce policies whose corresponding behaviors are misaligned with respect to the behaviors induced by rp . In these cases, r aux should be ignored during the search for an optimal policy. On the other hand, if rp and r aux may be combined in a way that results in the desired behaviors, then combinations that produce frequent and informative feedback to the agent should be favored, as they are likely to facilitate faster learning.
To tackle the challenges discussed above, we employ a bi-level optimization procedure. This approach aims to create a behavior alignment reward by combining r aux and rp using a parameterized function. Our method is inspired by the optimal rewards framework by Singh et al. [52, 53]. Let γφ ∈ [0 , 1) be
3
a discount rate value parameterized by φ ∈ Γ. [2] Let rϕ : S ×A → R be a behavior alignment reward : a function of both rp and r aux, parameterized by ϕ ∈ Υ, where Υ and Γ are function classes. One example of a behavior alignment reward function is rϕ ( s, a ):= fϕ 1( s, a )+ ϕ 2 rp ( s, a )+ ϕ 3 r aux( s, a ), where fϕ : S × A → R and ϕ :=( ϕ 1 , ϕ 2 , ϕ 3). Let Alg be any gradient/semi-gradient/non-gradientbased algorithm that outputs policy parameters. To mitigate possible divergence issues arising from certain policy optimization algorithms like DQN [60, 1], we make the following simplifying assumption, which can generally be met with appropriate regularizers and step sizes:
Assumption 1. Given rϕ and γφ, the algorithm Alg ( rϕ, γφ ) converges to a fixed point θ— which we denote as θ ( ϕ, φ ) ∈ Θ to emphasize its indirect dependence on ϕ and φ through Alg, rϕ, and γφ.
Given this assumption, we now specify the following bi-level objective:
ϕ [∗] , φ [∗] ∈ arg max ϕ∈ Υ ,φ∈ Γ
J ( θ ( ϕ, φ )) − λγγφ, where θ ( ϕ, φ ) := Alg( rϕ, γφ ) . (2)
Here, λγ serves as the regularization coefficient for the value of γφ, and Alg denotes a given policy optimization algorithm. Let, as an example, Alg be an on-policy gradient algorithm that uses samples to estimate the gradient ∆( θ, rp ), as in (1). We can then define a corresponding variant of ∆( θ, rp ) that is compatible with our formulation and objective, and which uses both rϕ and γφ, as follows:
. (3)
∆on( θ, ϕ, φ ) := E πθ
T
ψθ ( St, At )
t =0
T
- γφ [j][−][t] rϕ ( Sj, Aj )
j = t
Notice that the bi-level formulation in (2) is composed of three key components: outer and inner objectives, and an outer regularization term. In what follows, we discuss the need for these.
Need for Outer- and Inner-Level Objectives: The outer-level objective in Equation (2) serves a critical role: it evaluates different parameterizations, denoted by ϕ, for the behavior alignment reward function. These parameterizations influence the induced policy θ ( ϕ, φ ), which is evaluated using the performance metric J . Recall that this metric quantifies the alignment of a policy with the designer’s primary reward function, rp . In essence, the outer-level objective seeks to optimize the behavior alignment reward function to produce policies that are effective according to rp . This design adds robustness against any misspecification of the auxiliary rewards. [3] In the inner-level optimization, by contrast, Alg identifies a policy θ ( ϕ, φ ) that is optimal or near-optimal with respect to rϕ (which combines r aux through the behavior alignment reward). In the inner-level optimization, the algorithm Alg works to identify a policy θ ( ϕ, φ ) that is optimal or near-optimal in terms of rϕ (which incorporates r aux via the behavior alignment reward). By employing a bi-level optimization structure, several benefits emerge. When r aux is well-crafted, rϕ can exploit its detailed information to give Alg frequent/dense reward feedback, thus aiding the search for an optimal θ [∗] . Conversely, if r aux leads to sub-optimal policies, then the influence of auxiliary rewards can be modulated or decreased accordingly by the optimization process by adjusting rϕ . Consider, for example, a case where the behavior alignment reward function is defined as rϕ ( s, a ) := fϕ 1( s, a ) + ϕ 2 rp ( s, a ) + ϕ 3 r aux( s, a ). In an adversarial setting—where the designer-specified auxiliary reward r aux may lead to undesired behavior—the bi-level optimization process has the ability to set ϕ 3 to 0. This effectively allows the behavior alignment reward function rϕ to exclude r aux from consideration. Such a bi-level approach to optimizing the parameters of behavior alignment reward functions can act as a safeguard against the emergence of sub-optimal behaviors due to a misaligned auxiliary reward, r aux. This design is particularly valuable because it allows the objective in (2) to leverage the potentially dense reward structure of r aux to provide frequent action evaluations when the auxiliary reward function is well-specified. At the same time, the approach maintains robustness against possible misalignments.
Need for Outer Regularization: The bi-level optimization problem (2) may have multiple optimal solutions for ϕ —including the trivial solution where r aux is always ignored. The goal of regularizing the outer-level objective (in the form of the term λγγφ ) is to incorporate a prior that adds a preference for solutions, ϕ [∗], that provide useful and frequent evaluative feedback to the underlying RL algorithm. In the next paragraphs, we discuss the need for such a regularizer and motivate its mathematical form. First, recall that sparse rewards can pose challenges for policy optimization. An intuitive solution
2Our framework can be generalized to support state-action dependent discount rates, γ . 3“Misspecification” indicates that an optimal policy for rp + r aux may not be optimal for rp alone.
4
to this problem could involve biasing the optimization process towards denser behavior alignment reward functions, e.g., by penalizing for sparsity of rϕ . Unfortunately, the distinction between sparse and dense rewards alone may not fully capture the nuances of what designers typically consider to be a “good” reward function. This is the case because a reward function can be dense and still may not be informative ; e.g., a reward function that provides − 1 to the agent in every non-goal state is dense but fails to provide useful feedback regarding how to reach a goal state. A better characterization of how useful (or informative) a reward function is may be constructed in terms of how instructive and instantaneous the evaluation or feedback it generates is. We consider a reward function to be instructive if it produces rewards that are well-aligned with the designer’s goals. A reward function is instantaneous if its corresponding rewards are dense, rather than sparse, and are more readily indicative of the optimal action at any given state. [4] Reward functions that are both instructive and instantaneous can alleviate issues associated with settings with sparse rewards and long horizons. To bias our bi-level optimization objective towards this type of reward function, we introduce a regularizer, γφ . This regularizer favors solutions that can generate policies with high performance (i.e., high expected return J with respect to rp ) even when the discount factor γφ is small . To see why, first notice that this regularizer encourages behavior alignment reward functions that provide more instantaneous feedback to the agent. This has to be the case; otherwise, it would be challenging to maximize long-term reward should the optimized alignment reward function be sparse. Second, the regularizer promotes instructive alignment reward functions—i.e., functions that facilitate learning policies that maximize J . This is equally crucial: effective policies under the metric J are the ones that align well with the designer’s objectives as outlined in the original reward function, rp .
4.1 Overcoming Imperfections of Policy Optimization Algorithms
The advantages of the bi-level formulation in (2) extend beyond robustness to sub-optimality from misspecified r aux. Even with a well-specified r aux, RL algorithms often face design choices, such as the bias-variance trade-off, that can induce sub-optimal solutions. Below we present examples to show how bias in the underlying RL algorithm may be mitigated by carefully optimizing rϕ and γφ .
4.1.1 Bias in policy gradients: Recall that the popular “policy gradient” ∆( θ, rp ) is not, in fact, the gradient of any function, and using it in gradient methods may result in biased and sub-optimal policies [44]. However, policy gradient methods based on ∆( θ, rp ) remain vastly popular in the RL literature since they tend to be sample efficient [59]. Let ∆ γ ( θ, rp ) denote the unbiased policy gradient, where ∆ γ ( θ, rp ) := E[ [�] [T] t =0 [γ][t][ψ][θ] [(] [S][t][, A][t] [)][ �] j [T] = t [γ][j][−][t][r][p] [(] [S][j][, A][j] [)]][. We can show that with] a sufficiently expressive parameterization, optimized rϕ and γφ can effectively mimic the updates that would have resulted from using the unbiased gradient ∆ γ ( θ, rp ), even if the underlying RL algorithm uses the biased “gradient”, ∆on( θ, ϕ, φ ), as defined in (3). Detailed proofs are in Appendix A.
Property 2. There exists rϕ : S × A → R and γφ ∈ [0 , 1) such that ∆on( θ, ϕ, φ ) = ∆ γ ( θ, rp ) .
4.1.2 Off-policy learning without importance sampling: To increase sample efficiency when evaluating a given policy πθ, it is often useful to use off-policy data collected by a different policy, β . Under the assumption that ∀s ∈S, ∀a ∈A, [π] β [θ] ( [(] s,a [s,a] ) [)] [<][ ∞] [, importance ratios] [ ρ][j] [ :=][ �] k [j] =0 πβθ (( s,as,a )) [can]
be used to adjust the updates and account for the distribution shift between trajectories generated by β and πθ . However, to avoid the high variance stemming from ρj, many methods tend to drop most of the importance ratios and thus only partially correct for the distribution shift—-which can lead to bias [51]. We can show (given a sufficiently expressive parameterization for the behavior alignment reward function) that this type of bias can also be mitigated by carefully optimizing rϕ and γφ .
Let us denote the unbiased off-policy update with full-distribution correction as ∆off( θ, rp ) := E β [ [�] [T] t =0 [γ][t][ψ][θ] [(] [S][t][, A][t] [)][ �] j [T] = t [ρ][j][γ][j][r][p] [(] [S][j][, A][j] [)]][. Now consider an extreme scenario where off-policy] evaluation is attempted without any correction for distribution shift . In this situation, and with a slight abuse of notation, we define ∆off( θ, ϕ, φ ) := E β [ [�] [T] t =0 [ψ][θ] [(] [S][t][, A][t] [)][ �] j [T] = t [γ] φ [j][−][t] rϕ ( Sj, Aj )].
Property 3. There exists rϕ : S × A → R and γφ ∈ [0 , 1) such that ∆off( θ, ϕ, φ ) = ∆off( θ, rp ) .
Remark 1. Our method is capable of mitigating various types of algorithmic biases and imperfections in underlying RL algorithms, without requiring any specialized learning rules. Additionally, thanks
4E.g., if rϕ ≈ q∗, then its corresponding rewards are instantly indicative of the optimal action at any state.
5
to the γφ∗ regularization, it favors reward functions that lead to faster learning of high-performing policies aligned with the designer’s objectives, as outlined in the original reward function rp.
5 BARFI: Implicitly Learning Behavior Alignment Rewards
Having introduced our bi-level objective and discussed the benefits of optimizing rϕ and γφ, an important question arises: Although θ ( ϕ, φ ) can be optimized using any policy learning algorithm, how can we efficiently identify the optimal ϕ [∗] and φ [∗] in equation (2)? Given the practical advantages of gradient-based methods, one would naturally consider using them for optimizing ϕ [∗] and φ [∗] as well. However, a key challenge in our setting lies in computing d J ( θ ( ϕ, φ )) / d ϕ and d J ( θ ( ϕ, φ )) / d φ . These computations require an analytical characterization of the impact that rϕ and γφ have on the entire optimization process of the inner-level algorithm, Alg.
In addressing this challenge, we initially focus on an Alg that employs policy gradients for updating πθ . Similar extensions for other update rules can be derived similarly. We start by re-writing the expression for d J ( θ ( ϕ, φ )) / d ϕ using the chain rule:
d J ( θ ( ϕ, φ ))
d θ ( ϕ, φ )
d ϕ
�-�( b )
( ϕ, φ )) = [d] [J] [(] [θ] [(] [ϕ, φ] [))]
d ϕ d θ ( ϕ, φ )
d θ ( ϕ, φ )
���( a )
, (4)
where (a) is the policy gradient at θ ( ϕ, φ ), and (b) can be computed via implicit bi-level optimization, as discussed below.
Implicit Bi-Level Optimization: We compute (4) by leveraging implicit gradients [14, 34, 19], an approach previously employed, e.g., in few-shot learning [38, 49] and model-based RL algorithms [50]. First, observe that when Alg converges to θ ( ϕ, φ ), then it follows that
∆( θ ( ϕ, φ ) , ϕ, φ ) = 0 . (5)
Let ∂f denote the partial derivative with respect to the immediate arguments of f, and d f be the total derivative as before. That is, if f ( x, g ( x )) := xg ( x ), then [∂f] ∂x [(] [x, g] [(] [x] [)) =] [ g] [(] [x] [)][ and] [d] d [f] x [(] [x, g] [(] [x] [)) =]
g ( x ) + x [∂g] [(] [x] [)][. Therefore, taking the total derivative of (][5][) with respect to] [ ϕ] [ yields]
[∂f] [d] [f]
∂x [(] [x, g] [(] [x] [)) =] [ g] [(] [x] [)][ and] d x
∂x [(] [x] [)][. Therefore, taking the total derivative of (][5][) with respect to] [ ϕ] [ yields]
) , ϕ, φ )
= [∂] [∆(] [θ] [(] [ϕ, φ] [)] [, ϕ, φ] [)] d ϕ ∂ϕ
[θ] [(] [ϕ, φ] [)] [, ϕ, φ] [)] ∂θ ( ϕ, φ )
∂θ ( ϕ, φ ) ∂ϕ
= 0 . (6) ∂ϕ
d∆( θ ( ϕ, φ ) , ϕ, φ )
[)] [, ϕ, φ] [)]
- [∂] [∆(] [θ] [(] [ϕ, φ] [)] [, ϕ, φ] [)] ∂ϕ ∂θ ( ϕ, φ )
By re-arranging terms in (6), we obtain the term (b) in (4). In particular,
( ϕ, φ ) - ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
= − ∂ϕ ∂θ ( ϕ, φ )
- − 1 ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
. (7) ∂ϕ
∂θ ( ϕ, φ )
∂θ ( ϕ, φ )
Furthermore, by combining (7) and (4) we obtain the desired gradient expression for ϕ :
- − 1 ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂ϕ
�-�A
∂J ( θ ( ϕ, φ ))
( ϕ, φ ))
= − [∂J] [(] [θ] [(] [ϕ, φ] [))] ∂ϕ ∂θ ( ϕ, φ )
∂θ ( ϕ, φ )
∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂θ ( ϕ, φ )
�-�H
. (8)
Similarly, a gradient expression for φ can be derived; the full derivation is detailed in Appendix E. Using θ [∗] as shorthand for θ ( ϕ, φ ), we find that the terms A and H can be expressed as
- j = t γφ [j][−][t] ∂rϕ ( ∂ϕSj , Aj )
∂ϕ
.
⊤ []
T
- γφ [j][−][t] rϕ ( Sj , Aj )
j = t
T
T
t =0
∂ψθ∗ ( St, At )
∂θ [∗]
A = E D
T
ψθ∗ ( St, At )
t =0
, H = E D
When working with the equations above, we assume the inverse of H [−] [1] exists. To mitigate the risk of ill-conditioning, we discuss regularization strategies for Alg in Appendix D. Notice that equations (8) and (15) are the key elements needed to calculate the updates to ϕ and φ in our bi-level optimization’s outer loop. However, computing A and H directly can be impractical for high-dimensional problems due to the need for outer products and second derivatives. To address this, we employ two strategies: (1) We approximate H [−] [1] using the Neumann series [40], and (2) we calculate (8) and (15) via Hessian-vector products [47], which are readily available in modern auto-diff libraries [46]. These methods eliminate the need for explicit storage or computation of H or A .
6
The mathematical approach outlined above results in an algorithm with linear compute and memory
footprint, having O ( d ) complexity, where d is the number of parameters for both the policy and the
reward function. Details can be found in Appendix C. We refer to our method as BARFI, an acronym
for behavior alignment reward function’s implicit optimization. [5] BARFI is designed to iteratively
solve the bi-level optimization pr oblem defined in (2). With policy regularization, the updates to rϕ
and γφ incrementally modify θ ( ϕ, φ ). This enables us to initialize Alg using the fixed point achieved
in the previous inner optimization step, further reducing the time for subsequent inner optimizations.
6 Empirical Analyses
Our experiments serve multiple purposes and include detailed ablation studies. First, we demonstrate our bi-level objective’s efficacy in discovering behavior alignment reward functions that facilitate learning high-performing policies. We focus especially on its robustness in situations where designers provide poorly specified or misaligned auxiliary rewards that could disrupt the learning process (Section 6.1). Second, we present a detailed analysis of the limitations of potential-based reward shaping, showing how it can lead to suboptimal policies (Section 6.2). We then provide a qualitative illustration of the behavior alignment reward function learned by BARFI (Section 6.3). Finally, we evaluate how well BARFI scales to problems with high-dimensional, continuous action and state spaces (Section 6.4).
In the sections that follow, we examine a range of methods and reward combinations for comparison:
Baseline RL methods : We consider baseline RL methods that employ a naive reward combination strategy: ˜ r naive( s, a ) := rp ( s, a ) + r aux( s, a ). In this case, the auxiliary reward from the designer is simply added to the original reward without checks for alignment. Both the REINFORCE and Actor-Critic algorithms are used for optimization.
Potential-based shaping : To assess how well potential-based reward shaping performs, we introduce variants of the baseline methods. Specifically, we investigate the effectiveness of the reward function r ˜Φ( s, a, s [′] ) := rp ( s, a ) + γr aux( s [′] ) − r aux( s ).
BARFI: We use REINFORCE as the underlying RL algorithm when implementing BARFI and define rϕ ( s, a ) := ϕ 1( s, a ) + ϕ 2( s ) rp ( s, a ) + ϕ 3( s ) r aux( s, a ). Our implementation includes a warm-up period wherein the agent collects data for a fixed number of episodes, using ˜ r naive, prior to performing the first updates to ϕ and φ (See Appendix 5 for the complete algorithm).
We evaluate each algorithm across four distinct environments: GridWorld, MountainCar [58], CartPole [16], and HalfCheetah-v4 [9]. These domains offer increasing levels of complexity and are intended to assess the algorithms’ adaptability. Furthermore, we examine their performance under a variety of auxiliary reward functions, ranging from well-aligned to misaligned with respect to the designer’s intended objectives.
In our experiments, we investigate different types of auxiliary reward functions for each environment: some are action-dependent, while others are designed to reward actions aligned with either effective or ineffective known policies. These functions, therefore, vary in their potential to either foster rapid learning or inadvertently mislead the agent away from the designer’s primary objectives, hindering the efficiency of the learning process. Comprehensive details of each environment and their corresponding auxiliary reward functions can be found in Appendix F.
6.1 BARFI’s Robustness to Misaligned Auxiliary Reward Functions
In this section, we evaluate the performance of various methods for reward combination, particularly in scenarios where auxiliary reward functions can either be well-aligned with a designer’s intended goals or be misaligned or poorly specified, thus inadvertently hindering efficient learning. We introduce two types of auxiliary reward functions for CartPole. First, we used domain knowledge to design an r aux that provides bonuses when the agent’s actions align with a known effective policy in this domain. Second, we designed an adversarial example where the auxiliary reward function rewards actions that are consistent with a particularly poorly performing policy. For MountainCar, we first leveraged knowledge about an energy pumping policy (i.e., a well-known effective policy [18]) to
5“BARFI” commonly refers to a type of south-Asian sweet confectionery, typically pronounced as ‘bur-fee’.
7
Table 1: Summary of the performance of various reward combination methods and types of r aux
CartPole MountainCar Method for Reward Combination
Well-aligned r aux Misaligned r aux Well-aligned r aux Partially-aligned r aux (w.r.t. energy policy ) (w.r.t. high velocity policy )
BARFI ( our method ) 487 . 2 ± 9 . 4 475 . 5 ± 15 . 5 0 . 99 ± 0 . 0 0 . 90 ± 0 . 1 r ˜naive ( naive reward combination ) 498 . 9 ± 1 . 0 9 . 04 ± 0 . 2 0 . 99 ± 0 . 0 0 . 63 ± 0 . 1 r ˜Φ ( potential-based shaping ) 8 . 98 ± 0 . 2 500 ± 0 . 0 0 . 00 ± 0 . 0 0 . 00 ± 0 . 0
BARFI’s performance compared to two baselines that use: ˜ r naive and ˜ r Φ, respectively. CartPole uses an action-dependent r aux function that either rewards agents when actions align with a known effective policy ( well-aligned raux ) or with a poorly-performing policy ( misaligned raux ). MountainCar uses either an action-dependent function aligned with an energy-pumping policy [18] or a partially-aligned function incentivizing higher velocities. BARFI consistently achieves near-optimal performance across scenarios, even if given poorly specified/misaligned auxiliary rewards. Competitors, by contrast, often induce suboptimal policies. Performances significantly below the optimal are shown in red, above.
craft an auxiliary reward function that provides bonuses for actions in line with such a control strategy. We also experimented with a partially-aligned auxiliary function that rewards high velocity—a factor not particularly indicative of high performance.
Table 1 summarizes the results across different reward functions and combination methods. The results suggest that if auxiliary rewards provide positive feedback when agents’ actions align with effective policies, naive combination methods perform well. In such cases, auxiliary rewards effectively “nudge” agents towards emulating expert actions. However, our experimental results also indicate that all baseline methods are susceptible to poor performance when auxiliary rewards are not well aligned with the designer’s goals. We provide more discussion for potential-based shaping in Section 6.2.
The key takeaway from the experimental results in Table 1 is that BARFI consistently performs well across various domains and under different types of auxiliary rewards. Specifically, when designer-specified feedback is appropriate and can assist in accelerating learning, BARFI efficiently exploits it to produce high-performing policies. Conversely, if auxiliary rewards are misaligned with the designer’s intended goals, BARFI is capable of adapting and effectively dismissing “misleading rewards”. This adaptability ensures that high-performing policies can be reliably identified. Other methods, by contrast, succeed only in some of these scenarios. Importantly, the unpredictability of whether a given auxiliary reward function will aid or hinder learning makes such alternative methods less reliable, as they may fail to learn effective policies.
6.2 Pitfalls of potential-based reward shaping
We now turn our attention to the (possibly negative) influence of action-dependent auxiliary rewards, particularly when used in combination with potential-based reward shaping. Our results in Table 1 reveal a key limitation: potential-based shaping struggles to learn efficient policies even when auxiliary rewards are well-aligned with effective strategies. This shortcoming is attributable to the action-dependent nature of the auxiliary rewards, which compromises the potential shaping technique’s guarantee of policy optimality.
As there is no prescribed way for designing potential shaping when r aux is action-dependent, we use a direct extension of the original formulation [41] by considering ˜ r Φ( s, a, s [′] , a [′] ) := rp ( s, a ) + γr aux( s [′] , a [′] ) − r aux( s, a ). Furthermore, we designed an auxiliary reward function, r aux, that is well aligned: it provides positive reward signals of fixed magnitude both for ( s, a ) and ( s [′] , a [′] ) whenever the agent’s actions coincide with the optimal policy. Notice, however, that if γ < 1, the resultant value from γr aux( s [′] , a [′] ) − r aux( s, a ) is negative . Such a negative component may deter the agent from selecting actions that are otherwise optimal, depending on how r aux and rp differ in magnitude. Conversely, potential-based shaping can also occasionally perform well under misaligned rewards. In these cases, the shaping function may yield a positive value whenever the agent selects an optimal action, which could induce well-performing behaviors.
8
GridWorld
100
0
−20
| Col1 | Col2 | Col3 | Col4 | Goal +100 |
|---|---|---|---|---|
| +50 | ||||
6.3 What does rϕ learn?
We now investigate BARFI’s performance and robustness in the GridWorld when operating under misspecified auxiliary reward functions. Consider the reward function depicted in Figure 2 [left]. This reward function provides the agent with a bonus for visiting the state at the center, akin to providing intermediate feedback to the agent when it makes progress towards the goal. However, such intermediate positive feedback can lead to behaviors where the agent repeatedly cycles around the middle state (i.e., behaviors that are misaligned with the original objective of reaching the goal state at the top right corner of the grid). Importantly, BARFI is capable of autonomously realizing that it should disregard such misleading incentives (Figure 2 [center left]), thereby avoiding poorlyperforming behaviors that focus on revisiting irrelevant central states. Similarly, when Cartpole operates under a misspecified r aux (Figure 2 [right]), BARFI is capable of rapidly adapting (after a warm-up period) and effectively disregarding misleading auxiliary reward signals. These results highlight once again BARFI’s robustness when faced with reward misspecification.
6.4 Scalability to High-Dimensional Continuous Control
One might wonder whether computing implicit gradients for ϕ and φ would be feasible in highdimensional problems, due to the computational cost of inverting Hessians. To address this concern, we leverage Neumann series approximation with Hessian-vector products (See Appendix C) and conduct further experiments, as shown in Figure 3. These experiments focus on evaluating the scalability of BARFI in control problems with high-dimensional state spaces and continuous actions—scenarios that often rely on neural networks for both the policy and critic function approximators. For a more comprehensive evaluation, we also introduced an alternative method named BARFI unrolled. Unlike BARFI, which uses implicit bi-level optimization, BARFI unrolled employs path-wise bi-level optimization. It maintains a complete record of the optimization path to determine updates for ϕ and φ . Further details regarding this alternative method can be found in Appendix C.6.
We conducted experiments on the HalfCheetah-v4 domain and investigated, in particular, a reward function comprising two components with varying weights. This empirical analysis was designed to help us understand how different weight assignments to each reward component could influence the learning process. Specifically, in HalfCheetah-v4, the agent receives a positive reward rp proportional to how much it moved forward. It also incurs a small negative reward (concretely, an auxiliary reward, r aux( s, a ) := c∥a∥ [2] 2 [, known as a] [ control cost] [) for the torque applied to its joints.] A hyperparameter c determines the balance between these rewards. The naive combination of such primary and auxiliary rewards is defined as ˜ r naive( s, a ) = rp ( s, a ) + r aux( s, a ). Figure 3 [left] shows that the baselines and both variants of BARFI appear to learn effectively. With alternative reward weighting schemes, however, only BARFI and BARFI unrolled show learning progress, as seen in Figure 3 [middle]. It is worth noting that path-wise bi-level optimization can become impractical as the number of update steps in (4) increases, due to growing computational and memory requirements (Figure 3 [right]). Although we do not recommend BARFI unrolled, we include its results for completeness. Additional ablation studies on (a) the effect of the inner optimization step; (b) Neumann approximations; (c) decay of γ ; and (d) returns based on rϕ, are provided in Appendix H.
9
Figure 3: Results for MuJoCo environment. ( Left ) Auxiliary reward is defined to be −c∥a∥ [2] 2 [, where] [ c] [ is a] positive hyperparameter and a is the continuous high-dimensional action vector. ( Middle ) Similar setting as before, but uses an amplified variant of the auxiliary reward: − 4 c∥a∥ [2] 2 [. It is worth highlighting that even under] alternative reward weighting schemes, both variants of our (behavior-aligned) bi-level optimization methods demonstrate successful learning. Learning curves correspond to mean return over 15 trials, and the shaded regions correspond to one standard error. ( Right ) Required compute and memory for BARFI unrolled, compared to BARFI, as a function of the number of inner-optimization updates. This figure also showcases BARFI’s characteristics under various orders of Neumann approximation.
7 Related work
This paper focuses primarily on how to efficiently leverage auxiliary rewards r aux. Notice, however, that in the absence of r aux, the resulting learned behavior alignment rewards rϕ may be interpreted as intrinsic rewards [70, 71]. Furthermore, several prior works have investigated meta-learning techniques, which are methods akin to the bi-level optimization procedures used in our work. Such prior works have employed meta-learning in various settings, including automatically inferring the effective return of trajectories [68, 62, 7, 71], parameters of potential functions [72, 28, 17], targets for TD learning [69], rewards for planning [54, 23], and even fully specified reinforcement learning update rules [33, 45]. Additionally, various other relevant considerations to effectively learning rewards online have been discussed by Armstrong et al. [5]. Our work complements these efforts by focusing on the reward alignment problem, specifically in settings where auxiliary information is available. An extended discussion on related works can be found in Appendix B. It is worth mentioning that among the above-mentioned techniques, most rely on path-wise meta-gradients. As discussed in Section 6.4, this approach can be disadvantageous as it often performs only one or a few inner-optimization steps, which limits its ability to fully characterize the result of the inner optimization [67]. Further, it requires caching intermediate steps, which increases computational and memory costs. BARFI, by contrast, exploits implicit gradients to alleviate these issues by directly characterizing the fixed point of Alg induced by learned behavior alignment rewards.
Finally, it is also important to highlight that a concurrent work on reward alignment using bi-level optimization was made publicly available after our manuscript was submitted for peer-reviewing at NeurIPS [10]. While our work analyses drawbacks of potential-based shaping and establishes different forms of correction that can be performed via bi-level optimization, this concurrent work provides complementary analyses on the convergence rates of bi-level optimization, as well as a discussion on its potential applications to Reinforcement Learning from Human Feedback (RLHF).
8 Conclusion and Future Work
In this paper, we introduced BARFI, a novel framework that empowers RL practitioners—who may not be experts in the field—to incorporate domain knowledge through heuristic auxiliary reward functions. Our framework allows for more expressive reward functions to be learned while ensuring they remain aligned with a designer’s original intentions. BARFI can also identify reward functions that foster faster learning while mitigating various limitations and biases in underlying RL algorithms. We empirically show that BARFI is effective in training agents in sparse-reward scenarios where (possibly poorly-specified) auxiliary reward information is available. If the provided auxiliary rewards are determined to be misaligned with the designer’s intended goals, BARFI autonomously adapts and effectively disincentivizes their use as needed. This adaptability results in a reliable pathway to identifying high-performing policies. The conceptual insights offered by this work provide RL practitioners with a structured way to design more robust and easy-to-optimize reward functions. We believe this will contribute to making RL more accessible to a broader audience.
10
Acknowledgement and Funding Disclosures
We thank Andy Barto for invaluable discussions and insightful feedback on an earlier version of this manuscript, which significantly improved the quality of our work.
This work is partially supported by the National Science Foundation under grant no. CCF-2018372 and by a gift from the Berkeley Existential Risk Initiative.
References
[1] Joshua Achiam, Ethan Knight, and Pieter Abbeel. Towards characterizing divergence in deep q-learning. arXiv preprint arXiv:1903.08894, 2019.
[2] Akshay Agrawal, Brandon Amos, Shane Barratt, Stephen Boyd, Steven Diamond, and Zico Kolter. Differentiable convex optimization layers. arXiv preprint arXiv:1910.12430, 2019.
[3] Ron Amit, Ron Meir, and Kamil Ciosek. Discount factor as a regularizer in reinforcement learning. In International Conference on Machine Learning, 2020.
[4] Brandon Amos and J Zico Kolter. Optnet: Differentiable optimization as a layer in neural networks. In International Conference on Machine Learning, 2017.
[5] Stuart Armstrong, Jan Leike, Laurent Orseau, and Shane Legg. Pitfalls of learning a reward function online. arXiv preprint arXiv:2004.13654, 2020.
[6] Karl J Åström and Tore Hägglund. Pid control. IEEE Control Systems Magazine, 2006.
[7] Sarah Bechtle, Artem Molchanov, Yevgen Chebotar, Edward Grefenstette, Ludovic Righetti, Gaurav Sukhatme, and Franziska Meier. Meta-learning via learned loss. arXiv preprint arXiv:1906.05374, 2019.
[8] Yoshua Bengio. Gradient-based optimization of hyperparameters. Neural computation, 2000.
[9] Greg Brockman, Vicki Cheung, Ludwig Pettersson, Jonas Schneider, John Schulman, Jie Tang, and Wojciech Zaremba. Openai gym. arXiv preprint arXiv:1606.01540, 2016.
[10] Souradip Chakraborty, Amrit Singh Bedi, Alec Koppel, Dinesh Manocha, Huazheng Wang, Furong Huang, and Mengdi Wang. Aligning agent policy with externalities: Reward design via bilevel rl. arXiv preprint arXiv:2308.02585, 2023.
[11] Xu Chu Dennis Ding, Stephen L Smith, Calin Belta, and Daniela Rus. LTL control in uncertain environments with probabilistic satisfaction guarantees. IFAC Proceedings Volumes, 2011.
[12] Chuong B Do, Chuan-Sheng Foo, and Andrew Y Ng. Efficient multiple hyperparameter learning for log-linear models. In Advances in Neural Information Processing Systems, 2007.
[13] Justin Domke. Generic methods for optimization-based modeling. In Artificial Intelligence and Statistics, 2012.
[14] Asen L Dontchev and R Tyrrell Rockafellar. Implicit functions and solution mappings, volume 543. Springer, 2009.
[15] Chelsea Finn, Pieter Abbeel, and Sergey Levine. Model-agnostic meta-learning for fast adaptation of deep networks. In, Proceedings of the 34th International Conference on Machine Learning, ICML 2017, Sydney, NSW, Australia, 6-11 August 2017, 2017.
[16] Razvan V Florian. Correct equations for the dynamics of the cart-pole system. Center for Cognitive and Neural Studies (Coneural), Romania, 2007.
[17] Zhao-Yang Fu, De-Chuan Zhan, Xin-Chun Li, and Yi-Xing Lu. Automatic successive reinforcement learning with multiple auxiliary rewards. In IJCAI, 2019.
11
[18] Sina Ghiassian, Banafsheh Rafiee, Yat Long Lo, and Adam White. Improving performance in reinforcement learning by breaking generalization in neural networks. In, Proceedings of the 19th International Conference on Autonomous Agents and Multiagent Systems, AAMAS ’20, Auckland, New Zealand, May 9-13, 2020, 2020.
[19] Stephen Gould, Basura Fernando, Anoop Cherian, Peter Anderson, Rodrigo Santa Cruz, and Edison Guo. On differentiating parameterized argmin and argmax problems with application to bi-level optimization. arXiv preprint arXiv:1607.05447, 2016.
[20] Edward Grefenstette, Brandon Amos, Denis Yarats, Artem Molchanov, Franziska Meier, and Kyunghyun Cho. higher: A pytorch meta-learning library. 2020.
[21] Ricardo Grunitzki, Bruno C da Silva, and Ana LC Bazzan. A flexible approach for designing optimal reward functions. In Proceedings of the 16th Conference on Autonomous Agents and MultiAgent Systems, 2017.
[22] Ricardo Grunitzki, Bruno C da Silva, and LC Ana Bazzan. Towards designing optimal reward functions in multi-agent reinforcement learning problems. In 2018 International Joint Conference on Neural Networks (IJCNN), 2018.
[23] Xiaoxiao Guo, Satinder Singh, Richard Lewis, and Honglak Lee. Deep learning for reward design to improve monte carlo tree search in atari games. arXiv preprint arXiv:1604.07095, 2016.
[24] Joshua Hare. Dealing with sparse rewards in reinforcement learning. arXiv preprint arXiv:1910.09281, 2019.
[25] Geoffrey Hinton, Nitish Srivastava, and Kevin Swersky. Neural networks for machine learning lecture 6a overview of mini-batch gradient descent. Cited on, 2012.
[26] Mark K Ho, Michael L Littman, Fiery Cushman, and Joseph L Austerweil. Teaching with rewards and punishments: Reinforcement or communication? In CogSci, 2015.
[27] Mark K Ho, Fiery Cushman, Michael L Littman, and Joseph L Austerweil. People teach with rewards and punishments as communication, not reinforcements. Journal of Experimental Psychology: General, 2019.
[28] Yujing Hu, Weixun Wang, Hangtian Jia, Yixiang Wang, Yingfeng Chen, Jianye Hao, Feng Wu, and Changjie Fan. Learning to utilize shaping rewards: A new approach of reward shaping. Advances in Neural Information Processing Systems, 2020.
[29] Rodrigo Toro Icarte, Toryn Klassen, Richard Valenzano, and Sheila McIlraith. Using reward machines for high-level task specification and decomposition in reinforcement learning. In International Conference on Machine Learning, 2018.
[30] Rodrigo Toro Icarte, Ethan Waldie, Toryn Klassen, Rick Valenzano, Margarita Castro, and Sheila McIlraith. Learning reward machines for partially observable reinforcement learning. Advances in Neural Information Processing Systems, 2019.
[31] Rodrigo Toro Icarte, Toryn Q Klassen, Richard Valenzano, and Sheila A McIlraith. Reward machines: Exploiting reward function structure in reinforcement learning. arXiv preprint arXiv:2010.03950, 2020.
[32] Diederik P. Kingma and Jimmy Ba. Adam: A method for stochastic optimization. In, 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings, 2015.
[33] Louis Kirsch, Sjoerd van Steenkiste, and Jürgen Schmidhuber. Improving generalization in meta reinforcement learning using learned objectives. arXiv preprint arXiv:1910.04098, 2019.
[34] Steven G Krantz and Harold R Parks. The implicit function theorem: history, theory, and applications . Springer Science & Business Media, 2012.
[35] Hadas Kress-Gazit, Georgios E Fainekos, and George J Pappas. Temporal-logic-based reactive mission and motion planning. IEEE Transactions on Robotics, 2009.
12
[36] Karl Kunisch and Thomas Pock. A bilevel optimization approach for parameter learning in variational models. SIAM Journal on Imaging Sciences, 2013.
[37] Jan Larsen, Lars Kai Hansen, Claus Svarer, and M Ohlsson. Design and regularization of neural networks: the optimal use of a validation set. In Neural Networks for Signal Processing VI. Proceedings of the 1996 IEEE Signal Processing Society Workshop, 1996.
[38] Kwonjoon Lee, Subhransu Maji, Avinash Ravichandran, and Stefano Soatto. Meta-learning with differentiable convex optimization. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2019.
[39] Michael L Littman, Ufuk Topcu, Jie Fu, Charles Isbell, Min Wen, and James MacGlashan. Environment-independent task specifications via GLTL. arXiv preprint arXiv:1704.04341, 2017.
[40] Jonathan Lorraine, Paul Vicol, and David Duvenaud. Optimizing millions of hyperparameters by implicit differentiation. In International Conference on Artificial Intelligence and Statistics, 2020.
[41] Andrew Y Ng, Daishi Harada, and Stuart Russell. Policy invariance under reward transformations: Theory and application to reward shaping. In ICML, 1999.
[42] Alex Nichol, Joshua Achiam, and John Schulman. On first-order meta-learning algorithms. CoRR, 2018.
[43] Scott Niekum, Andrew G Barto, and Lee Spector. Genetic programming for reward function search. IEEE Transactions on Autonomous Mental Development, 2010.
[44] Chris Nota and Philip S. Thomas. Is the policy gradient a gradient? arXiv preprint arXiv:1906.07073, 2020.
[45] Junhyuk Oh, Matteo Hessel, Wojciech M Czarnecki, Zhongwen Xu, Hado van Hasselt, Satinder Singh, and David Silver. Discovering reinforcement learning algorithms. arXiv preprint arXiv:2007.08794, 2020.
[46] Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. Pytorch: An imperative style, high-performance deep learning library. In Advances in Neural Information Processing Systems 32 . Curran Associates, Inc., 2019.
[47] Barak A Pearlmutter. Fast exact multiplication by the hessian. Neural computation, 1994.
[48] Silviu Pitis. Rethinking the discount factor in reinforcement learning: A decision theoretic approach. In Proceedings of the AAAI Conference on Artificial Intelligence, 2019.
[49] Aravind Rajeswaran, Chelsea Finn, Sham M Kakade, and Sergey Levine. Meta-learning with implicit gradients. In Advances in Neural Information Processing Systems, 2019.
[50] Aravind Rajeswaran, Igor Mordatch, and Vikash Kumar. A game theoretic framework for model based reinforcement learning. arXiv preprint arXiv:2004.07804, 2020.
[51] John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov. Proximal policy optimization algorithms. arXiv preprint arXiv:1707.06347, 2017.
[52] Satinder Singh, Richard L Lewis, and Andrew G Barto. Where do rewards come from. In Proceedings of the Annual Conference of the Cognitive Science Society, 2009.
[53] Satinder Singh, Richard L Lewis, Andrew G Barto, and Jonathan Sorg. Intrinsically motivated reinforcement learning: An evolutionary perspective. IEEE Transactions on Autonomous Mental Development, 2010.
[54] Jonathan Sorg, Richard L Lewis, and Satinder Singh. Reward design via online gradient ascent. Advances in Neural Information Processing Systems, 2010.
13
[55] Jonathan Sorg, Satinder P Singh, and Richard L Lewis. Internal rewards mitigate agent boundedness. In Proceedings of the 27th international conference on machine learning (ICML- 10), 2010.
[56] Jonathan Sorg, Satinder P Singh, and Richard L Lewis. Optimal rewards versus leaf-evaluation heuristics in planning agents. In Proceedings of the AAAI Conference on Artificial Intelligence, 2011.
[57] Jonathan Daniel Sorg. The Optimal Reward Problem: Designing Effective Reward for Bounded Agents. PhD thesis, University of Michigan, 2011.
[58] Richard S Sutton and Andrew G Barto. Reinforcement learning: An introduction . MIT press, 2018.
[59] Philip Thomas. Bias in natural actor-critic algorithms. In International Conference on Machine Learning, 2014.
[60] John N Tsitsiklis and Benjamin Van Roy. An analysis of temporal-difference learning with function approximation. IEEE Transactions on Automatic Control, 1997.
[61] Marin Vlastelica, Anselm Paulus, Vít Musil, Georg Martius, and Michal Rolínek. Differentiation of blackbox combinatorial solvers. arXiv preprint arXiv:1912.02175, 2019.
[62] Yufei Wang, Qiwei Ye, and Tie-Yan Liu. Beyond exponentially discounted sum: Automatic learning of return function. arXiv preprint arXiv:1905.11591, 2019.
[63] Martha White. Unifying task specification in reinforcement learning. In International Confer- ence on Machine Learning, 2017.
[64] Eric Wiewiora. Potential-based shaping and q-value initialization are equivalent. Journal of Artificial Intelligence Research, 2003.
[65] Eric M Wolff, Ufuk Topcu, and Richard M Murray. Robust control of uncertain markov decision processes with temporal logic specifications. In 2012 IEEE 51st IEEE Conference on Decision and Control (CDC), 2012.
[66] David H Wolpert and Kagan Tumer. Optimal reward functions in distributed reinforcement learning. In Intelligent agent technology: Research and development . World Scientific, 2001.
[67] Yuhuai Wu, Mengye Ren, Renjie Liao, and Roger Grosse. Understanding short-horizon bias in stochastic meta-optimization. arXiv preprint arXiv:1803.02021, 2018.
[68] Zhongwen Xu, Hado P van Hasselt, and David Silver. Meta-gradient reinforcement learning. In Advances in Neural Information Processing Systems, 2018.
[69] Zhongwen Xu, Hado P van Hasselt, Matteo Hessel, Junhyuk Oh, Satinder Singh, and David Silver. Meta-gradient reinforcement learning with an objective discovered online. Advances in Neural Information Processing Systems, 2020.
[70] Zeyu Zheng, Junhyuk Oh, and Satinder Singh. On learning intrinsic rewards for policy gradient methods. In Advances in Neural Information Processing Systems, 2018.
[71] Zeyu Zheng, Junhyuk Oh, Matteo Hessel, Zhongwen Xu, Manuel Kroiss, Hado Van Hasselt, David Silver, and Satinder Singh. What can learned intrinsic rewards capture? In International Conference on Machine Learning, 2020.
[72] Haosheng Zou, Tongzheng Ren, Dong Yan, Hang Su, and Jun Zhu. Reward shaping via meta-learning. arXiv preprint arXiv:1901.09330, 2019.
14
Behavior Alignment via Reward Function Optimization (Supplemental Material)
Table 2: Notations
Symbol Description
θ Parameters for policy π ϕ Parameters for reward function φ Parameters for learned γ πθ, rϕ, γφ Functional form of policy, reward and γ with their respective parameters αθ, αϕ, αφ Step sizes for the respective parameters λθ, λϕ, λφ Regularization for policy, reward and γ function δ Number of on-policy samples collected between subsequent updates to ϕ, φ η Neumann Approximator Eigen value scaling factor n Number of loops used in Neumann Approximation optim Any standard optimizer like Adam, RMSprop, SGD, which takes input as gradients and outputs the appropriate update E Total Number of episodes to sample from the environment Ni Number of updates to be performed for updating the π by Alg N 0 Number of initial updates to be peformed τ Sample of a trajectory from a full episode
A Proofs for Theoretical Results
In this section, we provide proofs for Property 1, Property 2, and Property 3. For the purpose of these proofs, we introduce some additional notation. To have a unified MDP notation for goal-based and time-based tasks, we first consider that in the the time-based task, time is a part of the state such that Markovian dynamics is ensured.
The (un-normalized) discounted and (un-normalized) undiscounted visitation probability is denoted as
d [π] γ [(] [s, a] [) :=]
d ¯ [π] ( s, a ) :=
T
- γ [t] Pr( St = s, At = a ; π ) , (9)
t =0
T
- Pr( St = s, At = a ; π ) . (10)
t =0
We can normalize it so that it is a distribution as follows :
d ¯ [π] ( s, a ) d [π] ( s, a ) :=
�
s [′] ∈S,a [′] ∈A [d] [¯] [π] [(] [s][′][, a][′] [)] [.]
Property 1. The expected update performed by the biased policy gradient update is same when using the primary reward and reward modified with potential-based shaping, i.e., ∆( θ, ˜ r ) = ∆( θ, rp ) . Further, the variance of the update when using potential-based reward shaping can be higher than the
- - - _variance of the update performed using the primary reward, i.e.,_ Var ˆ∆( _θ,_ ˜ _r_ ) _≥_ Var ˆ∆( _θ, rp_ ) _._
15
Proof. Part 1: Equality of the expected update
T
- γ [j][−][t] r ˜( Sj, Aj )
j = t
∆( θ, ˜ r ) = E πθ
= E πθ
= E πθ
T
T
ψθ ( St, At )
t =0
ψθ ( St, At )
t =0
T
T
ψθ ( St, At )
t =0
- γ [j][−][t] ( rp ( Sj, Aj ) + γ Φ( Sj +1) − Φ( Sj ))
j = t
T
- γ [j][−][t] rp ( Sj, Aj )
j = t
+ E πθ
T
ψθ ( St, At )
t =0
T
- γ [j][−][t] ( γ Φ( Sj +1) − Φ( Sj ))
j = t
T
- γ [j][−][t] ( γ Φ( Sj +1) − Φ( Sj ))
j = t
= ∆( θ, rp ) + E πθ
( a ) = ∆( θ, rp ) + E πθ
( b ) = ∆( θ, rp ) + E πθ
( c ) = ∆( θ, rp ) + E πθ
( d ) = ∆( θ, rp ) ,
T
ψθ ( St, At )
t =0
T
ψθ ( St, At )( γ [T][ −][t] [+1] Φ( ST +1) − Φ( St ))
t =0
T
ψθ ( St, At )( γ [T][ −][t] [+1] c − Φ( St ))
t =0
- T
( γ [T][ −][t] [+1] c − Φ( St ))E πθ [ ψθ ( St, At ) |St ] t =0
where (a) holds because on the expansion of future return, intermediate potential values cancel out, (b) holds because ST +1 is the terminal state and potential function is defined to be a fixed constant c for any terminal state [41], (c) holds from the law of total expectation, and (d) holds because,
- πθ ( St, a ) [∂] [ln] [ π][θ] [(] [S][t][, a] [)]
∂θ
a∈A
∂πθ ( St, a )
E πθ [ ψθ ( St, At ) |St ] =
[θ] [t] = ∂θ
- πθ ( St, a ) = 0 .
a∈A
a∈A
( St, a )
= [∂] ∂θ ∂θ
∂θ
In the stochastic setting, i.e., when using sample average estimates instead of the true expectation, γ [T][ −][t] [+1] c − ϕ ( St ) is analogous to a state-dependent baseline for the sum of discounted future primary rewards. It may reduce or increase the variance of ∆( θ, rp ), depending on this baseline’s co-variance with [�] j [T] = t [γ][j][−][t][r][p] [(] [S][j][, A][j] [)][.]
Note: As we encountered the potential at the terminal state to be c, as it is a constant, we will use the value of c = 0 in accordance with [41].
Part 2: Variance characterization
For this result that discusses the possibility of the variance being higher when using potential-based reward shaping, we demonstrate the result using a simple example. We will consider the single-step case wherein an episode lasts for one time step. That is, the agent takes an action A 0 at the starting state S 0 and then transitions to the terminal state. Hence, the stochastic update ∆( [ˆ] θ, ˜ r ) can be written as:
ˆ∆( θ, ˜ r ) = ψθ ( S 0 , A 0)˜ r ( S 0 , A 0) = ψθ ( S 0 , A 0)( rp ( S 0 , A 0) − Φ( S 0)) ,
wherein, we assume that Φ for terminal states is 0 and similarly, ∆( [ˆ] θ, rp ) = ψθ ( S 0 , A 0) rp ( S 0 , A 0).
For the purpose of this proof we will consider the case wherein we have a scalar θ, i.e., θ ∈ R, such that, ψθ ( ., . ) ∈ R.
16
- Hence, Var ˆ∆( _θ,_ ˜ _r_ ) can be written as:
- �2 Var ˆ∆( θ, ˜ r ) =E ˆ∆( θ, ˜ r ) [2][�] − E ˆ∆( θ, ˜ r )
=E�( ψθ ( S 0 , A 0)( rp ( S 0 , A 0) − Φ( S 0))) [2][�] − E[ ψθ ( S 0 , A 0)( rp ( S 0 , A 0) − Φ( S 0))] [2]
(= a )E� ψθ ( S 0 , A 0) [2] ( rp ( S 0 , A 0) [2] + Φ( S 0) [2] − 2Φ( S 0) rp ( S 0 , A 0))� − E[ ψθ ( S 0 , A 0)( rp ( S 0 , A 0))] [2]
=E� ψθ ( S 0 , A 0) [2] (Φ( S 0) [2] − 2Φ( S 0) rp ( S 0 , A 0))� +
E� ψθ ( S 0 , A 0) [2] rp ( S 0 , A 0) [2][�] − E[ ψθ ( S 0 , A 0)( rp ( S 0 , A 0))] [2]
��Var(∆( [ˆ] θ,rp ))
.
Therefore,
Var�ˆ∆( θ, ˜ r )� − Var�ˆ∆( θ, rp )� = E� ψθ ( S 0 , A 0) [2] (Φ( S 0) [2] − 2Φ( S 0) rp ( S 0 , A 0))� .
Subsequently, variance of ∆( [ˆ] θ, ˜ r ) will be higher than that of ∆( [ˆ] θ, rp ) if E� ψθ ( S 0 , A 0) [2] Φ( S 0) [2][�] − 2E� ψθ ( S 0 , A 0) [2] Φ( S 0) rp ( S 0 , A 0)� > 0.
Example: Let us look at an example where the above condition can be true. Let us consider an MDP with a single state and a single-step horizon. In that case, we can consider the variance of the update to the policy at the said state, i.e.,
Var π �ˆ∆( θ, ˜ r )� − Var π �ˆ∆( θ, rp )� = Φ( s ) [2] E π - ψθ ( s, A ) [2][�] − 2Φ( s )E π - ψθ ( s, A ) [2] ( rp ( s, A ))� ,
where s is the fixed state. Hence, the variance of the potential-based method might be more than the variance from using only the primary reward when
Φ( s ) [2] E π - ψθ ( s, A ) [2][�] − 2Φ( s )E π - ψθ ( s, A ) [2] ( rp ( s, A ))� > 0
Φ( s ) [2] E π - ψθ ( s, A ) [2][�] > 2Φ( s )E π - ψθ ( s, A ) [2] ( rp ( s, A ))� .
Further, let us consider the case where Φ( s ) ̸ = 0, because otherwise the variance of the update for those states would be same, and Φ( s ) > 0.
Φ( s ) [2][�] E π - ψθ ( s, A ) [2][�] > 2�Φ( [�] - s )E π - ψθ ( s, A ) [2] ( rp ( s, A ))�
Φ( s )E π - ψθ ( s, A ) [2][�] > 2E π - ψθ ( s, A ) [2] ( rp ( s, A ))� .
We can see that the above condition can be satisfied by choosing a potential function that might be overly optimistic about the average reward of the state s, i.e. any Φ( s ) , s.t. Φ( s ) > 2 rp ( s, a ) ∀a would lead to an increase in variance. A common place where this might be true is the use of an optimal value function (as hinted by [41]) as a baseline for a bad/mediocre policy initially.
Property 2. There exists rϕ : S × A → R and γφ ∈ [0 , 1) such that ∆ on ( θ, ϕ, φ ) = ∆ γ ( θ, rp ) .
Proof. Recall the definition of ∆ γ ( θ, rp ) from Section 4.1:
γ [t] ψθ ( St, At )
17
.
T
- γ [j][−][t] rp ( Sj, Aj )
j = t
∆ γ ( θ, rp ) = E πθ
T
t =0
Using the law of total expectation,
St, At ������
T
- γ [j][−][t] rp ( Sj, Aj )
j = t
∆ γ ( θ, rp ) = E πθ
= E πθ
T
t =0
- T
t =0
γ [t] ψθ ( St, At )E πθ
γ [t] ψθ ( St, At ) q [π][θ] ( St, At )
=
s∈S,a∈A
T
t =0
γ [t] Pr( St = s, At = a ; πθ ) ψθ ( s, a ) q [π][θ] ( s, a )
= - ψθ ( s, a ) q [π][θ] ( s, a )
s∈S,a∈A
T
t =0
γ [t] Pr( St = s, At = a ; πθ )
= - ψθ ( s, a ) q [π][θ] ( s, a ) d [π] γ [θ] [(] [s, a] [)] [.] (11)
s∈S,a∈A
Notice from (9) and (10) that for any ( s, a ) pair, if d [π] γ [θ] [(] [s, a] [)] [ >] [ 0][, then][ ¯] [d][π][θ] [(] [s, a] [)] [ >] [ 0][ since] [ γ][ ≥] [0][.] Therefore, dividing and multiplying by d [¯] [π][θ] ( s, a ) leads to:
∆ γ ( θ, rp ) = - d ¯ [π] θ ( s, a ) ψθ ( s, a ) q [π] θ ( s, a ) [d] d ¯ γ [π] π [θ] θ [(] ( [s, a] s, a ) [)]
s∈S,a∈A
=
s∈S,a∈A
T
- γ [(] [s, a] [)]
Pr( St = s, At = a ; πθ ) ψθ ( s, a ) q [π][θ] ( s, a ) [d] d ¯ π [π][θ] θ ( s, a )
t =0
= E πθ
T
γ [(] [S][t][, A][t] [)]
t =0 ψθ ( St, At ) q [π][θ] ( St, At ) [d] d ¯ [π] π [θ] θ ( St, At )
.
πθ
Now, notice that if γφ = 0 and rϕ ( s, a ) = q [π][θ] ( s, a ) [d] d ¯ γ [π] θ ( [(] [s,a] s,a [)] ) [, for all] [ s][ ∈S] [ and] [ a][ ∈A] [, then]
∆on( θ, ϕ, φ ) = ∆ γ ( θ, rp ) .
Property 3. There exists rϕ : S × A → R and γφ ∈ [0 , 1) such that ∆ off ( θ, ϕ, φ ) = ∆ off ( θ, rp ) .
Proof. This proof follows a similar technique as the proof for Property 2. Recall the definition of ∆off( θ, rp ):
γ [t] ρtψθ ( St, At )
18
T
- γ [j][−][t] ρjrp ( Sj, Aj )
j = t
∆off( θ, rp ) := E β
:= E β
T
t =0
T
t =0
γ [t] ψθ ( St, At )
.
T
- γ [j][−][t] ρj−trp ( Sj, Aj )
j = t
Now using the law of total expectations,
- γ [j][−][t] ρj−trp ( Sj, Aj )
j = t
St, At ������
∆off( θ, rp ) = E β
T
γ [t] ρtψθ ( St, At )E β
t =0
T
St, At ������
T
- γ [j][−][t] rp ( Sj, Aj )
j = t
= E πθ
= E πθ
T
t =0
- T
t =0
γ [t] ψθ ( St, At )E πθ
γ [t] ψθ ( St, At ) q [π][θ] ( Sj, Aj )
= - ψθ ( s, a ) q [π][θ] ( s, a ) d [π] γ [θ] [(] [s, a] [)] [,]
s∈S,a∈A
where the last line follows similar to (11). Now, notice that for any ( s, a ) pair, the assumption that πθ ( s, a ) /β ( s, a ) < ∞_ for all _s ∈S, a ∈A_, implies _d_ _[π]_ _γ_ _[θ]_ [(] _[s, a]_ [)] _[/d]_ _γ_ _[β]_ [(] _[s, a]_ [)] _[ <][ ∞]_ [. Further, if] _d_ _[β]_ _γ_ [(] _[s, a]_ [)] _[ >] [ 0][ it has to be that] [ d][β] [(] [s, a] [)] [ >] [ 0][ as well. Therefore,] [ d][π] γ [θ] [(] [s, a] [)] [/d][β] [(] [s, a] [)] [ <][ ∞] [as well.] Multiplying and dividing by d [β] ( s, a ) results in:
∆off( θ, rp ) = - d ¯ [β] ( s, a ) ψθ ( s, a ) q [π] θ ( s, a ) [d] d ¯ γ [π] β [θ] ( [(] s, a [s, a] ) [)]
s∈S,a∈A
T
- γ [(] [s, a] [)]
= Pr( St = s, At = a ; β ) ψθ ( s, a ) q [π][θ] ( s, a ) [d] d
¯[π] β [θ] ( s, a )
- γ [(] [s, a] [)]
= Pr( St = s, At = a ; β ) ψθ ( s, a ) q [π][θ] ( s, a ) [d] d
s∈S,a∈A t =0
= E β
T
γ [(] [S][t][, A][t] [)]
t =0 ψθ ( St, At ) q [π][θ] ( St, At ) [d] d ¯ [π] β [θ] ( St, At )
.
πθ
Finally, notice that if γφ = 0 and rϕ ( s, a ) = q [π][θ] ( s, a ) [d] d ¯ γβ ( [(] s,a [s,a] ) [)] [for all] [ s][ ∈S] [ and] [ a][ ∈A] [,]
∆off( θ, ϕ, φ ) = ∆off( θ, rp ) .
Remark 2. Notice that as with any optimization problem, issues of realizability and identifiability of the desired rϕ must be taken into account. The examples provided in this section aim to highlight the capability of optimized behavior alignment reward functions. In particular, they not only improve and accelerate the learning process but are also capable of inducing updates capable of ‘fixing’ imperfections in the underlying RL algorithm.
B Extended Related Works
The bi-level objective draws inspiration from the seminal work of Singh et al. [52, 53] that provides an optimal-rewards framework for an agent. Prior works have built upon it to explore search techniques using evolutionary algorithms [43, 21], develop extensions for multi-agent setting [66, 22], and mitigate sub-optimality due to use of inaccurate models [55–57]. Our work also builds upon this direction and focuses on various aspects of leveraging auxiliary rewards r aux, while staying robust against its misspecification.
Apart from specifying auxiliary rewards r aux directly, other techniques for reward specification include linear temporal logic [35, 11, 65, 39] or reward machines [29–31] that allow exposing the reward functions as a white-box to the agent.
Recent works also explore γ that is state-action dependent [63, 48], or establishes connection between γ and value function regularization in TD learning Amit et al. [3]. These ideas are complementary to our proposed work and combining these with BARFI remains interesting directions for the future.
The concept of path-based meta-learning was initially popularized for few-shot task learning in supervised learning [15, 42]. Similar path-based approaches have been adopted in reinforcement
19
learning (RL) in various forms [28, 62, 69, 71]. Initially designed for stochastic gradient descent, these methods have been extended to other optimizers such as Adam [32] and RMSprop [25], treating them as differentiable counterparts [20].
C Algorithm
In this section we discuss the algorithm for the proposed method. As the proposed method does behavior alignment reward function’s implicit optimization, we name it BARFI. Pseudo-code for BARFI is presented in Algorithm 5. We will first build on some preliminaries to understand the concepts.
C.1 Vector Jacobian Product
Let us assume that, x ∈ R [d] , y ∈ R [m] , f ( x, y ) ∈ R. Then, we know that ∂f ( x, y ) /∂x ∈ R [d] , ∂f ( x, y ) /∂y ∈ R [m] , ∂ [2] f ( x, y ) /∂y∂x ∈ R [d][×][m] . Let us also assume that we have a vector v ∈ R [d], and if we need to calculate the following, we can pull the derivative outside as shown:
= [∂]
∂y
.
v , [∂f] ∂x [(] [x,y] [)]
����
R [d] - � - �
R [d]
v ���� R [d]
∂ [2] f ( x, y )
���� ∂y∂x R [d]
���R [d][×][m]
� R � [m] - �
� �� �
R [1]
� R �� [m] �
As we can see, the vector Jacobian product can be broken down into differentiating a vector product but shifting the place of multiplication, in which case we assume that the gradient passes through v w.r.t. y and hence we don’t ever have to deal with large multiplications. Also note that the outer partial w.r.t. can easily be handled by autodiff packages. A pseudo-code is show in Algorithm 1.
Algorithm 1: Jacobian Vector Product
1 Input: f ( x, y ) ∈ R [1] , x ∈ R [d] , y ∈ R [m] , v ∈ R [d]
2 f [′] ← grad( f ( x, y ) , x )
3 jvp ← grad( f [′] , y, grad_outputs = v )
4 Return: jvp
C.2 Neumann Series Approximation for Hessian Inverse
Recall, that for a given real number β ∈ R, such that 0 ≤ β < 1, we know that the geomertric series of this has a closed form solution, i.e., s = 1 + β [1] + β [2] + β [3] + · · · +
1
1 − β [.]
Similarly, given we have a value α such that β = 1 − α, we can write α [−] [1] as follows: 1 1 − β [= 1 +] [ β] [ +] [ β] [2][ +] [ β] [3][ +] [ · · ·] [ +]
1 1 − (1 − α ) [= 1 + (1] [ −] [α] [) + (1] [ −] [α] [)][2][ + (1] [ −] [α] [)][3][ +] [ · · ·] [ +]
α [−] [1] = 1 + (1 − α ) + (1 − α ) [2] + (1 − α ) [3] + · · · +
α [−] [1] =
∞ �(1 − α ) [i] .
i =0
The same can be generalized for a matrix, i.e., given a matrix A ∈ R [d][×][d], we can write A [−] [1] as follows:
A [−] [1] =
∞ �( I − A ) [i] .
i =0
20
Note for the above to hold, matrix A, where we represent eig( A ) as the eigenvalues of matrix A, we should have the following condition to hold, 0 < eig( A ) < 1. Note here we would regularize A to ensure that all eigenvalues are positive, and then we can always scale the matrix A, by its biggest eigenvalue to ensure that the above condition holds. Let say η = 1 / max eig( A ). Then we can write the following:
A [−] [1] = [η]
η [A] [−] [1]
= η ( η A ) [−] [1]
= η
∞ �( I − η A ) [i] .
i =0
As η A would always satisfy the above condition.
C.3 Neumann Approximation for Hessian Vector Product
Given we have seen how we can approximate the Inverse of a matrix without relying O ( d [3] ) operations, through Neumann approximation, lets look what needs to be done for our updates. Recall that the update ϕ, φ (8) and (15) were,
- − 1 ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂ϕ
� � - �
A
( ϕ, φ ))
= − [∂J] [(] [θ] [(] [ϕ, φ] [))] ∂ϕ ∂θ ( ϕ, φ )
∂J ( θ ( ϕ, φ ))
∂θ ( ϕ, φ )
� �� �
v
∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂θ ( ϕ, φ )
� � - �
H
and
- − 1 ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂φ
���B
∂ - J ( θ ( ϕ, φ )) − [1]
[1] 2 [∥][γ][φ][∥] [2][�]
)) − 2 [∥][γ][φ][∥]
= − [∂J] [(] [θ] [(] [ϕ, φ] [))] ∂φ ∂θ ( ϕ, φ )
∂θ ( ϕ, φ )
� �� �
v
∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂θ ( ϕ, φ )
� - � �
H
− [∂γ][φ]
∂φ [.]
Let us look closely at the update for ϕ and we can generalize the updates easily for the case of φ .
∂J ( θ ( ϕ, φ ))
= −v H [−] [1] A ∂ϕ
We first look at how we can approximate the value of v H [−] [1] efficiently, as we can always make use of the Jacobian Vector product later to get ( v H [−] [1] ) A, as v H [−] [1] becomes a vector. Let us assume we wish to run the Neumann approximation up to n steps, i.e., we want to approximate H [−] [1] up to n order Neumann expansion,
η ( η H [−] [1] ) ≈ η
n �( I − η H ) [i] (12)
i =0
Here we are assuming that the outer optimization for update (1) is for the function J ( θ ( ϕ, φ )) and the inner optimization which is represented by the update (3) is f ( θ ( ϕ, φ ) , ϕ, φ ), i.e.,
∆( θ, rp ) = [∂J] [(] [θ] [(] [ϕ, φ] [))]
[(] [ϕ, φ] [))]
, ∆( θ, ϕ, φ ) = [∂f] [(] [θ] [(] [ϕ, φ] [)] [, ϕ, φ] [)] ∂θ ∂θ
. ∂θ
The most common form in which f (; B ) is usually defined is the following:
.
1 f ( θ, ϕ, φ ; B ) := |B|
τ ∈B
- log( πθ ( St [τ] [, A] t [τ] [))]
t =0
T
T
- γφ [j][−][t] rϕ ( Sj [τ] [, A] j [τ] [)]
j = t
21
Algorithm 2: Vector Hessian Inverse Product for (8) i.e., v H [−] [1]
1 Input: θ, ϕ, φ, J, f, n, η, D off , D on 2 v ← grad( J ( θ ; D on) , θ )
3 v [′] ← η × grad( f ( θ, ϕ, φ ; D off) , θ )
4 Let: v 0 ← v, p 0 ← v
5 for i ∈ [0 , n ) do
6 vi +1 ← vi − grad( v [′] , θ, grad_outputs = vi )
7 pi +1 ← pi + vi +1
8 Return: ηpn ; // Approximation of v H [−] [1] as in (12)
Similarly this can be defined for J, except making use of rp and problem defined γ :
.
1 J ( θ ; B ) := |B|
τ ∈B
- log( πθ ( St [τ] [, A] t [τ] [))]
t =0
T
T
- γ [j][−][t] rp ( Sj [τ] [, A] j [τ] [)]
j = t
Finally, once we have v H [−] [1], we can use the Vector Jacobian Product to calculate ( v H [−] [1] ) A as described in Algorithm 3:
Algorithm 3: Update for ϕ, i.e. (8) i.e., v H [−] [1] A
1 Input: θ, ϕ, φ, J, f, n, η, D off , D on 2 v ← Algorithm 2 ( θ, ϕ, φ, J, f, n, η, D off , D on)
3 v [′] ← grad( f ( θ, ϕ, φ ; D off) , θ )
4 ∆ ϕ ← grad( v [′] , ϕ, grad_outputs = v )
5 Return ∆ ϕ
We can similarly derive updates for φ . Note we are not including the different forms of regularizers
Algorithm 4: Update for ϕ, i.e. (15) i.e., v H [−] [1] B
1 Input: θ, ϕ, φ, J, f, n, η, D off , D on 2 v ← Algorithm 2 ( θ, ϕ, φ, J, f, n, η, D off , D on)
3 v [′] ← grad( f ( θ, ϕ, φ ) , D off) , θ )
4 ∆ φ ← grad( v [′] , φ, grad_outputs = v )
5 Return ∆ φ
over here to reduce clutter, but adding them is simple.
C.4 Pseudo Code (Algorithm 5)
Lines 8–10 and 21–23 of Algorithm 5 represent the inner optimization process, and the outer optimization process if from lines 16-17. Lines 8–10 is the initial step of updates to converge to the current values of ϕ, φ, and from there onwards after each update of outer optimization, we consequently update the policy in (21–23). The flow of the algorithm is show in Figure 4.
As discussed in Section D, using regularizers in ∆( θ, ϕ, φ ) smoothens the objective J ( θ ( ϕ, φ )) with respect to ϕ and φ . This is helpful as gradual changes in rϕ an γφ can result in gradually changes in the fixed point for the inner optimization. Therefore, for computational efficiency, we initialize the policy parameters from the fixed-point of the previous inner-optimization procedure such that the inner-optimization process may start close to the new fixed-point.
In lines 8–10, the inner optimization for the policy parameters θ are performed till (approximate) convergence. Note that only trajectories from past interactions are used and no new-trajectories are sampled for the inner optimization.
22
Algorithm 5: BARFI: Behavior Alignment Reward Function’s Implicit optimization
1 Input: J, f, αθ, αϕ, αφ, η, n, δ, optim , E, Ni, N 0 ,
2 Initialize: πθ, rϕ, γφ 3 Initialize: optim θ ← optim( αθ ) , optim ϕ ← optim( αϕ ) , optim φ ← optim( αφ )
4 D off ← [ ]
Collect a batch of data for warmup period
5 for e ∈ [1 , N 0) do
6 Generate τe using πθ 7 Append τe to D off
Initial training steps using warmup data
8 for i ∈ [0 , Ni + N 0) do
9 Sample a batch of trajectories B from D off
Update policy
10 θ ← θ + optim θ (grad( f ( θ, ϕ, φ ; B ) , θ ))
Start reward alignment
11 for e ∈ [ N 0 , E ) do
Collect a batch of on-policy data
12 D on ← [ ]
13 for j ∈ [0 , δ ) do
14 Generate trajectory τe + j using πθ and append in D on
15 e ← e + δ
Update rϕ and γφ
16 ∆ ϕ ← Algorithm 3( θ, ϕ, φ, J, f, n, η, D off , D on)
17 ∆ φ ← Algorithm 4( θ, ϕ, φ, J, f, n, η, D off , D on)
18 ϕ ← ϕ + optim ϕ (∆ ϕ )
19 φ ← φ + optim φ (∆ φ )
20 D off ←D off + D on
Learn policy for new reward function, initializing from the last
21 for i ∈ [0 , Ni ) do
22 Sample a batch of trajectories B from D off
Update policy
23 θ ← θ + optim θ (grad( f ( θ, ϕ, φ ; B ) , θ ))
Figure 4: Algorithm Flow: The change in different parameters
In Lines 13–14, a new batch D on of data is sampled using the policy returned by the inner-optimization process. This data is used to compute ∂J ( θ ( ϕ, φ )) /∂θ ( ϕ, φ ). Existing data D off that was used in the inner-optimization process is then used to compute ∂θ ( ϕ, φ ) /∂ϕ and ∂θ ( ϕ, φ ) /∂φ . Using these in (8) and (15), the parameters for rϕ and γφ are updated in Lines 16 and 17, respectively.
Finally, the new data D on is merged into the existing data D off and the entire process continues.
C.5 Note on Approximation
An important limitation of the methods discussed above is that θ ( ϕ, φ ) is considered such that ∆( θ ( ϕ, φ ) , ϕ, φ ) = 0, i.e., the Alg is run to convergence. In practice, we only execute Alg for a predetermined number of update steps that need not result in convergence to an optimum exactly . However, the impact of this approximation can be bounded by assuming convergence to an ϵ neighborhood of the optima [49]. Furthermore, due to smoothness in the functional space, slight
23
changes to ϕ and φ should result in slight shifts in the optimum θ ( ϕ, φ ). The continuity property allows for improvements in the optimization process: it suffices to initialize the parameters of each inner-loop optimization problem with the final parameters of the approximate fixed point solution, ( ϕ, φ ), identified in the previous iteration of the inner loop. The complete resulting algorithm is presented in the appendix as Algorithm 5.
C.6 Path-wise Bi-level Optimization
An alternative approach for computing the term (b) in (4) is possible. The formulation of BARFI described above, based on implicit bi-level optimization, is agnostic to the optimization path taken by Alg. For the sake of completeness, let us also consider a version of BARFI that does take into account the path followed by the inner optimization loop. This is advantageous because it allows us to eliminate the need for the convergence criteria (5). We call this variant BARFI unrolled. The main difference, in this case, is that when computing the term (b) in (4), we now consider each inner update step until the point θ ( ϕ, φ ) is reached—where the sequence of steps depends on the specific Alg used for the inner updates. Details are deferred to Appendix C. Notice that this approach results in a path-wise optimization process that can be more demanding in terms of computation and memory. We further discuss this issue, and demonstrate the efficacy of this alternative approach, in the empirical analyses section (Section ?? ).
D Smoothing the objective
To understand why J ( θ ( ϕ, φ )) might be ill-conditioned is to note that, often a small perturbation in the reward function doesn’t necessarily lead to a change in the corresponding optimal policy. This can lead lack of gradient directions in the neighborhood of ϕ, φ for gradient methods to be effective. This issue can be addressed by employing common regularization techniques like L2 regularization of the policy parameters or entropy regularization for the policy [6] . We discuss two ways to regularize the objective in the upcoming sections.
D.1 L2 Regularization
To understand how severely ill-conditioned J ( θ ( ϕ, φ )) can be, notice that a small perturbation in the reward function often does not change the corresponding optimal policies or the outcome of a policy optimization algorithm Alg. Therefore, if the parameters of the behavior alignment reward are perturbed from ϕ to ϕ [′], it may often be that J ( θ ( ϕ, φ )) = J ( θ ( ϕ [′] , φ )) and this limits any gradient based optimization for ϕ as ∂J ( θ ( ϕ, φ )) /∂ϕ is 0. Similarly, minor perturbations in φ may result in no change in J ( θ ( ϕ, φ )) either.
Fortunately, there exists a remarkably simple solution: incorporate regularization for the policy parameters θ in objective for Alg in the inner-level optimization. For example, the optimal policy for the following regularized objective E πθ [ [�] [T] t =0 [γ] φ [t] [r][ϕ] [(] [S][t][, A][t] [)]] [ −] [λ] 2 [∥][θ][∥] [2][ varies smoothly to trade-off]
between the regularization value of θ and the magnitude of the performance characterized by ( rϕ, γφ ), which changes with the values of rϕ and γφ . See Figure 5 for an example with L2 regularization.
D.2 Entropy Regularized
In Section D.1, smoothing of J ( θ ( ϕ, φ )) was done by using L2 regularization on the policy parameters θ in the inner-optimization process. However, alternate regularization methods can also be used. For example, in the following we present an alternate update rule for θ based on entropy regularization,
.
∆( θ, ϕ, φ ) := E D
T
ψθ ( St, At )
t =0
T
- γφ [j][−][t] ( rϕ ( Sj, Aj ) − λ ln πθ ( Sj, Aj ))
j = t
6This regularization is performed so as to avoid a noninvertible Hessian as we had discussed in Section 5
24
Figure 5: (Left) A bandit problem, where the data is collected from a policy β that samples action A mostly. (Middle) Each point on the 3D surface corresponds to the performance of θ ( ϕ, 1) returned by an Alg that uses the update rule ∆off( θ, ϕ, 1) corresponding to the value of rϕ for actions A and C in the bottom axes; rθ for action B is set to 0 to avoid another variable in a 3D plot. Notice that small perturbation in rϕ may lead to no or sudden changes in J ( θ ( ϕ, 1)). (Right) Performance of θ ( ϕ, 1) returned by an Alg that uses the update rule ∆off( θ, ϕ, 1) − θ that incorporates gradient of the L2 regularizer. Vector fields in Figure 1 were also obtained from this setup.
Notice that new update rule for ϕ and φ can be obtained from steps (4) to (15) with the following A, B, and H instead, where for shorthand θ [∗] = θ ( ϕ, φ ),
T
- ψθ [∗] ( St, At )
t =0
∂ϕ
T
γφ [j][−][t] rϕ ( S∂ϕj, Aj )
j = t
- ⊤ []
,
A = E D
B = E D
H = E D
T
∂ψθ [∗] ( St, At )
∂θ [∗]
t =0
T
��
∂γφ [j][−][t] ( rϕ ( Sj, Aj ) − λ ln πθ [∗] ( Sj, Aj )) ∂φ
��
T
ψθ [∗] ( St, At )
t =0
T
T
j = t
,
− λψθ [∗] ( St, At )
.
T
γφ [j][−][t] ( rϕ ( Sj, Aj ) − λ ln πθ [∗] ( Sj, Aj ))
j = t
T ��
γφ [j][−][t] ψθ [∗] ( Sj, Aj ) [⊤]
j = t
E Meta Learning via Implicit Gradient: Derivation
The general technique of implicit gradients [14, 34, 19] has been used in a vast range of applications, ranging from energy models [13, 36], differentiating through black-box solvers [61], few-shot learning
[38, 49], model-based RL [50], differentiable convex optimization neural-networks layers [4, 2], to hyper-parameter optimization [37, 8, 12, 40]. In this work, we show how implicit gradients can also be useful to efficiently leverage auxiliary rewards ra and overcome various sub-optimalities.
Taking total derivative in (5) with respect to ϕ,
d ∆( θ ( ϕ, φ ) , ϕ, φ )
) , ϕ, φ )
= [∂] [∆(] [θ] [(] [ϕ, φ] [)] [, ϕ, φ] [)] dϕ ∂ϕ
[)] [, ϕ, φ] [)]
- [∂] [∆(] [θ] [(] [ϕ, φ] [)] [, ϕ, φ] [)] ∂ϕ ∂θ ( ϕ, φ )
[θ] [(] [ϕ, φ] [)] [, ϕ, φ] [)] ∂θ ( ϕ, φ )
∂θ ( ϕ, φ ) ∂ϕ
= 0 . (13) ∂ϕ
Let us try to understand why the above is true, considering the finite difference approach for this derivative,
) , ϕ, φ ) ∆( θ ( ϕ + dϕ, φ ) , ϕ + dϕ, φ ) − ∆( θ ( ϕ, φ ) , ϕ, φ )
= lim dϕ ∥dϕ∥→ 0 dϕ
d ∆( θ ( ϕ, φ ) , ϕ, φ )
dϕ
= [0] [ −] [0] = 0 ,
dϕ
∆( θ ( ϕ + dϕ, φ ) , ϕ + dϕ, φ ) = ∆( θ ( ϕ, φ ) , ϕ, φ ) = 0, as θ ( ·, · ) defines convergence to fixed point.
By re-arranging terms in (13) we obtain the term (b) in (4),
ϕ, φ ) - ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
= − ∂ϕ ∂θ ( ϕ, φ )
- − 1 ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
. (14) ∂ϕ
∂θ ( ϕ, φ )
∂θ ( ϕ, φ )
25
By combining (14) with (4) we obtain the desired gradient expression for ϕ,
- − 1 ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
,
∂ϕ
- �� A
∂J ( θ ( ϕ, φ ))
( ϕ, φ ))
= − [∂J] [(] [θ] [(] [ϕ, φ] [))] ∂ϕ ∂θ ( ϕ, φ )
∂θ ( ϕ, φ )
∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂θ ( ϕ, φ )
��H
and following similar steps, it can be observed that the gradient expression for φ,
- − 1 ∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂φ
��B
[1] 2 [∥][γ][φ][∥] [2][�]
∂ - J ( θ ( ϕ, φ )) − [1]
)) − 2 [∥][γ][φ][∥]
= − [∂J] [(] [θ] [(] [ϕ, φ] [))] ∂φ ∂θ ( ϕ, φ )
∂ ∆( θ ( ϕ, φ ) , ϕ, φ )
∂θ ( ϕ, φ )
�- H
− [∂γ][φ]
∂φ [,]
∂θ ( ϕ, φ )
where using θ [∗] as a shorthand for θ ( ϕ, φ ) the terms A , B and H can be expressed as
T
- ψθ [∗] ( St, At )
t =0
∂ϕ
T
ψθ [∗] ( St, At )
t =0
- T
j = t
��
∂γφ [j][−][t] ∂φ [r][ϕ] [(] [S][j][, A][j] [)]
(15)
,
T
γφ [j][−][t] ∂rϕ ( ∂ϕSj, Aj )
j = t
- ⊤ []
, B = E D
- T
A = E D
��
− λ.
T
γφ [j][−][t] rϕ ( Sj, Aj )
j = t
H = E D
- T
t =0
∂ψθ [∗] ( St, At )
∂θ [∗]
These provide the necessary expressions for updating ϕ and φ in the outer loop. As A involves an outer product and H involves second derivatives, computing them exactly might not be practical when dealing with high-dimensions. Standard approximation techniques like conjugate-gradients or Neumann series can thus be used to make it more tractable [40]. In our experiments, we made use of the Neumann approximation to the Hessian Inverse vector product ( AH [−] [1] ), which requires the same magnitude of resources as the baseline policy gradient methods that we build on top off.
Algorithm: Being based on implicit gradients, we call our method BARFI, shorthand for behavior alignment reward function’s implicit optimization. Overall, BARFI iteratively solves the bi-level optimization specified in (2) by alternating between using (3) till approximate converge of Alg to θ ( ϕ, φ ) and then updating rϕ and γφ . Importantly, being based on (3) for sample efficiency, Alg leverages only the past samples and does not sample any new trajectories for the inner level optimization. Further, due to policy regularization which smoothens the objective as discussed in D, updates in rϕ and γφ changes the policy resulting from Alg gradually. Therefore, for compute efficiency, we start Alg from the policy obtained from the previous inner optimization, such that it is in proximity of the new fixed point. This allows BARFI to be both sample and compute efficient while solving the bi-level optimization iteratively online. Pseudo-code for BARFI and more details on the approximation techniques can be found in Appendix C.
F Environment & Reward Details
The first environment is a GridWorld (GW), where the start state is in the bottom left corner and a goal state is in the top right corner. The agent receives an rp of +100 on reaching the goal followed by termination of the episode. The second environment is MountainCar (MC) [58], wherein we make use of the sparse reward variant, wherein the agent receives a +1 reward on reaching on top of the hill and 0 otherwise. The third environment is CartPole (CP) [16]. Finally, to assess the scalability we pick HalfCheetah-v4 from Mujoco (MJ) suite of OpenAI Gym [9].
For each environment, we define two auxiliarly reward functions. For GridWorld, we define the functions: r aux [1] , GW [:=] [ −] [(] [s][ −] [s] [goal][)][2][, which provides the negative L2 squared distance from the goal] position, and r aux [1] , GW [:= 50] [×] [1] [s][∈S] Center [, which provides an additional bonus of][ +50][ to the agent along] the desired path to the goal state (i.e. the center states). In MountainCar the state is composed of two components: the position x, and velocity v. The first auxiliary reward function, r aux [1] , MC [(] [s, a] [) :=] [ |] [v] [|] [,] encourages a higher absolute velocity of the car, and the second, r aux [1] , MC [(] [s, a] [) :=] [ 1] [sign(v)][=] [a] [,] encourages the direction of motion to increase the magnitude of the velocity (also knows as the energy pumping policy [18]). For CartPole, we consider a way to reuse knowledge from a hand crafted policy. CartPole can be solved using a Proportional Derivate (PD) controller [6], hence we tune a PD controller, PD [∗] : S →A, to solve CartPole for the max possible return. We design two auxiliary
26
reward functions which make use of this PD controller. The first, r aux [1] , CP [(] [s, a] [) := 5] [ ×] [ 1] PD [∗] ( s )= a [−] (1 − 1PD ∗ ( s )= a ), encourages the agent to match the action of the optimal PD controller, and penalizes it for not matching. The second auxiliary reward function, r aux [1] , GW [(] [s, a] [) :=] [ −][r] aux [1] , CP [(] [s, a] [)][, encourages] the agent to do the opposite. In the case of Mujoco, the reward function provided by the environment is itself composed of multiple different functions. We explain the same and the respective auxiliary functions for this case later.
We have considered several forms of information encoded as auxiliary rewards for these experiments. We have heuristic-based reward functions (i.e., r aux [1] , GW [, r] aux [1] , GW [, r] aux [1] , MC [). Reward func-] tions that encode a guess of an optimal policy (i.e., r aux [1] , MC [, r] aux [1] , CP [) and reward functions that] change the optimal policy (i.e., r aux [1] , GW [, r] aux [1] , CP [).] We also have rewards that only depend on states (i.e., r aux [1] , GW [, r] aux [1] , GW [, r] aux [1] , MC [) as well as ones that depend on both state and actions (i.e.,] r aux [1] , MC [, r] aux [1] , CP [, r] aux [1] , CP [). Therefore, we can test if][ BARFI][ can overcome misspecified auxiliary] reward functions and does not hurt performance when well-specified.
Mujoco Environment In this experiment, we investigate the scalability of BARFI in learning control policies for high-dimensional state spaces with continuous action spaces. In HalfCheetah-v4 the agent’s task is to move forward, and it receives a reward based on its forward movement (denoted as rp ). Additionally, there is a small cost associated with the magnitude of torque required for action execution (denoted as r aux( s, a ) := c|a| [2] 2 [). The weighting between the main reward and] the control cost is pre-defined as c for this environment, and we form the reward as ˜ r ( s, a ) = rp ( s, a ) + r aux( s, a ). We explore how an arbitrary weighting choice can cause the agent to fail in learning, while BARFI is still able to adapt and learn the appropriate weighting, remaining robust to possible misspecification. We consider two different weightings for the control cost: the first weighting, denoted as r aux [1] , MJ [(] [s, a] [) :=] [ −][c][|][a][|] [2][2][, uses the default setting, while the second weighting,] denoted as r aux [1] , MJ [(] [s, a] [) :=] [ −] [4] [c][|][a][|] [2] 2 [, employs a scaled variant of the first weighting. Additionally, we] implement the path-wise bi-level optimization variant i.e., BARFI Unrolled. In these experiments, we keep the value of γ fixed to isolate the agent’s capability to adapt and recover from an arbitrary reward weighting. We will also measure what computational and performance tradeoffs we might have to make between using the implicit version i.e., BARFI against, the path-wise version i.e., BARFI Unrolled.
G Details for the Empirical Results
G.1 Implementation Details
In this section we will briefly describe the implementation details around the different environments that were used.
GridWorld (GW): In the case of GridWorld we made use of the Fourier basis (of Order = 3) over the raw coordinates of agent position in the GridWorld. Details about this could be found in the src/utils/Basis.py file.
MountainCar (MC): For this environment, to reduce the limitation because of the function approximator we used TileCoding [58], which offers a suitable representation for the MountainCar problem. We used 4 Tiles and Tilings of 5.
CartPole (CP): For CartPole also make use of Fourier Basis of (Order = 3), with linear function approximator on top of that.
MuJoco (MJ): For this we made use of a neural network with 1 hidden layer of 32 nodes and ReLU activation as the function approximator over the raw observations. The output of the policy is continuous actions, hence we used a Gaussian representation, where the policy outputs the mean of the multivariate Gaussian and we used a fixed diagonal standard deviation, fixed to σ = 0 . 1.
General Details: All the outer returns are evaluated without any discounting, whereas all the inner optimizations were initialized with γφ = 0 . 99. Hence to do this we made φ a single bias unit, initialized to 4 . 6, and passed through a sigmoid (i.e., σ (4 . 6) = 0 . 99).
For GW, CP and MC rϕ is defined as below
rϕ ( s, a ) = ϕ 1( s ) + ϕ 2( s ) rp + ϕ 3( s ) ra
27
Wherein ϕ 1 , ϕ 2 , ϕ 3 are scalar outputs of a 3-headed function, in this case simply a linear layer over the states inputs.
Whereas in the case of MJ, we have
rϕ ( s, a ) = ϕ 1 + rp + ϕ 3 ra
Wherein ϕ 1 is initialized to zero and ϕ 3 is 1 . 0 act like bias units.
Gradient normalization was used for all the cases where neural nets were involved (i.e., MJ), and also for MJ we modified the Baseline (REINFORCE) update to subtract the running average of the performance as a baseline to get acceptable performance for the baseline method.
G.2 Hyper-parameter Selection
As different make use of different function approximators the range of hyper-params can vary we talk about all the above over here.
Best-performing Parameters for different methods and environments are listed where
Table 3: Hyper-parameters for GridWorld
Hyper Parameter BARFI Value REINFORCE Value Actor-Critic Value
αθ 1 × 10 [−] [3] 1 × 10 [−] [3] 1 × 10 [−] [3]
αϕ 5 × 10 [−] [3] − − αφ 5 × 10 [−] [3] − − optim RMSprop RMSprop RMSprop λθ 0 . 25 0 . 25 0 . 25 λϕ 0 . 0625 − − λφ 4 . 0 − − Buffer 1000 − − Batch Size 1 1 1 η 0 . 0005 − − δ 3 − − n 5 − − N 0 150 − − Ni 15 − −
Table 4: Hyper-parameters for MountainCar
Hyper Parameter BARFI Value REINFORCE Value Actor-Critic Value
αθ 0 . 015625 0 . 125 0 . 03125 αϕ 0 . 0625 − − αφ 0 . 0625 − − optim RMSprop RMSprop RMSprop λθ 0 . 0 0 . 0 0 . 25 λϕ 0 . 0 − − λφ 0 . 25 − − Buffer 50 − − Batch Size 1 1 1 η 0 . 001 − − δ 3 − − n 5 − − N 0 50 − − Ni 15 − −
Hyperparameter Sweep : Here we list the details about how we swept the values for different hyper-params. We used PyTorch [46] for all our implementations. We usually used an optimizer between RMSProp or Adam with default parameters as provided in Pytorch. For αθ ∈{ 5 ×
28
Table 5: Hyper-parameters for CartPole
Hyper Parameter BARFI Value REINFORCE Value Actor-Critic Value
αθ 1 × 10 [−] [3] 1 × 10 [−] [3] 5 × 10 [−] [4]
αϕ 1 × 10 [−] [3] − − αφ 5 × 10 [−] [3] − − optim RMSprop RMSprop RMSprop λθ 1 . 0 1 . 0 0 . 0 λϕ 0 . 0 − − λφ 4 . 0 − − Buffer 10000 − − Batch Size 1 1 1 η 0 . 0005 − − δ 3 − − n 5 − − N 0 150 − − Ni 15 − −
Table 6: Hyper-parameters for MuJoco
Hyper Parameter BARFI Value REINFORCE Value Actor-Critic Value
αθ 7 . 5 × 10 [−] [5] 5 × 10 [−] [4] 2 . 5 × 10 [−] [4]
αϕ 2 . 5 × 10 [−] [3] − − αφ 0 . 0 − − optim Adam Adam Adam λϕ 0 . 0625 − − λφ 0 . 0 − − Buffer 50 − − Batch Size 1 1 1 η 0 . 0005 − − δ 3 − − n 5 − − N 0 30 − − Ni 15 − −
10 [−] [3] , 2 . 5 × 10 [−] [3] , 1 × 10 [−] [3] , 5 × 10 [−] [4] , 2 . 5 × 10 [−] [4] , 1 × 10 [−] [4] , 7 . 5 × 10 [−] [5] }, we use similar ranges for αϕ, αφ (which tend to be larger). For λθ and λϕ, we sweeped from [0 , 0 . 25 , 0 . 5 , 1 . 0] and for λγ we sweeped from [0 , 0 . 25 , 1 . 0 , 4 . 0 , 16 . 0]. We simply list ranges for different values and later we present sensitivity curves showing that these values are usually robust for BARFI across different methods as we can see from the tables above. δ ∈ [1 , 3 , 5], n ∈ [1 , 3 , 5], Ni ∈ [1 , 3 , 6 , 9 , 12 , 15], η ∈ [1 × 10 [−] [3] , 5 × 10 [−] [4] , 1 × 10 [−] [4] ], N 0 ∈ [30 , 50 , 100 , 150], buffer ∈ [25 , 50 , 100 , 1000]. α for Tilecoding was adopted from [58] and hence similar ranges were sweeped in that case. Most sweeps were done with around 10 seeds, and later the parameter ranges were reduced and performed with more seeds.
G.3 Compute
The computer is used for a cluster where the CPU class is Intel Xeon Gold 6240 CPU @2 . 60GHz. The total compute required for GW was around 3 CPU years [7], CP also required around 3 CPU years, and MC required around 4 CPU years. For MJ we needed around 5-6 CPU years. In total we utilized around 15-16 CPU years, where we needed around 1 GB of memory per thread.
71 CPU year := Compute equal to running a CPU thread for a year.
29
H Extra Results & Ablations
H.1 Experiment on partially misspecified r aux
In these set of experiments, we consider the case where auxiliary reward signals could be helpful only in a few—possibly arbitrary—state-action pairs. In general, we anticipate that solutions in this scenario would be such that assigns weightings, allowing the agent to avoid regions where might be misspecified. Meanwhile, the agent would still make use of the places where is well specified and useful.
We consider another r aux in the GridWorld domain in which the auxiliary reward is misspecified for a subset of states near the starting position. Meanwhile, it is still well-specified for states near the goal (Figure 6 (a)). Figures 6 (b) and (c) illustrate the learned and the weighting on, showcasing the agent’s ability to depict the expected behavior described above.
(a) r aux( s )
| Col1 | 70 60 50 40 30 20 |
|---|---|
| 10 |
|
| 0 |
| Col1 | 101 100 0 10 |
|---|---|
| 1 |
|
(c) The net reward induced i.e., rp ( s ) + ϕ 3( s ) r aux( s )
(b) Learned ϕ 3( s ), the weighting on r aux( s )
(d) Learning performance
Figure 6: 40 random seeds were used to generate the plots. The starting state is at the bottom left and the goal state is at the top right corner. The primary reward rp is +100 when the agent reaches the goal and 0 otherwise. (a) A state-dependent r aux function that is partially misspecified (in the blue region r aux provides a value equal to the Manhattan distance, thereby incentivizing the agent to stay near the start), and partially well specified (in the red region, it is the negative Manhattan distance and encourages movement towards the goal). (b) The state-dependent weighting ϕ 3( s ) learned by BARFI negates the positive value from r aux near the start state. (c) The effective reward function rp ( s ) + ϕ 3( s ) r aux( s ) learned by BARFI. (d) Learning curves for BARFI, and the baseline that uses a naive addition ( rp ( s ) + r aux( s )) of the above auxiliary reward.
30
H.2 Return based on learned rϕ and γφ
Figure 7 and Figure 8 summarize the achievable return based on rϕ and the γ learned by the agent across different domains and reward specification. We observe that REINFORCE often optimizes the naive combination of reward for sure, but that doesn’t really lead to a good performance on rp, whereas BARFI does achieve an appropriate return on rϕ, but is also able to successively decay γ as the learning progress across different domains. Particularly notice Figure 7 (a) Bottom, where REINFORCE does optimize aux return a lot, but actually fails to solve the problem, as it simply learns to loop around the center state.
H.3 Ablations
Figure 9 represents the ablation of BARFI on GridWorld with the misspecified reward for its different params. We can see that usually having η = 0 . 001 , 0 . 0005, n = 5 works for the approximation.
31
MountainCar
GridWorld
CartPole
(a) (b) (c)
Figure 8: Learned discounting γφ : This figure illustrates the learned γφ for BARFI and normal γ for other methods, the curves are chosen based on best-performing curves on rp, and averaged over 20 runs (except 40 for GW). (a) Top - r aux [1] , GW [,] [ Bottom] [ –] [ r] aux [2] , GW [,] [ (b) Top] [ –] [ r] aux [1] , CP [,] [ Bottom]
- r aux [2] , CP [,] [ (c) Top] [ –] [ r] aux [2] , MC [,] [ Bottom] [ –] [ r] aux [1] , MC [. Mujoco is not included as the] [ γ] [ was not learned in] that case. We can observe that the agents start to learn to decay γ at the appropriate pace. Note that the curves for methods other than BARFI and BARFI Unrolled are overlapping as the baselines don’t change the value of γ .
32
98
97
96
95
94
100
80
60
40
20
98.0
97.5
97.0
96.5
96.0
95.5
2 12 2 10 2 8 2 6 2 4
95
90
85
80
75 2 12 2 10 2 8 2 6 2 4
98
97
96
95
94
93
2 [0] 2 [1] 2 [2] 2 [3]
99
98
97
96
95
94
93
92
2 12 2 10 2 8 2 6 2 4
98
96
94
92
90
88
86
2 17 2 15 2 13 2 11 2 9 2 7
95.0
94.5
94.0 2 [0] 2 [1] 2 [2]
Figure 9: Sensitivity Curves: The set of graphs representing the sensitivity of different hyperparams keeping all the other params fixed. The sensitivity is for BARFI in GW with r aux,GW [2] [, i.e.,] the misspecified reward. We choose the best-performing parameters and vary each parameter to see its influence. The curves are obtained for 50 runs (seeds) in each case, and error bars are standard errors. We can notice that αθ and αϕ can have a large influence, and tend to stay around similar values. λθ,ϕ,φ tends to help but doesn’t really influence a lot in terms of its magnitude, except larger values of λφ seem to do better. Smaller values of η seems to work fine, hence something around 5 × 10 [−] [4] , 1 × 10 [−] [3] usually should suffice. n, δ can be chosen to around 5 and 3, and usually workout fine. We also defined Ni = 5 × δ in this case.
33