aepsych.utils

aepsych.utils module

aepsych.utils.make_scaled_sobol(lb, ub, size, seed=None)[source]

Create a scaled Sobol grid

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

  • ub (torch.Tensor) – Upper bounds

  • size (int) – Number of points to generate

  • seed (int, optional) – Random seed. Defaults to None.

Returns:

Scaled Sobol grid

Return type:

torch.Tensor

aepsych.utils.promote_0d(x)[source]

Ensure x is iterable.

Parameters:

x (Any) – Input that might not be iterable

Returns:

Either x unchanged or x in a list ([x]).

Return type:

Any

aepsych.utils.dim_grid(lower, upper, gridsize=30, slice_dims=None)[source]

Create a grid Create a grid based on lower, upper, and dim. Parameters

Parameters:
  • lower (int) – lower bound.

  • upper (int) – upper bound.

  • gridsize (int) – size for grid. Defaults to 30.

  • slice_dims (Mapping[int, float], optional) – values to use for slicing axes, as an {index:value} dict. Defaults to None.

Returns:

Tensor of grid points.

Return type:

torch.Tensor

aepsych.utils.interpolate_monotonic(x, y, z, min_x=- inf, max_x=inf)[source]

Interpolate a monotonic function

Parameters:
  • x (Union[torch.Tensor, np.ndarray]) – x values.

  • y (Union[torch.Tensor, np.ndarray]) – y values.

  • z (Union[torch.Tensor, np.ndarray, float]) – z values.

  • min_x (Union[torch.Tensor, np.ndarray, float]) – Minimum x value. Defaults to -np.inf.

  • max_x (Union[torch.Tensor, np.ndarray, float]) – Maximum x value. Defaults to np.inf.

Returns:

Interpolated value.

Return type:

Any

aepsych.utils.get_lse_interval(model, mono_grid, target_level, grid_lb, grid_ub, cred_level=None, mono_dim=- 1, n_samps=500, lb=- inf, ub=inf, gridsize=30, **kwargs)[source]

Get the level set estimate interval

Parameters:
  • model (GPyTorchModel) – Model to use for sampling.

  • mono_grid (Union[torch.Tensor, np.ndarray]) – Monotonic grid.

  • target_level (float) – Target level.

  • grid_lb (torch.Tensor) – The lower bound of the grid to sample from to calculate LSE.

  • grid_ub (torch.Tensor) – The upper bound of the grid to sample from to calculate LSE.

  • cred_level (float, optional) – Credibility level. Defaults to None.

  • mono_dim (int) – Monotonic dimension. Defaults to -1.

  • n_samps (int) – Number of samples. Defaults to 500.

  • lb (float) – Theoreticaly true lower bound for the parameter. Defaults to -float(“inf”).

  • ub (float) – Theoretical true uppper bound for the parameters. Defaults to float(“inf”).

  • gridsize (int) – Grid size. Defaults to 30.

Returns:

Level set estimate interval.

Return type:

Union[Tuple[torch.Tensor, torch.Tensor, torch.Tensor], torch.Tensor]

aepsych.utils.get_lse_contour(post_mean, mono_grid, level, mono_dim=- 1, lb=- inf, ub=inf)[source]

Get the level set estimate contour

Parameters:
  • post_mean (torch.Tensor) – Posterior mean.

  • mono_grid (Union[torch.Tensor, np.ndarray]) – Monotonic grid.

  • level (float) – Level.

  • mono_dim (int) – Monotonic dimension. Defaults to -1.

  • lb (float) – Lower bound. Defaults to -np.inf.

  • ub (float) – Upper bound. Defaults to np.inf.

Returns:

Level set estimate contour.

Return type:

torch.Tensor

aepsych.utils.get_jnd_1d(post_mean, mono_grid, df=1, mono_dim=- 1, lb=- inf, ub=inf)[source]

Get the just noticeable difference for a 1D function

Parameters:
  • post_mean (torch.Tensor) – Posterior mean.

  • mono_grid (torch.Tensor) – Monotonic grid.

  • df (int) – Degrees of freedom. Defaults to 1.

  • mono_dim (int) – Monotonic dimension. Defaults to -1.

  • lb (Union[torch.Tensor, float]) – Lower bound. Defaults to -float(“inf”).

  • ub (Union[torch.Tensor, float]) – Upper bound. Defaults to float(“inf”).

Returns:

Just noticeable difference.

Return type:

torch.Tensor

aepsych.utils.get_jnd_multid(post_mean, mono_grid, df=1, mono_dim=- 1, lb=- inf, ub=inf)[source]

Get the just noticeable difference for a multidimensional function

Parameters:
  • post_mean (torch.Tensor) – Posterior mean.

  • mono_grid (torch.Tensor) – Monotonic grid.

  • df (int) – Degrees of freedom. Defaults to 1.

  • mono_dim (int) – Monotonic dimension. Defaults to -1.

  • lb (Union[torch.Tensor, float]) – Lower bound. Defaults to -float(“inf”).

  • ub (Union[torch.Tensor, float]) – Upper bound. Defaults to float(“inf”).

Returns:

Just noticeable difference.

Return type:

torch.Tensor

aepsych.utils.get_bounds(config)[source]

Return the bounds for all parameters in config. Note that these bounds are likely to be in the raw parameter space and any transformations that may affect these bounds are unaccounted for. If the transformed bounds are needed, use the transforms.transform_options() function to first transform the config and manually get the transformed bounds from the ub/lb options in the common section.

Parameters:

config (Config) – The config to find the bounds from.

Returns:

A [2, d] tensor with the lower and upper bounds for each

parameter.

Return type:

torch.Tensor

aepsych.utils.get_optimizer_options(config, name)[source]

Return the optimizer options for the model to pass to the SciPy L-BFGS-B optimizer. Only the somewhat useful ones for AEPsych are searched for: maxcor, ftol, gtol, maxfun, maxiter, maxls. See docs for details: https://docs.scipy.org/doc/scipy/reference/optimize.minimize-lbfgsb.html#optimize-minimize-lbfgsb

Parameters:
  • config (Config) – Config to search for options.

  • name (str) – Model name to look for options for.

Returns:

Dictionary of options to pass to SciPy’s minimize, assuming the

method is L-BFGS-B.

Return type:

Dict[str, Any]

aepsych.utils.get_dims(config)[source]

Return the number of dimensions in the parameter space. This accounts for any transforms that may modify the the parameter space for the model (e.g., Fixed parameters will not be included).

Parameters:

config (Config) – The config to look for the number of dimensions.

Returns:

The number of dimensions in the search space.

Return type:

int