Utils¶
Module containing functions that are used across Fitr modules
References¶
[R98b6f8855756-Akam2015] | Akam, T. et al. (2015) Simple Plans or Sophisticated Habits? State, Transition and Learning Interactions in the Two-Step Task. PLoS Comput. Biol. 11, 1–25 |
Module Documentation¶
-
fitr.utils.
action
(x)¶ Selects an action based on state-action values
Parameters: - x : ndarray
Array of action values (scaled by inverse softmax temperature).
Returns: - int
The index corresponding to the selected action
Notes
This function computes the softmax probability for each action in the input array, and subsequently samples from a multinomial distribution parameterized by the results of the softmax computation. Finally, it returns the index where the value is equal to 1 (i.e. which action was selected).
-
fitr.utils.
logsumexp
(x)¶ Numerically stable logsumexp.
Parameters: - x : ndarray(shape=(nactions))
Returns: - float
Notes
The numerically stable log-sum-exp is computed as follows:
\[\max X + \log \sum_X e^{X - \max X}\]
-
fitr.utils.
softmax
(x)¶ Computes numerically stable softmax
Parameters: - x : ndarray(shape=(nactions))
Returns: - ndarray(shape=(nactions))
Softmax probabilities for each action
-
fitr.utils.
trans_UC
(values_U, rng)¶ Transforms parameters from unconstrained to constrained space
Parameters: - values_U : ndarray
Parameter values
- rng : {‘unit’, ‘pos’, ‘half’, ‘all_unc’}
The constrained range of the parameter
Returns: - ndarray(shape=(nparams))
Notes
This code was taken from that published along with [Akam2015].