class_docstr: A class implementing image preprocessing for Atari 2600 agents.
  
  Specifically, this provides the following subset from the JAIR paper
  (Bellemare et al., 2013) and Nature DQN paper (Mnih et al., 2015):
  
    * Frame skipping (defaults to 4).
    * Terminal signal when a life is lost (off by default).
    * Grayscale and max-pooling of the last two frames.
    * Downsample the screen to a square image (defaults to 84x84).
  
  More generally, this class follows the preprocessing guidelines set down in
  Machado et al. (2018), "Revisiting the Arcade Learning Environment:
  Evaluation Protocols and Open Problems for General Agents".
  
  It also provides random starting no-ops, which are used in the Rainbow, Apex
  and R2D2 papers.
class_docstr_tok: ["A","class","implementing","image","preprocessing","for","Atari","2600","agents",".","Specifically",",","this","provides","the","following","subset","from","the","JAIR","paper","(","Bellemare","et","al.",",","2013",")","and","Nature","DQN","paper","(","Mnih","et","al.",",","2015",")",":","*","Frame","skipping","(","defaults","to","4",")",".","*","Terminal","signal","when","a","life","is","lost","(","off","by","default",")",".","*","Grayscale","and","max-pooling","of","the","last","two","frames",".","*","Downsample","the","screen","to","a","square","image","(","defaults","to","84x84",")",".","More","generally",",","this","class","follows","the","preprocessing","guidelines","set","down","in","Machado","et","al",".","(","2018",")",",","``","Revisiting","the","Arcade","Learning","Environment",":","Evaluation","Protocols","and","Open","Problems","for","General","Agents","''",".","It","also","provides","random","starting","no-ops",",","which","are","used","in","the","Rainbow",",","Apex","and","R2D2","papers","."]
docstr: Constructor for an Atari 2600 preprocessor.
  
  Args:
    environment: Gym environment whose observations are preprocessed.
    frame_skip: int, the frequency at which the agent experiences the game.
    terminal_on_life_loss: bool, If True, the step() method returns
      is_terminal=True whenever a life is lost. See Mnih et al. 2015.
    screen_size: int, size of a resized Atari 2600 frame.
    max_random_noops: int, maximum number of no-ops to apply at the beginning
      of each episode to reduce determinism. These no-ops are applied at a
      low-level, before frame skipping.
  
  Raises:
    ValueError: if frame_skip or screen_size are not strictly positive.
docstr_tok: ["Constructor","for","an","Atari","2600","preprocessor",".","Args",":","environment",":","Gym","environment","whose","observations","are","preprocessed",".","frame_skip",":","int",",","the","frequency","at","which","the","agent","experiences","the","game",".","terminal_on_life_loss",":","bool",",","If","True",",","the","step","(",")","method","returns","is_terminal=True","whenever","a","life","is","lost",".","See","Mnih","et","al",".","2015.","screen_size",":","int",",","size","of","a","resized","Atari","2600","frame",".","max_random_noops",":","int",",","maximum","number","of","no-ops","to","apply","at","the","beginning","of","each","episode","to","reduce","determinism",".","These","no-ops","are","applied","at","a","low-level",",","before","frame","skipping",".","Raises",":","ValueError",":","if","frame_skip","or","screen_size","are","not","strictly","positive","."]
code: def __init__(
      self,
      environment,
      frame_skip=4,
      terminal_on_life_loss=False,
      screen_size=84,
      max_random_noops=0,
  ):
      """Constructor for an Atari 2600 preprocessor.
  
      Args:
        environment: Gym environment whose observations are preprocessed.
        frame_skip: int, the frequency at which the agent experiences the game.
        terminal_on_life_loss: bool, If True, the step() method returns
          is_terminal=True whenever a life is lost. See Mnih et al. 2015.
        screen_size: int, size of a resized Atari 2600 frame.
        max_random_noops: int, maximum number of no-ops to apply at the beginning
          of each episode to reduce determinism. These no-ops are applied at a
          low-level, before frame skipping.
  
      Raises:
        ValueError: if frame_skip or screen_size are not strictly positive.
      """
      if frame_skip <= 0:
          raise ValueError(
              "Frame skip should be strictly positive, got {}".format(
                  frame_skip
              )
          )
      if screen_size <= 0:
          raise ValueError(
              "Target screen size should be strictly positive, got {}".format(
                  screen_size
              )
          )
  
      self.environment = environment
      self.terminal_on_life_loss = terminal_on_life_loss
      self.frame_skip = frame_skip
      self.screen_size = screen_size
      self.max_random_noops = max_random_noops
  
      obs_dims = self.environment.observation_space
      # Stores temporary observations used for pooling over two successive
      # frames.
      self.screen_buffer = [
          np.empty(
              (obs_dims.shape[0], obs_dims.shape[1]), dtype=np.uint8
          ),
          np.empty(
              (obs_dims.shape[0], obs_dims.shape[1]), dtype=np.uint8
          ),
      ]
  
      self.game_over = False
      self.lives = 0
  
file_path: moolib/examples/atari/atari_preprocessing.py
imports: from gym.spaces.box import Box
  import numpy
  import cv2
label_desc: Use image node_id 1 to create a new AtariPreprocessing object from inherited base classes: object with example: obj = AtariPreprocessing(environment, frame_skip, terminal_on_life_loss, screen_size, max_random_noops)