Controllers#

Available controllers

class digital_experiments.controllers.GridSearch(**dimensions: Iterable)#

Controller that suggests experiments based on an exhaustive grid search

Parameters:

dimensions (dict[str, Iterable]) – a mapping from parameter names to sequences of values

Example

from digital_experiments import experiment
from digital_experiments.controllers import GridSearch

@experiment
def example(a, b):
    return (2 * a - 1) * b

GridSearch(a=[0, 1], b=range(3)).control(example, n=6)
class digital_experiments.controllers.RandomSearch(**dimensions: Sequence | RVS)#

Controller that suggests experiments based on a random search

Parameters:

dimensions (dict[str, Sequence | RVS]) – a mapping from parameter names to random dimensions. A random dimension can be a sequence of values, a scipy.stats distribution or any object with an rvs method

Example

from digital_experiments import experiment
from digital_experiments.controllers import RandomSearch
from scipy.stats import uniform

@experiment
def example(a, b):
    return (2 * a - 1) * b

RandomSearch(a=uniform(-1, 1), b=[1, 2, 3]).control(example, n=10)

Implementing your own controller#

class digital_experiments.controllers.Controller#

Abstract base class for experiment controllers.

A controller is responsible for:

  • suggesting experiments to run next

  • running them

Subclasses must override the suggest() method.

abstract suggest(experiment: Experiment) dict[str, Any] | None#

Suggest a configuration for the next experiment to run.

Parameters:

experiment (Experiment) – The experiment to suggest a configuration for

Returns:

The suggested configuration, or None if no further experiments are required.

Return type:

dict[str, Any] | None

control(experiment: Experiment, n: int = 1, **overloads) None#

Run an experiment using this controller.

Parameters:
  • experiment (Experiment) – The experiment to run

  • n (int) – The number of experiments to run. Defaults to 1.

  • overloads (dict[str, Any]) – A dictionary of additional keyword arguments to pass to each experiment.