Simulating choices¶
Often we will want to create simulated data containing choices made based on the values learned by a particular model.
In [1]:
Copied!
from behavioural_modelling.utils import choice_from_action_p
import jax
import numpy as np
import jax.numpy as jnp
from behavioural_modelling.utils import choice_from_action_p
import jax
import numpy as np
import jax.numpy as jnp
Example of generating choices based on choice probabilities¶
We can use the choice_from_action_p function to generate choices based on the action probabilities output by a model.
As this is built using JAX, it requires a random key to be passed in. This can be generated using the jax.random.PRNGKey function.
In [2]:
Copied!
key = jax.random.PRNGKey(0)
key = jax.random.PRNGKey(0)
WARNING:jax._src.lib.xla_bridge:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
We can then generate some action probabilities.
In [3]:
Copied!
rng = np.random.default_rng(12345)
# Generate random probabilities
probs = rng.uniform(size=(40, 100, 3))
rng = np.random.default_rng(12345)
# Generate random probabilities
probs = rng.uniform(size=(40, 100, 3))
And generate choices.
In [8]:
Copied!
choices = choice_from_action_p(key, probs)
print(choices)
choices = choice_from_action_p(key, probs)
print(choices)
[[2 1 2 ... 2 1 2] [1 0 1 ... 1 1 1] [1 2 1 ... 1 1 2] ... [2 1 1 ... 1 1 1] [0 1 1 ... 1 2 1] [1 2 1 ... 1 0 2]]