Bardo.Examples.Benchmarks.Dpb (Bardo v0.1.0)

View Source

Double Pole Balancing (DPB) benchmark for neuroevolution algorithms.

This module provides functionality for running and testing the Double Pole Balancing benchmark problem, a common benchmark for testing the efficacy of neural network controllers evolved through neuroevolution.

The benchmark consists of balancing a double pole system attached to a cart that can move horizontally back and forth. The cart must balance two poles of different lengths by applying a horizontal force to keep them upright.

Two versions of the benchmark are available:

  1. DPB With Damping - Velocities are provided to the agent
  2. DPB Without Damping - A harder task where velocities are not provided

This module provides functionality for both versions, and includes features for:

  • Running a complete evolutionary experiment with the DPB benchmark
  • Testing evolved controllers
  • Visualizing the behavior of the controllers

Summary

Functions

configure_with_damping(id, population_size \\ 100, iterations \\ 50, max_steps \\ 100_000)

@spec configure_with_damping(atom(), pos_integer(), pos_integer(), pos_integer()) ::
  map()

Creates a configuration for a DPB experiment with damping.

Parameters

  • id - Identifier for this experiment
  • population_size - Number of individuals per generation (default: 100)
  • iterations - Maximum number of generations to evolve (default: 50)
  • max_steps - Maximum simulation steps in fitness evaluation (default: 100000)

Returns

  • Map with experiment configuration

configure_without_damping(id, population_size \\ 100, iterations \\ 50, max_steps \\ 100_000)

@spec configure_without_damping(atom(), pos_integer(), pos_integer(), pos_integer()) ::
  map()

Creates a configuration for a DPB experiment without damping.

Parameters

  • id - Identifier for this experiment
  • population_size - Number of individuals per generation (default: 100)
  • iterations - Maximum number of generations to evolve (default: 50)
  • max_steps - Maximum simulation steps in fitness evaluation (default: 100000)

Returns

  • Map with experiment configuration

run_with_damping(experiment_id, population_size, generations, max_steps \\ 1000, visualize \\ false)

@spec run_with_damping(atom(), pos_integer(), pos_integer(), pos_integer(), boolean()) ::
  :ok | {:error, term()}

Run the Double Pole Balancing benchmark with damping forces.

This runs the simpler variant of DPB where velocities are provided to the neural network. This variant is helpful for verifying that the system works as expected before moving to more difficult versions.

Parameters

  • experiment_id - Identifier for this experiment
  • population_size - Number of individuals per generation
  • generations - Maximum number of generations to evolve
  • max_steps - Maximum simulation steps in fitness evaluation (default: 1000)
  • visualize - Whether to visualize best agent after evolution (default: false)

Returns

  • :ok - Experiment started successfully
  • {:error, reason} - If there was an error starting the experiment

run_without_damping(experiment_id, population_size, generations, max_steps \\ 1000, visualize \\ false)

@spec run_without_damping(
  atom(),
  pos_integer(),
  pos_integer(),
  pos_integer(),
  boolean()
) ::
  :ok | {:error, term()}

Run the Double Pole Balancing benchmark without damping forces.

This runs the harder variant of DPB where velocities are not provided to the neural network. The agent must approximate the velocities through the use of recurrent connections.

Parameters

  • experiment_id - Identifier for this experiment
  • population_size - Number of individuals per generation
  • generations - Maximum number of generations to evolve
  • max_steps - Maximum simulation steps in fitness evaluation (default: 1000)
  • visualize - Whether to visualize best agent after evolution (default: false)

Returns

  • :ok - Experiment started successfully
  • {:error, reason} - If there was an error starting the experiment

test_best_solution(experiment_id, max_steps \\ 100_000, visualize \\ false)

@spec test_best_solution(atom() | binary(), pos_integer(), boolean()) ::
  map() | {:error, any()}

Test the best solution from an experiment.

This function loads the best genotype from a completed experiment and tests it by running a simulation with the neural network controller.

Parameters

  • experiment_id - The ID of the experiment to test
  • max_steps - Maximum steps to run the simulation (default: 100000)
  • visualize - Whether to visualize the run (default: false)

Returns

  • Map of test results if successful
  • {:error, reason} - If there was an error during testing

Returns results of the test run.