Environment

class env_wrapper.chickai_env_wrapper.ChickAIEnvWrapper(run_id: str, env_path=None, base_port=5004, **kwargs)[source]

Wrapper class for the ChickAI environment.

Parameters:
  • run_id (str) – The ID of the current run.

  • env_path (str) – The path to the Unity environment executable.

  • base_port (int) – The base port number for the Unity environment.

  • **kwargs – Additional keyword arguments.

env

The wrapped Unity environment.

Type:

UnityToGymWrapper

mode

The mode of the environment.

Type:

str

step()[source]

Step the environment for one timestep.

log()[source]

Write to the log file.

close()[source]

Close the environment.

reset()[source]

Reset the environment.

steps_from_eps()[source]

Get the number of steps from the given episode.

close()[source]

Close the environment.

Returns:

None

log(msg: str) None[source]

Write a message to the log file.

Parameters:

msg (str) – The message to write.

Returns:

None

reset(seed: int | None = None, **kwargs)[source]

Reset the environment.

Parameters:
  • seed (int) – The random seed for the environment.

  • **kwargs – Additional keyword arguments.

Returns:

The initial state of the environment.

step(action)[source]

Step the environment for one timestep.

Parameters:

action – The action to take in the environment.

Returns:

A tuple containing the next state, reward, done flag, and additional information.

Return type:

tuple

abstract steps_from_eps(eps)[source]

Get the number of steps from the given episode.

Parameters:

eps – The episode.

Returns:

The number of steps.

Return type:

int

class env_wrapper.parsing_env_wrapper.ParsingEnv(run_id: str, env_path=None, base_port=5004, **kwargs)[source]

A class representing the Parsing Environment.

numb_conditions

The number of test conditions in the environment.

Type:

int

__init__(self, run_id

str, env_path=None, base_port=5004, **kwargs): Initializes the ParsingEnv object.

steps_from_eps(self, eps)[source]

Calculates the number of steps based on the number of episodes.

steps_from_eps(eps)[source]

Calculates the number of steps based on the number of episodes.

Parameters:

eps (int) – The number of episodes.

Returns:

The total number of steps.

Return type:

int

class env_wrapper.dvs_wrapper.DVSWrapper(env, change_threshold=60, kernel_size=(3, 3), sigma=1)[source]

A gym observation wrapper that performs Dynamic Vision Sensor (DVS) transformation on the environment observations.

Parameters:
  • env (gym.Env) – The environment to wrap.

  • change_threshold (int) – The threshold value for detecting changes in pixel intensity.

  • kernel_size (tuple) – The size of the Gaussian kernel used for blurring.

  • sigma (float) – The standard deviation of the Gaussian kernel.

change_threshold

The threshold value for detecting changes in pixel intensity.

Type:

int

kernel_size

The size of the Gaussian kernel used for blurring.

Type:

tuple

sigma

The standard deviation of the Gaussian kernel.

Type:

float

num_stack

The number of frames to stack.

Type:

int

env

The wrapped environment.

Type:

gym.Env

stack

A deque to store the stacked frames.

Type:

collections.deque

shape

The shape of the observation space.

Type:

tuple

observation_space

The modified observation space.

Type:

gym.spaces.Box

create_grayscale(image)[source]

Converts an image to grayscale.

gaussianDiff(previous, current)[source]

Computes the difference between two images using Gaussian blur.

observation(obs)[source]

Performs the DVS transformation on the observation.

threshold(change)[source]

Applies a threshold to the change map.

reset(**kwargs)[source]

Resets the environment and returns the initial observation.

create_grayscale(image)[source]

Converts an image to grayscale.

Parameters:

image (numpy.ndarray) – The input image.

Returns:

The grayscale image.

Return type:

numpy.ndarray

gaussianDiff(previous, current)[source]

Computes the difference between two images using Gaussian blur.

Parameters:
  • previous (numpy.ndarray) – The previous image.

  • current (numpy.ndarray) – The current image.

Returns:

The difference map.

Return type:

numpy.ndarray

observation(obs)[source]

Performs the DVS transformation on the observation.

Parameters:

obs (list) – The list of stacked frames.

Returns:

The transformed observation.

Return type:

numpy.ndarray

reset(**kwargs)[source]

Resets the environment and returns the initial observation.

Parameters:

**kwargs – Additional keyword arguments for resetting the environment.

Returns:

The initial observation.

Return type:

numpy.ndarray

threshold(change)[source]

Applies a threshold to the change map.

Parameters:

change (numpy.ndarray) – The change map.

Returns:

The thresholded change map.

Return type:

numpy.ndarray

class env_wrapper.observation_wrapper.ObservationWrapper(env)[source]

Gym env wrapper that transpose visual observations to (C,H,W).