當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。