Problem

Problem

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

Bases: ABC

Abstract Base Class used to define problem definitions.

It is in charge of fitness evaluation for the problem to solve.

abstract 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

evaluate_population(population_manager: PopulationManager, use_freshness: bool = True, update_manager: bool = True, train: bool = True, *args, **kwargs) dict[slice(<class 'int'>, <class 'float'>, None)][source]

Default behavior for evaluating the entire population, to update if it is wanted to introduce parallelization or other behaviors.

Any instance of evaluate_population should always: - update the population fitness in the population manager by calling population_manager.set_individual_fitness. - If freshness is being used, then it should set the population freshness in the population manager by calling population_manager.set_freshness.

Parameters:
  • population_manager

  • use_freshness

  • update_manager

Returns: the fitness dictionary of the population

Problem_factory

class gaggle.problem.problem_factory.ProblemFactory[source]

Bases: object

Factory that generates pre-existing available Problems. ProblemFactory.problems stores said Problems as a dictionary. It stores problems as 4 types: classification, rl, leap and custom. Each is a key that holds a dictionary of available problems/datasets/environments.

classmethod convert_and_register_leap_problem(problem_name: str, leap_problem: Callable, *args, **kwargs)[source]

Shortcut method that both converts the leap problem to our Problem class and registers it

Parameters:
  • problem_name

  • leap_problem

  • *args

  • **kwargs

Returns:

classmethod from_problem_args(problem_args: ProblemArgs = None, sys_args: SysArgs = None) Problem[source]

Initializes the requested Problem from the dictionary of available Problems.

This is done by using the attributes problem_args.problem_type and problem_args.problem_name as the lookup keys to ProblemFactory.problems.

Parameters:
  • problem_args

  • sys_args

Returns:

The initialized Problem requested.

problems = {'classification': {'CIFAR10': <class 'gaggle.problem.dataset.base_datasets.cifar10.CIFAR10'>, 'MNIST': <class 'gaggle.problem.dataset.base_datasets.mnist.MNIST'>}, 'custom': {}, 'leap': {}, 'rl': {'cartpole': <gaggle.problem.environment.environment_factory.GymWrapper object>}}
classmethod register_problem(problem_type: str, problem_name: str, problem: Callable, *args, **kwargs)[source]

Register a new problem to the factory of pre-existing available Problems. Said problem has to be a problem that is registrable. ProblemFactory.registrable_problems stores the list of problem types that are allowed to be registrables. For the other types, please check their respective documentation to see how to register them (for classification: ClassificationProblem and DatasetFactory, for rl: RLProblem and EnvironmentFactory).

If custom arguments need to be passed at initialization time of the Problem (for example when ProblemFactory.from_problem_args is called), they can also be passed as *args and **kwargs and they will be used to initialize the problem. :param problem_type: The key to ProblemFactory.problems. :param problem_name: The new problem’s name as a str. :param problem: The uninitialized problem. :param *args: The args that need to be passed to the problem at initialization time :param **kwargs: the kwargs that need to be passed to the problem at initialization time.

Returns:

registrable_problems = ['leap', 'custom']