SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2107.12216 · IJCAI · 2021

Hindsight Value Function for Variance Reduction in Stochastic Dynamic Environment

Qi Guo, Rui Zhang, Xing Hu, Zidong Du, Yunji Chen, Xishan Zhang, Shaohui Peng, Jiaming Guo, Qi Yi

arXiv · PDF · Open in the Atlas

Code that ran

6 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (6 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 0 failures of our instrument; 2 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/2107.12216.json · badge: /api/ran/2107.12216.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
guojm14/HVF community
Papers with Code archive
6 ran · 2 no recorded run
FunctionStatusWhere it lives
Actor Ran
ran on a synthesized input · constructed an object; no result was computed
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("f9dab6339e71b2bb")
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, Actor: 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 torch
import torch.nn as nn
import torch.nn.functional as F

torch.manual_seed(0)

def identity(x):
    return x

class FC(nn.Module):
    def __init__(self, inc, outc, act='id', norm='id'):
        super(FC, self).__init__()
        if act == 'relu':
            self.act = F.relu
        elif act == 'lrelu':
            self.act = F.leaky_relu
        elif act == 'id':
            self.act = identity
        else:
            print('error activation function')
        if norm == 'bn':
            self.norm = nn.BatchNorm1d(outc)
        elif norm == 'ln':
            self.norm = nn.LayerNorm(outc)
        elif norm == 'id':
            self.norm = identity
        else:
            print('error normalization')
        self.fc = nn.Linear(inc, outc)

    def forward(self, x):
        return self.act(self.norm(self.fc(x)))

class Actor(nn.Module):
    def __init__(self, in_dim, h_dim, out_dim, layer_num):
        super(Actor, self).__init__()
        self.in_dim = in_dim
        self.h_dim = h_dim
        self.layer_num = layer_num
        self.fc = []
        self.fc.append(FC(self.in_dim, self.h_dim, act='lrelu'))
        for i in range(self.layer_num - 1):
            self.fc.append(FC(self.h_dim, self.h_dim, act='lrelu'))
        self.fc = nn.Sequential(*self.fc)
        self.outfc_mu = FC(self.h_dim, out_dim)
        self.outfc_sigma = FC(self.h_dim, out_dim)

    def forward(self, x):
        h = self.fc(x)
        mu = self.outfc_mu(h)
        sigma = torch.clamp(self.outfc_sigma(h), min=-20, max=2).exp()
        return (mu, sigma)

ARGS = {
    'in_dim': 4,
    'h_dim': 8,
    'out_dim': 3,
    'layer_num': 2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Actor — 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 Actor 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
CLUB Ran
ran on a synthesized input · constructed an object; no result was computed
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("843e21ea97909b70")
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, CLUB: 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 torch
import torch.nn as nn

torch.manual_seed(0)

class CLUB(nn.Module):

    def __init__(self, x_dim, hidden_size, y_dim):
        super(CLUB, self).__init__()
        self.p_mu = nn.Sequential(nn.Linear(x_dim, hidden_size // 2), nn.ELU(), nn.Linear(hidden_size // 2, hidden_size // 2), nn.ELU(), nn.Linear(hidden_size // 2, hidden_size // 2), nn.ELU(), nn.Linear(hidden_size // 2, y_dim))
        self.p_logvar = nn.Sequential(nn.Linear(x_dim, hidden_size // 2), nn.ELU(), nn.Linear(hidden_size // 2, hidden_size // 2), nn.ELU(), nn.Linear(hidden_size // 2, hidden_size // 2), nn.ELU(), nn.Linear(hidden_size // 2, y_dim), nn.Tanh())

    def get_mu_logvar(self, x_samples):
        mu = self.p_mu(x_samples)
        logvar = self.p_logvar(x_samples)
        return (mu, logvar)

    def mi_est(self, x_samples, y_samples):
        mu, logvar = self.get_mu_logvar(x_samples)
        positive = -(mu - y_samples) ** 2 / 2.0 / logvar.exp()
        prediction_1 = mu.unsqueeze(1)
        y_samples_1 = y_samples.unsqueeze(0)
        negative = -((y_samples_1 - prediction_1) ** 2).mean(dim=1) / 2.0 / logvar.exp()
        return (positive.sum(dim=-1) - negative.sum(dim=-1)).mean()

    def loglikeli(self, x_samples, y_samples):
        mu, logvar = self.get_mu_logvar(x_samples)
        return (-(mu - y_samples) ** 2 / logvar.exp() - logvar).sum(dim=1).mean(dim=0)


x_dim = 4
hidden_size = 8
y_dim = 3

x_samples = torch.randn(2, x_dim)
y_samples = torch.randn(2, y_dim)

club_model = CLUB(x_dim, hidden_size, y_dim)

ARGS = {
    "x_dim": x_dim,
    "hidden_size": hidden_size,
    "y_dim": y_dim
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type CLUB — 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 CLUB 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
Critic Ran
ran on a synthesized input · constructed an object; no result was computed
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("05a92190f86414b3")
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, Critic: 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 torch
import torch.nn as nn
import torch.nn.functional as F

torch.manual_seed(0)

def identity(x):
    return x

class FC(nn.Module):
    def __init__(self, inc, outc, act='id', norm='id'):
        super(FC, self).__init__()
        if act == 'relu':
            self.act = F.relu
        elif act == 'lrelu':
            self.act = F.leaky_relu
        elif act == 'id':
            self.act = identity
        else:
            print('error activation function')
        if norm == 'bn':
            self.norm = nn.BatchNorm1d(outc)
        elif norm == 'ln':
            self.norm = nn.LayerNorm(outc)
        elif norm == 'id':
            self.norm = identity
        else:
            print('error normalization')
        self.fc = nn.Linear(inc, outc)

    def forward(self, x):
        return self.act(self.norm(self.fc(x)))

class MLP(nn.Module):
    def __init__(self, in_dim, h_dim, out_dim, layer_num):
        super(MLP, self).__init__()
        self.in_dim = in_dim
        self.h_dim = h_dim
        self.layer_num = layer_num
        self.fc = []
        self.fc.append(FC(self.in_dim, self.h_dim, act='lrelu'))
        for i in range(self.layer_num - 1):
            self.fc.append(FC(self.h_dim, self.h_dim, act='lrelu'))
        self.fc = nn.Sequential(*self.fc)
        self.outfc = FC(self.h_dim, out_dim)

    def forward(self, x):
        out = self.outfc(self.fc(x))
        return out

class Critic(nn.Module):
    def __init__(self, input_dim, h_dim, l_dim):
        super(Critic, self).__init__()
        self.snet = MLP(input_dim, h_dim, h_dim, 4)
        self.out = MLP(h_dim, h_dim, 1, 2)

    def forward(self, state):
        s_feature = self.snet(state)
        return self.out(s_feature)

ARGS = {
    'input_dim': 4,
    'h_dim': 8,
    'l_dim': 16
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Critic — 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 Critic 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
FC Ran
ran on a synthesized input · constructed an object; no result was computed
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("781c9791864d968d")
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, FC: 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 torch
import torch.nn as nn
import torch.nn.functional as F

torch.manual_seed(0)

ARGS = {
    'inc': 4,
    'outc': 3,
    'act': 'relu',
    'norm': 'bn'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type FC — 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 FC 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
MLP Ran
ran on a synthesized input · constructed an object; no result was computed
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("6ef29899c0c79c2b")
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, MLP: 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 torch
import torch.nn as nn
import torch.nn.functional as F

torch.manual_seed(0)

def identity(x):
    return x

class FC(nn.Module):

    def __init__(self, inc, outc, act='id', norm='id'):
        super(FC, self).__init__()
        if act == 'relu':
            self.act = F.relu
        elif act == 'lrelu':
            self.act = F.leaky_relu
        elif act == 'id':
            self.act = identity
        else:
            print('error activation function')
        if norm == 'bn':
            self.norm = nn.BatchNorm1d(outc)
        elif norm == 'ln':
            self.norm = nn.LayerNorm(outc)
        elif norm == 'id':
            self.norm = identity
        else:
            print('error normalization')
        self.fc = nn.Linear(inc, outc)

    def forward(self, x):
        return self.act(self.norm(self.fc(x)))

class MLP(nn.Module):

    def __init__(self, in_dim, h_dim, out_dim, layer_num):
        super(MLP, self).__init__()
        self.in_dim = in_dim
        self.h_dim = h_dim
        self.layer_num = layer_num
        self.fc = []
        self.fc.append(FC(self.in_dim, self.h_dim, act='lrelu'))
        for i in range(self.layer_num - 1):
            self.fc.append(FC(self.h_dim, self.h_dim, act='lrelu'))
        self.fc = nn.Sequential(*self.fc)
        self.outfc = FC(self.h_dim, out_dim)

    def forward(self, x):
        out = self.outfc(self.fc(x))
        return out

ARGS = {
    'in_dim': 4,
    'h_dim': 8,
    'out_dim': 3,
    'layer_num': 2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MLP — 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 MLP 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
Pre Ran
ran on a synthesized input · constructed an object; no result was computed
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("a7e740d8e575e056")
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, Pre: 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 torch
import torch.nn as nn
import torch.nn.functional as F

torch.manual_seed(0)

def identity(x):
    return x

class FC(nn.Module):

    def __init__(self, inc, outc, act='id', norm='id'):
        super(FC, self).__init__()
        if act == 'relu':
            self.act = F.relu
        elif act == 'lrelu':
            self.act = F.leaky_relu
        elif act == 'id':
            self.act = identity
        else:
            print('error activation function')
        if norm == 'bn':
            self.norm = nn.BatchNorm1d(outc)
        elif norm == 'ln':
            self.norm = nn.LayerNorm(outc)
        elif norm == 'id':
            self.norm = identity
        else:
            print('error normalization')
        self.fc = nn.Linear(inc, outc)

    def forward(self, x):
        return self.act(self.norm(self.fc(x)))

class MLP(nn.Module):

    def __init__(self, in_dim, h_dim, out_dim, layer_num):
        super(MLP, self).__init__()
        self.in_dim = in_dim
        self.h_dim = h_dim
        self.layer_num = layer_num
        self.fc = []
        self.fc.append(FC(self.in_dim, self.h_dim, act='lrelu'))
        for i in range(self.layer_num - 1):
            self.fc.append(FC(self.h_dim, self.h_dim, act='lrelu'))
        self.fc = nn.Sequential(*self.fc)
        self.outfc = FC(self.h_dim, out_dim)

    def forward(self, x):
        out = self.outfc(self.fc(x))
        return out

class Pre(nn.Module):

    def __init__(self, input_dim, action_dim, h_dim=32, l_dim=16):
        super(Pre, self).__init__()
        self.state_pre = MLP(in_dim=input_dim + action_dim + l_dim, h_dim=h_dim, out_dim=input_dim, layer_num=2)
        self.pre_base = MLP(in_dim=input_dim + action_dim, h_dim=h_dim, out_dim=input_dim, layer_num=2)
        self.lucky_net = MLP(in_dim=input_dim + action_dim + input_dim, h_dim=h_dim, out_dim=l_dim, layer_num=2)

    def get_l(self, x):
        return F.tanh(self.lucky_net(x))

    def forward(self, state, action, state_next):
        l = F.tanh(self.lucky_net(torch.cat([state, action, state_next], 1)))
        return (self.pre_base(torch.cat([state, action], 1)) + self.state_pre(torch.cat([state, action, l], 1)), l)

ARGS = {
    'input_dim': 4,
    'action_dim': 3,
    'h_dim': 8,
    'l_dim': 2
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Pre — 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 Pre 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
Critic_net_lstm Not yet run
unverified (harvested, no recorded run)
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("d6e2dd5c77bfdf2d")
How it ran

no invocation recorded.

Lucky Not yet run
unverified (harvested, no recorded run)
guojm14/HVF/reduce_var/mlp.py
code served (permissive licence) · get_code("a1dc1eb245fd0d7d")
How it ran

no invocation recorded.

Also present in other papers' code

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

Policy gradient methods are appealing in deep reinforcement learning but suffer from high variance of gradient estimate. To reduce the variance, the state value function is applied commonly. However, the effect of the state value function becomes limited in stochastic dynamic environments, where the unexpected state dynamics and rewards will increase the variance. In this paper, we propose to replace the state value function with a novel hindsight value function, which leverages the information from the future to reduce the variance of the gradient estimate for stochastic dynamic environments. Particularly, to obtain an ideally unbiased gradient estimate, we propose an informationtheoretic approach, which optimizes the embeddings of the future to be independent of previous actions. In our experiments, we apply the proposed hindsight value function in stochastic dynamic environments, including discrete-action environments and continuous-action environments. Compared with the standard state value function, the proposed hindsight value function consistently reduces the variance, stabilizes the training, and improves the eventual policy.

For agents

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

get_harvested_code_for_paper("2107.12216")
get_code_for_paper("2107.12216")
have("2107.12216")

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

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

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

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

Connect an agent — have() is free.