当前位置: 首页>>代码示例>>Python>>正文


Python seeding.np_random方法代码示例

本文整理汇总了Python中gym.utils.seeding.np_random方法的典型用法代码示例。如果您正苦于以下问题:Python seeding.np_random方法的具体用法?Python seeding.np_random怎么用?Python seeding.np_random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gym.utils.seeding的用法示例。


在下文中一共展示了seeding.np_random方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: step

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def step(self, action):
        reward = -1
        done = False
        self.step_n += 1
        if self.digit==-1:
            pass
        else:
            if self.digit==action:
                reward = +1
            done = self.step_n > 20 and 0==self.np_random.randint(low=0, high=5)
        self.digit = self.np_random.randint(low=0, high=10)
        obs = np.zeros( (FIELD_H,FIELD_W,3), dtype=np.uint8 )
        obs[:,:,:] = self.color_bg
        digit_img = np.zeros( (6,6,3), dtype=np.uint8 )
        digit_img[:] = self.color_bg
        xxx = self.bogus_mnist[self.digit]==42
        digit_img[xxx] = self.color_digit
        obs[self.digit_y-3:self.digit_y+3, self.digit_x-3:self.digit_x+3] = digit_img
        self.last_obs = obs
        return obs, reward, done, {} 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:22,代码来源:memorize_digits.py

示例2: _step

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def _step(self, action):
        assert self.action_space.contains(action)
        if action:  # hit: add a card to players hand and return
            self.player.append(draw_card(self.np_random))
            if is_bust(self.player):
                done = True
                reward = -1
            else:
                done = False
                reward = 0
        else:  # stick: play out the dealers hand, and score
            done = True
            while sum_hand(self.dealer) < 17:
                self.dealer.append(draw_card(self.np_random))
            reward = cmp(score(self.player), score(self.dealer))
            if self.natural and is_natural(self.player) and reward == 1:
                reward = 1.5
        return self._get_obs(), reward, done, {} 
开发者ID:DanielTakeshi,项目名称:rl_algorithms,代码行数:20,代码来源:blackjack.py

示例3: __init__

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def __init__(self, strict=False):
    self.strict = strict

    # What about metadata and spec?
    self.reward_range = (-1.0, 1.0)

    # Action space -- 9 positions that we can chose to mark.
    self.action_space = spaces.Discrete(9)

    # Observation space -- this hopefully does what we need.
    self.observation_space = spaces.Box(
        low=-1, high=1, shape=(3, 3), dtype=np.int64)

    # Set the seed.
    self.np_random = None
    self.seed()

    # Start the game.
    self.board_state = None
    self.done = False
    self.reset() 
开发者ID:tensorflow,项目名称:tensor2tensor,代码行数:23,代码来源:tic_tac_toe_env.py

示例4: step

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def step(self, action):
        action = action/100.0 # convert from pennies to dollars
        if action > self.wealth: # treat attempts to bet more than possess as == betting everything
          action = self.wealth
        if self.wealth < 0.000001:
            done = True
            reward = 0.0
        else:
          if self.rounds == 0:
            done = True
            reward = self.wealth
          else:
            self.rounds = self.rounds - 1
            done = False
            reward = 0.0
            coinflip = flip(self.edge, self.np_random)
            if coinflip:
              self.wealth = min(self.maxWealth, self.wealth + action)
            else:
              self.wealth = self.wealth - action
        return self._get_obs(), reward, done, {} 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:23,代码来源:kellycoinflip.py

示例5: step

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def step(self, action):
        assert self.action_space.contains(action)
        if action:  # hit: add a card to players hand and return
            self.player.append(draw_card(self.np_random))
            if is_bust(self.player):
                done = True
                reward = -1
            else:
                done = False
                reward = 0
        else:  # stick: play out the dealers hand, and score
            done = True
            while sum_hand(self.dealer) < 17:
                self.dealer.append(draw_card(self.np_random))
            reward = cmp(score(self.player), score(self.dealer))
            if self.natural and is_natural(self.player) and reward == 1:
                reward = 1.5
        return self._get_obs(), reward, done, {} 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:20,代码来源:blackjack.py

示例6: _seed

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def _seed(self, seed=None):
    self.np_random, seed = seeding.np_random(seed)
    return [seed] 
开发者ID:utra-robosoccer,项目名称:soccer-matlab,代码行数:5,代码来源:minitaur_gym_env.py

示例7: _seed

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def _seed(self, seed=None):
        self.np_random, seed = seeding.np_random(seed)
        return [seed] 
开发者ID:xuwd11,项目名称:cs294-112_hws,代码行数:5,代码来源:lunar_lander.py

示例8: draw_card

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def draw_card(np_random):
    return np_random.choice(deck) 
开发者ID:DanielTakeshi,项目名称:rl_algorithms,代码行数:4,代码来源:blackjack.py

示例9: draw_hand

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def draw_hand(np_random):
    return [draw_card(np_random), draw_card(np_random)] 
开发者ID:DanielTakeshi,项目名称:rl_algorithms,代码行数:4,代码来源:blackjack.py

示例10: _reset

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def _reset(self):
        self.dealer = draw_hand(self.np_random)
        self.player = draw_hand(self.np_random)

        # Auto-draw another card if the score is less than 12
        while sum_hand(self.player) < 12:
            self.player.append(draw_card(self.np_random))

        return self._get_obs() 
开发者ID:DanielTakeshi,项目名称:rl_algorithms,代码行数:11,代码来源:blackjack.py

示例11: seed

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def seed(self, seed=None):
        self.np_random, seed = seeding.np_random(seed)
        return [seed] 
开发者ID:rlgraph,项目名称:rlgraph,代码行数:5,代码来源:bit_flip.py

示例12: seed

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def seed(self, seed=None):
    self.np_random, seed = seeding.np_random(seed)
    return [seed]

  # TODO(afrozm): Parametrize by some policy so that the env plays in an optimal
  # way. 
开发者ID:tensorflow,项目名称:tensor2tensor,代码行数:8,代码来源:tic_tac_toe_env.py

示例13: play_random_move

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def play_random_move(self):
    # Select open spaces.
    open_spaces = get_open_spaces(self.board_state)

    if not open_spaces:
      return False

    # Choose a space and mark it.
    pos = self.np_random.choice(open_spaces)
    i, j = decode_pos(pos)

    self.board_state[i, j] = -1 
开发者ID:tensorflow,项目名称:tensor2tensor,代码行数:14,代码来源:tic_tac_toe_env.py

示例14: reset

# 需要导入模块: from gym.utils import seeding [as 别名]
# 或者: from gym.utils.seeding import np_random [as 别名]
def reset(self):
    self.board_state = np.zeros((3, 3), dtype=np.int64)

    # We"ll start with a 50% chance.
    if self.np_random.choice([0, 1]) == 0:
      self.play_random_move()

    # Return the observation.
    return self.board_state 
开发者ID:tensorflow,项目名称:tensor2tensor,代码行数:11,代码来源:tic_tac_toe_env.py


注:本文中的gym.utils.seeding.np_random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。