Beta Models
beta_models
Functions:
-
average_betas–Average two beta distributions, weighted by W.
-
beta_mean_var–Calculate mean and variance of a beta distribution.
-
generalised_beta_mean_var–Calculate mean and variance of a generalised beta distribution.
-
leaky_beta_update–Update estimates using the (asymmetric) leaky beta model.
-
multiply_beta_by_scalar–Multiply a beta distribution by a scalar.
-
sum_betas–Sum two beta distributions. This uses an approximation described in the following paper:
average_betas
average_betas(beta1_params: ArrayLike, beta2_params: ArrayLike, W1: float = 0.5, W2: float = 0.5) -> ndarray
Average two beta distributions, weighted by W.
Parameters:
-
(beta1_paramsArrayLike) –Parameters of first beta distribution.
-
(beta2_paramsArrayLike) –Parameters of second beta distribution.
Returns:
-
ndarray–jnp.ndarray: New beta distribution parameters.
Source code in behavioural_modelling/learning/beta_models.py
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 | |
beta_mean_var
beta_mean_var(beta_params: ArrayLike) -> Tuple[ArrayLike, ArrayLike]
Calculate mean and variance of a beta distribution.
Parameters:
-
(beta_paramsArrayLike) –Parameters of the beta distribution. Of shape (n_options, 2),
Returns:
-
Tuple[ArrayLike, ArrayLike]–tuple[ArrayLike, ArrayLike]: Mean and variance of the beta distribution.
Source code in behavioural_modelling/learning/beta_models.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
generalised_beta_mean_var
Calculate mean and variance of a generalised beta distribution.
Parameters:
-
(alphafloat) –Alpha parameter of the beta distribution.
-
(betafloat) –Beta parameter of the beta distribution.
-
(afloat) –Lower bound of the beta distribution.
-
(bfloat) –Upper bound of the beta distribution.
Returns:
Source code in behavioural_modelling/learning/beta_models.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
leaky_beta_update
leaky_beta_update(estimate: ArrayLike, choices: ArrayLike, outcome: float, tau_p: float, tau_n: float, decay: float, update: int = 1, increment: int = 1) -> ndarray
Update estimates using the (asymmetric) leaky beta model.
This models represents the probability of the outcome associated with each option (e.g., bandits in a bandit task) as a beta distribution.
Values are updated according to the following equations:
This function also allows for updating to be turned off (i.e., the estimate is not updated at all) and for incrementing to be turned off (i.e., decay is applied, but the outcome is not registered).
Only chosen options incremented, but all options decay.
Parameters:
-
(estimateArrayLike) –Alpha and beta estimates for this trial. Should be an array of shape (n, 2) where
-
(choicesArrayLike) –Choices made in this trial. Should have as many entries as there are options, with
-
(outcomesfloat) –Observed outcome for this trial.
-
(tau_pfloat) –Update rate for outcomes equal to 1.
-
(tau_nfloat) –Update rate for outcomes equal to 0.
-
(decayfloat) –Decay rate.
-
(updateint, default:1) –Whether to update the estimate. If 0, the estimate is not updated (i.e., no decay is
-
(incrementint, default:1) –Whether to increment the estimate. If 0, the estimate is not incremented but
Returns: jnp.ndarray: Updated value estimates for this trial, with one entry per bandit.
Source code in behavioural_modelling/learning/beta_models.py
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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
multiply_beta_by_scalar
multiply_beta_by_scalar(beta_params: ArrayLike, scalar: float) -> ndarray
Multiply a beta distribution by a scalar.
Parameters:
-
(beta_paramsArrayLike) –Parameters of beta distribution. Of shape (n_options, 2),
-
(scalarfloat) –Scalar to multiply beta distribution by.
Returns:
-
ndarray–jnp.ndarray: New beta distribution parameters, specified as [a, b].
Source code in behavioural_modelling/learning/beta_models.py
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 81 | |
sum_betas
sum_betas(beta1_params: ArrayLike, beta2_params: ArrayLike) -> ndarray
Sum two beta distributions. This uses an approximation described in the following paper:
Pham, T.G., Turkkan, N., 1994. Reliability of a standby system with beta-distributed component lives. IEEE Transactions on Reliability 43, 71–75. https://doi.org/10.1109/24.285114
Where the first two moments of the summed distribution are calculated as follows:
We then calculate the parameters of the new beta distribution using the following equations:
This function assumes that the means of the two beta distributions sum to <=1. If this is not the case, the output will be invalid.
Parameters:
-
(beta1_paramsArrayLike) –Parameters of the first beta distribution. Of shape (n_options, 2),
-
(beta2_paramsArrayLike) –Parameters of second beta distribution.
Returns:
-
ndarray–jnp.ndarray: New beta distribution parameters.
Source code in behavioural_modelling/learning/beta_models.py
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 | |