tensorpack.RL package

class tensorpack.RL.PreventStuckPlayer(player, nr_repeat, action)[source]

Bases: tensorpack.RL.envbase.ProxyPlayer

Prevent the player from getting stuck (repeating a no-op) by inserting a different action. Useful in games such as Atari Breakout where the agent needs to press the ‘start’ button to start playing.

It does auto-reset, but doesn’t auto-restart the underlying player.

__init__(player, nr_repeat, action)[source]
Parameters:
  • nr_repeat (int) – trigger the ‘action’ after this many of repeated action.

  • action – the action to be triggered to get out of stuck.

action(act)[source]
restart_episode()[source]
class tensorpack.RL.LimitLengthPlayer(player, limit)[source]

Bases: tensorpack.RL.envbase.ProxyPlayer

Limit the total number of actions in an episode. Will restart the underlying player on timeout.

__init__(player, limit)[source]
Parameters:limit (int) – the time limit
action(act)[source]
restart_episode()[source]
class tensorpack.RL.AutoRestartPlayer(player)[source]

Bases: tensorpack.RL.envbase.ProxyPlayer

Auto-restart the player on episode ends, in case some player wasn’t designed to do so.

action(act)[source]
class tensorpack.RL.MapPlayerState(player, func)[source]

Bases: tensorpack.RL.envbase.ProxyPlayer

Map the state of the underlying player by a function.

__init__(player, func)[source]
Parameters:func – takes the old state and return a new state.
current_state()[source]
class tensorpack.RL.RLEnvironment[source]

Bases: object

Base class of RL environment.

action(act)[source]

Perform an action. Will automatically start a new episode if isOver==True

Parameters:act – the action
Returns:tuple – (reward, isOver)
current_state()[source]

Observe, return a state representation

finish_episode()[source]

Get called when an episode finished

get_action_space()[source]

Returns: ActionSpace

play_one_episode(func, stat='score')[source]

Play one episode for eval.

Parameters:
  • func – the policy function. Takes a state and returns an action.

  • stat – a key or list of keys in stats to return.

Returns:

the stat(s) after running this episode

reset_stat()[source]

Reset all statistics counter

restart_episode()[source]

Start a new episode, even if the current hasn’t ended

class tensorpack.RL.ProxyPlayer(player)[source]

Bases: tensorpack.RL.envbase.RLEnvironment

Serve as a proxy to another player

action(act)[source]
current_state()[source]
finish_episode()[source]
get_action_space()[source]
reset_stat()[source]
restart_episode()[source]
stats
class tensorpack.RL.DiscreteActionSpace(num)[source]

Bases: tensorpack.RL.envbase.ActionSpace

num_actions()[source]
sample()[source]
tensorpack.RL.GymEnv

alias of _Dummy

class tensorpack.RL.HistoryFramePlayer(player, hist_len)[source]

Bases: tensorpack.RL.envbase.ProxyPlayer

Include history frames in state, or use black images. It assumes the underlying player will do auto-restart.

Map the original frames into (H, W, HIST x channels). Oldest frames first.

__init__(player, hist_len)[source]
Parameters:hist_len (int) – total length of the state, including the current and hist_len-1 history.
action(act)[source]
current_state()[source]
restart_episode()[source]