當前位置: 首頁>>代碼示例>>Python>>正文


Python running_mean_std.RunningMeanStd方法代碼示例

本文整理匯總了Python中baselines.common.running_mean_std.RunningMeanStd方法的典型用法代碼示例。如果您正苦於以下問題:Python running_mean_std.RunningMeanStd方法的具體用法?Python running_mean_std.RunningMeanStd怎麽用?Python running_mean_std.RunningMeanStd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在baselines.common.running_mean_std的用法示例。


在下文中一共展示了running_mean_std.RunningMeanStd方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, venv, ob=True, ret=True, clipob=10., cliprew=10., gamma=0.99, epsilon=1e-8):
        VecEnvWrapper.__init__(self, venv)
        try:
            self.num_agents = num_agents = len(self.observation_space)
            self.ob_rms = [RunningMeanStd(shape=self.observation_space[k].shape) for k in range(num_agents)] if ob else None
        except:
            self.num_agents = num_agents = len(self.observation_space.spaces)
            self.ob_rms = [RunningMeanStd(shape=self.observation_space.spaces[k].shape) for k in range(num_agents)] if ob else None

        self.ret_rms = RunningMeanStd(shape=()) if ret else None
        #[RunningMeanStd(shape=()) for k in range(num_agents)] if ret else None
        self.clipob = clipob
        self.cliprew = cliprew
        # self.ret = [np.zeros(self.num_envs) for _ in range(num_agents)]
        self.ret = np.zeros(self.num_envs)
        self.gamma = gamma
        self.epsilon = epsilon 
開發者ID:ermongroup,項目名稱:multiagent-gail,代碼行數:19,代碼來源:vec_normalize.py

示例2: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, input_dim, hidden_dim, device):
        super(Discriminator, self).__init__()

        self.device = device

        self.trunk = nn.Sequential(
            nn.Linear(input_dim, hidden_dim), nn.Tanh(),
            nn.Linear(hidden_dim, hidden_dim), nn.Tanh(),
            nn.Linear(hidden_dim, 1)).to(device)

        self.trunk.train()

        self.optimizer = torch.optim.Adam(self.trunk.parameters())

        self.returns = None
        self.ret_rms = RunningMeanStd(shape=()) 
開發者ID:ikostrikov,項目名稱:pytorch-a2c-ppo-acktr-gail,代碼行數:18,代碼來源:gail.py

示例3: test_runningmeanstd

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def test_runningmeanstd():
    for (x1, x2, x3) in [
        (np.random.randn(3), np.random.randn(4), np.random.randn(5)),
        (np.random.randn(3,2), np.random.randn(4,2), np.random.randn(5,2)),
        ]:

        rms = RunningMeanStd(epsilon=0.0, shape=x1.shape[1:])

        x = np.concatenate([x1, x2, x3], axis=0)
        ms1 = [x.mean(axis=0), x.var(axis=0)]
        rms.update(x1)
        rms.update(x2)
        rms.update(x3)
        ms2 = [rms.mean, rms.var]

        assert np.allclose(ms1, ms2) 
開發者ID:cxxgtxy,項目名稱:deeprl-baselines,代碼行數:18,代碼來源:vec_normalize.py

示例4: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, venv, ob=True, ret=True, clipob=10., cliprew=10., gamma=0.99, epsilon=1e-8):
        VecEnvWrapper.__init__(self, venv)
        self.ob_rms = RunningMeanStd(shape=self.observation_space.shape) if ob else None
        self.ret_rms = RunningMeanStd(shape=()) if ret else None
        self.clipob = clipob
        self.cliprew = cliprew
        self.ret = np.zeros(self.num_envs)
        self.gamma = gamma
        self.epsilon = epsilon 
開發者ID:Hwhitetooth,項目名稱:lirpg,代碼行數:11,代碼來源:vec_normalize.py

示例5: __call__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __call__(self, x):
        x = np.asarray(x)
        if self.rms is None:
            self.rms = RunningMeanStd(shape=(1,) + x.shape[1:])
        if not self.read_only:
            self.rms.update(x)
        return np.clip((x - self.rms.mean) / np.sqrt(self.rms.var + self.epsilon),
                       -self.clip, self.clip) 
開發者ID:ShangtongZhang,項目名稱:DeepRL,代碼行數:10,代碼來源:normalizer.py

示例6: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, venv, ob=True, ret=True, clipob=10., cliprew=10., gamma=0.99, epsilon=1e-8, eval=False):
        VecEnvWrapper.__init__(self, venv)
        self.ob_rms = RunningMeanStd(shape=self.observation_space.shape) if ob else None
        self.ret_rms = RunningMeanStd(shape=()) if ret else None
        self.clipob = clipob
        self.cliprew = cliprew
        self.ret = np.zeros(self.num_envs)
        self.gamma = gamma
        self.epsilon = epsilon
        self.eval = eval 
開發者ID:hiwonjoon,項目名稱:ICML2019-TREX,代碼行數:12,代碼來源:vec_normalize.py

示例7: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, venv, num_models, model_dir, include_action, num_layers, embedding_dims, ctrl_coeff=0., alive_bonus=0.):
        super().__init__(venv, num_models, model_dir, include_action, num_layers, embedding_dims, ctrl_coeff, alive_bonus)

        self.rew_rms = [RunningMeanStd(shape=()) for _ in range(num_models)]
        self.cliprew = 10.
        self.epsilon = 1e-8 
開發者ID:hiwonjoon,項目名稱:ICML2019-TREX,代碼行數:8,代碼來源:custom_reward_wrapper.py

示例8: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, venv, reward_net_path, env_name):
        VecEnvWrapper.__init__(self, venv)
        self.reward_net = AtariNet()
        self.reward_net.load_state_dict(torch.load(reward_net_path))
        self.device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
        self.reward_net.to(self.device)

        self.rew_rms = RunningMeanStd(shape=())
        self.epsilon = 1e-8
        self.cliprew = 10.
        self.env_name = env_name 
開發者ID:hiwonjoon,項目名稱:ICML2019-TREX,代碼行數:13,代碼來源:custom_reward_wrapper.py

示例9: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, venv, ob=True, ret=True, clipob=10., cliprew=10., gamma=0.99, epsilon=1e-8, use_tf=False):
        VecEnvWrapper.__init__(self, venv)
        if use_tf:
            from baselines.common.running_mean_std import TfRunningMeanStd
            self.ob_rms = TfRunningMeanStd(shape=self.observation_space.shape, scope='ob_rms') if ob else None
            self.ret_rms = TfRunningMeanStd(shape=(), scope='ret_rms') if ret else None
        else:
            from baselines.common.running_mean_std import RunningMeanStd
            self.ob_rms = RunningMeanStd(shape=self.observation_space.shape) if ob else None
            self.ret_rms = RunningMeanStd(shape=()) if ret else None
        self.clipob = clipob
        self.cliprew = cliprew
        self.ret = np.zeros(self.num_envs)
        self.gamma = gamma
        self.epsilon = epsilon 
開發者ID:openai,項目名稱:baselines,代碼行數:17,代碼來源:vec_normalize.py

示例10: __init__

# 需要導入模塊: from baselines.common import running_mean_std [as 別名]
# 或者: from baselines.common.running_mean_std import RunningMeanStd [as 別名]
def __init__(self, venv, ob=True, ret=True, clipob=10., cliprew=10., gamma=0.99, epsilon=1e-8):
        self.venv = venv
        self._observation_space = self.venv.observation_space
        self._action_space = venv.action_space
        self.ob_rms = RunningMeanStd(shape=self._observation_space.shape) if ob else None
        self.ret_rms = RunningMeanStd(shape=()) if ret else None
        self.clipob = clipob
        self.cliprew = cliprew
        self.ret = np.zeros(self.num_envs)
        self.gamma = gamma
        self.epsilon = epsilon 
開發者ID:cxxgtxy,項目名稱:deeprl-baselines,代碼行數:13,代碼來源:vec_normalize.py


注:本文中的baselines.common.running_mean_std.RunningMeanStd方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。