sweetbean.stimulus.Choice
Bandit
Bases: HtmlChoice
Multi-armed bandit screen built on HtmlChoice.
Displays N colored “slot machine” squares laid out in a grid. Clicking a square
selects that bandit. The grid HTML and the values array are generated from
bandits=[{"color": <css_color>, "value": <number/label>}, ...]. Records the
selected index as choice and its associated value, mirrored to bean_response
and bean_value. Exposes a short post-response window that shows the value of the
chosen bandit.
Source code in sweetbean/stimulus/Choice.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
__init__(duration=None, bandits=None, time_after_response=2000, side_effects=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
int | None
|
Stimulus display time in ms. If None, runs until a bandit is chosen. |
None
|
bandits
|
list
|
List of dicts, each with: - color (str): CSS color to outline the square - value (any): payout/label recorded when the bandit is chosen |
None
|
time_after_response
|
int
|
Extra time in ms after a click for “slot machine” animation. |
2000
|
side_effects
|
dict | None
|
Optional side-effect configuration. |
None
|
Layout & styling: - Squares are arranged in a near-square grid (rows × cols) computed from N. - CSS custom properties are set before the trial: --slotmachine-time, --slotmachine-time-after (both ~ time_after_response/2)
Emits (adds to jsPsych data) — same as HtmlChoice: - choice (int), value (any), bean_response (int), bean_value (any)
Source code in sweetbean/stimulus/Choice.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
HtmlChoice
Bases: _BaseStimulus
Clickable HTML choice screen.
Renders an array of arbitrary HTML elements; a mouse click selects one item.
Records choice (0-based index) and value of the selected item from the
provided lists, and mirrors them to bean_response and bean_value.
Supports an optional post-response delay to allow animations to complete.
Source code in sweetbean/stimulus/Choice.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
__init__(duration=None, html_array=None, values=None, correct_values=None, time_after_response=3000, side_effects=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
int | None
|
Stimulus display time in ms. If None, runs until a choice is made. |
None
|
html_array
|
list
|
List of HTML strings to display as clickable options. Must align 1:1
with |
None
|
values
|
list
|
List of opaque values (numbers/strings/objects) mapped to |
None
|
time_after_response
|
int
|
Extra time in ms after a click before ending the trial (useful for short animations/visual confirmation). |
3000
|
Emits (adds to jsPsych data):
- choice (int): 0-based index of the clicked item
- value (any): the corresponding entry from values
- bean_response (int): copy of choice for downstream consistency
- bean_value (any): copy of value
Notes
len(html_array)should equallen(values). Empty lists are allowed but will yield no clickable options.- This stimulus collects responses via mouse/touch clicks on the provided elements.
Source code in sweetbean/stimulus/Choice.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |