aepsych.plotting¶
aepsych.plotting module¶
- aepsych.plotting.plot_predict_1d(x, prediction, ax=None, pred_lower=None, pred_upper=None, shaded_kwargs=None, **kwargs)[source]¶
Return the ax with the model predictions plotted in place as a 1D line plot. Usually plots the predictions in the posterior space or the probability space.
- Parameters:
x (Iterable[float]) – The values where the model was evaluated, assumed to be ordered from lb to ub.
prediction (Iterable[float]) – The values of the predictions at every point it was evaluated, assumed to be the same order as x.
ax (Axes, optional) – The Matplotlib axes to plot onto. If not set, an axes is made and returned.
post_lower (Iterable[float], optional) – The lower part of the shaded region around the prediction line, both post_lower/post_upper must be set to plot the band.
post_upper (Iterable[float], optional) – The upper part of the shaded region around the prediction line, both post_lower/post_upper must be set to plot the band.
shaded_kwargs (Dict[Any, Any], optional) – Kwargs to pass to the ax.fill_between() call to modify the shaded regions, defaults to None.
**kwargs – Extra kwargs passed to the ax.plot() call, not passed to the plotting functions in charge of shaded regions.
pred_lower (Optional[Iterable[float]]) –
pred_upper (Optional[Iterable[float]]) –
- Returns:
- The input axes with the prediction plotted onto it. Note that plotting is
done in-place.
- Return type:
Axes
- aepsych.plotting.plot_points_1d(x, y, ax=None, pred_x=None, pred_y=None, point_size=5.0, cmap_colors=['r', 'b'], label_points=True, legend_loc='best', **kwargs)[source]¶
Return the ax with the points plotted based on x and y in a 1D plot. If pred_x/pred_y is not set, these are plotted as marks at the bottom of the plot, otherwise, each point is plotted as close as possible to the line defined by the prediction values (pred_x/pred_y). Usually use alongside plot_predict_1d().
- Parameters:
x (Iterable[Union[float, Iterable[float]]]) – The (n, 1) or (n, d, 2) points to plot. The 3D case will be considered a pairwise plot.
y (Iterable[float]) – The (n, 1) responses to plot.
ax (Axes, optional) – The Matplotlib axes to plot onto. If not set, an axes is made and returned.
pred_x (Iterable[float], optional) – The points where the model was evaluated, used to position each point as close as possible to the line. If not set, the points are plotted as marks at the bottom of the plot.
pred_y (Iterable[float], optional) – The model outputs at each point in pred_x, used to position each point as close as possible to the line. If not set, the points are plotted as marks at the bottom of the plot.
point_size (float) – The size of each plotted point, defaults to 5.0.
cmap_colors (List[ColorType]) – A list of colors to map the point colors to from min to max of y. At least 2 colors are needed, but more colors will allow customizing intermediate colors. Defaults to [“r”, “b”].
label_points (bool) – Add a way to identify the value of the points, whether as a legend for cases there are 6 or less unique responses or a colorbar for 7 or more unique responses. Defaults to True.
legend_loc (str) – If a legend is added, where should it be placed.
**kwargs – Extra kwargs passed to the ax.plot() call, note that every point is plotted with an individual call so these kwargs must be applicable to single points.
- Returns:
- The input axes with the points plotted onto it. Note that plotting is done
in-place.
- Return type:
Axes
- aepsych.plotting.plot_predict_2d(prediction, lb, ub, ax=None, vmin=None, vmax=None, edge_multiplier=0.0, colorbar=True, **kwargs)[source]¶
Return the ax with the model predictions plotted in-place as a 2D heatmap. Usually used to plot the model outputs in posterior space or probability space.
- Parameters:
prediction (Iterable[Iterable[float]]) – A 2D array of the predictions, assumes it was a square parameter grid where each cell was evaluated by the model.
lb (Iterable[float]) – The lower bound of the two parameters being plotted.
ub (Iterable[float]) – The upper bound of the two parameters being plotted.
ax (Axes, optional) – The Matplotlib axes to plot onto. If not set, an axes is made and returned.
vmin (float, optional) – The minimum value of the predictions, if not set, it will be the minimum of prediction.
vmax (float, optional) – The maximum of the predictions, if not set, it will be the maximum of prediction.
edge_multiplier (float) – How much to extend the plot extents beyond the parameter bounds (lb, ub), the plot extends beyond the bounds by the absolute difference multiplied by the edge_multiplier. Setting this to 0 will not extend the edge, any postive value will plot beyond the bounds, negative will plot less than the bounds. Used when you do not want the edges of the heatmap to be right at the parameter boundaries, especially useful if many points are at parameter boundaries. Defaults to 0.
colorbar (bool) – Whether to add a colorbar (with bounds of [vmin, vmax]) to the parent figure of the Axes, defaults to True.
**kwargs – Extra kwargs passed to the ax.imshow() call that creates the heatmap.
- Returns:
- The input axes with the predictions plotted onto it. Note that the plotting
is done in-place.
- Return type:
Axes
- aepsych.plotting.plot_points_2d(x, y, point_size=5.0, ax=None, axis=None, slice_vals=None, slice_gradient=1.0, cmap_colors=['r', 'b'], label_points=True, legend_loc='best', **kwargs)[source]¶
Return the axes with the points defined by the parameters (x) and the outcomes (y) plotted in-place. If the inputs are from an experiment with stimuli per trial, a line is drawn between both. Usually used alongside plot_predict_2d().
- Parameters:
x (Iterable[Iterable[float]]) – The (n, d, 2) or (n, d) data points to plot. Each point is a different trial.
y (Iterable[float]) – The (n, 1) responses given each set of datapoints. Each value is the response to a given trial.
ax (Axes, optional) – The Matplotlib axes to plot onto. If not set, an axes is made and returned.
point_size (float) – The size of the points, defaults to 5.
axis (List[int], optional) – If the dimensionality d is higher than 2, which two dimensions should the points be positioned with.
slice_vals (Iterable[float]) – If the dimensionality d is higher than 2, where was the other dimensions sliced at. This is used to determine the size/alpha gradient of the points based on how close each point is to the slice. If not set, the points will not change size/alpha based on slice distance. The Euclidean distance (s) of each point is calculated and converted to a multipler by exp(-c * s), where c is the slice_gradient. The multipler is applied to the point_size and the alpha (transparency) of the points.
slice_gradient (float) – The rate at which the multiplier decreases as a function of the distance between a point and the slice. Defaults to 1.
cmap_colors (List[ColorType]) – A list of colors to map the point colors to from min to max of y. At least 2 colors are needed, but more colors will allow customizing intermediate colors. Defaults to [“r”, “b”].
label_points (bool) – Add a way to identify the value of the points, whether as a legend for cases there are 6 or less unique responses or a colorbar for 7 or more unique responses. Defaults to True.
legend_loc (str) – If a legend is added, where should it be placed.
**kwargs – Extra kwargs passed to the ax.plot() call, note that every point is plotted with an individual call so these kwargs must be applicable to single points.
- Returns:
The axes with the points plotted in-place.
- Return type:
Axes
- aepsych.plotting.plot_contours(prediction, lb, ub, ax=None, levels=None, edge_multiplier=0, color='white', labels=False, linestyles='solid', **kwargs)[source]¶
Plot contour lines at the levels onto the axes based on the model predictions with extents defined by lb and ub. Assumes that you’re plotting ontop of a heatmap of those predictions given the same extents.
- Parameters:
prediction (Iterable[Iterable[float]]) – A 2D array of the predictions, assumes it was a square parameter grid where each cell was evaluated by the model.
lb (Iterable[float]) – The lower bound of the two parameters being plotted.
ub (Iterable[float]) – The upper bound of the two parameters being plotted.
ax (Axes, optional) – The Matplotlib axes to plot onto. If not set, an axes is made and returned.
levels (Iterable[float], optional) – A sequence of values to plot the contours given the predictions. If not set, a contour will be plotted at each integer.
edge_multiplier (float) – How much to extend the plot extents beyond the parameter bounds (lb, ub), the plot extends beyond the bounds by the absolute difference multiplied by the edge_multiplier. Setting this to 0 will not extend the edge, any postive value will plot beyond the bounds, negative will plot less than the bounds. Used when you do not want the edges of the heatmap to be right at the parameter boundaries, especially useful if many points are at parameter boundaries. Defaults to 0.
color (ColorType) – What colors the contours should be, defaults to white.
labels (bool) – Whether or not to label the contours.
linestyles (linestyle_str, optional) – How should the contour lines be styled, defaults to “solid”. Options are “solid”, “dashsed”, “dashdot”, “dotted”, can be set to None to default to the Matplotlib default.
**kwargs – Extra keyword arguments to pass to the ax.contour() call that plots the contours.
- Returns:
The axes with the points plotted in-place.
- Return type:
Axes
- aepsych.plotting.facet_slices(prediction, plotted_axes, lb, ub, nrows, ncols, plot_size, **kwargs)[source]¶
Sets up a set of subplots to plot either a 3D or a 4D space where two dimensions are plotted and the other dimensions are sliced over the subplots.
- Parameters:
prediction (Union[torch.Tensor, np.ndarray]) – The model predictions cube to slice, in a 3D parameter space, it would be a 3D array, in a 4D parameter space it would be a 4D array.
plotted_axes (List[int]) – The two parameter indices that will be plotted, the other parameters will be sliced over subplots.
lb (Iterable[Float]) – The lower bound of the parameter space.
ub (Iterable[Float]) – The upper bound of the parameter space.
nrows (int) – How many rows to plot, which will also be how many slices there are of the first sliced dimension.
ncols (int) – How many columns to plot, which will also be how many slices there are of the second sliced dimesion.
plot_size (float) – The width of each individual square plot in inches.
**kwargs – Kwargs passed to the plt.subplots() call.
- Returns:
A Matplotlib figure of all of the subplots. np.ndarray[Axes]: 2D object array of each subplot. np.ndarray[torch.Tensor]: 2D object array of tensors representing the values of the sliced
dimensions for each subplot.
- np.ndarray[torch.Tensor]: 2D object array of tensors representing the sliced predictions for
each subplot.
- Return type:
Figure
- aepsych.plotting.plot_strat(strat, ax=None, true_testfun=None, cred_level=0.95, target_level=0.75, xlabel=None, ylabel=None, yes_label='Yes trial', no_label='No trial', flipx=False, logx=False, gridsize=30, title='', save_path=None, show=True, include_legend=True, include_colorbar=True)[source]¶
Creates a plot of a strategy, showing participants responses on each trial, the estimated response function and threshold, and optionally a ground truth response threshold.
- Parameters:
strat (Strategy) – Strategy object to be plotted. Must have a dimensionality of 2 or less.
ax (plt.Axes, optional) – Matplotlib axis to plot on (if None, creates a new axis). Default: None.
true_testfun (Callable, optional) – Ground truth response function. Should take a n_samples x n_parameters tensor as input and produce the response probability at each sample as output. Default: None.
cred_level (float) – Percentage of posterior mass around the mean to be shaded. Default: 0.95.
target_level (float, optional) – Response probability to estimate the threshold of. Default: 0.75.
xlabel (str, optional) – Label of the x-axis. Default: “Context (abstract)”.
ylabel (str, optional) – Label of the y-axis (if None, defaults to “Response Probability” for 1-d plots or “Intensity (Abstract)” for 2-d plots). Default: None.
yes_label (str) – Label of trials with response of 1. Default: “Yes trial”.
no_label (str) – Label of trials with response of 0. Default: “No trial”.
flipx (bool) –
- Whether the values of the x-axis should be flipped such that the min becomes the max and vice
versa.
(Only valid for 2-d plots.) Default: False.
logx (bool) – Whether the x-axis should be log-transformed. (Only valid for 2-d plots.) Default: False.
gridsize (int) – The number of points to sample each dimension at. Default: 30.
title (str) – Title of the plot. Default: ‘’.
save_path (str, optional) – File name to save the plot to. Default: None.
show (bool) – Whether the plot should be shown in an interactive window. Default: True.
include_legend (bool) – Whether to include the legend in the figure. Default: True.
include_colorbar (bool) – Whether to include the colorbar indicating the probability of “Yes” trials. Default: True.
- Return type:
None
- aepsych.plotting.plot_strat_3d(strat, parnames=None, outcome_label='Yes Trial', slice_dim=0, slice_vals=5, contour_levels=None, probability_space=False, gridsize=30, extent_multiplier=None, save_path=None, show=True)[source]¶
Creates a plot of a 2d slice of a 3D strategy, showing the estimated model or probability response and contours :param strat: Strategy object to be plotted. Must have a dimensionality of 3. :type strat: Strategy :param parnames: list of the parameter names. If None, defaults to [“x1”, “x2”, “x3”]. :type parnames: List[str], optional :param outcome_label: The label of the outcome variable :type outcome_label: str :param slice_dim: dimension to slice on. Default: 0. :type slice_dim: int :param slice_vals: values to take slices; OR number of values to take even slices from. Default: 5. :type slice_vals: Union[List[float], int] :param contour_levels: List contour values to plot. Default: None. If true, all integer levels. :type contour_levels: Union[Iterable[float], bool], optional :param probability_space: Whether to plot probability. Default: False :type probability_space: bool :param gridsize: The number of points to sample each dimension at. Default: 30. :type gridsize: int :param extent_multiplier: multipliers for each of the dimensions when plotting. If None, defaults to [1, 1, 1]. :type extent_multiplier: List[float], optional :param save_path: File name to save the plot to. Default: None. :type save_path: str, optional :param show: Whether the plot should be shown in an interactive window. Default: True. :type show: bool
- Parameters:
strat (Strategy) –
parnames (Optional[List[str]]) –
outcome_label (str) –
slice_dim (int) –
slice_vals (Union[List[float], int]) –
contour_levels (Optional[Union[Iterable[float], bool]]) –
probability_space (bool) –
gridsize (int) –
extent_multiplier (Optional[List[float]]) –
save_path (Optional[str]) –
show (bool) –
- Return type:
None
- aepsych.plotting.plot_slice(ax, strat, parnames, slice_dim, slice_val, vmin, vmax, gridsize=30, contour_levels=None, lse=False, extent_multiplier=None)[source]¶
Creates a plot of a 2d slice of a 3D strategy, showing the estimated model or probability response and contours :param ax: Matplotlib axis to plot on :type ax: plt.Axes :param start: Strategy object to be plotted. Must have a dimensionality of 3. :type start: Strategy :param parnames: list of the parameter names. :type parnames: List[str] :param slice_dim: dimension to slice on. :type slice_dim: int :param slice_val: value to take the slice along that dimension. :type slice_val: int :param vmin: global model minimum to use for plotting. :type vmin: float :param vmax: global model maximum to use for plotting. :type vmax: float :param gridsize: The number of points to sample each dimension at. Default: 30. :type gridsize: int :param contour_levels: Contours to plot. Default: None :type contour_levels: Sized, optional :param lse: Whether to plot probability. Default: False :type lse: bool :param extent_multiplier: multipliers for each of the dimensions when plotting. Default:None :type extent_multiplier: List, optional
- Returns:
The axis object with the plot.
- Return type:
AxesImage
- Parameters:
ax (Axes) –
strat (Strategy) –
parnames (List[str]) –
slice_dim (int) –
slice_val (int) –
vmin (float) –
vmax (float) –
gridsize (int) –
contour_levels (Optional[Sized]) –
lse (bool) –
extent_multiplier (Optional[List]) –