SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2306.16803 · NeurIPS · 2023

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

Gregory Wayne, Alexander Meulemans, Nathaniel Daw, Seijin Kobayashi, Simon Schug

arXiv · PDF · Open in the Atlas

Code that ran

2 of 4 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 0 failures of our instrument; 2 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2306.16803.json · badge: /api/ran/2306.16803.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
seijin-kobayashi/cocoa community
Papers with Code archive
2 ran · 2 no recorded run
FunctionStatusWhere it lives
CoefficientBaseState Ran
ran on a synthesized input · constructed an object; no result was computed
seijin-kobayashi/cocoa/ccoa/contribution/modules/contribution_coefficient.py
code served (permissive licence) · get_code("dea9cc45782d671b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, CoefficientBaseState: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import haiku as hk
import optax
from flax import struct
import jax
import jax.numpy as jnp

# Define a simple Haiku function to generate params
def dummy_model(x):
    return hk.Linear(4)(x)

# Initialize params
key = jax.random.PRNGKey(0)
dummy_input = jnp.ones((2, 3))
init_fn = hk.transform(dummy_model)
params = init_fn.init(key, dummy_input)

# Create an optimizer state
optimizer = optax.adam(learning_rate=0.001)
optim_state = optimizer.init(params)

ARGS = {
    "params": params,
    "optim": optim_state,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, haiku, jax, optax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type CoefficientBaseState — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a CoefficientBaseState output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
ContrastiveCoefficient Ran
ran on a synthesized input · constructed an object; no result was computed
seijin-kobayashi/cocoa/ccoa/contribution/modules/contribution_coefficient.py
code served (permissive licence) · get_code("001c97916629271f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, ContrastiveCoefficient: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import jax
import jax.numpy as jnp
import haiku as hk
import optax

# Create a simple model function that takes observations, hindsight_objects, and logits
def model_fn(observations, hindsight_objects, logits):
    """Simple model that processes observations and returns predictions"""
    # observations shape: (batch, time, obs_dim)
    # hindsight_objects shape: (batch, time, time, hindsight_dim)
    # logits shape: (batch, time, action_dim)
    
    x = observations
    x = hk.Linear(4)(x)
    x = jax.nn.relu(x)
    x = hk.Linear(1)(x)
    return x

# Create a simple optimizer
optimizer = optax.adam(learning_rate=1e-3)

# Set up random key
rng_key = jax.random.PRNGKey(0)

# Create dummy inputs for initialization
batch_size = 2
time_steps = 3
obs_dim = 4
hindsight_dim = 5
action_dim = 6

dummy_observation = jnp.ones((time_steps, obs_dim))
dummy_hindsight_object = jnp.ones((time_steps, time_steps, hindsight_dim))
dummy_logits = jnp.ones((time_steps, action_dim))

# Arguments for ContrastiveCoefficient constructor
ARGS = {
    'model': model_fn,
    'optimizer': optimizer,
    'steps': 2,
    'mask_zero_reward_loss': True,
    'max_grad_norm': 1.0,
    'clip_contrastive': 0.5,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, haiku, jax, optax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ContrastiveCoefficient — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ContrastiveCoefficient output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
CoefficientBase Not yet run
unverified (harvested, no recorded run)
seijin-kobayashi/cocoa/ccoa/contribution/modules/contribution_coefficient.py
code served (permissive licence) · get_code("4b4ac3bce0d958c0")
How it ran

no invocation recorded.

ContributionCoefficientModule Not yet run
unverified (harvested, no recorded run)
seijin-kobayashi/cocoa/ccoa/contribution/modules/contribution_coefficient.py
code served (permissive licence) · get_code("b0995b91a26d0b7b")
How it ran

no invocation recorded.

Also present in other papers' code

Of 4 samples lifted from this paper's linked repositories, 4 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 4 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

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 * Equal contribution; ordering determined by coin flip. 2 Code available at https://github.com/seijin-kobayashi/cocoa 37th Conference on Neural Information Processing Systems (NeurIPS 2023).

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2306.16803")
get_code_for_paper("2306.16803")
have("2306.16803")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2306.16803.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2306.16803.svg)](https://syntology.ai/paper/2306.16803)

Connect an agent — have() is free.