Title: Would I have gotten that reward? Long-term credit assignment by counterfactual contribution analysis
Venue: NeurIPS 2023
Accepted: yes
Keywords: Reinforcement learning

Long-term credit assignment

contribution analysis

hindsight credit assignment

policy gradient methods
Abstract: To make reinforcement learning more sample efficient, we need better credit assignment methods that measure an action’s influence on future rewards. Building upon Hindsight Credit Assignment (HCA), we introduce Counterfactual Contribution Analysis (COCOA), a new family of model-based credit assignment algorithms. Our algorithms achieve precise credit assignment by measuring the contribution of actions upon obtaining subsequent rewards, by quantifying a counterfactual query: ‘Would the agent still have reached this reward if it had taken another action?’. We show that measuring contributions w.r.t. rewarding _states_, as is done in HCA, results in spurious estimates of contributions, causing HCA to degrade towards the high-variance REINFORCE estimator in many relevant environments. Instead, we measure contributions w.r.t. rewards or learned representations of the rewarding objects, resulting in gradient estimates with lower variance. We run experiments on a suite of problems specifically designed to evaluate long-term credit assignment capabilities. By using dynamic programming, we measure ground-truth policy gradients and show that the improved performance of our new model-based credit assignment methods is due to lower bias and variance compared to HCA and common baselines. Our results demonstrate how modeling action contributions towards rewarding outcomes can be leveraged for credit assignment, opening a new path towards sample-efficient reinforcement learning.

Would I have gotten that reward? Long-term credit assignment by counterfactual contribution analysis

Abstract

To make reinforcement learning more sample efficient, we need better credit assignment methods that measure an action's influence on future rewards. Building upon Hindsight Credit Assignment (HCA) [1], we introduce Counterfactual Contribution Analysis (COCOA), a new family of model-based credit assignment algorithms. Our algorithms achieve precise credit assignment by measuring the contribution of actions upon obtaining subsequent rewards, by quantifying a counterfactual query: 'Would the agent still have reached this reward if it had taken another action?'. We show that measuring contributions w.r.t. rewarding states , as is done in HCA, results in spurious estimates of contributions, causing HCA to degrade towards the high-variance REINFORCE estimator in many relevant environments. Instead, we measure contributions w.r.t. rewards or learned representations of the rewarding objects, resulting in gradient estimates with lower variance. We run experiments on a suite of problems specifically designed to evaluate long-term credit assignment capabilities. By using dynamic programming, we measure ground-truth policy gradients and show that the improved performance of our new model-based credit assignment methods is due to lower bias and variance compared to HCA and common baselines. Our results demonstrate how modeling action contributions towards rewarding outcomes can be leveraged for credit assignment, opening a new path towards sample-efficient reinforcement learning. 2

1 Introduction

Reinforcement learning (RL) faces two central challenges: exploration and credit assignment [2]. We need to explore to discover rewards and we need to reinforce the actions that are instrumental for obtaining these rewards. Here, we focus on the credit assignment problem and the intimately linked problem of estimating policy gradients. For long time horizons, obtaining the latter is notoriously difficult as it requires measuring how each action influences expected subsequent rewards. As the number of possible trajectories grows exponentially with time, future rewards come with a considerable variance stemming from stochasticity in the environment itself and from the stochasticity of interdependent future actions leading to vastly different returns [3-5].

Monte Carlo estimators such as REINFORCE [6] therefore suffer from high variance, even after variance reduction techniques like subtracting a baseline [6-9]. Similarly, in Temporal Difference methods such as Q-learning, this high variance in future rewards results in a high bias in the value estimates, requiring exponentially many updates to correct for it [5]. Thus, a common technique to

reduce variance and bias is to discount rewards that are far away in time resulting in a biased estimator which ignores long-term dependencies [10-13]. Impressive results have nevertheless been achieved in complex environments [14-16] at the cost of requiring billions of environment interactions, making these approaches sample inefficient.

Especially in settings where obtaining such large quantities of data is costly or simply not possible, model-based RL that aims to simulate the dynamics of the environment is a promising alternative. While learning such a world model is a difficult problem by itself, when successful it can be used to generate a large quantity of synthetic environment interactions. Typically, this synthetic data is combined with model-free methods to improve the action policy [17-19]. A notable exception to simply using world models to generate more data are the Stochastic Value Gradient method [20] and the closely related Dreamer algorithms [21-23]. These methods perform credit assignment by backpropagating policy gradients through the world model. Crucially, this approach only works for environments with a continuous state-action space, as otherwise sensitivities of the value with respect to past actions are undefined [20, 22, 24]. Intuitively, we cannot compute sensitivities of discrete choices such as a yes / no decision as the agent cannot decide 'yes' a little bit more or less.

Building upon Hindsight Credit Assignment (HCA) [1], we develop Counterfactual Contribution Analysis (COCOA), a family of algorithms that use models for credit assignment compatible with discrete actions. We measure the contribution of an action upon subsequent rewards by asking a counterfactual question: 'would the agent still have achieved the rewarding outcome, if it had taken another action?' (c.f. Fig. 1A). We show that measuring contributions towards achieving a future state , as is proposed in HCA, leads to spurious contributions that do not reflect a contribution towards a reward. This causes HCA to degrade towards the high-variance REINFORCE method in most environments. Instead, we propose to measure contributions directly on rewarding outcomes and we develop various new ways of learning these contributions from observations. The resulting algorithm differs from value-based methods in that it measures the contribution of an action to individual rewards, instead of estimating the full expected sum of rewards. This crucial difference allows our contribution analysis to disentangle different tasks and ignore uncontrollable environment influences, leading to a gradient estimator capable of long-term credit assignment (c.f. Fig. 1B). We introduce a new method for analyzing policy gradient estimators which uses dynamic programming to allow comparing to ground-truth policy gradients. We leverage this to perform a detailed biasvariance analysis of all proposed methods and baselines showing that our new model-based credit assignment algorithms achieve low variance and bias, translating into improved performance (c.f. Fig. 1C).

2 Background and notation

We consider an undiscounted Markov decision process (MDP) defined as the tuple ( S , A , p, p r ) , with S the state space, A the action space, p ( S t +1 | S t , A t ) the state-transition distribution and p r ( R | S, A ) the reward distribution with bounded reward values r . We use capital letters for random variables and lowercase letters for the values they take. The policy π ( A | S ) , parameterized by θ , denotes the probability of taking action A at state S . We consider an undiscounted infinite-horizon setting with a zero-reward absorbing state s ∞ that the agent eventually reaches: lim t →∞ p ( S t = s ∞ ) = 1 . Both the discounted and episodic RL settings are special cases of this setting. (c.f. App. B), and hence all theoretical results proposed in this work can be readily applied to both (c.f. App J).

We use T ( s, π ) and T ( s, a, π ) as the distribution over trajectories T = ( S t , A t , R t ) t ≥ 0 starting from S 0 = s and ( S 0 , A 0 ) = ( s, a ) respectively, and define the return Z t = ∑ ∞ t =0 R t . The value function V π ( s ) = E T ∼T ( s,π ) [ Z t ] and action value function Q π ( s, a ) = E T ∼T ( s,a,π ) [ Z t ] are the expected return when starting from state s , or state s and action a respectively. Note that these infinite sums have finite values due to the absorbing zero-reward state (c.f. App. B).

The objective of reinforcement learning is to maximize the expected return V π ( s 0 ) , where we assume the agent starts from a fixed state s 0 . Policy gradient algorithms optimize V π ( s 0 ) by repeatedly estimating its gradient ∇ θ V ( s 0 ) w.r.t. the policy parameters. REINFORCE [6] (c.f. Tab. 1) is the canonical policy gradient estimator, however, it has a high variance resulting in poor parameter updates. Common techniques to reduce the variance are (i) subtracting a baseline, typically a value estimate, from the sum of future rewards [2, 25] (c.f. 'Advantage' in Tab. 1); (ii) replacing the sum of future rewards with a learned action value function Q [2, 3, 25, 26] (c.f. 'Q-critic' in Tab. 1); and (iii) using temporal discounting. Note that instead of using a discounted formulation of MDPs, we treat the discount factor as a variance reduction technique in the undiscounted problem [10, 11, 13] as this more accurately reflects its practical use [4, 27]. Rearranging the summations of REINFORCE with discounting lets us interpret temporal discounting as a credit assignment heuristic, where for each reward, past actions are reinforced proportional to their proximity in time.

Crucially, long-term dependencies between actions and rewards are exponentially suppressed, thereby reducing variance at the cost of disabling long-term credit assignment [4, 28]. The aim of this work is to replace the heuristic of time discounting by principled contribution coefficients quantifying how much an action contributed towards achieving a reward, and thereby introducing new policy gradient estimators with reduced variance, without jeopardizing long-term credit assignment.

HCA [1] makes an important step in this direction by introducing a new gradient estimator:

with r ( s, a ) a reward model, and the hindsight ratio p π ( a | S t = s,S ′ = S t + k ) π ( a | S t ) measuring how important action a was to reach the state S ′ at some point in the future. Although the hindsight ratio delivers precise credit assignment w.r.t. reaching future states, it has a failure mode of practical importance, creating the need for an updated theory of model-based credit assignment which we will detail in the next section.

3 Counterfactual Contribution Analysis

To formalize the 'contribution' of an action upon subsequent rewards, we generalize the theory of HCA [1] to measure contributions on rewarding outcomes instead of states. We introduce unbiased policy gradient estimators that use these contribution measures, and show that HCA suffers from high variance, making the generalization towards rewarding outcomes crucial for obtaining low-variance estimators. Finally, we show how we can estimate contributions using observational data.

3.1 Counterfactual contribution coefficients

To assess the contribution of actions towards rewarding outcomes, we propose to use counterfactual reasoning: 'how does taking action a influence the probability of obtaining a rewarding outcome, compared to taking alternative actions a ′ ?'.

Definition 1 (Rewarding outcome) . A rewarding outcome U ′ ∼ p ( U ′ | s ′ , a ′ , r ′ ) is a probabilistic encoding of the state-action-reward triplet.

If action a contributed towards the reward, the probability of obtaining the rewarding outcome following action a should be higher compared to taking alternative actions. We quantify the contribution of action a taken in state s upon rewarding outcome u ′ as

From a given state, we compare the probability of reaching the rewarding outcome u ′ at any subsequent point in time, given we take action a versus taking counterfactual actions according to the policy π , as p π ( U t + k = u ′ | S t = s ) = ∑ a ′ π ( a ′ | s ) p π ( U t + k = u ′ | S t = s, A t = a ′ ) . Subtracting this ratio by one results in an intuitive interpretation of the contribution coefficient w ( s, a, u ′ ) : if the coefficient is positive/negative, performing action a results in a higher/lower probability of obtaining rewarding outcomes u ′ , compared to following the policy π . Using Bayes' rule, we can convert the counterfactual formulation of the contribution coefficients into an equivalent hindsight formulation (right-hand side of Eq. 3), where the hindsight distribution p π ( A t = a | S t = s, U ′ = u ′ ) reflects the probability of taking action a in state s , given that we encounter the rewarding outcome u ′ at some future point in time . We refer the reader to App. C for a full derivation.

Choice of rewarding outcome. For u ′ = s ′ , we recover state-based HCA [1]. 3 In the following, we show that a better choice is to use u ′ = r ′ , or an encoding p ( u ′ | s ′ , a ′ ) of the underlying object that causes the reward. Both options lead to gradient estimators with lower variance (c.f. Section 3.3), while using the latter becomes crucial when different underlying rewarding objects have the same scalar reward (c.f. Section 4).

3.2 Policy gradient estimators

We now show how the contribution coefficients can be used to learn a policy. Building upon HCA [1], we propose the Counterfactual Contribution Analysis (COCOA) policy gradient estimator

When comparing to the discounted policy gradient of Eq. 1, we see that the temporal discount factors are substituted by the contribution coefficients, replacing the time heuristic with fine-grained credit assignment. Importantly, the contribution coefficients enable us to evaluate all counterfactual actions instead of only the observed ones, further increasing the quality of the gradient estimator (c.f. Fig. 1A). The contribution coefficients allow for various different gradient estimators (c.f. App. C). For example, independent action samples can replace the sum over all actions, making it applicable to large action spaces. Here, we use the gradient estimator of Eq. 4, as our experiments consist of small action spaces where enumerating all actions is feasible. When U = S , the above estimator is almost equivalent to

the state-based HCA estimator of Eq. 2, except that it does not need a learned reward model r ( s, a ) . We use the notation HCA+ to refer to this simplified version of the HCA estimator. Theorem 1 below shows that the COCOA gradient estimator is unbiased, as long as the encoding U is fully predictive of the reward, thereby generalizing the results of Harutyunyan et al. [1] to arbitrary rewarding outcome encodings.

Definition 2 (Fully predictive) . A rewarding outcome U is fully predictive of the reward R , if the following conditional independence condition holds for all k ≥ 0 : p π ( R k = r | S 0 = s, A 0 = a, U k = u ) = p π ( R = r | U = u ) , where the right-hand side does not depend on the time k .

Theorem 1. Assuming that U is fully predictive of the reward (c.f. Definition 2), the COCOA policy gradient estimator ˆ ∇ U θ V π ( s 0 ) is unbiased, when using the ground-truth contribution coefficients of Eq. 3, that is

3.3 Optimal rewarding outcome encoding for low-variance gradient estimators

Theorem 1 shows that the COCOA gradient estimators are unbiased for all rewarding outcome encodings U that are fully predictive of the reward. The difference between specific rewarding outcome encodings manifests itself in the variance of the resulting gradient estimator. Proposition 2 shows that for U ′ = S ′ as chosen by HCA there are many cases where the variance of the resulting policy gradient estimator degrades to the high-variance REINFORCE estimator [6]:

Proposition 2. In environments where each action sequence leads deterministically to a different state, we have that the HCA+ estimator is equal to the REINFORCE estimator (c.f. Tab. 1).

In other words, when all previous actions can be perfectly decoded from a given state, they trivially all contribute to reaching this state. The proof of Propostion 2 follows immediately from observing that p π ( a | s, s ′ ) = 1 for actions a along the observed trajectory, and zero otherwise. Substituting this expression into the contribution analysis gradient estimator (4) recovers REINFORCE. A more general issue underlies this special case: State representations need to contain detailed features to allow for a capable policy but the same level of detail is detrimental when assigning credit to actions for reaching a particular state since at some resolution almost every action will lead to a slightly different outcome. Measuring the contribution towards reaching a specific state ignores that the same rewarding outcome could be reached in slightly different states, hence overvaluing the importance of previous actions and resulting in spurious contributions . Many commonly used environments, such as pixel-based environments, continuous environments, and partially observable MDPs exhibit this property to a large extent due to their fine-grained state representations (c.f. App. G). Hence, our generalization of HCA to rewarding outcomes is a crucial step towards obtaining practical low-variance gradient estimators with model-based credit assignment.

Using rewards as rewarding outcomes yields lowest-variance estimators. The following Theorem 3 shows in a simplified setting that (i) the variance of the REINFORCE estimator is an upper bound on the variance of the COCOA estimator, and (ii) the variance of the COCOA estimator is smaller for rewarding outcome encodings U that contain less information about prior actions. We formalize this with the conditional independence relation of Definition 2 by replacing R with U ′ : encoding U contains less or equal information than encoding U ′ , if U ′ is fully predictive of U . Combined with Theorem 1 that states that an encoding U needs to be fully predictive of the reward R , we have that taking the reward R as our rewarding outcome encoding U results in the gradient estimator with the lowest variance of the COCOA family.

Theorem 3. Consider an MDP where only the states at a single (final) time step contain a reward, and where we optimize the policy only at a single (initial) time step. Furthermore, consider two rewarding outcome encodings U and U ′ , where S is fully predictive of U ′ , U ′ fully predictive of U , and U fully predictive of R . Then, the following relation holds between the policy gradient estimators:

with ˆ ∇ X θ V π ( s 0 ) the COCOA estimator (4) using U = X , V [ Y ] the covariance matrix of Y and A ≼ B indicating that B -A is positive semi-definite.

As Theorem 3 considers a simplified setting, we verify empirically whether the same arguments hold more generally. We construct a tree environment where we control the amount of information a

state contains about the previous actions by varying the overlap of the children of two neighbouring nodes (c.f. Fig 2), and assign a fixed random reward to each state-action pair. We compute the ground-truth contribution coefficients by leveraging dynamic programming (c.f. Section 4). Fig. 2B shows that the variance of HCA is as high as REINFORCE for zero state overlap, but improves when more states overlap, consistent with Proposition 2 and Theorem 3. To investigate the influence of the information content of U on the variance, we consider rewarding outcome encodings U with increasing information content, which we quantify with how many different values of u belong to the same reward r . Fig. 2B shows that by increasing the information content of U , we interpolate between the variance of COCOA with u = r and HCA+, consistent with Theorem 3.

Why do rewarding outcome encodings that contain more information than the reward lead to higher variance? To provide a better intuition on this question we use the following theorem:

Theorem 4. The policy gradient on the expected number of occurrences O π ( u ′ , s ) = ∑ k ≥ 1 p π ( U k = u ′ | S 0 = s ) is proportional to

̸

Recall that the COCOA gradient estimator consists of individual terms that credit past actions a at state s for a current reward r encountered in u according to ∑ a ∈A ∇ θ π ( a | s ) w ( s, a, u ′ ) r ′ (c.f. Eq. 4). Theorem 4 indicates that each such term aims to increase the average number of times we encounter u ′ in a trajectory starting from s , proportional to the corresponding reward r ′ . If U ′ = R ′ , this update will correctly make all underlying states with the same reward r ′ more likely while decreasing the likeliness of all states for which u ′ = r ′ . Now consider the case where our rewarding outcome encoding contains a bit more information, i.e. U ′ = f ( R ′ , ∆ S ′ ) where ∆ S ′ contains a little bit of information about the state. As a result the update will distinguish some states even if they yield the same reward and increase the number of occurrences only of states containing the encountered ∆ S ′ while decreasing the number of occurrences for unseen ones. As in a single trajectory, we do not visit each possible ∆ S ′ , this adds variance. The less information an encoding U has, the more underlying states it groups together, and hence the less rewarding outcomes are 'forgotten' in the gradient estimator, leading to lower variance.

3.4 Learning the contribution coefficients

In practice, we do not have access to the ground-truth contribution coefficients, but need to learn them from observations. Following Harutyunyan et al. [1], we can approximate the hindsight distribution p π ( A t = a | S t = s, U ′ = u ′ ) , now conditioned on rewarding outcome encodings instead of states, by training a model h ( a | s, u ′ ) on the supervised discriminative task of classifying the observed action a t given the current state s t and some future rewarding outcome u ′ . Note that if the model h does not approximate the hindsight distribution perfectly, the COCOA gradient estimator (4) can be biased (c.f. Section 4). A central difficulty in approximating the hindsight distribution is that it is policy dependent, and hence changes during training. Proposition 5 shows that we can provide the policy logits as an extra input to the hindsight network without altering the learned hindsight

distribution, to make the parameters of the hindsight network less policy-dependent. This observation justifies and generalizes the strategy of adding the policy logits to the hindsight model output, as proposed by Alipov et al. [29].

Proposition 5. p π ( a | s, u ′ , l ) = p π ( a | s, u ′ ) , with l a deterministic function of s , representing the sufficient statistics of π ( a | s ) .

As an alternative to learning the hindsight distribution, we can directly estimate the probability ratio p π ( A t = a | S t = s, U ′ = u ′ ) /π ( a | s ) using a contrastive loss (c.f. App. D). Yet another path builds on the observation that the sums ∑ k ≥ 1 p π ( U t + k = u ′ | s, a ) are akin to Successor Representations and can be learned via temporal difference updates [30, 31] (c.f. App. D). We experimented both with the hindsight classification and the contrastive loss and found the former to work best in our experiments. We leverage the Successor Representation to obtain ground truth contribution coefficients via dynamic programming for the purpose of analyzing our algorithms.

4 Experimental analysis

To systematically investigate long-term credit assignment performance of COCOA compared to standard baselines, we design an environment which pinpoints the core credit assignment problem and leverage dynamic programming to compute ground-truth policy gradients, contribution coefficients, and value functions (c.f. App E.2). This enables us to perform detailed bias-variance analyses and to disentangle the theoretical optimal performance of the various gradient estimators from the approximation quality of learned contribution coefficients and (action-)value functions.

We consider the linear key-to-door environment (c.f. Fig. 3A), a simplification of the key-to-door environment [3, 4, 32] to a one-dimensional track. Here, the agent needs to pick up a key in the first time step, after which it engages in a distractor task of picking up apples with varying reward values. Finally, it can open a door with the key and collect a treasure. This setting allows us to parametrically increase the difficulty of long-term credit assignment by increasing the distance between the key and door, making it harder to pick up the learning signal of the treasure reward

among a growing number of varying distractor rewards [4]. We use the signal-to-noise ratio, SNR = ∥∇ θ V π ∥ 2 / E [ ∥ ˆ ∇ θ V π -∇ θ V π ∥ 2 ] , to quantify the quality of the different policy gradient estimators; a higher SNR indicates that we need fewer trajectories to estimate accurate policy gradients [33].

Previously, we showed that taking the reward as rewarding outcome encoding results in the lowestvariance policy gradients when using ground-truth contribution coefficients. In this section, we will argue that when learning the contribution coefficients, it is beneficial to use an encoding u of the underlying rewarding object since this allows to distinguish different rewarding objects when they have the same scalar reward value and allows for quick adaptation when the reward function but not the environment dynamics changes.

We study two variants of COCOA, COCOA-reward which uses the reward identity for U , and COCOA-feature which acquires features of rewarding objects by learning a reward model r ( s, a ) and taking the penultimate network layer as U . We learn the contribution coefficients by approximating the hindsight distribution with a neural network classifier h ( a | s, u ′ , l ) that takes as input the current state s , resulting policy logits l , and rewarding outcome u ′ , and predicts the current action a (c.f. App. E for all experimental details). As HCA+ (c.f. Tab. 1) performs equally or better compared to HCA [1] in our experiments (c.f. App. F), we compare to HCA+ and several other baselines: (i) three classical policy gradient estimators, REINFORCE, Advantage and Q-critic, (ii) TrajCV [34], a state-of-the-art control variate method that uses hindsight information in its baseline, and (iii) HCA-return [1], a different HCA variant that uses the hindsight distribution conditioned on the return as an action-dependent baseline (c.f. Tab. 1).

4.1 COCOA improves sample-efficiency due to favorable bias-variance trade-off.

To investigate the quality of the policy gradient estimators of COCOA, we consider the linear key-todoor environment with a distance of 100 between key and door. Our dynamic programming setup allows us to disentangle the performance of the estimators independent of the approximation quality of learned models by using ground truth contribution coefficients and (action-)value functions. The left panel of figure 3B reveals that in this ground truth setting, COCOA-reward almost immediately solves the task performing as well as the theoretically optimal Q-critic with a perfect action-value function. This is in contrast to HCA and HCA-return which perform barely better than REINFORCE, all failing to learn to consistently pick up the key in the given number of episodes. This result translates to the setting of learning the underlying models using neural networks. COCOA-reward and -feature outperform competing policy gradient estimators in terms of sample efficiency while HCA only improves over REINFORCE. Notably, having to learn the full action-value function leads to a less sample-efficient policy gradient estimator for the Q-critic.

In Figure 3C and D we leverage dynamic programming to compare to the ground truth policy gradient. This analysis reveals that improved performance of COCOA is reflected in a higher SNR compared to other estimators due to its favorable bias-variance trade-off. Fig 12 in App. F indicates that COCOAmaintains a superior SNR, even when using significantly biased contribution coefficients. As predicted by our theory in Section 3.3, HCA significantly underperforms compared to baselines due to its high variance caused by spurious contributions. In particular, the Markov state representation of the linear key-to-door environment contains the information of whether the key has been picked up. As a result, HCA always credits picking up the key or not, even for distractor rewards. These spurious contributions bury the useful learning signal of the treasure reward in noisy distractor rewards. HCAreturn performs poorly as it is a biased gradient estimator, even when using the ground-truth hindsight distribution (c.f. Appendix F and L). Interestingly, the variance of COCOA is significantly lower compared to a state-of-the-art control variate method, TrajCV, pointing to a potential benefit of the multiplicative interactions between contribution coefficients and rewards in the COCOA estimators, compared to the additive interaction of the control variates: the value functions used in TrajCV need to approximate the full average returns, whereas COCOA can ignore rewards from the distractor subtask, by multiplying them with a contribution coefficient of zero.

4.2 COCOA enables long-term credit assignment by disentangling rewarding outcomes.

The linear key-to-door environment allows us to parametrically increase the difficulty of the longterm credit assignment problem by increasing the distance between the key and door and thereby increasing the variance due to the distractor task [4]. Figure 1B reveals that as this distance increases, performance measured as the average fraction of treasure collected over a fixed number of episodes

drops for all baselines including HCA but remains relatively stable for the COCOA estimators. Hung et al. [4] showed that the SNR of REINFORCE decreases inversely proportional to growing distance between key and door. Figure 1B shows that HCA and all baselines follow this trend, whereas the COCOA estimators maintain a robust SNR.

We can explain the qualitative difference between COCOA and other methods by observing that the key-to-door task consists of two distinct subtasks: picking up the key to get the treasure, and collecting apples. COCOA can quickly learn that actions relevant for one task, do not influence rewarding outcomes in the other task, and hence output a contribution coefficient equal to zero for those combinations. Value functions in contrast estimate the expected sum of future rewards, thereby mixing the rewards of both tasks. When increasing the variance of the return in the distractor task by increasing the number of stochastic distractor rewards, estimating the value functions becomes harder, whereas estimating the contribution coefficients between state-action pairs and distinct rewarding objects remains of equal difficulty, showcasing the power of disentangling rewarding outcomes.

To further showcase the power of disentangling subtasks, we consider a simplified version of the task interleaving environment of Mesnard et al. [3] (c.f. Fig. 4A, App. E.7). Here, the agent is faced with a sequence of contextual bandit tasks, where the reward for a correct decision is given at a later point in time, together with an observation of the relevant context. The main credit assignment difficulty is to relate the reward and contextual observation to the correct previous contextual bandit task. Note that the variance in the return is now caused by the stochastic policy, imperfectly solving future tasks, and by stochastic state transitions, in contrast to the linear key-to-door environment where the variance is caused by stochastic distractor rewards. Figure 4B shows that our COCOA algorithms outperform all baselines. The learned contribution coefficients of COCOA reward accurately capture that actions in one context only contribute to rewards in the same context as opposed to HCA that fails to disentangle the contributions (c.f. Figure 4C).

4.3 Learned credit assignment

features allow for disentangling aliased rewards

For COCOA-reward we use the scalar reward value to identify rewarding outcomes in the hindsight distribution, i.e. U = R . In cases where multiple rewarding outcomes yield an identical scalar reward value, the hindsight distribution cannot distinguish between them and has to estimate a common hindsight

probability, making it impossible to disentangle the tasks and hence rendering learning of the contribution coefficients potentially more difficult. In contrast, COCOA-feature learns hindsight features of rewarding objects that are predictive of the reward. Even when multiple rewarding objects lead to an identical scalar reward value their corresponding features are likely different, allowing COCOA-feature to disentangle the rewarding outcomes.

In Fig. 5, we test this reward aliasing setting experimentally and slightly modify the linear key-to-door environment by giving the treasure reward the same value as one of the two possible values of the stochastic distractor rewards. As expected, COCOA-feature is robust to reward aliasing, continuing to perform well on the task of picking up the treasure while performance of COCOA-reward noticeably suffers. Note that the performance of all methods has slightly decreased compared to Fig. 3, as the magnitude of the treasure reward is now smaller relative to the variance of the distractor rewards, resulting in a worse SNR for all methods.

5 Discussion

We present a theory for model-based credit assignment compatible with discrete actions and show in a comprehensive theoretical and experimental analysis that this yields a powerful policy gradient estimator, enabling long-term credit assignment by disentangling rewarding outcomes.

Building upon HCA [1], we focus on amortizing the estimation of the contribution coefficients in an inverse dynamics model, p π ( a | s, u ′ ) . The quality of this model is crucial for obtaining low-bias gradient estimates, but it is restricted to learn from on-policy data, and rewarding observations in case of u = r . Scaling these inverse models to complex environments will potentially exacerbate this tension, especially in sparse reward settings. A promising avenue for future work is to leverage forward dynamics models and directly estimate contribution coefficients from synthetic trajectories. While learning a forward model is a difficult problem in its own, its policy independence increases the data available for learning it. This would result in an algorithm close in spirit to Stochastic Value Gradients [20] and Dreamer [21-23] with the crucial advance that it enables model-based credit assignment on discrete actions. Another possibility to enable learning from non-rewarding observations is to learn a generative model that can recombine inverse models based on state representations into reward contributions (c.f. App. H).

Related work has explored the credit assignment problem through the lens of transporting rewards or value estimates towards previous states to bridge long-term dependencies [4, 5, 32, 35-41]. This approach is compatible with existing and well-established policy gradient estimators but determining how to redistribute rewards has relied on heuristic contribution analyses, such as via the access of memory states [4], linear decompositions of rewards [32, 35-39] or learned sequence models [5, 40, 41]. Leveraging our unbiased contribution analysis framework to reach more optimal reward transport is a promising direction for future research.

While we have demonstrated that contribution coefficients with respect to states as employed by HCA suffer from spurious contributions, any reward feature encoding that is fully predictive of the reward can in principle suffer from a similar problem in the case where each environment state has a unique reward value. In practice, this issue might occur in environments with continuous rewards. A potential remedy in this situation is to assume that the underlying reward distribution is stochastic, smoothing the contribution coefficients as now multiple states could have led to the same reward. This lowers the variance of the gradient estimator as we elaborate in App. G.

Finally, we note that our contribution coefficients are closely connected to causality theory [42] where the contribution coefficients correspond to performing Do-interventions on the causal graph to estimate their effect on future rewards (c.f. App I). Within causality theory, counterfactual reasoning goes a step further by inferring the external, uncontrollable environment influences and considering the consequences of counterfactual actions given that all external influences remain the same [3, 20, 42-44]. Extending COCOA towards this more advanced counterfactual setting by building upon recent work [3, 43] is an exciting direction for future research (c.f. App. I).

Concluding remarks. By overcoming the failure mode of spurious contributions in HCA, we have presented here a comprehensive theory on how to leverage model information for credit assignment, compatible with discrete action spaces. COCOA-reward and COCOA-feature are promising first algorithms in this framework, opening the way towards sample-efficient reinforcement learning by model-based credit assignment.

References

Anna Harutyunyan, Will Dabney, Thomas Mesnard, Mohammad Gheshlaghi Azar, Bilal Piot, Nicolas Heess, Hado P van Hasselt, Gregory Wayne, Satinder Singh, Doina Precup, and Remi Munos. Hindsight Credit Assignment. In H. Wallach, H. Larochelle, A. Beygelzimer, F AlchéBuc, E. Fox, and R. Garnett, editors, Advances in Neural Information Processing Systems 32 , pages 12488-12497. Curran Associates, Inc., 2019.

Richard S. Sutton and Andrew G. Barto. Reinforcement Learning, second edition: An Introduction . MIT Press, November 2018.

Thomas Mesnard, Théophane Weber, Fabio Viola, Shantanu Thakoor, Alaa Saade, Anna Harutyunyan, Will Dabney, Tom Stepleton, Nicolas Heess, Arthur Guez, Marcus Hutter, Lars Buesing, and Rémi Munos. Counterfactual Credit Assignment in Model-Free Reinforcement Learning. In Proceedings of the 38 th International Conference on Machine Learning, PMLR 139 , 2021.

Chia-Chun Hung, Timothy Lillicrap, Josh Abramson, Yan Wu, Mehdi Mirza, Federico Carnevale, Arun Ahuja, and Greg Wayne. Optimizing agent behavior over long time scales by transporting value. Nature Communications , 10(1):5223, November 2019. Number: 1 Publisher: Nature Publishing Group.

Jose A. Arjona-Medina, Michael Gillhofer, Michael Widrich, Thomas Unterthiner, Johannes Brandstetter, and Sepp Hochreiter. RUDDER: Return Decomposition for Delayed Rewards. In H. Wallach, H. Larochelle, A. Beygelzimer, F. d\textquotesingle Alché-Buc, E. Fox, and R. Garnett, editors, Advances in Neural Information Processing Systems 32 , pages 13566-13577. Curran Associates, Inc., 2019.

Ronald J. Williams. Simple statistical gradient-following algorithms for connectionist reinforcement learning. Machine Learning , 8(3):229-256, May 1992.

Evan Greensmith, Peter L. Bartlett, and Jonathan Baxter. Variance Reduction Techniques for Gradient Estimates in Reinforcement Learning. Journal of Machine Learning Research , 5(Nov): 1471-1530, 2004.

Théophane Weber, Nicolas Heess, Lars Buesing, and David Silver. Credit Assignment Techniques in Stochastic Computation Graphs. In Proceedings of the Twenty-Second International Conference on Artificial Intelligence and Statistics , pages 2650-2660. PMLR, April 2019. ISSN: 2640-3498.

Jonathan Baxter and Peter L. Bartlett. Infinite-Horizon Policy-Gradient Estimation. Journal of Artificial Intelligence Research , 15:319-350, November 2001.

Philip Thomas. Bias in Natural Actor-Critic Algorithms. In Proceedings of the 31st International Conference on Machine Learning , pages 441-448. PMLR, January 2014. ISSN: 1938-7228.

Sham Kakade. Optimizing Average Reward Using Discounted Rewards. In David Helmbold and Bob Williamson, editors, Computational Learning Theory , Lecture Notes in Computer Science, pages 605-615, Berlin, Heidelberg, 2001. Springer.

John Schulman, Philipp Moritz, Sergey Levine, Michael Jordan, and Pieter Abbeel. HighDimensional Continuous Control Using Generalized Advantage Estimation. In International Conference on Learning Representations . arXiv, 2016. arXiv:1506.02438 [cs].

Peter Marbach and John Tsitsiklis. Approximate Gradient Methods in Policy-Space Optimization of Markov Reward Processes. Discrete Event Dynamic Systems , page 38, 2003.

OpenAI, Christopher Berner, Greg Brockman, Brooke Chan, Vicki Cheung, Przemysław D˛ ebiak, Christy Dennison, David Farhi, Quirin Fischer, Shariq Hashme, Chris Hesse, Rafal Józefowicz, Scott Gray, Catherine Olsson, Jakub Pachocki, Michael Petrov, Henrique P. d O. Pinto, Jonathan Raiman, Tim Salimans, Jeremy Schlatter, Jonas Schneider, Szymon Sidor, Ilya Sutskever, Jie Tang, Filip Wolski, and Susan Zhang. Dota 2 with Large Scale Deep Reinforcement Learning, December 2019. arXiv:1912.06680 [cs, stat].

OpenAI, Ilge Akkaya, Marcin Andrychowicz, Maciek Chociej, Mateusz Litwin, Bob McGrew, Arthur Petron, Alex Paino, Matthias Plappert, Glenn Powell, Raphael Ribas, Jonas Schneider, Nikolas Tezak, Jerry Tworek, Peter Welinder, Lilian Weng, Qiming Yuan, Wojciech Zaremba, and Lei Zhang. Solving Rubik's Cube with a Robot Hand, October 2019. arXiv:1910.07113 [cs, stat].

Oriol Vinyals, Igor Babuschkin, Wojciech M. Czarnecki, Michaël Mathieu, Andrew Dudzik, Junyoung Chung, David H. Choi, Richard Powell, Timo Ewalds, Petko Georgiev, Junhyuk Oh, Dan Horgan, Manuel Kroiss, Ivo Danihelka, Aja Huang, Laurent Sifre, Trevor Cai, John P. Agapiou, Max Jaderberg, Alexander S. Vezhnevets, Rémi Leblond, Tobias Pohlen, Valentin Dalibard, David Budden, Yury Sulsky, James Molloy, Tom L. Paine, Caglar Gulcehre, Ziyu Wang, Tobias Pfaff, Yuhuai Wu, Roman Ring, Dani Yogatama, Dario Wünsch, Katrina McKinney, Oliver Smith, Tom Schaul, Timothy Lillicrap, Koray Kavukcuoglu, Demis Hassabis, Chris Apps, and David Silver. Grandmaster level in StarCraft II using multi-agent reinforcement learning. Nature , 575(7782):350-354, November 2019. Number: 7782 Publisher: Nature Publishing Group.

Richard S. Sutton. Dyna, an integrated architecture for learning, planning, and reacting. ACM SIGART Bulletin , 2(4):160-163, July 1991.

Jacob Buckman, Danijar Hafner, George Tucker, Eugene Brevdo, and Honglak Lee. SampleEfficient Reinforcement Learning with Stochastic Ensemble Value Expansion. In 32nd Conference on Neural Information Processing Systems . arXiv, 2018. arXiv:1807.01675 [cs, stat].

Thanard Kurutach, Ignasi Clavera, Yan Duan, Aviv Tamar, and Pieter Abbeel. Model-Ensemble Trust-Region Policy Optimization. 2018.

Nicolas Heess, Gregory Wayne, David Silver, Timothy Lillicrap, Tom Erez, and Yuval Tassa. Learning Continuous Control Policies by Stochastic Value Gradients. In Advances in Neural Information Processing Systems , volume 28. Curran Associates, Inc., 2015.

Danijar Hafner, Timothy Lillicrap, Jimmy Ba, and Mohammad Norouzi. Dream to Control: Learning Behaviors by Latent Imagination. In International Conference on Learning Representations , March 2020. Number: arXiv:1912.01603 arXiv:1912.01603 [cs].

Danijar Hafner, Timothy Lillicrap, Mohammad Norouzi, and Jimmy Ba. Mastering Atari with Discrete World Models. In International Conference on Learning Representations , 2021. Number: arXiv:2010.02193 arXiv:2010.02193 [cs, stat].

Danijar Hafner, Jurgis Pasukonis, Jimmy Ba, and Timothy Lillicrap. Mastering Diverse Domains through World Models, January 2023. arXiv:2301.04104 [cs, stat].

Mikael Henaff, William F. Whitney, and Yann LeCun. Model-Based Planning with Discrete and Continuous Actions, April 2018. arXiv:1705.07177 [cs].

Volodymyr Mnih, Adria Puigdomenech Badia, Mehdi Mirza, Alex Graves, Timothy Lillicrap, Tim Harley, David Silver, and Koray Kavukcuoglu. Asynchronous Methods for Deep Reinforcement Learning. In Proceedings of The 33rd International Conference on Machine Learning , pages 1928-1937. PMLR, June 2016. ISSN: 1938-7228.

Richard S Sutton, David A McAllester, Satinder P Singh, and Yishay Mansour. Policy Gradient Methods for Reinforcement Learning with Function Approximation. In Advances in Neural Information Processing Systems 12 , 1999.

Chris Nota and Philip S Thomas. Is the Policy Gradient a Gradient? In Proc. of the 19th International Conference on Autonomous Agents and Multiagent Systems (AAMAS 2020) , page 9, 2020.

John Schulman, Philipp Moritz, Sergey Levine, Michael Jordan, and Pieter Abbeel. HighDimensional Continuous Control Using Generalized Advantage Estimation, October 2018. arXiv:1506.02438 [cs].

Vyacheslav Alipov, Riley Simmons-Edler, Nikita Putintsev, Pavel Kalinin, and Dmitry Vetrov. Towards Practical Credit Assignment for Deep Reinforcement Learning, February 2022. arXiv:2106.04499 [cs].

Peter Dayan. Improving Generalization for Temporal Difference Learning: The Successor Representation. Neural Computation , 5(4):613-624, July 1993. Conference Name: Neural Computation.

Tejas D. Kulkarni, Ardavan Saeedi, Simanta Gautam, and Samuel J. Gershman. Deep Successor Reinforcement Learning, June 2016. Number: arXiv:1606.02396 arXiv:1606.02396 [cs, stat].

David Raposo, Sam Ritter, Adam Santoro, Greg Wayne, Theophane Weber, Matt Botvinick, Hado van Hasselt, and Francis Song. Synthetic Returns for Long-Term Credit Assignment. arXiv:2102.12425 [cs] , February 2021. arXiv: 2102.12425.

John W. Roberts and Russ Tedrake. Signal-to-Noise Ratio Analysis of Policy Gradient Algorithms. In D. Koller, D. Schuurmans, Y. Bengio, and L. Bottou, editors, Advances in Neural Information Processing Systems 21 , pages 1361-1368. Curran Associates, Inc., 2009.

Ching-An Cheng, Xinyan Yan, and Byron Boots. Trajectory-wise Control Variates for Variance Reduction in Policy Gradient Methods. In Proceedings of the Conference on Robot Learning , pages 1379-1394. PMLR, May 2020. ISSN: 2640-3498.

Zhizhou Ren, Ruihan Guo, Yuan Zhou, and Jian Peng. Learning Long-Term Reward Redistribution via Randomized Return Decomposition. January 2022.

Yonathan Efroni, Nadav Merlis, and Shie Mannor. Reinforcement Learning with Trajectory Feedback. In The Thirty-Fifth AAAI Conference on Artificial Intelligenc . arXiv, March 2021.

Minah Seo, Luiz Felipe Vecchietti, Sangkeum Lee, and Dongsoo Har. Rewards PredictionBased Credit Assignment for Reinforcement Learning With Sparse Binary Rewards. IEEE ACCESS , 7:118776-118791, 2019. Accepted: 2019-09-24T11:21:52Z Publisher: IEEE-INST ELECTRICAL ELECTRONICS ENGINEERS INC.

Markel Sanz Ausin, Hamoon Azizsoltani, Song Ju, Yeo Jin Kim, and Min Chi. InferNet for Delayed Reinforcement Tasks: Addressing the Temporal Credit Assignment Problem. In 2021 IEEE International Conference on Big Data (Big Data) , pages 1337-1348, December 2021.

Hamoon Azizsoltani, Yeo Jin Kim, Markel Sanz Ausin, Tiffany Barnes, and Min Chi. Unobserved Is Not Equal to Non-existent: Using Gaussian Processes to Infer Immediate Rewards Across Contexts. In Proceedings of the Twenty-Eighth International Joint Conference on Artificial Intelligence , pages 1974-1980, 2019.

Vihang P. Patil, Markus Hofmarcher, Marius-Constantin Dinu, Matthias Dorfer, Patrick M. Blies, Johannes Brandstetter, Jose A. Arjona-Medina, and Sepp Hochreiter. Align-RUDDER: Learning From Few Demonstrations by Reward Redistribution. Proceedings of Machine Learning Research , 162, 2022. arXiv: 2009.14108.

Johan Ferret, Raphaël Marinier, Matthieu Geist, and Olivier Pietquin. Self-Attentional Credit Assignment for Transfer in Reinforcement Learning. In Proceedings of the TwentyNinth International Joint Conference on Artificial Intelligence , pages 2655-2661, July 2020. arXiv:1907.08027 [cs].

Jonas Peters, Dominik Janzing, and Bernhard Schölkopf. Elements of causal inference: foundations and learning algorithms . Adaptive Computation and Machine Learning. November 2018.

Lars Buesing, Theophane Weber, Yori Zwols, Sebastien Racaniere, Arthur Guez, Jean-Baptiste Lespiau, and Nicolas Heess. Woulda, Coulda, Shoulda: Counterfactually-Guided Policy Search. In International Conference on Learning Representations , 2019. arXiv: 1811.06272.

Ioana Bica, Ahmed M. Alaa, James Jordon, and Mihaela van der Schaar. Estimating Counterfactual Treatment Outcomes over Time Through Adversarially Balanced Representations. In International Conference on Learning Representations . arXiv, February 2020. arXiv:2002.04083 [cs, stat].

Pushi Zhang, Li Zhao, Guoqing Liu, Jiang Bian, Minlie Huang, Tao Qin, and Tie-Yan Liu. Independence-aware Advantage Estimation. In Proceedings of the Thirtieth International Joint Conference on Artificial Intelligence , pages 3349-3355, Montreal, Canada, August 2021. International Joint Conferences on Artificial Intelligence Organization.

Kenny Young. Variance Reduced Advantage Estimation with $\delta$ Hindsight Credit Assignment. arXiv:1911.08362 [cs] , September 2020. arXiv: 1911.08362.

Michel Ma and Bacon Pierre-Luc. Counterfactual Policy Evaluation and the Conditional Monte Carlo Method. In Offline Reinforcement Learning Workshop, NeurIPS , 2020.

Paul Bratley, Bennett L. Fox, and Linus E. Schrage. A Guide to Simulation . Springer, New York, NY, 1987.

J. M. Hammersley. Conditional Monte Carlo. Journal of the ACM , 3(2):73-76, April 1956.

Dilip Arumugam, Peter Henderson, and Pierre-Luc Bacon. An Information-Theoretic Perspective on Credit Assignment in Reinforcement Learning. arXiv:2103.06224 [cs, math] , March 2021. arXiv: 2103.06224.

Kenny Young. Hindsight Network Credit Assignment: Efficient Credit Assignment in Networks of Discrete Stochastic Units. Proceedings of the AAAI Conference on Artificial Intelligence , 36 (8):8919-8926, June 2022. Number: 8.

Shixiang Gu, Timothy Lillicrap, Zoubin Ghahramani, Richard E. Turner, and Sergey Levine. Q-Prop: Sample-Efficient Policy Gradient with An Off-Policy Critic. 2017.

Philip S. Thomas and Emma Brunskill. Policy Gradient Methods for Reinforcement Learning with Function Approximation and Action-Dependent Baselines, June 2017. arXiv:1706.06643 [cs].

Hao Liu*, Yihao Feng*, Yi Mao, Dengyong Zhou, Jian Peng, and Qiang Liu. Action-dependent Control Variates for Policy Optimization via Stein Identity. February 2022.

Cathy Wu, Aravind Rajeswaran, Yan Duan, Vikash Kumar, Alexandre M. Bayen, Sham Kakade, Igor Mordatch, and Pieter Abbeel. Variance Reduction for Policy Gradient with ActionDependent Factorized Baselines. February 2022.

George Tucker, Surya Bhupatiraju, Shixiang Gu, Richard Turner, Zoubin Ghahramani, and Sergey Levine. The Mirage of Action-Dependent Baselines in Reinforcement Learning. In Proceedings of the 35th International Conference on Machine Learning , pages 5015-5024. PMLR, July 2018. ISSN: 2640-3498.

Chris Nota, Philip Thomas, and Bruno C. Da Silva. Posterior Value Functions: Hindsight Baselines for Policy Gradient Methods. In Proceedings of the 38th International Conference on Machine Learning , pages 8238-8247. PMLR, July 2021. ISSN: 2640-3498.

Arthur Guez, Fabio Viola, Theophane Weber, Lars Buesing, Steven Kapturowski, Doina Precup, David Silver, and Nicolas Heess. Value-driven Hindsight Modelling. Advances in Neural Information Processing Systems , 33, 2020.

David Venuto, Elaine Lau, Doina Precup, and Ofir Nachum. Policy Gradients Incorporating the Future. January 2022.

Jiawei Huang and Nan Jiang. From Importance Sampling to Doubly Robust Policy Gradient. In Proceedings of the 37th International Conference on Machine Learning , pages 4434-4443. PMLR, November 2020. ISSN: 2640-3498.

Andrew Y. Ng, Daishi Harada, and Stuart J. Russell. Policy Invariance Under Reward Transformations: Theory and Application to Reward Shaping. In Proceedings of the Sixteenth International Conference on Machine Learning , ICML '99, pages 278-287, San Francisco, CA, USA, June 1999. Morgan Kaufmann Publishers Inc.

Jürgen Schmidhuber. Formal Theory of Creativity, Fun, and Intrinsic Motivation (1990-2010). IEEE Transactions on Autonomous Mental Development , 2(3):230-247, September 2010.

Marc Bellemare, Sriram Srinivasan, Georg Ostrovski, Tom Schaul, David Saxton, and Remi Munos. Unifying Count-Based Exploration and Intrinsic Motivation. In Advances in Neural Information Processing Systems , volume 29. Curran Associates, Inc., 2016.

Yuri Burda, Harrison Edwards, Amos Storkey, and Oleg Klimov. Exploration by random network distillation. December 2018.

Ofir Marom and Benjamin Rosman. Belief Reward Shaping in Reinforcement Learning. Proceedings of the AAAI Conference on Artificial Intelligence , 32(1), April 2018. Number: 1.

Farzan Memarian, Wonjoon Goo, Rudolf Lioutikov, Scott Niekum, and Ufuk Topcu. Self-Supervised Online Reward Shaping in Sparse-Reward Environments, July 2021. arXiv:2103.04529 [cs].

Halit Bener Suay, Tim Brys, Matthew E. Taylor, and Sonia Chernova. Learning from Demonstration for Shaping through Inverse Reinforcement Learning. In Proceedings of the 2016 International Conference on Autonomous Agents & Multiagent Systems , AAMAS '16, pages 429-437, Richland, SC, May 2016. International Foundation for Autonomous Agents and Multiagent Systems.

Yuchen Wu, Melissa Mozifian, and Florian Shkurti. Shaping Rewards for Reinforcement Learning with Imperfect Demonstrations using Generative Models, November 2020. arXiv:2011.01298 [cs].

John Schulman, Nicolas Heess, Theophane Weber, and Pieter Abbeel. Gradient Estimation Using Stochastic Computation Graphs. In Advances in Neural Information Processing Systems , volume 28. Curran Associates, Inc., 2015.

Michel Ma, Pierluca D'Oro, Yoshua Bengio, and Pierre-Luc Bacon. Long-Term Credit Assignment via Model-based Temporal Shortcuts. In Deep RL Workshop NeurIPS , October 2021.

Nan Rosemary Ke, Anirudh Goyal ALIAS PARTH GOYAL, Olexa Bilaniuk, Jonathan Binas, Michael C Mozer, Chris Pal, and Yoshua Bengio. Sparse Attentive Backtracking: Temporal Credit Assignment Through Reminding. In S. Bengio, H. Wallach, H. Larochelle, K. Grauman, N. Cesa-Bianchi, and R. Garnett, editors, Advances in Neural Information Processing Systems 31 , pages 7640-7651. Curran Associates, Inc., 2018.

Tom Schaul, Daniel Horgan, Karol Gregor, and David Silver. Universal Value Function Approximators. In Proceedings of the 32nd International Conference on Machine Learning , pages 1312-1320. PMLR, June 2015. ISSN: 1938-7228.

Marcin Andrychowicz, Filip Wolski, Alex Ray, Jonas Schneider, Rachel Fong, Peter Welinder, Bob McGrew, Josh Tobin, OpenAI Pieter Abbeel, and Wojciech Zaremba. Hindsight Experience Replay. In Advances in Neural Information Processing Systems , volume 30. Curran Associates, Inc., 2017.

Paulo Rauber, Avinash Ummadisingu, Filipe Mutz, and Jürgen Schmidhuber. Hindsight policy gradients. December 2018.

Anirudh Goyal, Philemon Brakel, William Fedus, Soumye Singhal, Timothy Lillicrap, Sergey Levine, Hugo Larochelle, and Yoshua Bengio. Recall Traces: Backtracking Models for Efficient Reinforcement Learning. In International Conference on Learning Representations . arXiv, January 2019. arXiv:1804.00379 [cs, stat].

Juergen Schmidhuber. Reinforcement Learning Upside Down: Don't Predict Rewards - Just Map Them to Actions, June 2020. arXiv:1912.02875 [cs].

Rupesh Kumar Srivastava, Pranav Shyam, Filipe Mutz, Wojciech Ja´ skowski, and Jürgen Schmidhuber. Training Agents using Upside-Down Reinforcement Learning, September 2021. arXiv:1912.02877 [cs].

Lili Chen, Kevin Lu, Aravind Rajeswaran, Kimin Lee, Aditya Grover, Misha Laskin, Pieter Abbeel, Aravind Srinivas, and Igor Mordatch. Decision Transformer: Reinforcement Learning via Sequence Modeling. In Advances in Neural Information Processing Systems , volume 34, pages 15084-15097. Curran Associates, Inc., 2021.

Michael Janner, Qiyang Li, and Sergey Levine. Offline Reinforcement Learning as One Big Sequence Modeling Problem. In Advances in Neural Information Processing Systems , volume 34, pages 1273-1286. Curran Associates, Inc., 2021.

Richard S. Sutton. Learning to predict by the methods of temporal differences. Machine Learning , 3(1):9-44, August 1988.

Hado van Hasselt, Sephora Madjiheurem, Matteo Hessel, David Silver, André Barreto, and Diana Borsa. Expected Eligibility Traces. In Association for the Advancement of Artificial Intelligence . arXiv, February 2021. arXiv:2007.01839 [cs, stat].

Igor Babuschkin, Kate Baumli, Alison Bell, Surya Bhupatiraju, Jake Bruce, Peter Buchlovsky, David Budden, Trevor Cai, Aidan Clark, Ivo Danihelka, Antoine Dedieu, Claudio Fantacci, Jonathan Godwin, Chris Jones, Ross Hemsley, Tom Hennigan, Matteo Hessel, Shaobo Hou, Steven Kapturowski, Thomas Keck, Iurii Kemaev, Michael King, Markus Kunesch, Lena Martens, Hamza Merzic, Vladimir Mikulik, Tamara Norman, George Papamakarios, John Quan, Roman Ring, Francisco Ruiz, Alvaro Sanchez, Rosalia Schneider, Eren Sezener, Stephen Spencer, Srivatsan Srinivasan, Wojciech Stokowiec, Luyu Wang, Guangyao Zhou, and Fabio Viola. The DeepMind JAX Ecosystem, 2020.

Alexander A. Alemi, Ian Fischer, Joshua V. Dillon, and Kevin Murphy. Deep Variational Information Bottleneck. 2017.

Naftali Tishby, Fernando C. Pereira, and William Bialek. The information bottleneck method, April 2000. arXiv:physics/0004057.

Matthew Hausknecht and Peter Stone. Deep Recurrent Q-Learning for Partially Observable MDPs. In Association for the Advancement of Artificial Intelligence . arXiv, 2015. arXiv:1507.06527 [cs].

Danijar Hafner, Timothy Lillicrap, Ian Fischer, Ruben Villegas, David Ha, Honglak Lee, and James Davidson. Learning Latent Dynamics for Planning from Pixels. In Proceedings of the 36th International Conference on Machine Learning , pages 2555-2565. PMLR, May 2019. ISSN: 2640-3498.

Karol Gregor, Danilo Jimenez Rezende, Frederic Besse, Yan Wu, Hamza Merzic, and Aaron van den Oord. Shaping Belief States with Generative Environment Models for RL. In 33rd Conference on Neural Information Processing Systems (NeurIPS 2019) . arXiv, June 2019. Number: arXiv:1906.09237 arXiv:1906.09237 [cs, stat].

Karol Gregor, George Papamakarios, Frederic Besse, Lars Buesing, and Theophane Weber. Temporal Difference Variational Auto-Encoder. 2019.

Matthijs T J Spaan. Partially Observable Markov Decision Processes. Reinforcement Learning , page 27.

K. J. Astrom. Optimal Control of Markov decision processes with incomplete state estimation. J. Math. Anal. Applic. , 10:174-205, 1965.

Edward C. Tolman. Cognitive maps in rats and men. Psychological Review , 55:189-208, 1948. Place: US Publisher: American Psychological Association.

Alexander A. Alemi, Ben Poole, Ian Fischer, Joshua V. Dillon, Rif A. Saurous, and Kevin Murphy. Fixing a Broken ELBO. In Proceedings of the 35 th International Conference on Machine Learning, . arXiv, February 2018. arXiv:1711.00464 [cs, stat].

Irina Higgins, Loic Matthey, Arka Pal, Christopher Burgess, Xavier Glorot, Matthew Botvinick, Shakir Mohamed, and Alexander Lerchner. beta-VAE: Learning Basic Visual Concepts with a Constrained Variational Framework. July 2022.

Diederik P. Kingma and Max Welling. Auto-Encoding Variational Bayes. arXiv, May 2014. Number: arXiv:1312.6114 arXiv:1312.6114 [cs, stat].

James Bradbury, Roy Frostig, Peter Hawkins, Matthew James Johnson, Chris Leary, Dougal Maclaurin, George Necula, Adam Paszke, Jake VanderPlas, Skye Wanderman-Milne, and Qiao Zhang. JAX: composable transformations of Python+NumPy programs, 2018.

Lukas Biewald. Experiment Tracking with Weights and Biases, 2020.

Plotly Technologies Inc. Collaborative data science, 2015. Place: Montreal, QC Publisher: Plotly Technologies Inc.

Supplementary Materials

Table of Contents

A Related work

Our work builds upon Hindsight Credit Assignment (HCA) [1] which has sparked a number of follow-up studies. We generalize the theory of HCA towards estimating contributions upon rewarding outcomes instead of rewarding states and show through a detailed variance analysis that HCA suffers from spurious contributions leading to high variance, while using rewards or rewarding objects as rewarding outcome encodings leads to low-variance gradient estimators. Follow-up work on HCA discusses its potential high variance in constructed toy settings, and reduces the variance of the HCA advantage estimates by combining it with Monte Carlo estimates [45] or using temporal difference errors instead of rewards [46]. Alipov et al. [29] leverages the latter approach to scale up HCA towards more complex environments. However, all of the above approaches still suffer from spurious contributions, a significant source of variance in the HCA gradient estimator. In addition, recent studies have theoretically reinterpreted the original HCA formulation from different angles: Ma and Pierre-Luc [47] create the link to Conditional Monte Carlo methods [48, 49] and Arumugam et al. [50] provide an information theoretic perspective on credit assignment. Moreover, Young [51] applies HCA to the problem of estimating gradients in neural networks with stochastic, discrete units.

Long-term credit assignment in RL is hard due to the high variance of the sum of future rewards for long trajectories. A common technique to reduce the resulting variance in the policy gradients is to subtract a baseline from the sum of future rewards [6-9]. To further reduce the variance, a line of work introduced state-action-dependent baselines [52-55]. However, Tucker et al. [56] argues that these methods offer only a small benefit over the conventional state-dependent baselines, as the current action often only accounts for a minor fraction of the total variance. More recent work proposes improved baselines by incorporating hindsight information about the future trajectory into the baseline, accounting for a larger portion of the variance [1, 3, 34, 57-60].Cheng et al. [34] includes Q-value estimates of future state-action pairs into the baseline, and Huang and Jiang [60] goes one step further by also including cheap estimates of the future Q-value gradients.Mesnard et al. [3] learn a summary metric of the uncontrollable, external environment influences in the future trajectory, and provide this hindsight information as an extra input to the value baseline. Nota et al. [57] consider partially observable MDPs, and leverage the future trajectory to more accurately infer the current underlying Markov state, thereby providing a better value baseline. Harutyunyan et al. [1] propose return-HCA, a different variant of HCA that uses a return-conditioned hindsight distribution to construct a baseline, instead of using state-based hindsight distributions for estimating contributions. Finally, Guez et al. [58] and Venuto et al. [59] learn a summary representation of the full future trajectory and provide it as input to the value function, while imposing an information bottleneck to prevent the value function from overly relying on this hindsight information.

Environments with sparse rewards and long delays between actions and corresponding rewards put a high importance on long-term credit assignment. A popular strategy to circumvent the sparse and delayed reward setting is to introduce reward shaping [61-68]. These approaches add auxiliary rewards to the sparse reward function, aiming to guide the learning of the policy with dense rewards. A recent line of work introduces a reward-shaping strategy specifically designed for long-term credit assignment, where rewards are decomposed and distributed over previous state-action pairs that were instrumental in achieving that reward [4, 5, 32, 35-41]. To determine how to redistribute rewards,

these approaches rely on heuristic contribution analyses, such as via the access of memory states [4], linear decompositions of rewards [32, 35-39] or learned sequence models [5, 40, 41]. Leveraging our unbiased contribution analysis framework to reach more optimal reward transport is a promising direction for future research.

When we have access to a (learned) differentiable world model of the environment, we can achieve precise credit assignment by leveraging path-wise derivatives, i.e. backpropagating value gradients through the world model [20-24, 69]. For stochastic world models, we need access to the noise variables to compute the path-wise derivatives. The Dreamer algorithms [21-23] approach this by computing the value gradients on simulated trajectories, where the noise is known. The Stochastic Value Gradient (SVG) method [20] instead infers the noise variables on real observed trajectories. To enable backpropagating gradients over long time spans, Ma et al. [70] equip the learned recurrent world models of SVG with an attention mechanism, allowing the authors to leverage Sparse Attentive Backtracking [71] to transmit gradients through skip connections. Buesing et al. [43] leverages the insights from SVG in partially observable MDPs, using the inferred noise variables to estimate the effect of counterfactual policies on the expected return. Importantly, the path-wise derivatives leveraged by the above model-based credit assignment methods are not compatible with discrete action spaces, as sensitivities w.r.t. discrete actions are undefined. In contrast, COCOA can leverage model-based information for credit assignment, while being compatible with discrete actions.

Incorporating hindsight information has a wide variety of applications in RL. Goal-conditioned policies [72] use a goal state as additional input to the policy network or value function, thereby generalizing it to arbitrary goals. Hindsight Experience Replay [73] leverages hindsight reasoning to learn almost as much from undesired outcomes as from desired ones, as at hindsight, we can consider every final, possibly undesired state as a 'goal' state and update the value functions or policy network [74] accordingly. Goyal et al. [75] train an inverse environment model to simulate alternative past trajectories leading to the same rewarding state, hence leveraging hindsight reasoning to create a variety of highly rewarding trajectories. A recent line of work frames RL as a supervised sequence prediction problem, learning a policy conditioned on goal states or future returns [76-79]. These models are trained on past trajectories or offline data, where we have in hindsight access to states and returns, considering them as targets for the learned policy.

Finally, Temporal Difference (TD) learning [80] has a rich history of leveraging proximity in time as a proxy for credit assignment [2]. TD( λ ) [80] considers eligibility traces to trade off bias and variance, crediting past state-action pairs in the trajectory for the current reward proportional to how close they are in time. van Hasselt et al. [81] estimate expected eligibility traces, taking into account that the same rewarding state can be reached from various previous states. Hence, not only the past state-actions on the trajectory are credited and updated, but also counterfactual ones that lead to the same rewarding state. Extending the insights from COCOA towards temporal difference methods is an exciting direction for future research.

B Undiscounted infinite-horizon MDPs

In this work, we consider an undiscounted MDP with a finite state space S , bounded rewards and an infinite horizon. To ensure that the expected return and value functions remain finite, we require some standard regularity conditions [2]. We assume the MDP contains an absorbing state s ∞ that transitions only to itself and has zero reward. Moreover, we assume proper transition dynamics, meaning that an agent following any policy will eventually end up in the absorbing state s ∞ with probability one as time goes to infinity.

The discounted infinite horizon MDP formulation is a special case of this setting, with a specific class of transition dynamics. An explicit discounting of future rewards ∑ k ≥ o γ k R k with discount factor γ ∈ [0 , 1] , is equivalent to considering the above undiscounted MDP setting, but modifying the state transition probability function p ( S t +1 | S t , A t ) such that each state-action pair has a fixed probability (1 -γ ) of transitioning to the absorbing state [2]. Hence, all the results considered in this work can be readily applied to the discounted MDP setting, by modifying the environment transitions as outlined above. We can also explicitly incorporate temporal discounting in the policy gradients and contribution coefficients, which we outline in App. J.

The undiscounted infinite-horizon MDP with an absorbing state can also model episodic RL with a fixed time horizon. We can include time as an extra feature in the states S , and then have a probability of 1 to transition to the absorbing state when the agent reaches the final time step.

(a)

(b)

C Theorems, proofs and additional information for Section 3

C.1 Contribution coefficients, hindsight distribution and graphical models

Here, we provide more information on the derivation of the contribution coefficients of Eq. 3.

Abstracting time. In an undiscounted environment, it does not matter at which point in time the agent achieves the rewarding outcome u ′ . Hence, the contribution coefficients (3) sum over all future time steps, to reflect that the rewarding outcome u ′ can be encountered at any future time, and to incorporate the possibility of encountering u ′ multiple times. Note that when using temporal discounting, we can adjust the contribution coefficients accordingly (c.f. App J).

Hindsight distribution. To obtain the hindsight distribution p ( A t = a | S t = s, U ′ = u ′ ) , we convert the classical graphical model of an MDP (c.f. Fig. 6a) into a graphical model that incorporates the time k into a separate node (c.f. Fig. 6b). Here, we rewrite p ( U k = u ′ | S = s, A = a ) , the probability distribution of a rewarding outcome U k k time steps later, as p ( U ′ = u ′ | S = s, A = a, K = k ) . By giving K the geometric distribution p ( K = k ) = (1 -β ) β k -1 for some β , we can rewrite the infinite sums used in the time-independent contribution coefficients as a marginalization over K :

̸

Note that this limit is finite, as for k →∞ , the probability of reaching an absorbing state s ∞ and corresponding rewarding outcome u ∞ goes to 1 (and we take u ′ = u ∞ ). Via Bayes rule, we then have that

where we assume π ( a | s ) > 0 and where we dropped the limit of β → 1 in the notation, as we will always take this limit henceforth. Note that when π ( a | s ) = 0 , the hindsight distribution p π ( a | s, u ′ ) is also equal to zero, and hence the right-hand-side of the above equation is undefined. However, the middle term using p π ( U = u ′ | S = s, A = a ) is still well-defined, and hence we can use the contribution coefficients even for actions where π ( a | s ) = 0 .

C.2 Proof Theorem 1

We start with a lemma showing that the contribution coefficients can be used to estimate the advantage A π ( s, a ) = Q π ( s, a ) -V π ( s ) , by generalizing Theorem 1 of Harutyunyan et al. [1] towards rewarding outcomes.

Definition 3 (Fully predictive, repeated from main text) . A rewarding outcome encoding U is fully predictive of the reward R , if the following conditional independence condition holds: p π ( R k = r |

S 0 = s, A 0 = a, U k = u ) = p π ( R = r | U = u ) , where the right-hand side does not depend on the time k .

Lemma 6. For each state-action pair ( s, a ) with π ( a | s ) > 0 , and assuming that u = f ( s, a, r ) is fully predictive of the reward (c.f. Definition 3), we have that

with the advantage function A π , and the reward function r ( s, a ) ≜ E [ R | s, a ] .

Proof. We rewrite the undiscounted state-action value function in the limit of a discounting factor β → 1 -(the minus sign indicating that we approach 1 from the left):

where we use the property that u is fully predictive of the reward (c.f. Definition 2), and where we define r ( s, a ) ≜ E [ R | s, a ] and r ( u ) ≜ E [ R | u ] Using the graphical model of Fig. 6b where we abstract time k (c.f. App. C.1), we have that 1 1 -β p π β ( R = r ′ | s, a ) = ∑ k =0 β k p π ( R k = r | s, a ) . Leveraging Bayes rule, we get

Where we dropped the limit of β → 1 -in the notation of p π ( a | s, R = r ) , as we henceforth always consider this limit. Taking everything together, we have that

Subtracting the value function, we get

Now we are ready to prove Theorem 1.

Proof. Using the policy gradient theorem [26], we have

where we used that removing a baseline ∑ a ′ ∈A π ( a ′ | s ) r ( s, a ′ ) independent from the actions does not change the policy gradient, and replaced E T ∼T ( s 0 ,π ) [ ∑ a ∈A ∇ θ π ( a | S t ) r ( S t , a )] by its sampled version E T ∼T ( s 0 ,π ) [ ∇ θ log π ( A t | S t ) R t ] . Hence the policy gradient estimator of Eq. 4 is unbiased.

C.3 Different policy gradient estimators leveraging contribution coefficients.

In this work, we use the COCOA estimator of Eq. 4 to estimate policy gradients leveraging the contribution coefficients of Eq. 3, as this estimator does not need a separate reward model, and it works well for the small action spaces we considered in our experiments. However, one can design other unbiased policy gradient estimators compatible with the same contribution coefficients.

Harutyunyan et al. [1] introduced the HCA gradient estimator of Eq. 2, which can readily be extended to rewarding outcomes U :

This gradient estimator uses a reward model r ( s, a ) to obtain the rewards corresponding to counterfactual actions, whereas the COCOA estimator (4) only uses the observed rewards R k .

For large action spaces, it might become computationally intractable to sum over all possible actions. In this case, we can sample independent actions from the policy, instead of summing over all actions, leading to the following policy gradient.

where we sample M actions from a m ∼ π ( · | S t ) . Importantly, for obtaining an unbiased policy gradient estimate, the actions a m should be sampled independently from the actions used in the trajectory of the observed rewards R t + k . Hence, we cannot take the observed A t as a sample a m , but need to instead sample independently from the policy. This policy gradient estimator can be used for continuous action spaces (c.f. App. G, and can also be combined with the reward model as in Eq. 26.

One can show that the above policy gradient estimators are unbiased with a proof akin to the one of Theorem 1.

Comparison of COCOA to using time as a credit assignment heuristic. In Section 2 we discussed briefly the following discounted policy gradient:

with discount factor γ ∈ [0 , 1] . Note that we specifically put no discounting γ t in front of ∇ θ log π ( A t | S t ) , which would be required for being an unbiased gradient estimate of the discounted expected total return, as the above formulation is most used in practice [12, 27]. Rewriting

the summations reveals that this policy gradient uses time as a heuristic for credit assignment:

Wecan rewrite the COCOA gradient estimator (4) with the same reordering of summation, showcasing that it leverages the contribution coefficient for providing precise credit to past actions, instead of using the time discounting heuristic:

C.4 Proof of Proposition 2

Proof. Proposition 2 assumes that each action sequence { A m } t + k m = t leads to a unique state s ′ . Hence, all previous actions can be decoded perfectly from the state s ′ , leading to p π ( A t = a | S t , S ′ = s ′ ) = δ ( a = a t ) , with δ the indicator function and a t the action taken in the trajectory that led to s ′ . Filling this into the COCOA gradient estimator leads to

where we used that ∑ a ∇ θ π ( a | s ) = 0 .

C.5 Proof Theorem 3

Proof. Theorem 3 considers the case where the environment only contains a reward at the final time step t = T , and where we optimize the policy only on a single (initial) time step t = 0 . Then, the policy gradients are given by

With U either S , R or Z , and s the state at t = 0 . As only the last time step can have a reward by assumption, and the encoding U needs to retain the predictive information of the reward, the contribution coefficients for u corresponding to a nonzero reward are equal to

The coefficients corresponding to zero-reward outcomes are multiplied with zero in the gradient estimator, and can hence be ignored. Now, we proceed by showing that E [ ˆ ∇ REINFORCE θ V π ( A 0 , R T ) | S T , R T ] = ˆ ∇ S θ V π ( S T , R T ) , E [ ˆ ∇ S θ V π ( S T , R T ) | U ′ T , R T ] = ˆ ∇ U ′ θ V π ( U ′ T , R T ) , E [ ˆ ∇ U ′ θ V π ( U ′ T , R T ) | U T , R T ] = ˆ ∇ U θ V π ( U T , R T ) , and E [ ˆ ∇ U θ V π ( U T , R T ) | R T ] = ˆ ∇ R θ V π ( R T ) , after which we can use the law of total variance to prove our theorem.

As S T is fully predictive of R T , the following conditional independence holds p π ( A 0 | S 0 = s, S T , R T ) = p π ( A 0 | S 0 = s, S T ) (c.f. Definition 2). Hence, we have that

where we used that ∑ a ∇ θ π ( a | s ) = ∇ θ ∑ a π ( a | s ) = 0 .

Similarly, as S T is fully predictive of U ′ T (c.f. Definition 2), we have that

Using the conditional independence relation p π ( S T | S 0 , U ′ T , R T ) = p π ( S T | S 0 , U ′ T ) , following from d-separation in Fig. 6b, this leads us to

Using the same derivation leveraging the fully predictive properties (c.f. Definition 2), we get

Now we can use the law of total variance, which states that V [ X ] = E [ V [ X | Y ]] + V [ E [ X | Y ]] . Hence, we have that

as E [ V [ ˆ ∇ REINFORCE θ V π | S T ]] is positive semi definite. Using the same construction for the other pairs, we arrive at

thereby concluding the proof.

Additional empirical verification. To get more insight into how the information content of the rewarding-outcome encoding U relates to the variance of the COCOA gradient estimator, we repeat the experiment of Fig. 2, but now plot the variance as a function of the amount of information in the rewarding outcome encodings, for a fixed state overlap of 3. Fig. 7 shows that the variance of the resulting COCOA gradient estimators interpolate between COCOA-reward and HCA+, with more informative encodings leading to a higher variance. These empirical results show that the insights of Theorem 3 hold in this more general setting of estimating full policy gradients in an MDP with random rewards.

C.6 Proof of Theorem 4

Proof. This proof follows a similar technique to the policy gradient theorem [26]. Let us first define the expected number of occurrences of u starting from state s as O π ( u, s ) = ∑ k ≥ 1 p π ( U k = u | S 0 = s ) , and its action equivalent O π ( u, s, a ) = ∑ k ≥ 1 p π ( U k = u | S 0 = s, A 0 = a ) . Expanding O π ( u, s ) leads to

which leads to

where we used that ∑ a ∈A ∇ θ π ( a | s ) = 0 , thereby concluding the proof.

D Learning the contribution coefficients

D.1 Proof Proposition 5

Proof. In short, as the logits l are a deterministic function of the state s , they do not provide any further information on the hindsight distribution and we have that p π ( A 0 = a | S 0 = s, L 0 = l, U ′ = u ′ ) = p π ( A 0 = a | S 0 = s, U ′ = u ′ ) .

1

2

5

10

2

5

100

12

13

14

15

COCOA-u-group

HCA+

COCOA-reward

REINFORCE

Number of groups per reward value

Var dB

Now define ϕ ( u, s ) = ∑ a ∈A ∇ θ π ( a | s ) O π ( u, s, a ) , and p π ( S l = s ′ | S 0 = s ) as the probability of reaching s ′ starting from s in l steps. We have that ∑ s ′′ ∈S p π ( S l = s ′′ | S 0 = s ) p π ( S 1 = s ′ | S 0 = s ′′ ) = p π ( S l +1 = s ′ | S 0 = s ) . Leveraging this relation and recursively applying the above equation leads to

where in the last step we normalized ∑ ∞ l =0 p π ( S l = s ′ | S 0 = s ) with ∑ s ′ ∈S ∑ ∞ l =0 p π ( S l = s ′ | S 0 = s ) , resulting in the state distribution S ∼ T ( s, π ) where S is sampled from trajectories starting from s and following policy π .

Finally, we can rewrite the contribution coefficients as

We can arrive at this result by observing that p ( A 0 = a | S 0 = s, L 0 = l ) = p ( A 0 = a | S 0 = s ) = π ( a | s ) , as the policy logits encode the policy distribution. Using this, we have that

D.2 Learning contribution coefficients via contrastive classification.

Instead of learning the hindsight distribution, we can estimate the probability ratio p π ( A t = a | S t = s, U ′ = u ′ ) /π ( a | s ) directly, by leveraging contrastive classification. Proposition 7 shows that by training a binary classifier D ( a, s, u ′ ) to distinguish actions sampled from p π ( A t = a | S t = s, R ′ = r ′ ) versus π ( a | s ) , we can directly estimate the probability ratio.

Proposition 7. Consider the contrastive loss

and D ( s, a, u ) its minimizer. Then the following holds

Proof. Consider a fixed pair s, u ′ . We can obtain the discriminator D ∗ ( a, s, u ′ ) that maximizes E a ∼ p π ( a | s,u ′ ) [log D ( a, s, u ′ )]+ E a ∼ π ( a | s ) [ log ( 1 -D ( a, s, u ′ ) )] by taking the point-wise derivative of this objective and equating it to zero:

As for any ( a, b ) ∈ R 2 / 0 , the function f ( x ) = a log x + b log(1 -x ) achieves its global maximum on support x ∈ [0 , 1] at a a + b , the above maximum is a global maximum. Repeating this argument for all ( s, u ′ ) pairs concludes the proof.

We can approximate the training objective of D by sampling a ( m ) , s ( m ) , u ′ ( m ) along the observed trajectories, while leveraging that we have access to the policy π , leading to the following loss

Numerical stability. Assuming D uses the sigmoid nonlinearity on its outputs, we can improve the numerical stability by computing the logarithm and sigmoid jointly. This results in

The probability ratio D/ (1 -D ) can then be computed with

D.3 Successor representations.

If we take u ′ equal to the state s ′ , we can observe that the sum ∑ k ≥ 1 p π ( S t + k = s ′ | s, a ) used in the contribution coefficients (3) is equal to the successor representation M ( s, a, s ′ ) introduced by Dayan [30]. Hence, we can leverage temporal differences to learn M ( s, a, s ′ ) , either in a tabular setting [30], or in a deep feature learning setting [31]. Using the successor representations, we can construct the state-based contribution coefficients as w ( s, a, s ′ ) = M ( s, a, s ′ ) / [ ∑ ˜ a ∈A π (˜ a | s ) M ( s, ˜ a, s ′ )] -1 .

For a rewarding outcome encoding U different from S , we can recombine the state-based successor representations to obtain the required contribution coefficients using the following derivation.

where in the second line we used that S is fully predictive of U (c.f. Definition 2). Note that p ( U ′ | S ′ ) is policy independent, and can hence be approximated efficiently using offline data. We use this recombination of successor representations in our dynamic programming setup to compute the ground-truth contribution coefficients (c.f. App. E).

E Experimental details and additional results

Here, we provide additional details to all experiments performed in the manuscript and present additional results.

E.1 Algorithms

Algorithm 1 shows pseudocode for the COCOA family of algorithms.

E.2 Dynamic programming setup

In order to delineate the different policy gradient methods considered in this work, we develop a framework to compute ground-truth policy gradients and advantages as well as ground-truth contribution coefficients. We will first show how we can recursively compute a quantity closely related to the successor representation using dynamic programming which then allows us to obtain expected advantages and finally expected policy gradients.

E.2.1 Computing ground truth quantities

To compute ground truth quantities, we assume that the environment reaches an absorbing, terminal state s ∞ after T steps for all states s , i.e. p π ( S T = s ∞ | s 0 = s ) = 1 . This assumption is satisfied by the linear key-to-door and tree environment we consider. As a helper quantity, we define the successor representation:

which captures the cumulative probability over all time steps of reaching state s ′ when starting from state S 0 = s , choosing initial action A 0 = a and following the policy π thereafter. We can compute M ( s, a, s ′ , T ) recursively as

where 1 is the indicator function and M ( s, a, s ′ , 0) is initialized to 0 everywhere. Then, the various quantities can be computed exactly as follows.

Algorithm 1 COCOA

Require: Initial π , h , episode length T , number of episodes N , number of pretraining episodes M , batch size L , K number of pretraining update steps.

Contribution coefficients

where

similar to the successor representations detailed in Section D. To discover the full state space S for an arbitrary environment, we perform a depth-first search through the environment transitions (which are deterministic in our setting), and record the encountered states.

Value function

where r ( s ′ , a ′ ) = ∑ r ′ r ′ p ( r ′ | s ′ , a ′ )

Action-value function

where r ( s ′ , a ′ ) = ∑ r ′ r ′ p ( r ′ | s ′ , a ′ )

E.2.2 Computing expected advantages

As a next step we detail how to compute the true expected advantage given a potentially imperfect estimator of the contribution coefficient ˆ w , the value function ˆ V or the action-value function ˆ Q .

COCOA

where r ( u ′ ) = ∑ r ′ r ′ p ( r ′ | u ′ ) and M ( s, a ′ , u ′ , T ) is defined as in E.2.1.

Advantage

where Q is the ground truth action-value function obtained following E.2.1.

Q-critic

E.2.3 Computing expected policy gradients

Finally, we show how we can compute the expected policy gradient, E π [ ˆ ∇ · θ V π ] of a potentially biased gradient estimator, given the expected advantage E π [ ˆ A π ( s, a ) ] .

Using automatic differentiation to obtain ∇ θ π ( a | s 0 ) , and the quantity M ( s, a, s ′ , T ) we defined above, we can then compute the expected policy gradient.

Computing the ground-truth policy gradient. To compute the ground-truth policy gradient, we can apply the same strategy as for Eq. 90 and replace the expected (possibly biased) advantage E π [ ˆ A π ( s 0 , a ) ] by the ground-truth advantage function, computed with the ground-truth action-value function (c.f. Section E.2.1).

E.3 Bias, variance and SNR metrics

To analyze the quality of the policy gradient estimators, we use the signal-to-noise ratio (SNR), which we further subdivide into variance and bias. A higher SNR indicates that we need fewer trajectories to estimate accurate policy gradients, hence reflecting better credit assignment. To obtain meaningful

scales, we normalize the bias and variance by the norm of the ground-truth policy gradient.

We compute the full expectations E π [ ˆ ∇ · θ V π ] and ground-truth policy gradient ∇ θ V π by leveraging our dynamic programming setup, while for the expectation of the squared differences E π [ ∥ ˆ ∇ · θ V π -∇ θ V π ∥ 2 ] we use Monte Carlo sampling with a sample size of 512. We report the metrics in Decibels in all figures.

Focusing on long-term credit assignment. As we are primarily interested in assessing the longterm credit assignment capabilities of the gradient estimators, we report the statistics of the policy gradient estimator corresponding to learning to pick up the key or not. Hence, we compare the SNR, variance and bias of a partial policy gradient estimator considering only t = 0 in the outer sum (corresponding to the state with the key) for all considered estimators (c.f. Table 1).

Shadow training. Policy gradients evaluated during training depend on the specific learning trajectory of the agent. Since all methods' policy gradient estimators contain noise, these trajectories are likely different for the different methods. As a result, it is difficult to directly compare the quality of the policy gradient estimators, since it depends on the specific data generated by intermediate policies during training. In order to allow for a controlled comparison between methods independent of the noise introduced by different trajectories, we consider a shadow training setup in which the policy is trained with the Q-critic method using ground-truth action-value functions. We can then compute the policy gradients for the various estimators on the same shared data along this learning trajectory without using it to actually train the policy. We use this strategy to generate the results shown in Fig. 1B (right), Fig. 2B and Fig. 3C-D.

E.4 Linear key-to-door environment setup

We simplify the key-to-door environment previously considered by various papers [e.g. 3, 4, 32], to a one-dimensional, linear track instead of the original two-dimensional grid world. This version still captures the difficulty of long-term credit assignment but reduces the computational burden allowing us to thoroughly analyze different policy gradient estimators with the aforementioned dynamic programming based setup. The environment is depicted in Fig. 3A. Here, the agent needs to pick up a key in the first time step, after which it engages in a distractor task of picking up apples which can either be to the left or the right of the agent and which can stochastically assume two different reward values. Finally, the agent reaches a door which it can open with the key to collect a treasure reward.

In our simulations we represent states using a nine-dimensional vector, encoding the relative position on the track as a floating number, a boolean for each item that could be present at the current location (empty, apple left, apple right, door, key, treasure) as well as boolean indicating whether the agent has the key and a boolean for whether the agent does not have the key.

There are four discrete actions the agent can pick at every time step: pick the key, pick to the left, pick to the right and open the door. Regardless of the chosen action, the agent will advance to the next position in the next time step. If it has correctly picked up the key in the first time step and opened the door in the penultimate time step, it will automatically pick up the treasure, not requiring an additional action.

Hung et al. [4] showed that the signal-to-noise ratio (SNR) of the REINFORCE policy gradient [6] for solving the main task of picking up the key can be approximated by

with ˆ ∇ REINF θ V π the REINFORCE estimator (c.f. Table 1), C ( θ ) a reward-independent constant, T 2 the set of time steps corresponding to the distractor task, and Tr [ V [ ˆ ∇ REINF θ V π | no T2 ] ] the trace of the covariance matrix of the REINFORCE estimator in an equivalent task setup without distractor rewards. Hence, we can adjust the difficulty of the task by increasing the number of distractor rewards and their variance. We perform experiments with environments of length L ∈ { 20 , 40 , . . . , 100 } choosing the reward values such that the total distractor reward remains approximately constant. Concretely, distractor rewards are sampled as r distractor ∼ U ( { 2 L , 18 L } ) and the treasure leads to a deterministic reward of r treasure = 4 L .

E.5 Reward switching setup

While learning to get the treasure in the key-to-door environment requires long term credit assignment as the agent needs to learn to 1) pickup the key and 2) open the door, learning to stop picking up the treasure does not require long term credit assignment, since the agent can simply learn to stop opening the door.

We therefore reuse the linear key-to-door environment of length L = 40 , with the single difference that we remove the requirement to open the door in order to get the treasure reward. The agent thus needs to perform similar credit assignment to both get the treasure and stop getting the treasure. When applying reward switching, we simply flip the sign of the treasure reward while keeping the distractor reward unchanged.

E.6 Tree environment setup

We parameterize the tree environment by its depth d , the number of actions n a determining the branching factor, and the state overlap o s , defined as the number of overlapping children from two neighbouring nodes. The states are represented by two integers: i < d representing the current level in the tree, and j the position of the state within that level. The root node has state ( i, j ) = (0 , 0) , and the state transitions are deterministic and given by i ← i +1 and j ← j ( n a -o s ) + a , where we represent the action by an integer 0 ≤ a < n a . We assign each state-action pair a reward r ∈ {-2 , -1 , 0 , 1 , 2 } , computed as

with the modulo operator mod , the number of reward values n r = 5 , idx( s ) a unique integer index for the state s = ( i, j ) , a large prime number p , and an environment seed .

To introduce rewarding outcome encodings with varying information content, we group state-action pairs corresponding to the same reward value in n g groups:

Environment parameters for Figure 2. For the experiment of Fig. 2, we use 6 actions and a depth of 4. We plotted the variance of the COCOA estimator for encodings U corresponding to n g = 4 and n g = 32 .

E.7 Task interleaving environment setup

We simplify the task interleaving environment of Mesnard et al. [3] in the following way: the environment is parameterized by the number of contexts C , the number of objects per context O , the maximum number of open contexts B , and finally the dying probability 1 -γ . In each context, a set of 2 O objects is given, and a subset of O objects is randomly chosen as the rewarding objects for that context. The task consists in learning, for all contexts, to chose the right objects when presented a pair of objects, one rewarding and one non rewarding. While this is reminiscent of a contextual bandit setting, crucially, the agent receives the reward associated to its choice only at a later time, after potentially making new choices for other contexts, and receiving rewards from other contexts, resulting in an interleaved bandit problem. The agent must thus learn to disentangle the reward associated to each context in order to perform proper credit assignment.

State and action At every timestep, there are 2 actions the agent can take: choose right, or choose left.

The state is defined by the following variables:

Aset of open contexts , i.e. contexts where choices have been made but no reward associated to those choices has been received

For each open context, a bit (or key) indicating whether the correct choice has been made or not

The context of the current task

A pair of objects currently being presented to the agent, if the current context is a query room. Each element of the pair is assigned to either the left side or the right side.

Transition and reward The transition dynamics work as follows. If the agent is in an answer room, then regardless of the action, it receives a context-dependent reward if it also has the key of the corresponding context (i.e. it has made the correct choice when last encountering query room corresponding to the context). Otherwise, it receives 0 reward. Then, the current context is removed from the set of open contexts.

If the agent is in a query room, then the agent is presented with 2 objects, one rewarding and one not, and must choose the side of the rewarding object. Regardless, the agent receives 0 reward at this timestep, and the current context is added to the set of open contexts. Furthermore, if it did make the correct choice, a key associated to the current context is given.

Finally, the next context is sampled. With a probability C o B (where C o is the number of open context), the agent samples uniformly one of the open contexts. Otherwise, the agent samples uniformly one of the non-open contexts. The 2 objects are then also sampled uniformly out of the O rewarding objects and O unrewarding objects. The rewarding object is placed either on the right or left side with uniform probability, and the unrewarding object placed on the other side.

Crucially, there is a probability 1 -γ of dying, in which case the agent receives the reward but is put into a terminal state at the next timestep.

Environment parameters For all our experiments, we choose C = 5 , B = 3 , O = 2 and γ = 0 . 95 .

Visualization of contribution coefficient magnitudes. For the heatmaps shown in Fig 4C, we computed each entry as ∑ a ∈A π ( a | s t ) · | w ( s t , a, r t + k ) | where states s t and rewards r t + k are grouped by the context of their corresponding room. We average over all query-answer pairs grouped by contexts excluding query-query or answer-answer pairs and only consider answer rooms with non-zero rewards.

E.8 Training details

E.8.1 Architecture

We use separate fully-connected ReLU networks to parameterize the policy, value function, and action-value function. For the policy we use two hidden layers of size 64, for the value function and action-value function respectively we use a single hidden layer of size 256. For the hindsight model of both HCA and COCOA we found a simple multilayer perceptron with the state s and rewarding outcome encoding u ′ as inputs to perform poorly. We hypothesize that this is due to the policy dependence of the hindsight distribution creating a moving target during learning as the

policy changes. Leveraging Proposition 5, we therefore add the policy logits as an extra input to the hindsight network to ease tracking the changing policy. We found good performance using a simple hypernetwork, depicted in Fig. 8 that combines the policy logits with the state and hindsight object inputs through a multiplicative interaction, outputting a logit for each possible action. The multiplicative interaction denoted by ⊗ consists of a matrix multiplication of a matrix output by the network with the policy logits, and can be interpreted as selecting a combination of policy logits to add to the output channel. In order to allow gating with both positive and negative values, we use a gated version of the ReLU nonlinearity in the second layer which computes the difference between the split, rectified input effectively halving the output dimension:

with n the dimension of x . Gating in combination with the multiplicative interaction is a useful inductive bias for the hindsight model, since for actions which have zero contribution towards the rewarding outcome u the hindsight distribution is equal to the policy. To increase the performance of our HCA+ baseline, we provide both the policy logits and one minus the policy logits to the multiplicative interaction.

E.8.2 Optimization

For training of all models we use the AdamW optimizer with default parameters only adjusting the learning rates and clipping the global norm of the policy gradient. We use entropy regularization in combination with epsilon greedy to ensure sufficient exploration to discover the optimal policy. To estimate (action-) value functions we use TD( λ ) treating each λ as a hyperparemeter. For all linear layers we use the default initialization of Haiku [82] where biases are initialized as zero and weights are sample from a truncated Gaussian with standard deviation 1 √ n input where n input is the input dimension of the respective layer and.

E.8.3 Reward features

Learned reward features should both be fully predictive of the reward (c.f. Theorem 1), and contain as little additional information about the underlying state-action pair as possible (c.f. Theorem 3). We can achieve the former by training a network to predict the rewards given a state-action pair, and take the penultimate layer as the feature u = f ( s, a ) . For the latter, there exist multiple approaches. When using a deterministic encoding u = f ( s, a ) , we can bin the features such that similar features predicting the same reward are grouped together. When using a stochastic encoding p ( U | S, A ) we can impose an information bottleneck on the reward features U , enforcing the encoding to discard as much information about U as possible [83, 84]. We choose the deterministic encoding approach, as our Dynamic Programming routines require a deterministic encoding. 4 We group the deterministic rewarding outcome encodings by discretizing the reward prediction network up to the penultimate layer.

Architecture. For the neural architecture of the reward prediction network we choose a linear model parameterized in the following way. The input is first multiplicatively transformed by an action-specific mask. The mask is parameterized by a vector of the same dimensionality as the input, and which is squared in order to ensure positivity. A ReLU nonlinearity with straight through gradient estimator is then applied to the transformation. Finally, an action-independent readout weight transforms the activations to the prediction of the reward. The mask parameters are initialized to 1 . Weights of the readout layer are initialized with a Gaussian distribution of mean 0 and std 1 √ d where d is the dimension of the input.

Loss function. We train the reward network on the mean squared error loss against the reward. To avoid spurious contributions (c.f. 3.3), we encourage the network to learn sparse features that discard information irrelevant to the prediction of the reward, by adding a L1 regularization term to all weights up to the penultimate layer with a strength of η L 1 = 0 . 001 . The readout weights are trained with standard L2 regularization with strength η L 2 = 0 . 03 . For the linear key-to-door experiments, we choose ( η L 1 , η L 2 ) = (0 . 001 , 0 . 03) . For the task interleaving environment, we choose ( η L 1 , η L 2 ) = (0 . 05 , 0 . 0003) .

All weights regularization are treated as weight decay, with the decay applied after the gradient update.

Pretraining. To learn the reward features, we collect the first B feature mini-batches of episodes in a buffer using a frozen random policy. We then sample triplets ( s, a, r ) from the buffer and train with full-batch gradient descent using the Adam optimizer over N feature steps. Once trained, the reward network is frozen, and the masked inputs, which are discretized using the element-wise threshold function 1 x> 0 . 05 , are used to train the contribution coefficient as in other COCOA methods. To ensure a fair comparison, other methods are already allowed to train the policy on the first B feature batches of episodes. For the linear key-to-door experiments, we chose ( B feature , N feature ) = (30 , 20000) . For the task interleaving environment, we chose ( B feature , N feature ) = (90 , 30000) .

E.8.4 Hyperparameters

Linear key-to-door setup (performance) For all our experiments on the linear key-to-door environment, we chose a batch size of 8, while using a batch size of 512 to compute the average performance, SNR, bias and variance metrics. We followed a 2-step selection procedure for selecting the hyperparameters: first, we retain the set of hyperparameters for which the environment can be solved for at least 90% of all seeds, given a large amount of training budget. An environment is considered to be solved for a given seed when the probability of picking up the treasure is above 90%. Then, out of all those hyperparameters, we select the one which maximizes the cumulative amount of treasures picked over 10000 training batches. We used 30 seeds for each set of hyperparameters to identify the best performing ones, then drew 30 fresh seeds for our evaluation. The range considered

for our hyperparameter search can be found in Table 2, and the selected hyperparameters in Table 3. Surprisingly, we found that for the environment length considered, the same hyperparameters were performing best, with the exception of entropy_reg . For the final values of entropy_reg for each environment length, we linearly interpolated in log-log space between the best performing values, 0 . 03 for length 20 and 0 . 01 for 100 . The values can be found in Table 5.

Linear key-to-door setup (shadow training) For measuring the bias and variances of different methods in the shadow training setting, we used the best performing hyperparameters found in the performance setting. We kept a batch size of 8 for the behavior policy and shadow training, while using a batch size of 512 during evaluation.

Reward switching setup For the reward switching experiment, we chose hyperparameters following a similar selection procedure as in the linear key-to-door setup, but in the simplified door-less environment of length 40, without any reward switching. We found very similar hyperparameters to work well despite the absence of a door compared to the linear key-to-door setup. However, in order to ensure that noisy methods such as REINFORCE fully converged before the moment of switching the reward, we needed to train the models for 60000 training batches before the switch. To stabilize the hindsight model during this long training period, we added coarse gradient norm clipping by 1 . . Furthermore, we found that a slightly decreased learning rate of 0 . 001 for the Q-critic performed best. Once the best hyperparameters were found, we applied the reward switching to record the speed of adaptation for each algorithm. We kept a batch size of 8 for the behavior policy and shadow training, while using a batch size of 512 during evaluation.

Task interleaving experiment We choose a batch size of 8 and train on 10000 batches, while using a batch size of 512 to compute the average performance. We used 5 seeds for each set of hyperparameters to identify the best performing ones, then drew 5 fresh seeds for our evaluation. The selected hyperparameters can be found in Table 4.

F Additional results

We perform additional experiments to corroborate the findings of the main text. Specifically, we investigate how reward aliasing affects COCOA-reward and COCOA-feature and show that there is no significant difference in performance between HCA and our simplified version, HCA+.

F.1 HCA vs HCA+

Our policy gradient estimator for U = S presented in Eq. 4 differs slightly from Eq. 2, the version originally introduced by Harutyunyan et al. [1], as we remove the need for a learned reward model r ( s, a ) . We empirically verify that this simplification does not lead to a decrease in performance in Fig. 9. We run the longest and hence most difficult version of the linear key-to-door environment considered in our experiments and find no significant difference in performance between our simplified version (HCA+) and the original variant (HCA).

F.2 Learned credit assignment features allow for quick adaptation to a change of the reward function.

Disentangling rewarding outcomes comes with another benefit: When the reward value corresponding to a rewarding outcome changes, e.g. the treasure that was once considered a reward turns out to be poisonous, we only have to relearn the contribution coefficients corresponding to this rewarding outcome. This is in contrast to value-based methods for which potentially many state values are altered. Moreover, once we have access to credit assignment features u that encode rewarding outcomes which generalize to the new setting, the contribution coefficients remain invariant to changes in reward contingencies. For example, if we remember that we need to open the door with

2k

4k

6k

8k

10k

0

0.2

0.4

0.6

0.8

1

HCA+

HCA

Episode

Treasure reward collected

the key to get to the treasure, we can use this knowledge to avoid picking up the key and opening the door when the treasure becomes poisonous.

To illustrate these benefits, we consider a variant of the linear key-to-door environment, where picking up the key always leads to obtaining the treasure reward, and where the treasure reward abruptly changes to be negative after 60k episodes. In this case, COCOA-feature learns to encode the treasure as the same underlying rewarding object before and after the switch, and hence can readily reuse the learned contribution coefficients adapting almost instantly (c.f. Fig. 10). COCOA-reward in contrast needs to encode the poisonous treasure as a new, previously unknown rewarding outcome. Since it only needs to relearn the contribution coefficients for the disentangled subtask of avoiding poison it nevertheless adapts quickly (c.f. Fig. 10). Advantage and Q-critic are both faced with relearning their value functions following the reward switch. In particular, they lack the property of disentangling different rewarding outcomes and all states that eventually lead to the treasure need to be updated.

F.3 Using returns instead of rewards as hindsight information

In Appendix L, we discussed that HCA-return is a biased estimator in many relevant environments, including our key-to-door and task-interleaving environments. This explains its worse performance compared to our COCOA algorithms. To isolate the difference of using returns instead of rewards as

hindsight information for constructing the contribution coefficients, we introduce the following new baseline:

Similar to HCA-return, this Counterfactual Return variant leverages a hindsight distribution conditioned on the return. Different from HCA-return, we use this hindsight distribution to compute contribution coefficients that can evaluate all counterfactual actions. We prove that this estimator is unbiased.

Figure 11 shows that the performance of HCA-return and Counterfactual return lags far behind the performance of COCOA-reward on the key-to-door environment. This is due to the high variance of HCA-return and Counterfactual Return, and the biasedness of the former. As the return is a combination of all the rewards of a trajectory, it cannot be used to disentangle rewarding outcomes, causing the variance of the distractor subtask to spill over to the subtask of picking up the treasure.

F.4 Investigation into the required accuracy of the hindsight models

To quantify the relation between the approximation quality of the hindsight models and value functions upon the SNR of the resulting policy gradient estimate, we introduce the following experiment. We start from the ground-truth hindsight models and value functions computed with our dynamic programming setup (c.f. E.2), and introduce a persistent bias into the output of the model by elementwise multiplying the output with (1+ σϵ ) , with ϵ zero-mean univariate Gaussian noise and σ ∈ { 0 . 001 , 0 . 003 , 0 . 01 , 0 . 03 , 0 . 1 , 0 . 3 } a scalar of which we vary the magnitude in the experiment.

Figure 12 shows the SNR of the COCOA-reward estimator and the baselines, as a function of the perturbance magnitude log σ , where we average the results over 30 random seeds. We see that the sensitivity of the COCOA-reward estimator to its model quality is similar to that of Q-critic. Furthermore, the SNR of COCOA-reward remains of better quality compared to Advantage and HCA-state for a wide range of perturbations.

G Contribution analysis in continuous spaces and POMDPs

In Section 3.3 we showed that HCA can suffer from spurious contributions, as state representations need to contain detailed features to allow for a capable policy. The same level of detail however is detrimental when assigning credit to actions for reaching a particular state, since at some resolution almost every action will lead to a slightly different outcome. Measuring the contribution towards a specific state ignores that often the same reward could be obtained in a slightly different state, hence overvaluing the importance of past actions. Many commonly used environments, such as pixel-based environments, continuous environments, and partially observable MDPs exhibit this property to a large extent due to their fine-grained state representations. Here, we take a closer look at how spurious contributions arise in continuous environments and Partially Observable MDPs (POMDPs).

0.001

2

5

0.01

2

5

0.1

2

-40

-20

0

20

Q-critic

HCA+

COCOA-reward

Advantage

Model Perturbation

SNR (dB)

G.1 Spurious contributions in continuous state spaces

When using continuous state spaces, p π ( S k = s ′ | s, a ) represents a probability density function (PDF) instead of a probability. A ratio of PDFs p ( X = x ) /p ( X = x ′ ) can be interpreted as a likelihood ratio of how likely a sample X will be close to x versus x ′ . Using PDFs, the contribution coefficients with U = S used by HCA result in

̸

and can be interpreted as a likelihood ratio of encountering a state 'close' to s ′ , starting from ( s, a ) versus starting from s and following the policy. The contribution coefficient will be high if p π ( S ′ = s ′ | s, a ) has a high probability density at s ′ conditioned on action a , compared to the other actions a ′ = a . Hence, the less p π ( S k = s ′ | s, a ) and p π ( S k = s ′ | s, a ′ ) overlap around s ′ , the higher the contribution coefficient for action a . The variance of the distribution p π ( S k = s ′ | s, a ) , and hence its room for overlap, is determined by how diffuse the environment transitions and policy are. For example, a very peaked policy and nearly deterministic environment transitions leads to a sharp distribution p π ( S k = s ′ | s, a ) .

The randomness of the policy and environment is a poor measure for the contribution of an action in obtaining a reward. For example, consider the musician's motor system, that learns to both: (i) play the violin and (ii) play the keyboard. We assume a precise control policy and near deterministic environment dynamics, resulting in peaked distributions p π ( S k = s ′ | s, a ) . For playing the violin, a slight change in finger position significantly influences the pitch, hence the reward function sharply declines around the target state with perfect pitch. For playing the keyboard, the specific finger position matters to a lesser extent, as long as the correct key is pressed, resulting in a relatively flat reward function w.r.t. the precise finger positioning. The state-based contribution coefficients of Eq. 100 result in a high contribution for the action taken in the trajectory for both tasks. For playing violin, this could be a good approximation of what we intuitively think of as a 'high contribution', whereas for the keyboard, this overvalues the importance of the past action in many cases. From this example, it is clear that measuring contributions towards rewarding states in continuous state spaces can lead to spurious contributions, as the contributions mainly depend on how diffuse the policy and environment dynamics are, and ignore that different reward structures can require vastly different contribution measures.

G.2 Deterministic continuous reward functions can lead to excessive variance

Proposition 2 shows that HCA degrades to REINFORCE in environments where each action sequence leads to distinct states. In Section G.1, we discussed that continuous state spaces exhibit this property to a large extend due to their fine-grained state representation. If each environment state has a unique reward value, COCOA can suffer from a similar degradation to HCA. As the rewarding outcome encoding U needs to be fully predictive of the reward (c.f. Theorem 1), it needs to have a distinct encoding for each unique reward, and hence for each state.

With a continuous reward function this can become a significant issue, if the reward function is deterministic. Due to the fine-grained state representation in continuous state spaces, almost every action will lead to a (slightly) different state. When we have a deterministic, continuous reward function, two nearby but distinct states will often lead to nearby but distinct rewards. Hence, to a large extent, the reward contains the information of the underlying state, encoded in its infinite precision of a real value, resulting in COCOA degrading towards the high-variance HCA estimator.

The above problem does not occur when the reward function p ( R | S, A ) is probabilistic, even for continuous rewards. If the variance of p ( R | S, A ) is bigger than zero, the variance of p ( S, A | R ) is also bigger than zero under mild assumptions. This means that it is not possible to perfectly decode the underlying state using a specific reward value r , and hence COCOA does not degrade towards HCA in this case. Intuitively, different nearby states can lead to the same sampled reward, removing the spurious contributions. In the following section, we will use this insight to alleviate spurious contributions, even for deterministic reward functions.

G.3 Smoothing can alleviate excess variance by trading variance for bias

When each state has a unique reward, an unbiased COCOA estimator degrades to the high-variance HCA estimator, since U needs to be fully predictive of the reward, and hence each state needs a unique rewarding outcome encoding. Here, we propose two ways forward to overcome the excess variance of the COCOA estimator in this extreme setting that trade variance for bias.

Rewarding outcome binning. One intuitive strategy to avoid that each state has a unique rewarding outcome encoding U , is to group rewarding outcome encodings corresponding to nearby rewards together, resulting in discrete bins. As the rewarding outcome encodings now contain less details, the resulting COCOA estimator will have lower variance. However, as now the rewarding outcome encoding is not anymore fully predictive of the reward, the COCOA estimator will be biased. An intimately connected strategy is to change the reward function in the environment to a discretized reward function with several bins. Policy gradients in the new discretized environments will not be exactly equal to the policy gradients in the original environment, however for fine discretizations, we would not expect much bias. Similarly for binning the rewarding outcome encodings, when we group few nearby rewarding outcome encodings together, we expect a low bias, but also a low variance reduction. Increasing the amount of rewarding outcomes we group together we further lower the bias, at a cost of an increasing bias, hence creating a bias-variance trade-off.

Stochastic rewarding outcomes. Wecan generalize the above binning technique towards rewarding outcome encodings that bin rewards stochastically. In Section G.2, we discussed that when the reward function is probabilistic, the excessive variance problem is less pronounced, as different states can lead to the same reward. When dealing with a deterministic reward function, we can introduce stochasticity in the rewarding outcome encoding to leverage the same principle and reduce variance at the cost of increasing bias. For example, we can introduce the rewarding outcome encoding U ∼ N ( R,σ ) , with N corresponding to a Gaussian distribution. As this rewarding outcome encoding is not fully predictive of the reward, it will introduce bias. We can control this bias-variance trade-off with the variance σ : a small sigma corresponds to a sharp distribution, akin to a fine discretization in the above binning strategy, and hence a low bias. Increasing σ leads to more states that could lead to the same rewarding outcome encoding, hence lowering the variance at the cost of increasing the bias.

Implicit smoothing by noise perturbations or limited capacity networks. Interestingly, the above strategy of defining stochastic rewarding outcomes is equivalent to adjusting the training scheme of the hindsight model h ( a | s, u ′ ) by adding noise to the input u ′ . Here, we take U equal to the (deterministic) reward R , but add noise to it while training the hindsight model. Due to the noise, the hindsight model cannot perfectly decode the action a from its input, resulting in the same effects as explicitly using stochastic rewarding outcomes. Adding noise to the input of a neural network is a frequently used regularization technique. Hence, an interesting route to investigate is whether other regularization techniques on the hindsight model, such as limiting its capacity, can result in a bias-variance trade-off for HCA and COCOA.

Smoothing hindsight states for HCA. We can apply the same (stochastic) binning technique to hindsight states for HCA, creating a more coarse-grained state representation for backward credit assignment. However, the bias-variance trade-off is more difficult to control for states compared to rewards. The sensitivity of the reward function to the underlying state can be big in some regions of state-space, whereas small in others. Hence, a uniform (stochastic) binning of the state-space

will likely result in sub-optimal bias-variance trade-offs, as it will be too coarse-grained in some regions causing large bias, whereas too fine-grained in other regions causing a low variance-reduction. Binning rewards in contrast does not suffer from this issue, as binning is directly performed in a space relevant to the task.

Proposition 8 provides further insight on what the optimal smoothing or binning for HCA looks like. Consider the case where we have a discrete reward function with not too many distinct values compared to the state space, such that COCOA-reward is a low-variance gradient estimator. Proposition 8 shows that we can recombine the state-based hindsight distribution p π ( A 0 = a | S 0 = s, S ′ = s ′ ) into the reward-based hindsight distribution p π ( A 0 = a | S 0 = s, R ′ = r ′ ) , by leveraging a smoothing distribution ∑ s ′ ∈S p π ( S ′ = s ′ | S 0 = s, R ′ = r ′ ) . When we consider a specific hindsight state s ′′ , this means that we can obtain the low-variance COCOA-reward estimator, by considering all states S ′ that could have lead to the same reward r ( s ′′ ) , instead of only s ′′ . Hence, instead of using a uniform stochastic binning strategy with e.g. S ′ ∼ N ( s ′′ , σ ) , a more optimal binning strategy is to take the reward structure into account through p π ( S ′ | S 0 = s, R ′ = r ( s ′′ ))

Proposition 8.

Proof. As A 0 is d-separated from R ′ conditioned on S ′ and S 0 (c.f. Fig. 6b) we can use the implied conditional independence to prove the proposition:

G.4 Continuous action spaces

In the previous section, we discussed how continuous state spaces can lead to spurious contributions resulting high variance for the HCA estimator. Here, we briefly discuss how COCOA can be applied to continuous action spaces, and how Proposition 2 translates to this setting.

Gradient estimator. We can adjust the COCOA gradient estimator of Eq. 4 towards continuous action spaces by replacing the sum over a ′ A by an integral over the action space A ′ .

In general, computing this integral is intractable. We can approximate the integral by standard numerical integration methods, introducing a bias due to the approximation. Alternatively, we introduced in App. C.3 another variant of the COCOA gradient estimator that samples independent actions A ′ from the policy instead of summing over the whole action space. This variant can readily be applied to continuous action spaces, resulting in

where we sample M actions independently from a m ∼ π ( · | S t ) . This gradient estimator is unbiased, but introduces extra variance through the sampling of actions.

Spurious contributions. Akin to discrete action spaces, HCA in continuous action spaces can suffer from spurious contributions when distinct action sequences lead to unique states. In this case, previous actions can be perfectly decoded from the hindsight state, and we have that the probability density function p π ( A 0 = a | S 0 = s, S ′ = s ′ ) is equal to the Dirac delta function δ ( a = a 0 ) , with a 0 the action taken in the trajectory that led to s ′ . Substituting this Dirac delta function into the policy gradient estimator of Eq. 106 results in the high-variance REINFORCE estimator. When we use the COCOA estimator of Eq. 107 using action sampling, HCA will even have a higher variance compared to REINFORCE.

G.5 Partially Observable MDPs

In many environments, agents do not have access to the complete state information s , but instead get observations with incomplete information. Partially observable Markov decision processes (POMDPs) formalize this case by augmenting MDPs with an observation space O . Instead of directly observing Markov states, the agent now acquires an observation o t at each time step. The probability of observing o in state s after performing action a is given by p o ( o | s, a ) .

A popular strategy in deep RL methods to handle partial observability is learning an internal state x t that summarizes the observation history h t = { o t ′ +1 , a t ′ , r t ′ } t -1 t ′ =0 , typically by leveraging recurrent neural networks [85-88]. This internal state is then used as input to a policy or value function. This strategy is intimately connected to estimating belief states [89]. The observation history h t provides us with information on what the current underlying Markov state s t is. We can formalize this by introducing the belief state b t , which captures the sufficient statistics for the probability distribution over the Markov states s conditioned on the observation history h t . Theoretically, such belief states can be computed by doing Bayesian probability calculus using the environment transition model, reward model and observation model:

Seminal work has shown that a POMDP can be converted to an MDP, using the belief states b as new Markov states instead of the original Markov states s [90]. Now the conventional optimal control techniques can be used to solve the belief-state MDP, motivating the use of standard RL methods designed for MDPs, combined with learning an internal state x .

HCA suffers from spurious contributions in POMDPs. As the internal state x summarizes the complete observation history h , past actions can be accurately decoded based on h , causing HCA to degrade to the high-variance REINFORCE estimator (c.f. Proposition 2). Here, the tension between forming good state representations for enabling capable policies and good representations for backward credit assignment is pronounced clearly. To enable optimal decision-making, a good internal state x needs to encode which underlying Markov states the agent most likely occupies, as well as the corresponding uncertainty. To this end, the internal state needs to incorporate information about the full history. However, when using the same internal state for backward credit assignment, this leads to spurious contributions, as previous actions are encoded directly into the internal state.

To make the spurious contributions more tangible, let us consider a toy example where the state space S consists of three states x , y and z . We assume the internal state represents a belief state b = { b 1 , b 2 } , which is a sufficient statistic for the belief distribution:

We assume that b t is deterministically computed from the history h t , e.g. by an RNN. Now consider that at time step k , our belief state is b k = { 0 . 5 , 0 . 25 } and we get a reward that resulted from the Markov state x . As the belief states are deterministically computed, the distribution p π ( B ′ = b ′ | b, a ) is a Dirac delta distribution. Now consider that the action a does not influence the belief distribution over the rewarding state x , but only changes the belief distribution over the non-rewarding states (e.g. B k = { 0 . 5 , 0 . 23 } instead of B k = { 0 . 5 , 0 . 25 } when taking action a ′ instead of a ). As the Dirac delta distributions p π ( B ′ = b ′ | b, a ) for different a do not overlap, we get a high contribution coefficient for the action a 0 that was taken in the actual trajectory that led to the belief state b ′ , and a low contribution coefficient for all other actions, even though the actions did not influence the distribution over the rewarding state.

The spurious contributions originate from measuring contributions towards reaching a certain internal belief state, while ignoring that the same reward could be obtained in different belief states as well.

Adapting Proposition 8 towards these internal belief states provides further insight on the difference between HCA and COCOA-reward:

Here, we see that the contribution coefficients of COCOA-reward take into account that the same reward can be obtained while being in different internal belief states x ′ by averaging over them, while HCA only considers a single internal state.

H Learning contribution coefficients from non-rewarding observations

H.1 Latent learning

Building upon HCA [1], we learn the contribution coefficients (3) by approximating the hindsight distribution p π ( a | s, u ′ ) . The quality of this model is crucial for obtaining low-bias gradient estimates. However, its training data is scarce, as it is restricted to learn from on-policy data, and rewarding observations in case the reward or rewarding object is used as encoding U . We can make the model that approximates the hindsight distribution less dependent on the policy by providing the policy logits as input (c.f. Proposition 5). Enabling COCOA-reward or COCOA-feature to learn from non-rewarding states is a more fundamental issue, as in general, the rewarding outcome encodings corresponding to zero rewards do not share any features with those corresponding to non-zero rewards.

Empowering COCOA with latent learning is an interesting direction to make the learning of contribution coefficients more sample efficient. We refer to latent learning as learning useful representations of the environment structure without requiring task information, which we can then leverage for learning new tasks more quickly [91]. In our setting, this implies learning useful representations in the hindsight model without requiring rewarding observations, such that when new rewards are encountered, we can quickly learn the corresponding contribution coefficients, leveraging the existing representations.

H.2 Optimal rewarding outcome encodings for credit assignment.

Theorem 3 shows that the less information a rewarding outcome encoding U contains, the lower the variance of the corresponding COCOA gradient estimator (4). Latent learning on the other hand considers the sample-efficiency and corresponding bias of the learned contribution coefficients: when the hindsight model can learn useful representations with encodings U corresponding to zero rewards, it can leverage those representations to quickly learn the contribution coefficients for rewarding outcome encodings with non-zero rewards, requiring less training data to achieve a low bias.

These two requirements on the rewarding outcome encoding U are often in conflict. To obtain a low-variance gradient estimator, U should retain as little information as possible while still being predictive of the reward. To enable latent learning for sample-efficient learning of the contribution coefficients, the hindsight model needs to pick up on recurring structure in the environment, requiring keeping as much information as possible in U to uncover the structural regularities. Using the state as rewarding outcome encoding is beneficial for enabling latent learning, as it contains rich information on the environment structure, but results in spurious contributions and a resulting high variance. Using the rewards or rewarding object as rewarding outcome encoding removes spurious contributions resulting in low variance, but renders latent learning difficult.

A way out of these conflicting pressures for an optimal rewarding outcome encoding is to use rewards or rewarding objects as the optimal encoding for low variance, but extract these contribution coefficients from models that allow for sample-efficient, latent learning. One possible strategy is to learn probabilistic world models [20, 21, 88] which can be done using both non-rewarding and rewarding observations, and use those to approximate the contribution coefficients of Eq. 3. Another strategy that we will explore in more depth is to learn hindsight models based on the state as rewarding outcome encoding to enable latent learning, but then recombine those learned hindsight models to obtain contribution coefficients using the reward or rewarding object as U .

H.3 Counterfactual reasoning on rewarding states

HCA results in spurious contributions because it computes contributions towards reaching a precise rewarding state, while ignoring that the same reward could be obtained in other (nearby) states.

Proposition 9 (a generalization of Proposition 8), shows that we can reduce the spurious contributions of the state-based contribution coefficients by leveraging counterfactual reasoning on rewarding states. Here, we obtain contribution coefficients for a certain rewarding outcome encoding (e.g. the rewarding object) by considering which other states s ′ could lead to the same rewarding outcome, and averaging over the corresponding coefficients w ( s, a, s ′ ) .

Proposition 9. Assuming S ′ is fully predictive of U ′ , we have that

The proof follows the same technique as that of Proposition 8. Proposition 8) shows that it is possible to learn state-based contribution coefficients, enabling latent learning, and obtain a low-variance COCOA estimator by recombining the state-based contribution coefficients into coefficients with less spurious contributions, if we have access to the generative model p π ( S ′ = s ′ | S 0 = s, U ′ = u ′ ) . This model embodies the counterfactual reasoning on rewarding states: 'which other states s ′ are likely considering I am currently in u ′ and visited state s somewhere in the past'.

In general, learning this generative model is as difficult or more difficult than approximating the hindsight distribution p π ( a | s, u ′ ) , as it requires rewarding observations as training data. Hence, it is not possible to directly use Proposition 9 to combine latent learning with low-variance estimators. In the following section, we propose a possible way forward to circumvent this issue.

H.4 Learning credit assignment representations with an information bottleneck

Here, we outline a strategy where we learn a latent representation Z that retains useful information on the underlying states S , and crucially has a latent space structure such that p π ( Z ′ = z ′ | S = s, U ′ = u ′ ) is easy to approximate. Then, leveraging Proposition 9 (and replacing S ′ by Z ′ ) allows us to learn a hindsight representation based on Z , enabling latent learning, while reducing the spurious contributions by counterfactual reasoning with p π ( z ′ | s, u ′ ) .

To achieve this, we use the Variational Information Bottleneck approach [83, 92], closely related to the β Variational Autoencoder [93]. Fig. 13 shows the graphical model with the relations between the various variables and encoding: we learn a probabilistic encoding p ( Z | S, A ; θ ) parameterized by θ , and we assume that the latent variable Z is fully predictive of the rewarding outcome encoding U and reward R . We aim to maximize the mutual information I ( Z ′ ; S ′ , A ′ | S, U ′ ) under some information bottleneck. We condition on S and U ′ , to end up later with a decoder and prior variational model that we can combine with Proposition 9.

Following rate-distortion theory, Alemi et al. [92] consider the following tractable variational bounds on the mutual information

with entropy H , distortion D and rate defined as follows:

where the decoder q ( s ′ , a ′ | s, z ′ ; ψ ) is a variational approximation to p ( s ′ , a ′ | s, z ′ ) , and the marginal q ( z ′ | s, u ′ ; ϕ ) is a variational approximation to the true marginal p ( z ′ | s, u ′ ) . The distortion D quantifies how well we can decode the state-action pair ( s ′ , a ′ ) from the encoding

z ′ , by using a decoder q ( s ′ , a ′ | s, z ′ ; ψ ) parameterized by ψ . The distortion is reminiscent of an autoencoder loss, and hence encourages the encoding p ( z ′ | s ′ , a ′ ) to retain as much information as possible on the state-action pair ( s ′ , a ′ ) . The rate measures the average KL-divergence between the encoder and variational marginal. In information theory, this rate measures the extra number of bits (or nats) required to encode samples from Z ′ with an optimal code designed for the variational marginal q ( z ′ | s, u ′ ; ϕ ) .

We can use the rate to impose an information bottleneck on Z ′ . If we constrain the rate to Rate ≤ a with a some positive constant, we restrict the amount of information Z ′ can encode about ( S ′ , A ′ ) , as p ( z ′ | s ′ , a ′ ; θ ) needs to remain close to the marginal q ( z ′ | s, u ′ ; ϕ ) , quantified by the KL-divergence. We can maximize the mutual information I ( Z ′ ; S ′ , A ′ | S, U ′ ) under the information bottleneck by minimizing the distortion under this rate constraint. Instead of imposing a fixed constraint on the rate, we can combine the rate and distortion into an unconstrained optimization problem by leveraging the Lagrange formulation

Here, the β parameter determines the strength of the information bottleneck. This formulation is equivalent to the β Variational Autoencoder [93], and for β = 1 we recover the Variational Autoencoder [94].

To understand why this information bottleneck approach is useful to learn credit assignment representations Z , we examine the rate in more detail. We can rewrite the rate as

Hence, optimizing the information bottleneck objective (116) w.r.t. ϕ fits the variational marginal q ( z ′ | s, u ′ ; ϕ ) to the true marginal p ( z ′ | s, u ′ ) induced by the encoder p ( z ′ | s ′ , a ′ ; θ ) . Proposition 9 uses this true marginal to recombine coefficients based on Z into coefficients based on U . Hence, by optimizing the information bottleneck objective, we learn a model q ( z ′ | s, u ′ ; ϕ ) that approximates the true marginal, which we then can use to obtain contribution coefficients with less spurious contributions by leveraging Proposition 9. Furthermore, minimizing the rate w.r.t. θ shapes the latent space of Z ′ such that the true marginal p ( z ′ | s, u ′ ) moves closer towards the variational marginal q ( z ′ | s, u ′ ; ϕ ) .

In summary, the outlined information bottleneck approach for learning a credit assignment representation Z is a promising way forward to merge the powers of latent learning with a low-variance COCOA gradient estimator. The distortion and rate terms in the information bottleneck objective of Eq. 116 represent a trade-off parameterized by β . Minimizing the distortion results in a detailed encoding Z ′ with high mutual information with the state-action pair ( S ′ , A ′ ) , which can be leveraged for latent learning. Minimizing the rate shapes the latent space of Z ′ in such way that the true marginal p ( z ′ | s, u ′ ) can be accurately approximated within the variational family of q ( z ′ | s, u ′ ; ϕ ) , and fits the parameters ϕ resulting in an accurate marginal model. We can then leverage the variational marginal q ( z ′ | s, u ′ ; ϕ ) to perform counterfactual reasoning on the rewarding state encodings Z ′ according to Proposition 9, resulting in a low-variance COCOA-estimator.

I Contribution analysis and causality

I.1 Causal interpretation of COCOA

COCOA is closely connected to causality theory [42], where the contribution coefficients (3) correspond to performing Do -interventions on the causal graph to estimate their effect on future rewards. To formalize this connection with causality, we need to use a new set of tools beyond conditional probabilities, as causation is in general not the same as correlation. We start with representing the MDP combined with the policy as a directed acyclic graphical model (c.f. Fig. 6a in App. C.1). In causal reasoning, we have two different 'modes of operation'. On the one hand, we can use observational data, corresponding to 'observing' the states of the nodes in the graphical model, which is compatible with conditional probabilities measuring correlations. On the other hand, we can perform interventions on the graphical model, where we manually set a node, e.g. A t to a specific value a independent from its parents S t , and see what the influence is on the probability distributions of other nodes in the graph, e.g. R t +1 . These interventions are formalized with do-calculus [42],

where we denote an intervention of putting a node V i equal to v as Do( V i = v ) , and can be used to investigate causal relations.

Using the graphical model of Fig. 6b that abstracts time, we can use do-interventions to quantify the causal contribution of an action A t = a taken in state S t = s upon reaching the rewarding outcome U ′ = u ′ in the future as,

As conditioning on S satisfies the backdoor criterion [42] for U ′ w.r.t. A , the interventional distribution p π ( U ′ = u ′ | S t = s, Do( A t = a ) ) is equal to the observational distribution p π ( U ′ = u ′ | S t = s, A t = a ) . Hence, the causal contribution coefficients of Eq. 119 are equal to the contribution coefficients of Eq. 3 used by COCOA.

I.2 Extending COCOA to counterfactual interventions

Within causality theory, counterfactual reasoning goes one step further than causal reasoning, by incorporating the hindsight knowledge of the external state of the world in its reasoning. Applied to COCOA, this more advanced counterfactual reasoning would evaluate the query: 'How does taking action a influence the probability of reaching a rewarding outcome, compared to taking alternative actions a ′ , given everything else remains the same '. To formalize the difference between causal and counterfactual reasoning, we need to convert the causal DAG of Figure 6a into a structural causal model (SCM), as shown in Figure 14. The SCM expresses all conditional distributions as deterministic functions with independent noise variables N , akin to the reparameterization trick [94]. In causal reasoning, we perform do-interventions on nodes, which is equivalent to cutting all incoming edges to a node. To compute the resulting probabilities, we still use the prior distribution over the noise variables N . Counterfactual reasoning goes one step further. First, it infers the posterior probability p π ( { N } | T = τ ) , with { N } the set of all noise variables, given the observed trajectory τ . Then it performs a Do-intervention as in causal reasoning. However now, to compute the resulting probabilities on the nodes, it uses the posterior noise distribution combined with the modified graph.

One possible strategy to estimate contributions using the above counterfactual reasoning is to explicitly estimate the posterior noise distribution and combine it with forward dynamics models to obtain the counterfactual probability of reaching specific rewarding outcomes. Leveraging the work of Buesing et al. [43] is a promising starting point for this direction of future work. Alternatively, we can avoid explicitly modeling the posterior noise distribution, by leveraging the hindsight distribution combined with the work of Mesnard et al. [3]. Here, we aim to learn a parameterized approximation h to the counterfactual hindsight distribution p π τ ( A t = a | S t = s, U ′ = u ′ ) , where the τ -subscript indicates the counterfactual distribution incorporating the noise posterior. Building upon the approach of Mesnard et al. [3], we can learn h ( a | s ′ , s, Φ t ( τ )) to approximate the counterfactual hindsight distribution, with Φ t ( τ ) a summary statistic trained to encapsulate the information of the posterior noise distribution p ( { N } | T = τ ) . Mesnard et al. [3] show that such a summary statistic Φ t ( τ ) can be used to amortize the posterior noise estimation if it satisfies the following two conditions: (i) it needs to provide useful information for predicting the counterfactual hindsight distribution and (ii) it needs to be independent from the action A t . We can achieve both characteristics by (i) training h ( a | s ′ , s, Φ t ( τ )) on the hindsight action classification task and backpropagating the gradients to Φ t ( τ ) , and (ii) training Φ t on an independence maximization loss L IM ( s ) , which is minimized iff

A t and Φ t are conditionally independent given S t . An example is to minimize the KL divergence between π ( a t | s t ) and p ( a t | s t , Φ t ( τ )) where the latter can be approximated by training a classifier q ( a t | s t , Φ t ( τ )) . Leveraging this approach to extend COCOA towards counterfactual interventions is an exciting direction for future research.

J Contribution analysis with temporal discounting

As discussed in App. B, we can implicitly incorporate discounting into the COCOA framework by adjusting the transition probabilities to have a fixed probability of (1 -γ ) of transitioning to the absorbing state s ∞ at each time step.

We can also readily incorporate explicit time discounting into the COCOA framework, which we discuss here. We consider now a discounted MDP defined as the tuple ( S , A , p, p r , γ ) , with discount factor γ ∈ [0 , 1] , and ( S , A , p, p r ) as defined in Section 2. The discounted value function V π γ ( s ) = E T ∼T ( s,π ) [ ∑ ∞ t =0 γ t R t ] and action value function Q π γ ( s, a ) = E T ∼T ( s,a,π ) [ ∑ ∞ t =0 γ t R t ] are the expected discounted return when starting from state s , or state s and action a respectively. Table 6 shows the policy gradient estimators of V π γ ( s ) for REINFORCE, Advantage and Q-critic.

In a discounted MDP, it matters at which point in time we reach a rewarding outcome u , as the corresponding rewards are discounted. Hence, we adjust the contribution coefficients to

Here, we define the discounted hindsight distribution p π γ ( A t = a | S t = s, U ′ = u ′ ) similarly to the undiscounted hindsight distribution explained in App. C.1, but now using a different probability distribution on the time steps k : p β ( K = k ) = (1 -β ) β k -1 , where we take β = γ . We can readily extend Theorems 1-4 to the explicit discounted setting, by taking β = γ instead of the limit of β → 1 , and using the discounted COCOA policy gradient estimator shown in Table 6.

To approximate the discounted hindsight distribution p π γ ( A t = a | S t = s, U ′ = u ′ ) , we need to incorporate the temporal discounting into the classification cross-entropy loss:

with CE the cross-entropy loss, h γ ( · | S t , U t + k ) the classification model that approximates the discounted hindsight distribution, and δ ( a = A t ) a one-hot encoding of A t .

K Bootstrapping with COCOA

Here, we show how COCOA can be combined with n-step returns, and we make a correction to Theorem 7 of Harutyunyan et al. [1] which considers n-step returns for HCA.

Consider the graphical model of Fig. 15a where we model time, K , as a separate node in the graphical model (c.f. App. C.1). To model n -step returns, we now define the following prior probability on K ,

(a)

(b)

parameterized by β :

Using p π n,β as the probability distribution induced by this graphical model, we have that

We introduce the following contribution coefficients that we will use for n-step returns

Now we are ready to prove the n-step return theorem for the discounted MDP setting. We can recover the undiscounted setting by taking the limit of γ → 1 -.

Theorem 10. Consider state s and action a for which it holds that π ( a | s ) > 0 and take β equal to the discount factor γ ∈ [0 , 1] . Furthermore, assume that the rewarding outcome encoding u = f ( s, a, r ) is fully predictive of the reward (c.f. Definition 2). Then the advantage A π ( s, a ) = Q π ( s, a ) -V π ( s ) is equal to

with r ( s, a ) the reward model and r π ( s ) = ∑ π ( a | s ) r ( s, a )

Proof. We start with the action-value function Q π , and will subtract the value V π to obtain the result on the advantage function.

(141)

where we use that U ′ is fully predictive of the reward R ′ , and define r ( u ′ ) = ∑ r ′ ∈R p ( R ′ = r ′ | U ′ = u ′ ) r ′ By subtracting the value function, we get

Finally, we can sample from this advantage function to obtain an n-step COCOA gradient estimator, akin to Theorem 1.

Note that we require to learn the state-based contribution coefficients w n ( s, a, s ′ ) to bootstrap the value function into the n-step return, as the value function requires a Markov state s ′ as input instead of a rewarding outcome encoding u ′ . Unfortunately, these state-based contribution coefficients will suffer from spurious contributions, akin to HCA, introducing a significant amount of variance into the n-step COCOA gradient estimator. We leave it to future research to investigate whether we can incorporate value functions into an n-step return, while using rewarding-outcome contribution coefficients w ( s, a, u ′ ) instead of state-based contribution coefficients w n ( s, a, s ′ ) .

̸

Learning the contribution coefficients. We can learn the contribution coefficients w β,n ( s, a, u ′ ) with the same strategies as described in Section 3, but now with training data from n -step trajectories instead of complete trajectories. If we use a discount γ = 1 , we need to take this discount factor into account in the training distribution or loss function (c.f. App. J).

Correction to Theorem 7 of Harutyunyan et al. [1]. Harutyunyan et al. [1] propose a theorem similar to Theorem 10, with two important differences. The first one concerns the distribution on K in the graphical model of Fig. 15a. Harutyunyan et al. [1] implicitly use this graphical model, but with a different prior probability distribution on K :

The graphical model combined with the distribution on K defines the hindsight distribution p π n,β,HCA ( A = a | S = s, S ′ = s ′ ) . The second difference is the specific Q -value estimator Harutyunyan et al. [1] propose. They use the hindsight distribution p π n,β,HCA ( A = a | S = s, S ′ = s ′ ) in front of the value function (c.f. Theorem 10), which considers that s ′ can be reached at any time step k ∼ p HCA n,β ( k ) , whereas Theorem 10 uses w n ( s, a, s ′ ) which considers that s ′ is reached exactly at time step k = n .

To the best of our knowledge, there is an error in the proposed proof of Theorem 7 by Harutyunyan et al. [1] for which we could not find a simple fix. For the interested reader, we briefly explain the error. One indication of the problem is that for β → 1 , all the probability mass of p HCA n,β ( K = k ) is concentrated at k = n , hence the corresponding hindsight distribution p π n,β,HCA ( A = a | S = s, S ′ = s ′ ) considers only hindsight states s ′ encountered at time k = n . While this is not a mathematical error, it does not correspond to the intuition of a 'time independent hindsight distribution' the authors provide. In the proof itself, a conditional independence relation is assumed that does not hold. The authors introduce a helper variable Z defined on the state space S , with a conditional distribution

with the normalized discounted visit distribution ˜ d π ( z | s ′ ) = (1 -γ ) ∑ k γ k p π ( S k = z | S 0 = s ) . We can model this setting as the graphical model visualized in Fig. 15b. In the proof (last line on page 15 in the supplementary materials of Harutyunyan et al. [1]), the following conditional independence is used:

However, Fig. 15b shows that S ′ is a collider on the path A 0 → S ′ ← K → Z . Hence, by conditioning on S ′ we open this collider path, making A 0 dependent on Z conditioned on S 0 and S ′ , thereby invalidating the assumed conditional independence. For example, if Z is different from S ′ , we know that K = n (c.f. Eq. 146), hence Z can contain information about action A 0 , beyond S ′ , as S ′ ignores at which point in time s ′ is encountered.

L HCA-return is a biased estimator in many relevant environments

L.1 HCA-return

Besides HCA-state, Harutyunyan et al. [1] introduced HCA-return, a policy gradient estimator that leverages the hindsight distribution conditioned on the return:

When comparing this estimator with COCOA-reward, we see two important differences: (i) HCAreturn uses a hindsight function conditioned on the return instead of individual rewards, and (ii) HCA-return leverages the hindsight function as an action-dependent baseline for a Monte Carlo policy gradient estimate, instead of using it for contribution coefficients to evaluate counterfactual actions. Importantly, the latter difference causes the HCA-return estimator to be biased in many environments of relevance, even when using the ground-truth hindsight distribution.

L.2 HCA-return can be biased

An important drawback of HCA-return is that it can be biased, even when using the ground-truth hindsight distribution. Theorem 2 of Harutyunyan et al. 2019, considering the unbiasedness HCAreturn, is valid under the assumption that for any possible random return Z for all possible trajectories

starting from state s , it holds that p π ( a | s, z ) > 0 . This restrictive assumption requires that for each observed state-action pair ( s t , a t ) along a trajectory, all counterfactual returns Z resulting from a counterfactual trajectory starting from s t (not including a t ) result in p π ( a t | s t , Z ) > 0 . This implies that all returns (or rewarding states) reachable from s t should also be reachable from ( s t , a t ) .

Consider the following bandit setting as a simple example where the above assumption is not satisfied. The bandit has two arms, with a reward of 1 and -2 , and a policy probability of 2 3 and 1 3 respectively. The advantage for both arms is 1 and -2 . Applying eq. 6 from Harutyunyan et al. results in A π ( s, a 1 ) = (1 -2 3 ) = 1 3 and A π ( s, a 2 ) = -2(1 -1 / 3) = -4 / 3 . This shows that the needed assumptions for an unbiased HCA-return estimator can be violated even in simple bandit settings.

M Additional details

M.1 Author contributions

This paper was a collaborative effort of all shared first authors working closely together. To do this fact better justice we give an idea of individual contributions in the following.

Alexander Meulemans ∗ . Original idea, conceptualizing the theory and proving the theorems, conceptual development of the algorithms, experiment design, implementation of main method and environments, debugging, neural network architecture design, running experiments, connecting the project to existing literature, writing of manuscript, first draft and supplementary materials, feedback to the figures.

Simon Schug ∗ . Conceptual development of the algorithms, experiment design, implementation of main method, baselines and environments, neural network architecture design, debugging, tuning and running experiments, writing of manuscript, creation of figures, writing of supplementary materials.

Seijin Kobayashi ∗ . Conceptual development of the algorithms, experiment design, implementation of environments, baselines, main method and Dynamic Programming-based ground-truth methods, debugging, tuning and running experiments, feedback to the manuscript, writing of supplementary materials.

Nathaniel Daw . Regular project meetings, conceptual input and feedback for method and experimental design, connecting the project to existing literature, feedback to the manuscript and figures.

Gregory Wayne . Senior project supervision, conceptualising of the project idea, conceptual development of the algorithms, regular project meetings, technical and conceptual feedback for method and experimental design, connecting the project to existing literature, feedback to the manuscript and figures.

M.2 Compute resources

We used Linux workstations with Nvidia RTX 2080 and Nvidia RTX 3090 GPUs for development and conducted hyperparameter searches and experiments using 5 TPUv2-8, 5 TPUv3-8 and 1 Linux server with 8 Nvidia RTX 3090 GPUs over the course of 9 months. All of the final experiments presented take less than a few hours to complete using a single Nvidia RTX 3090 GPU. In total, we spent an estimated amount of 2 GPU months.

M.3 Software and libraries

For the results produced in this paper we relied on free and open-source software. We implemented our experiments in Python using JAX [95, Apache License 2.0] and the Deepmind Jax Ecosystem [82, Apache License 2.0]. For experiment tracking we used wandb [96, MIT license] and for the generation of plots we used plotly [97, MIT license].

Peer reviews:
{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper lays out a goal of addressing a weakness in HCA that HCA can confuse the contributions of actions to reaching a state, increasing the variance of gradient estimation. Instead, the COCOA method proposed in this paper generalizes HCA to use any feature that is predictive of rewards, such as the reward or reward-predicting features. Thus, it allows for selecting an appropriate rewarding outcome to disentangle the contributions of each action from the observed rewards. The paper derives a new unbiased gradient estimator (given the exact hindsight model). Experiments are then conducted to show that when these models are known, they can reduce variance in cases not handled by standard control variates.\n\nSTRENGTHS:\nThe biggest strength of this paper is thorough experimentation to illustrate when COCOA reduces variance when the hindsight models are known. \n\nThe experiments and environment clearly show the COCOA method's impact in the cases: when distractor rewards are encountered during the episode and when the distractor rewards are of the same magnitude as the main reward. These experiments show clear evidence that selecting the appropriate disentangling factor is essential to reducing variance. \n\nThe experiments to show the SNR as a function of credit assignment distance highlights how each gradient estimator degrades as the episode length and distance between action and rewarding stimulus increases. However, this should be evaluated at longer distances as the slopes and shapes of the curves are difficult to observe in this range.\n\nWEAKNESSES:\nThe biggest weakness of this paper is that there is no investigation into how accurate the estimates of hindsight models need to be to reduce variance. Past variance reduction techniques for policy gradients have proven useless in practice (Tucker et al. 2018). So it is crucial to understand the practical limitations when developing a new method. \n\n\nThe comparison to q critic, when q is known, is odd. Because if q is known, then the natural gradient will be known (Kakade, 2001). It should be made precise what sources of variance these experiments are measuring. \n\nThe bias can be much higher for COCOA methods than other methods (Figure 3 (D)), and it needs to be clearly discussed since this method is supposed to be unbiased. \n \nA more relevant baseline instead of the Advantage method would be the doubly robust control variate for policy gradient methods (Huang and Jiang, 2020). This has a significant variance reduction compared to standard baselines in policy gradient. The comparison would also better highlight the limits of information between the two approaches. \n\nThe success/failure of an algorithm depends greatly on hyperparameter choices. It needs to be clear how each method's hyperparameters were chosen. Since this paper is trying to argue that COCOA has better sample efficiency, it should be made clear in what exact context this claim is being made. Furthermore, if one wants to say that COCOA has better information utilization through measuring performance, then the hyperparameters for the baseline methods need to be tuned to their absolute maximum. As the paper currently stands, the experiment design is insufficient to make this argument, even if it is likely true. \n\nThough not poor, the writing in the paper has room for improvement. One of the best ways for this paper to have a bigger impact is to make it written so that most RL people can easily understand the lessons. So I recommend that the authors spend time revising the writing for a future or camera-ready version of the paper. \n\n___minor comments__\nwhat are the decibel units? This is nonstandard in ML, so it is worth specifying. \n\nTable1: In the Advantage method, $v^\\pi$ should just be $v$ because the baseline can be any state-dependent function\n\nAlthough common in the ML community $\\nabla_\\theta$ is a mathematical symbol for a directional derivative. However, it is used in this work as a partial derivative. Further, since the gradient is a function that takes a derivative with respect to all inputs and partial derivates are the quantities of interest, it makes mathematical sense to use mathematical symbols for partial differentiation, not gradients. \n\nLine 100: \"it has a failure mode of practical importance\" —say what this is. \n\nSection 3.1 Define reward outcomes first. It is unclear what they mean, making it hard to interpret. It also needs to be made clear when or why one would use different choices of f. Giving a few motivating examples would help here. \n\nLine 133: Eq 1. Check the JMLR guidelines for standard practice for referencing equations. It should be just (1) not Eq, and equation blocks should only be numbered if they are referenced. \n\nLine 146: missing for all k?\n\nDefinition 1. Remark on definition 1 to clarify what is needed to satisfy this property in practice. \n\nTheorem 1: It is important to remark that the gradient estimator is unbiased only if the counterfactual term is known precisely, which is unlikely in practice. This would be like saying the DDPG is unbiased, which is misleading because it is only true if Q is known. \n\nTheorem 4. \"equals\" should be changed because the expression is not a statement of equality but proportionality. \n\nLine 246: \"SNR indicates… fewer trajectories…\" This is not universally true. It can require an exponential number of trajectories to get a gradient estimate, and lower variance estimates will not help this. \n\n\n\nREFERENCES\nHuang, Jiawei, and Nan Jiang. \"From importance sampling to doubly robust policy gradient.\" International Conference on Machine Learning. PMLR, 2020.\n\nKakade, Sham M. \"A natural policy gradient.\" Advances in neural information processing systems 14 (2001).\n\nTucker, George, et al. \"The mirage of action-dependent baselines in reinforcement learning.\" International conference on machine learning. PMLR, 2018.\n\nQUESTIONS:\nFrom Theorem 3 it wasn't clear if one should expect the same trend to hold in other cases. Would we expect the same ordering of variances in more settings?\n\nLIMITATIONS:\nThe authors do mention that further work is needed on developing methods to learn the hindsight models so they do acknowledge this limitation. But a pilot study on the same environment is really warranted in this work.", "TITLE": "Official Review", "RECOMMENDATION": 7, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-06-23"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper proposes Counterfactual Contribution Analysis (COCOA), an RL credit assignment approach inspired by the Hindsight Credit Assignment (HCA) family of algorithms. \n\nThe paper notes that in some instances, the previously proposed State-HCA approach can degrade to as high a variance as REINFORCE due to using the future state for obtaining hindsight weights. \n\nInstead of estimating hindsight contributions of actions based on future states (as in State-HCA), this paper introduces the idea of a rewarding outcome which is a function of a future state, action, and reward (s’, a’, r’) tuple. The paper proposes two choices for the rewarding outcome– the reward itself or the reward predictive features of the state-action pair (COCOA-reward and COCOA-feature). The paper provides intuitions on how the COCOA approaches should lead to lower-variance policy gradients compared to State-HCA due to reduced encoding of state information. \n\nExperiments in a key-to-door environment shows that the COCOA approaches perform much better than State-HCA, REINFORCE (with and without baseline), and all-actions policy gradient on Q-values.\n\nSTRENGTHS:\n**S1.** Hindsight-based approaches are a promising solution to the credit assignment problem in RL, which is of great interest to the research community. \n\n**S2.** While identifying the high-variance failure case of State-HCA may not be a novel contribution (see W2), the proposed solution to use rewards or reward predictive features instead of states is novel. The solution idea is simple, well-motivated with examples (e.g., Figure 2 and text below proposition 2), and fits the HCA family of approaches well. Focusing on features that can be useful for HCA is an interesting direction and opens a way to improve previous HCA approaches.\n\n**S3.** The paper is well-written and easy to follow.\n\nWEAKNESSES:\n**W1.** The paper's claims would be more accurate with the clarification that HCA refers to the State-HCA algorithm from the HCA paper. The claim that this approach generalizes HCA (e.g., line 103) is inaccurate. HCA generally proposes any function of the future trajectory to estimate contributions, and future states are simply one instance in the proposed family.\n\n**W2.** The observation that State-HCA-based approaches can suffer from high-variance or spurious contributions (even in comparison to Monte-Carlo approaches) is not a novel finding, as it has also been noted in previous work [1,2]. Could the authors clarify the similarities and differences to the observation made in the papers above? \n\n**W3.** A crucial weakness is that it is hard to judge the applicability of the proposed approach based on evaluation in a single environment (linear key-to-door). While linear key-to-door is a challenging problem from the perspective of credit assignment, an evaluation in Atari games (along the lines of Deep HCA [3]) could be more informative in guiding intuitions of how this approach scales to complex settings.\n\n**W4.** The paper also needs to include evaluation against other hindsight baselines, for instance, return-conditioned HCA, which was concretely proposed in the HCA paper. An even more interesting comparison would be to Counterfactual Credit Assignment [4], which learns features for hindsight contribution. \n\n\nOverall, I appreciate the direction the authors took to address the limitation of State-HCA. Should these weaknesses be adequately clarified/addressed, I would happily increase my score.\n\n\n—------------------—------------------—------------------—------------------—------------------\n\n### References\n\n[1] Young, K. (2019). Variance Reduced Advantage Estimation with $\\delta$ Hindsight Credit Assignment. arXiv preprint arXiv:1911.08362.\n\n[2] Zhang, P., Zhao, L., Liu, G., Bian, J., Huang, M., Qin, T., & Liu, T. Y. (2019). Independence-aware advantage estimation.\n\n[3] Alipov, V., Simmons-Edler, R., Putintsev, N., Kalinin, P., & Vetrov, D. (2021). Towards practical credit assignment for deep reinforcement learning. arXiv preprint arXiv:2106.04499.\n\n[4] Mesnard, T., Weber, T., Viola, F., Thakoor, S., Saade, A., Harutyunyan, A., ... & Munos, R. (2020). Counterfactual credit assignment in model-free reinforcement learning. arXiv preprint arXiv:2011.09464.\n\nQUESTIONS:\n- In Figure 4, why does the COCOA policy not always collect the treasure before the reward switch? Is it due to an exploratory policy? Furthermore, why does the REINFORCE with baseline (Advantage) get much closer to always collecting the treasure in that period?\n\nLIMITATIONS:\nNegative societal impact is not directly applicable. Limitations adequately discussed in the Discussion section.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 2, "DATE": "2023-07-09"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThis paper introduces COCOA, a new family of hindsight credit assignment methods that build on HCA, which uses hindsight importance weights for the policy gradient estimator to reduce its variance. HCA uses state-conditioned importance weights, i.e., the ratio of $p(a_t|s_t, s_{t+k})$ to $\\pi(a_t|s_t)$. COCOA generalizes HCA by replacing $s_{t+k}$ with $u_{t+k} = f(s_{t+k}, a_{t+k}, r_{t+k})$ with a general function $f$. Specifically, the authors suggest using either $f(s, a, r) = r$ or $f(s, a, r) = g(s, a)$ where $g(s, a)$ is a function that can fully determine the reward. These variants lead to a lower variance compared to vanilla HCA by conditioning only on information that is related to the reward function. They evaluate COCOA on synthetic domains, showing that COCOA outperforms HCA with improved credit assignment.\n\nSTRENGTHS:\n- The authors generalize HCA in an important direction, and the theoretical benefits of COCOA are significant and clear.\n- The paper contains informative discussions about various aspects of hindsight gradient estimators, which provides further insights into hindsight credit assignment in general.\n- The paper is well-written and easy to follow.\n\nWEAKNESSES:\n- The paper lacks discussion regarding return-conditioned HCA. While the authors argue that (state-conditioned) HCA suffers from high variance, the original HCA paper also proposes a return-conditioned variant (Sec 3.2 and Theorem 5 in Appendix B), which can enjoy similar benefits to COCOA. Also, when referring to HCA, the authors only mention its state-conditioned variant throughout the paper. Discussing and comparing with the return-conditioned variant of HCA would be more relevant given its similarity to COCOA-reward.\n- The novelty of the method is a bit limited, as the original HCA paper also proposes a general version of HCA that is conditioned on any function of the future trajectory (Sec 3 in the HCA paper). Nonetheless, the paper further discusses sufficient conditions of this function to make the policy gradient estimator unbiased.\n- The experiments are conducted only on toy, synthetic environments. It is questionable how COCOA works in more realistic domains.\n\nQUESTIONS:\n- How is COCOA-reward different from HCA-return?\n- Given that COCOA-reward shows the lowest variance (Theorem 3), when is COCOA-feature preferred to COCOA-reward?\n- Is COCOA-reward always *optimal* in terms of variance, meaning that there are no importance sampling-based gradient estimators with lower variance?\n- What would happen if the reward function is a constant function (e.g., $r(s, a) = 1$) but there are terminal signals? Can COCOA-reward directly handle this MDP (without transforming the MDP -- e.g., by creating an additional absorbing state with a zero reward)?\n\nLIMITATIONS:\nThe authors adequately address the limitations of COCOA in Section 5.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2023-07-12"}

comments: SUMMARY:
The paper presents a policy gradient estimator using credit assignment measure on influence of specific actions toward future rewards. The paper offers theoretical analysis on resulting algorithm such as (1) policy gradient estimator is unbiased, (2) variance of the estimator in relation to some existing methods, and so on. The authors also include numerical studies using a simple but specifically designed example to highlight the benefits of the proposed algorithm.

STRENGTHS:
1. With some assumptions, the paper provides analytical guarantees on a range of desirable aspects of the algorithm.

WEAKNESSES:
1. Given HCA, contribution seems marginal. 
2. Claims are either straightforward or require strong assumptions (quarantees in extreme cases such as Prop 2, Theorem 3)
3. Experiments too simple

QUESTIONS:
1. Rare but possible that reward-based approach may result in larger variance (e.g., S=(1,2) but r(s,a) \in {-100, 0, 100)).
2. Why did you use only state-conditional HCA? (i.e., not using return-conditional HCA)? 
3. In the last paragraph on p.5, it is argued that less informative encodings lead to lower variance. While this is intuitively true, less information also means less learning, which suggests that there should be a trade-off between lower variance and information loss in learning. How would you achieve a good balance?

LIMITATIONS:
None
TITLE: Official Review
SOUNDNESS_CORRECTNESS: 4
DATE: 2023-07-20

comments: SUMMARY:
The paper introduces a novel credit assignment algorithm for reinforcement learning known as COCOA (Counterfactual Contribution Analysis). The proposed method extends the concept of Hindsight Credit Assignment (HCA) and aims at making the learning process more sample efficient. By leveraging counterfactual reasoning, COCOA measures the contribution of actions upon obtaining subsequent reward, thereby achieving improved credit assignment. The paper provides an extensive theoretical analysis of COCOA while addressing its potential advantages and limitations.

STRENGTHS:
- The proposal of a novel approach to credit assignment in RL.
- Comprehensive theoretical derivations and analysis that support the argument.
- Improvement in policy gradient estimators and progression in long-term credit assignment by distinguishing rewarding outcomes.

WEAKNESSES:
- The absence of empirical comparisons with related methods, particularly RUDDER which is cited in the paper.
- Unclear scalability of the proposed method in more complex environments and restricted quality of the inverse dynamics model.
- Limited empirical evaluation and ablation studies, i.e. examining the influence of the dynamics model on performance.

QUESTIONS:
- How does COCOA compare to similar SOTA credit assignment methods?
- What is the expected influence of imperfect modelling on the performance of COCOA?
- When employing COCOA, what are best practices for modelling action contributions for ‘rewarding outcomes’ and how does this impact the learning process?

LIMITATIONS:
- Uncertain scalability to intricate environments.
- Examination on how the choice of the dynamics model impacts COCOA's performance (arguably this is kept open in the discussion section).
TITLE: Official Review
SOUNDNESS_CORRECTNESS: 3
DATE: 2023-07-25

comments: SUMMARY:
This paper proposes Counterfactual Contribution Analysis (COCOA) to improve credit assignment in the reinforcement learning problem by building upon Hindsight Credit Assignment.

STRENGTHS:
This paper is written in a clear manner and allows non-expert audiences to understand its difference and contribution in contrast to previous work.

WEAKNESSES:
I do not feel that I understand enough about this field to critique this paper.

QUESTIONS:
A space is missing between policy and [15-17] on line 41.

LIMITATIONS:
Seems okay to me.
TITLE: Official Review
SOUNDNESS_CORRECTNESS: 3
DATE: 2023-07-26

comments: SUMMARY:
This paper presents family of algorithms namely Counterfactual Contribution Analysis (COCOA), which is based on measuring contribution of an action by asking counterfactual question. The new measure of contribution performs better than existing methods such as HCA in terms of lower variance. They define rewarding outcome as function of state, action and reward. They compute contribution coefficients which can be used to learn a policy with COCOA policy gradient estimator.

STRENGTHS:
1. The authors show that the presented COCOA policy gradient estimator can result in lower variance than existing method such as HCA, which suffers from spurious contributions which can be alleviated by using less informative encodings.
2. The authors demonstrate demonstrate the performance of COCOA compared to standard baselines in key-to-door environment. They further present improvement in sample efficiency due to favorable bias-variance trade off
3. The way COCOA is learning the correct distanglement enables long-term credit assignment better than existing methods.

WEAKNESSES:
Compared to policy gradient methods like REINFORCE and Advantage, the COCOA estimators seem to be very computationally expensive.

QUESTIONS:
1. Could you please highlight how expensive it is to compute these contribution coefficients.
2. Policy gradient methods have shown great performance in continuous state and continuous action MDPs. How can the coefficients be computed in such a setting? Or the proposed method is limited to tabular setting?
3. In many real world applications, we only have sparse rewards, how does the performance of these estimators vary between dense and sparse reward scenarios?

LIMITATIONS:
-
TITLE: Official Review
SOUNDNESS_CORRECTNESS: 3
DATE: 2023-08-02