SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2212.03932 · 2022

Low Variance Off-policy Evaluation with State-based Importance Sampling

arXiv · PDF · Open in the Atlas

Code that ran

4 of 7 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 0 failures of our instrument; 3 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; 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/2212.03932.json · badge: /api/ran/2212.03932.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
bossdm/importancesampling canonical (classifier label)
classifier basis not recorded on the link
4 ran · 3 no recorded run
FunctionStatusWhere it lives
INCRIS Ran
ran on a synthesized input
bossdm/importancesampling/importance_sampling/INCRIS.py
code served (permissive licence) · get_code("4e57bb6562992e41")
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 tuple. 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 numpy as np

# Create minimal trajectories
# Each trajectory is a list of tuples (s, a, r, ro) or (s, a, r) depending on context
# s = state, a = action, r = reward, ro = importance ratio

# Trajectories with importance ratios (when p_e and p_b are None)
trajectory_1 = [
    (0, 0, 1.0, 1.2),
    (1, 1, 0.5, 0.9),
    (2, 0, 1.5, 1.1),
    (1, 1, 2.0, 0.8),
]

trajectory_2 = [
    (0, 1, 0.8, 1.0),
    (2, 0, 1.2, 1.3),
    (1, 0, 0.6, 0.95),
    (0, 1, 1.8, 1.05),
]

trajectories = [trajectory_1, trajectory_2]

# Policy dictionaries: p_e[state][action] = probability, p_b[state][action] = probability
# For simplicity, we'll use None so the function uses the ro values from trajectories
p_e = None
p_b = None

# Horizon parameter
H = 5

# Maximum lookback window
max_t = 3

# Weighted flag
weighted = False

# Negligible states (states that should contribute to A instead of B)
negligible_states = [2]

ARGS = {
    "trajectories": trajectories,
    "p_e": p_e,
    "p_b": p_b,
    "H": H,
    "max_t": max_t,
    "weighted": weighted,
    "negligible_states": negligible_states,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
convert_trajectories Ran
ran on a synthesized input
bossdm/importancesampling/IM_domain.py
code served (permissive licence) · get_code("f7e6d65af241b4a6")
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 list. 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 torch
import numpy as np

torch.manual_seed(0)

# The function iterates over trajectories, where each trajectory is an iterable of tuples.
# Each tuple contains 9 elements: (s, a, r, c, s_next, grad, actionProbs, grad_adv, probs_adv)
# The function extracts s[0] (first element of s), a, and r from each tuple.

# Build sample trajectories
trajectories = [
    # First trajectory with 2 steps
    [
        (
            torch.randn(3, 4),  # s (tensor with shape [3, 4])
            torch.tensor(0),     # a (action)
            1.5,                 # r (reward)
            0,                   # c
            torch.randn(3, 4),   # s_next
            None,                # grad
            torch.tensor([0.1, 0.9]),  # actionProbs
            None,                # grad_adv
            torch.tensor([0.2, 0.8])   # probs_adv
        ),
        (
            torch.randn(3, 4),   # s
            torch.tensor(1),     # a
            2.0,                 # r
            0,                   # c
            torch.randn(3, 4),   # s_next
            None,                # grad
            torch.tensor([0.3, 0.7]),  # actionProbs
            None,                # grad_adv
            torch.tensor([0.4, 0.6])   # probs_adv
        ),
    ],
    # Second trajectory with 2 steps
    [
        (
            torch.randn(3, 4),   # s
            torch.tensor(0),     # a
            -0.5,                # r
            0,                   # c
            torch.randn(3, 4),   # s_next
            None,                # grad
            torch.tensor([0.5, 0.5]),  # actionProbs
            None,                # grad_adv
            torch.tensor([0.1, 0.9])   # probs_adv
        ),
        (
            torch.randn(3, 4),   # s
            torch.tensor(1),     # a
            3.0,                 # r
            0,                   # c
            torch.randn(3, 4),   # s_next
            None,                # grad
            torch.tensor([0.6, 0.4]),  # actionProbs
            None,                # grad_adv
            torch.tensor([0.7, 0.3])   # probs_adv
        ),
    ],
]

ARGS = {
    "trajectories": trajectories,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is 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
get_A_B_r Ran
ran on a synthesized input
bossdm/importancesampling/importance_sampling/INCRIS.py
code served (permissive licence) · get_code("73beaa6b578bd82e")
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 tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 torch
import numpy as np

# Analyze the function to understand what it needs:
# - k: integer (used for slicing trajectory)
# - t: integer (compared with len(trajectory))
# - trajectory: list/sequence that can be sliced, contains tuples of (s, a, r, ro) or (s, a, r)
# - p_e: None or dict-like with structure p_e[s][a] for state s and action a
# - p_b: None or dict-like with structure p_b[s][a] for state s and action a
# - negligible_states: set or collection that supports 'in' operator

# Create a simple trajectory with tuples
# When p_e and p_b are None, tuples have 4 elements: (s, a, r, ro)
trajectory_with_ro = [
    (0, 0, 1.0, 0.9),
    (1, 1, 0.5, 0.95),
    (2, 0, 0.3, 0.88),
    (1, 1, 0.7, 0.92),
]

# For the case with p_e and p_b, tuples have 3 elements: (s, a, r)
trajectory_with_probs = [
    (0, 0, 1.0),
    (1, 1, 0.5),
    (2, 0, 0.3),
    (1, 1, 0.7),
]

# Create probability dictionaries p_e and p_b
# Structure: p_e[state][action] = probability
p_e_dict = {
    0: {0: 0.8, 1: 0.2},
    1: {0: 0.3, 1: 0.7},
    2: {0: 0.6, 1: 0.4},
}

p_b_dict = {
    0: {0: 0.9, 1: 0.1},
    1: {0: 0.4, 1: 0.6},
    2: {0: 0.5, 1: 0.5},
}

# Set of negligible states
negligible_states_set = {0, 2}

# Test case 1: with trajectory containing ro values and p_e/p_b as None
ARGS = {
    "k": 1,
    "t": 2,
    "trajectory": trajectory_with_ro,
    "p_e": None,
    "p_b": None,
    "negligible_states": negligible_states_set,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
get_MSE Ran
ran on a synthesized input
bossdm/importancesampling/importance_sampling/INCRIS.py
code served (permissive licence) · get_code("c0357ab665e6b496")
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 tuple. 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 numpy as np

# Construct valid arguments for get_MSE function

# k: integer for trajectory slicing
k = 2

# t: integer for time step
t = 3

# trajectories: list of trajectories
# Each trajectory is a list of tuples
# Based on the code, each tuple can be either:
# - (s, a, r, ro) when p_e and p_b are None
# - (s, a, r) when p_e and p_b are provided
# s: state (hashable, used in 'in' operator with negligible_states)
# a: action (used as key in p_e[s][a] and p_b[s][a])
# r: reward (numeric)
# ro: importance weight (numeric)

trajectories = [
    [
        (0, 0, 1.0, 0.9),
        (1, 1, 0.5, 0.95),
        (2, 0, 2.0, 0.85),
        (3, 1, 1.5, 0.88),
        (4, 0, 0.8, 0.92),
    ],
    [
        (1, 1, 1.2, 0.91),
        (2, 0, 0.7, 0.89),
        (3, 1, 1.8, 0.87),
        (4, 0, 1.1, 0.93),
        (0, 1, 0.9, 0.90),
    ],
]

# p_e: policy evaluation - dict of dicts mapping state -> action -> probability
# None in this case (will use ro from trajectory)
p_e = None

# p_b: behavior policy - dict of dicts mapping state -> action -> probability
# None in this case (will use ro from trajectory)
p_b = None

# negligible_states: set or list of states to treat specially
negligible_states = {0, 1}

ARGS = {
    "k": k,
    "t": t,
    "trajectories": trajectories,
    "p_e": p_e,
    "p_b": p_b,
    "negligible_states": negligible_states,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
get_DR_model Not yet run
unverified (harvested, no recorded run)
bossdm/importancesampling/importance_sampling/DoublyRobust.py
code served (permissive licence) · get_code("cb98bd3c05ea55b7")
How it ran

no invocation recorded.

get_DR_params Not yet run
unverified (harvested, no recorded run)
bossdm/importancesampling/importance_sampling/DoublyRobust.py
code served (permissive licence) · get_code("ed4c6ad06021ea63")
How it ran

no invocation recorded.

get_model Not yet run
unverified (harvested, no recorded run)
bossdm/importancesampling/importance_sampling/DoublyRobust.py
code served (permissive licence) · get_code("39936a9ef2687641")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 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 7 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

In many domains, the exploration process of reinforcement learning will be too costly as it requires trying out suboptimal policies, resulting in a need for off-policy evaluation, in which a target policy is evaluated based on data collected from a known behaviour policy. In this context, importance sampling estimators provide estimates for the expected return by weighting the trajectory based on the probability ratio of the target policy and the behaviour policy. Unfortunately, such estimators have a high variance and therefore a large mean squared error. This paper proposes state-based importance sampling estimators which reduce the variance by dropping certain states from the computation of the importance weight. To illustrate their applicability, we demonstrate state-based variants of ordinary importance sampling, weighted importance sampling, per-decision importance sampling, incremental importance sampling, doubly robust off-policy evaluation, and stationary density ratio estimation. Experiments in four domains show that state-based methods consistently yield reduced variance and improved accuracy compared to their traditional counterparts.

For agents

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

get_harvested_code_for_paper("2212.03932")
get_code_for_paper("2212.03932")
have("2212.03932")

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

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

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

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

Connect an agent — have() is free.