aepsych.generators

Submodules

aepsych.generators.base module

class aepsych.generators.base.AcqArgProtocol(*args, **kwargs)[source]

Bases: Protocol

classmethod from_config(config)[source]
Parameters:

config (Config) –

Return type:

Any

class aepsych.generators.base.AEPsychGenerator[source]

Bases: ABC, Generic[AEPsychModelType]

Abstract base class for generators, which are responsible for generating new points to sample.

baseline_requiring_acqfs = [botorch.acquisition.qNoisyExpectedImprovement, botorch.acquisition.NoisyExpectedImprovement, botorch.acquisition.qLogNoisyExpectedImprovement, botorch.acquisition.LogNoisyExpectedImprovement]
stimuli_per_trial = 1
max_asks: Optional[int] = None
acqf: botorch.acquisition.AcquisitionFunction
acqf_kwargs: Dict[str, Any]
abstract gen(num_points, model)[source]
Parameters:
  • num_points (int) –

  • model (AEPsychModelType) –

Return type:

Tensor

abstract classmethod from_config(config)[source]
Parameters:

config (Config) –

Return type:

Any

aepsych.generators.epsilon_greedy_generator module

class aepsych.generators.epsilon_greedy_generator.EpsilonGreedyGenerator(lb, ub, subgenerator, epsilon=0.1)[source]

Bases: AEPsychGenerator

Initialize EpsilonGreedyGenerator.

Parameters:
  • lb (torch.Tensor) – Lower bounds for the optimization.

  • ub (torch.Tensor) – Upper bounds for the optimization.

  • subgenerator (AEPsychGenerator) – The generator to use when not exploiting.

  • epsilon (float) – The probability of exploration. Defaults to 0.1.

classmethod from_config(config)[source]

Create an EpsilonGreedyGenerator from a Config object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

The generator.

Return type:

EpsilonGreedyGenerator

gen(num_points, model)[source]

Query next point(s) to run by sampling from the subgenerator with probability 1-epsilon, and randomly otherwise.

Parameters:
  • num_points (int) – Number of points to query.

  • model (ModelProtocol) – Model to use for generating points.

Return type:

Tensor

aepsych.generators.manual_generator module

class aepsych.generators.manual_generator.ManualGenerator(lb, ub, points, dim=None, shuffle=True, seed=None)[source]

Bases: AEPsychGenerator

Generator that generates points from a predefined list.

Iniatialize ManualGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param points: The points that will be generated. :type points: torch.Tensor :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional :param shuffle: Whether or not to shuffle the order of the points. True by default. :type shuffle: bool :param seed: Random seed. Defaults to None. :type seed: int, optional

Parameters:
  • lb (Tensor) –

  • ub (Tensor) –

  • points (Tensor) –

  • dim (Optional[int]) –

  • shuffle (bool) –

  • seed (Optional[int]) –

gen(num_points=1, model=None)[source]

Query next point(s) to run by quasi-randomly sampling the parameter space. :param num_points: Number of points to query. Defaults to 1. :type num_points: int :param model: Model to use for generating points. Not used in this generator. Defaults to None. :type model: AEPsychMixin, optional

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config, name=None)[source]
Parameters:
  • config (Config) –

  • name (Optional[str]) –

Return type:

ManualGenerator

classmethod get_config_options(config, name=None)[source]

Extracts and processes configuration options for initializing the ManualGenerator.

Parameters:
  • config (Config) – Configuration object containing initialization parameters.

  • name (str, optional) – Name of the configuration section for this generator. Defaults to the class name.

Returns:

A dictionary of options, including:

”lb” (torch.Tensor): Lower bounds of each parameter. “ub” (torch.Tensor): Upper bounds of each parameter. “dim” (int, optional): Dimensionality of the parameter space. “points” (torch.Tensor): Predefined points to generate. “shuffle” (bool): Whether to shuffle the order of points. “seed” (int, optional): Random seed for shuffling.

Return type:

Dict

property finished: bool
class aepsych.generators.manual_generator.SampleAroundPointsGenerator(lb, ub, window, points, samples_per_point, dim=None, shuffle=True, seed=None)[source]

Bases: ManualGenerator

Generator that samples in a window around reference points in a predefined list.

Iniatialize SampleAroundPointsGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param window: How far away to sample from the reference point along each dimension. :type window: torch.Tensor :param points: The points that will be generated. :type points: torch.Tensor :param samples_per_point: How many samples around each point to take. :type samples_per_point: int :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional :param shuffle: Whether or not to shuffle the order of the points. True by default. :type shuffle: bool :param seed: Random seed. :type seed: int, optional

Parameters:
  • lb (Tensor) –

  • ub (Tensor) –

  • window (Tensor) –

  • points (Tensor) –

  • samples_per_point (int) –

  • dim (Optional[int]) –

  • shuffle (bool) –

  • seed (Optional[int]) –

classmethod get_config_options(config, name=None)[source]

Extracts and processes configuration options for initializing the SampleAroundPointsGenerator.

Parameters:
  • config (Config) – Configuration object containing initialization parameters.

  • name (str, optional) – Name of the configuration section for this generator. Defaults to the class name.

Returns:

A dictionary of options, including:
  • ”lb” (torch.Tensor): Lower bounds of each parameter.

  • ”ub” (torch.Tensor): Upper bounds of each parameter.

  • ”dim” (int, optional): Dimensionality of the parameter space.

  • ”points” (torch.Tensor): Predefined reference points.

  • ”shuffle” (bool): Whether to shuffle the order of points.

  • ”seed” (int, optional): Random seed for shuffling.

  • ”window” (torch.Tensor): Sampling range around each reference point along each dimension.

  • ”samples_per_point” (int): Number of samples to generate around each reference point.

Return type:

Dict

aepsych.generators.monotonic_rejection_generator module

aepsych.generators.monotonic_rejection_generator.default_loss_constraint_fun(loss, candidates)[source]

Identity transform for constrained optimization.

This simply returns loss as-is. Write your own versions of this for constrained optimization by e.g. interior point method.

Parameters:
  • loss (torch.Tensor) – Value of loss at candidate points.

  • candidates (torch.Tensor) – Location of candidate points. Unused.

Returns:

New loss (unchanged)

Return type:

torch.Tensor

class aepsych.generators.monotonic_rejection_generator.MonotonicRejectionGenerator(acqf, lb, ub, acqf_kwargs=None, model_gen_options=None, explore_features=None)[source]

Bases: AEPsychGenerator[MonotonicRejectionGP]

Generator specifically to be used with MonotonicRejectionGP, which generates new points to sample by minimizing an acquisition function through stochastic gradient descent.

Initialize MonotonicRejectionGenerator. :param acqf: Acquisition function to use. :type acqf: AcquisitionFunction :param lb: Lower bounds for the optimization. :type lb: torch.Tensor :param ub: Upper bounds for the optimization. :type ub: torch.Tensor :param acqf_kwargs: Extra arguments to

pass to acquisition function. Defaults to None.

Parameters:
  • model_gen_options (Dict[str, Any], optional) – Dictionary with options for generating candidate, such as SGD parameters. See code for all options and their defaults. Defaults to None.

  • explore_features (Sequence[int], optional) – List of features that will be selected randomly and then fixed for acquisition fn optimization. Defaults to None.

  • acqf (botorch.acquisition.AcquisitionFunction) –

  • lb (Tensor) –

  • ub (Tensor) –

  • acqf_kwargs (Dict[str, object], optional) –

gen(num_points, model)[source]

Query next point(s) to run by optimizing the acquisition function. :param num_points: Number of points to query. Currently only supports 1. :type num_points: int :param model: Fitted model of the data. :type model: AEPsychMixin

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of MonotonicRejectionGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator class with specified acquisition function, gradient descent options, exploration features, and acquisition function arguments.

Return type:

MonotonicRejectionGenerator

aepsych.generators.monotonic_thompson_sampler_generator module

class aepsych.generators.monotonic_thompson_sampler_generator.MonotonicThompsonSamplerGenerator(n_samples, n_rejection_samples, num_ts_points, target_value, objective, explore_features=None)[source]

Bases: AEPsychGenerator[MonotonicRejectionGP]

A generator specifically to be used with MonotonicRejectionGP that uses a Thompson-sampling-style approach for gen, rather than using an acquisition function. We draw a posterior sample at a large number of points, and then choose the point that is closest to the target value.

Initialize MonotonicMCAcquisition

Parameters:
  • n_samples (int) – Number of samples to select point from.

  • num_rejection_samples (int) – Number of rejection samples to draw.

  • num_ts_points (int) – Number of points at which to sample.

  • target_value (float) – target value that is being looked for

  • objective (MCAcquisitionObjective) – Objective transform of the GP output before evaluating the acquisition. Defaults to identity transform.

  • explore_features (List[Type[int]], optional) – List of features that will be selected randomly and then fixed for acquisition fn optimization. Defaults to None.

  • n_rejection_samples (int) –

gen(num_points, model)[source]

Query next point(s) to run by optimizing the acquisition function. :param num_points: Number of points to query. current implementation only generates 1 point at a time. :type num_points: int :param model: Fitted model of the data. :type model: MonotonicRejectionGP

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of MonotonicThompsonSamplerGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator class with specified number of samples, rejection samples, Thompson sampling points, target value, objective transformation, and optional exploration features.

Return type:

MonotonicThompsonSamplerGenerator

aepsych.generators.optimize_acqf_generator module

class aepsych.generators.optimize_acqf_generator.OptimizeAcqfGenerator(lb, ub, acqf, acqf_kwargs=None, restarts=10, samps=1000, max_gen_time=None, stimuli_per_trial=1)[source]

Bases: AEPsychGenerator

Generator that chooses points by minimizing an acquisition function.

Initialize OptimizeAcqfGenerator. :param lb: Lower bounds for the optimization. :type lb: torch.Tensor :param ub: Upper bounds for the optimization. :type ub: torch.Tensor :param acqf: Acquisition function to use. :type acqf: AcquisitionFunction :param acqf_kwargs: Extra arguments to

pass to acquisition function. Defaults to no arguments.

Parameters:
  • restarts (int) – Number of restarts for acquisition function optimization. Defaults to 10.

  • samps (int) – Number of samples for quasi-random initialization of the acquisition function optimizer. Defaults to 1000.

  • max_gen_time (float, optional) – Maximum time (in seconds) to optimize the acquisition function. Defaults to None.

  • stimuli_per_trial (int) – Number of stimuli per trial. Defaults to 1.

  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • acqf (botorch.acquisition.AcquisitionFunction) –

  • acqf_kwargs (Dict[str, object], optional) –

baseline_requiring_acqfs = [botorch.acquisition.NoisyExpectedImprovement, botorch.acquisition.LogNoisyExpectedImprovement, botorch.acquisition.qNoisyExpectedImprovement, botorch.acquisition.qLogNoisyExpectedImprovement]
gen(num_points, model, **gen_options)[source]

Query next point(s) to run by optimizing the acquisition function. :param num_points: Number of points to query. :type num_points: int :param model: Fitted model of the data. :type model: ModelProtocol

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of OptimizeAcqfGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of OptimizeAcqfGenerator with specified acquisition function, restart and sample parameters, maximum generation time, and stimuli per trial.

Return type:

OptimizeAcqfGenerator

aepsych.generators.random_generator module

class aepsych.generators.random_generator.RandomGenerator(lb, ub, dim=None)[source]

Bases: AEPsychGenerator

Generator that generates points randomly without an acquisition function.

Iniatialize RandomGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional

Parameters:
  • lb (Tensor) –

  • ub (Tensor) –

  • dim (Optional[int]) –

gen(num_points=1, model=None)[source]

Query next point(s) to run by randomly sampling the parameter space. :param num_points: Number of points to query. Currently, only 1 point can be queried at a time. :type num_points: int :param model: Model to use for generating points. Not used in this generator. :type model: AEPsychMixin, optional

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Create an instance of RandomGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator with specified bounds and dimensionality.

Return type:

RandomGenerator

aepsych.generators.sobol_generator module

class aepsych.generators.sobol_generator.SobolGenerator(lb, ub, dim=None, seed=None, stimuli_per_trial=1)[source]

Bases: AEPsychGenerator

Generator that generates points from the Sobol Sequence.

Iniatialize SobolGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional :param seed: Random seed. :type seed: int, optional :param stimuli_per_trial: Number of stimuli per trial. Defaults to 1. :type stimuli_per_trial: int

Parameters:
  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • dim (Optional[int]) –

  • seed (Optional[int]) –

  • stimuli_per_trial (int) –

gen(num_points=1, model=None)[source]

Query next point(s) to run by quasi-randomly sampling the parameter space. :param num_points: Number of points to query. Defaults to 1. :type num_points: int :param moodel: Model to use for generating points. Not used in this generator. Defaults to None. :type moodel: AEPsychMixin, optional

Returns:

Next set of point(s) to evaluate, [num_points x dim] or [num_points x dim x stimuli_per_trial] if stimuli_per_trial != 1.

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of SobolGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator with specified bounds, dimensionality, random seed, and stimuli per trial.

Return type:

SobolGenerator

Module contents

class aepsych.generators.OptimizeAcqfGenerator(lb, ub, acqf, acqf_kwargs=None, restarts=10, samps=1000, max_gen_time=None, stimuli_per_trial=1)[source]

Bases: AEPsychGenerator

Generator that chooses points by minimizing an acquisition function.

Initialize OptimizeAcqfGenerator. :param lb: Lower bounds for the optimization. :type lb: torch.Tensor :param ub: Upper bounds for the optimization. :type ub: torch.Tensor :param acqf: Acquisition function to use. :type acqf: AcquisitionFunction :param acqf_kwargs: Extra arguments to

pass to acquisition function. Defaults to no arguments.

Parameters:
  • restarts (int) – Number of restarts for acquisition function optimization. Defaults to 10.

  • samps (int) – Number of samples for quasi-random initialization of the acquisition function optimizer. Defaults to 1000.

  • max_gen_time (float, optional) – Maximum time (in seconds) to optimize the acquisition function. Defaults to None.

  • stimuli_per_trial (int) – Number of stimuli per trial. Defaults to 1.

  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • acqf (botorch.acquisition.AcquisitionFunction) –

  • acqf_kwargs (Dict[str, object], optional) –

baseline_requiring_acqfs = [botorch.acquisition.NoisyExpectedImprovement, botorch.acquisition.LogNoisyExpectedImprovement, botorch.acquisition.qNoisyExpectedImprovement, botorch.acquisition.qLogNoisyExpectedImprovement]
acqf: botorch.acquisition.AcquisitionFunction
acqf_kwargs: Dict[str, Any]
gen(num_points, model, **gen_options)[source]

Query next point(s) to run by optimizing the acquisition function. :param num_points: Number of points to query. :type num_points: int :param model: Fitted model of the data. :type model: ModelProtocol

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of OptimizeAcqfGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of OptimizeAcqfGenerator with specified acquisition function, restart and sample parameters, maximum generation time, and stimuli per trial.

Return type:

OptimizeAcqfGenerator

class aepsych.generators.MonotonicRejectionGenerator(acqf, lb, ub, acqf_kwargs=None, model_gen_options=None, explore_features=None)[source]

Bases: AEPsychGenerator[MonotonicRejectionGP]

Generator specifically to be used with MonotonicRejectionGP, which generates new points to sample by minimizing an acquisition function through stochastic gradient descent.

Initialize MonotonicRejectionGenerator. :param acqf: Acquisition function to use. :type acqf: AcquisitionFunction :param lb: Lower bounds for the optimization. :type lb: torch.Tensor :param ub: Upper bounds for the optimization. :type ub: torch.Tensor :param acqf_kwargs: Extra arguments to

pass to acquisition function. Defaults to None.

Parameters:
  • model_gen_options (Dict[str, Any], optional) – Dictionary with options for generating candidate, such as SGD parameters. See code for all options and their defaults. Defaults to None.

  • explore_features (Sequence[int], optional) – List of features that will be selected randomly and then fixed for acquisition fn optimization. Defaults to None.

  • acqf (botorch.acquisition.AcquisitionFunction) –

  • lb (Tensor) –

  • ub (Tensor) –

  • acqf_kwargs (Dict[str, object], optional) –

gen(num_points, model)[source]

Query next point(s) to run by optimizing the acquisition function. :param num_points: Number of points to query. Currently only supports 1. :type num_points: int :param model: Fitted model of the data. :type model: AEPsychMixin

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of MonotonicRejectionGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator class with specified acquisition function, gradient descent options, exploration features, and acquisition function arguments.

Return type:

MonotonicRejectionGenerator

class aepsych.generators.MonotonicThompsonSamplerGenerator(n_samples, n_rejection_samples, num_ts_points, target_value, objective, explore_features=None)[source]

Bases: AEPsychGenerator[MonotonicRejectionGP]

A generator specifically to be used with MonotonicRejectionGP that uses a Thompson-sampling-style approach for gen, rather than using an acquisition function. We draw a posterior sample at a large number of points, and then choose the point that is closest to the target value.

Initialize MonotonicMCAcquisition

Parameters:
  • n_samples (int) – Number of samples to select point from.

  • num_rejection_samples (int) – Number of rejection samples to draw.

  • num_ts_points (int) – Number of points at which to sample.

  • target_value (float) – target value that is being looked for

  • objective (MCAcquisitionObjective) – Objective transform of the GP output before evaluating the acquisition. Defaults to identity transform.

  • explore_features (List[Type[int]], optional) – List of features that will be selected randomly and then fixed for acquisition fn optimization. Defaults to None.

  • n_rejection_samples (int) –

gen(num_points, model)[source]

Query next point(s) to run by optimizing the acquisition function. :param num_points: Number of points to query. current implementation only generates 1 point at a time. :type num_points: int :param model: Fitted model of the data. :type model: MonotonicRejectionGP

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of MonotonicThompsonSamplerGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator class with specified number of samples, rejection samples, Thompson sampling points, target value, objective transformation, and optional exploration features.

Return type:

MonotonicThompsonSamplerGenerator

class aepsych.generators.RandomGenerator(lb, ub, dim=None)[source]

Bases: AEPsychGenerator

Generator that generates points randomly without an acquisition function.

Iniatialize RandomGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional

Parameters:
  • lb (Tensor) –

  • ub (Tensor) –

  • dim (Optional[int]) –

gen(num_points=1, model=None)[source]

Query next point(s) to run by randomly sampling the parameter space. :param num_points: Number of points to query. Currently, only 1 point can be queried at a time. :type num_points: int :param model: Model to use for generating points. Not used in this generator. :type model: AEPsychMixin, optional

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Create an instance of RandomGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator with specified bounds and dimensionality.

Return type:

RandomGenerator

class aepsych.generators.SobolGenerator(lb, ub, dim=None, seed=None, stimuli_per_trial=1)[source]

Bases: AEPsychGenerator

Generator that generates points from the Sobol Sequence.

Iniatialize SobolGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional :param seed: Random seed. :type seed: int, optional :param stimuli_per_trial: Number of stimuli per trial. Defaults to 1. :type stimuli_per_trial: int

Parameters:
  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • dim (Optional[int]) –

  • seed (Optional[int]) –

  • stimuli_per_trial (int) –

gen(num_points=1, model=None)[source]

Query next point(s) to run by quasi-randomly sampling the parameter space. :param num_points: Number of points to query. Defaults to 1. :type num_points: int :param moodel: Model to use for generating points. Not used in this generator. Defaults to None. :type moodel: AEPsychMixin, optional

Returns:

Next set of point(s) to evaluate, [num_points x dim] or [num_points x dim x stimuli_per_trial] if stimuli_per_trial != 1.

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Creates an instance of SobolGenerator from a configuration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator with specified bounds, dimensionality, random seed, and stimuli per trial.

Return type:

SobolGenerator

class aepsych.generators.EpsilonGreedyGenerator(lb, ub, subgenerator, epsilon=0.1)[source]

Bases: AEPsychGenerator

Initialize EpsilonGreedyGenerator.

Parameters:
  • lb (torch.Tensor) – Lower bounds for the optimization.

  • ub (torch.Tensor) – Upper bounds for the optimization.

  • subgenerator (AEPsychGenerator) – The generator to use when not exploiting.

  • epsilon (float) – The probability of exploration. Defaults to 0.1.

classmethod from_config(config)[source]

Create an EpsilonGreedyGenerator from a Config object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

The generator.

Return type:

EpsilonGreedyGenerator

gen(num_points, model)[source]

Query next point(s) to run by sampling from the subgenerator with probability 1-epsilon, and randomly otherwise.

Parameters:
  • num_points (int) – Number of points to query.

  • model (ModelProtocol) – Model to use for generating points.

Return type:

Tensor

class aepsych.generators.ManualGenerator(lb, ub, points, dim=None, shuffle=True, seed=None)[source]

Bases: AEPsychGenerator

Generator that generates points from a predefined list.

Iniatialize ManualGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param points: The points that will be generated. :type points: torch.Tensor :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional :param shuffle: Whether or not to shuffle the order of the points. True by default. :type shuffle: bool :param seed: Random seed. Defaults to None. :type seed: int, optional

Parameters:
  • lb (Tensor) –

  • ub (Tensor) –

  • points (Tensor) –

  • dim (Optional[int]) –

  • shuffle (bool) –

  • seed (Optional[int]) –

gen(num_points=1, model=None)[source]

Query next point(s) to run by quasi-randomly sampling the parameter space. :param num_points: Number of points to query. Defaults to 1. :type num_points: int :param model: Model to use for generating points. Not used in this generator. Defaults to None. :type model: AEPsychMixin, optional

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config, name=None)[source]
Parameters:
  • config (Config) –

  • name (Optional[str]) –

Return type:

ManualGenerator

classmethod get_config_options(config, name=None)[source]

Extracts and processes configuration options for initializing the ManualGenerator.

Parameters:
  • config (Config) – Configuration object containing initialization parameters.

  • name (str, optional) – Name of the configuration section for this generator. Defaults to the class name.

Returns:

A dictionary of options, including:

”lb” (torch.Tensor): Lower bounds of each parameter. “ub” (torch.Tensor): Upper bounds of each parameter. “dim” (int, optional): Dimensionality of the parameter space. “points” (torch.Tensor): Predefined points to generate. “shuffle” (bool): Whether to shuffle the order of points. “seed” (int, optional): Random seed for shuffling.

Return type:

Dict

property finished: bool
class aepsych.generators.SampleAroundPointsGenerator(lb, ub, window, points, samples_per_point, dim=None, shuffle=True, seed=None)[source]

Bases: ManualGenerator

Generator that samples in a window around reference points in a predefined list.

Iniatialize SampleAroundPointsGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param window: How far away to sample from the reference point along each dimension. :type window: torch.Tensor :param points: The points that will be generated. :type points: torch.Tensor :param samples_per_point: How many samples around each point to take. :type samples_per_point: int :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional :param shuffle: Whether or not to shuffle the order of the points. True by default. :type shuffle: bool :param seed: Random seed. :type seed: int, optional

Parameters:
  • lb (Tensor) –

  • ub (Tensor) –

  • window (Tensor) –

  • points (Tensor) –

  • samples_per_point (int) –

  • dim (Optional[int]) –

  • shuffle (bool) –

  • seed (Optional[int]) –

classmethod get_config_options(config, name=None)[source]

Extracts and processes configuration options for initializing the SampleAroundPointsGenerator.

Parameters:
  • config (Config) – Configuration object containing initialization parameters.

  • name (str, optional) – Name of the configuration section for this generator. Defaults to the class name.

Returns:

A dictionary of options, including:
  • ”lb” (torch.Tensor): Lower bounds of each parameter.

  • ”ub” (torch.Tensor): Upper bounds of each parameter.

  • ”dim” (int, optional): Dimensionality of the parameter space.

  • ”points” (torch.Tensor): Predefined reference points.

  • ”shuffle” (bool): Whether to shuffle the order of points.

  • ”seed” (int, optional): Random seed for shuffling.

  • ”window” (torch.Tensor): Sampling range around each reference point along each dimension.

  • ”samples_per_point” (int): Number of samples to generate around each reference point.

Return type:

Dict

class aepsych.generators.PairwiseOptimizeAcqfGenerator(lb, ub, acqf, acqf_kwargs=None, restarts=10, samps=1000, max_gen_time=None, stimuli_per_trial=1)[source]

Bases: OptimizeAcqfGenerator

Deprecated. Use OptimizeAcqfGenerator instead.

Initialize OptimizeAcqfGenerator. :param lb: Lower bounds for the optimization. :type lb: torch.Tensor :param ub: Upper bounds for the optimization. :type ub: torch.Tensor :param acqf: Acquisition function to use. :type acqf: AcquisitionFunction :param acqf_kwargs: Extra arguments to

pass to acquisition function. Defaults to no arguments.

Parameters:
  • restarts (int) – Number of restarts for acquisition function optimization. Defaults to 10.

  • samps (int) – Number of samples for quasi-random initialization of the acquisition function optimizer. Defaults to 1000.

  • max_gen_time (float, optional) – Maximum time (in seconds) to optimize the acquisition function. Defaults to None.

  • stimuli_per_trial (int) – Number of stimuli per trial. Defaults to 1.

  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • acqf (botorch.acquisition.AcquisitionFunction) –

  • acqf_kwargs (Dict[str, object], optional) –

stimuli_per_trial = 2
classmethod from_config(config)[source]

Create an instance of PairwiseOptimizeAcqfGenerator from a configration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of OptimizeAcqfGenerator with specified acquisition function, restart and sample parameters, maximum generation time, and stimuli per trial(two in this case).

Return type:

OptimizeAcqfGenerator

class aepsych.generators.PairwiseSobolGenerator(lb, ub, dim=None, seed=None, stimuli_per_trial=1)[source]

Bases: SobolGenerator

Deprecated. Use SobolGenerator instead.

Iniatialize SobolGenerator. :param lb: Lower bounds of each parameter. :type lb: torch.Tensor :param ub: Upper bounds of each parameter. :type ub: torch.Tensor :param dim: Dimensionality of the parameter space. If None, it is inferred from lb and ub. :type dim: int, optional :param seed: Random seed. :type seed: int, optional :param stimuli_per_trial: Number of stimuli per trial. Defaults to 1. :type stimuli_per_trial: int

Parameters:
  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • dim (Optional[int]) –

  • seed (Optional[int]) –

  • stimuli_per_trial (int) –

stimuli_per_trial = 2
classmethod from_config(config)[source]

Create an instance of PairwiseSobolGenerator from a configration object.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

A configured instance of the generator with specified bounds, dimensionality, random seed, and stimuli per trial(two in this case).

Return type:

SobolGenerator

class aepsych.generators.IntensityAwareSemiPGenerator(lb, ub, acqf, acqf_kwargs=None, restarts=10, samps=1000, max_gen_time=None, stimuli_per_trial=1)[source]

Bases: OptimizeAcqfGenerator

Generator for SemiP. With botorch machinery, in order to optimize acquisition separately over context and intensity, we need two ingredients. 1. An objective that samples from some posterior w.r.t. the context. From the

paper, this is ThresholdBALV and needs the threshold posterior. SemiPThresholdObjective implements this for ThresholdBALV but theoretically this can be any subclass of SemiPObjectiveBase.

  1. A way to do acquisition over context and intensity separately, which is

    provided by this class. We optimize the acquisition function over context dimensions, then conditioned on the optimum we evaluate the intensity at the objective to obtain the intensity value.

We only developed ThresholdBALV that is specific to SemiP, which is what we tested with this generator. It should work with other similar acquisition functions.

Initialize OptimizeAcqfGenerator. :param lb: Lower bounds for the optimization. :type lb: torch.Tensor :param ub: Upper bounds for the optimization. :type ub: torch.Tensor :param acqf: Acquisition function to use. :type acqf: AcquisitionFunction :param acqf_kwargs: Extra arguments to

pass to acquisition function. Defaults to no arguments.

Parameters:
  • restarts (int) – Number of restarts for acquisition function optimization. Defaults to 10.

  • samps (int) – Number of samples for quasi-random initialization of the acquisition function optimizer. Defaults to 1000.

  • max_gen_time (float, optional) – Maximum time (in seconds) to optimize the acquisition function. Defaults to None.

  • stimuli_per_trial (int) – Number of stimuli per trial. Defaults to 1.

  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • acqf (botorch.acquisition.AcquisitionFunction) –

  • acqf_kwargs (Dict[str, object], optional) –

gen(num_points, model, context_objective=<class 'aepsych.acquisition.objective.semi_p.SemiPThresholdObjective'>)[source]

Query next point(s) to run by optimizing the acquisition function for both context and intensity.

Parameters:
  • num_points (int) – Number of points to query.

  • model (SemiParametricGPModel) – Fitted semi-parametric model of the data.

  • context_objective (Type) – The objective function used for context. Defaults to SemiPThresholdObjective.

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

class aepsych.generators.AcqfThompsonSamplerGenerator(lb, ub, acqf, acqf_kwargs=None, samps=1000, stimuli_per_trial=1)[source]

Bases: AEPsychGenerator

Generator that chooses points by minimizing an acquisition function.

Initialize OptimizeAcqfGenerator. :param lb: Lower bounds for the optimization. :type lb: torch.Tensor :param ub: Upper bounds for the optimization. :type ub: torch.Tensor :param acqf: Acquisition function to use. :type acqf: AcquisitionFunction :param acqf_kwargs: Extra arguments to

pass to acquisition function. Defaults to no arguments.

Parameters:
  • samps (int) – Number of samples for quasi-random initialization of the acquisition function optimizer. Defaults to 1000.

  • stimuli_per_trial (int) – Number of stimuli per trial. Defaults to 1.

  • lb (torch.Tensor) –

  • ub (torch.Tensor) –

  • acqf (botorch.acquisition.AcquisitionFunction) –

  • acqf_kwargs (Dict[str, object], optional) –

baseline_requiring_acqfs = [botorch.acquisition.NoisyExpectedImprovement, botorch.acquisition.LogNoisyExpectedImprovement, botorch.acquisition.qNoisyExpectedImprovement, botorch.acquisition.qLogNoisyExpectedImprovement]
gen(num_points, model, **gen_options)[source]

Query next point(s) to run by optimizing the acquisition function. :param num_points: Number of points to query. :type num_points: int :param model: Fitted model of the data. :type model: ModelProtocol

Returns:

Next set of point(s) to evaluate, [num_points x dim].

Return type:

torch.Tensor

Parameters:
classmethod from_config(config)[source]

Initialize AcqfThompsonSamplerGenerator from configuration.

Parameters:

config (Config) – Configuration object containing initialization parameters.

Returns:

The initialized generator.

Return type:

AcqfThompsonSamplerGenerator