Environment

Environment_factory

class gaggle.problem.environment.environment_factory.EnvironmentFactory[source]

Bases: object

Factory that generates available environments. EnvironmentFactory.environments stores said environments as a dictionary with their name as key and the uninitialized Environment object as value.

See also

Environment Class

environments = {'cartpole': <gaggle.problem.environment.environment_factory.GymWrapper object>}
classmethod from_gym_env_id(env_id: str)[source]

Takes in a gym env id and returns the associated OpenAI Gym Environment :param env_id: gym environment id

Returns: Gym environment

classmethod from_problem_args(problem_args: ProblemArgs)[source]
classmethod get_keys()[source]

Gets the keys (environment names) for the available pre-built environment.

Returns:

list of strings that are the keys to EnvironmentFactory.environments

classmethod update(key, environment)[source]

Add a new dataset to the dictionary of datasets that can be created.

It is added to EnvironmentFactory.environments

Parameters:
  • key – dataset name that will be used as the dictionary lookup key

  • environment – environment class object, it needs to not be already initialized

class gaggle.problem.environment.environment_factory.GymWrapper(environment_name: str)[source]

Bases: object

Callable wrapper that returns the gym environment

Rl_problem

class gaggle.problem.environment.rl_problem.RLProblem(problem_args: ProblemArgs = None, sys_args: SysArgs = None)[source]

Bases: Problem

Problem that uses a reinforcement learning environment as a fitness evaluation process. Used mainly for OpenAI gym environments but can be used for any environment that supports OpenAI Gym’s environment API.

evaluate(individual: Individual, *args, **kwargs) float[source]

Evaluate the given individual based on this problem.

Parameters:
  • individual – individual to be evaluated

  • train – whether this is a training or testing evaluation (matters for certain problems)

  • *args – additional args that would need to be passed to the individual forward function (call)

  • **kwargs – additional kwargs that would need to be passed to the individual forward function (call)

Returns: a float representing the individual’s fitness