sample_action

Contents

sample_action#

hybrid_aif.planning.sample_action(
key,
q_pi_or_marginals,
policies=None,
num_controls=None,
mode='marginal',
selection='stochastic',
alpha=None,
)[source]#

Select an action from a policy posterior: a control level per control node, or a vector.

After pymdp’s control.sample_action and control.sample_policy (pymdp/control.py): the marginal and policy modes, deterministic and stochastic selection, and the alpha precision on log-probabilities follow pymdp’s Agent.sample_action; the alpha-sharpened action marginal is SPM’s action selection in spm_MDP_VB_X.

mode="marginal" acts from the first-step action marginals (given as a tuple, or computed from q_pi, which then requires policies and num_controls); mode="policy" from a policy drawn from q_pi. selection="deterministic" takes the argmax (ties: lowest index; key unused). alpha sharpens marginal logits before stochastic selection. Over continuous actions only mode="policy" is defined; it returns the sequence’s first step, dtype preserved, and "marginal" raises. A mixed policy set, a ControlStep with leading axes (P, policy_len), takes mode="policy" and returns the drawn policy’s first step as a ControlStep with one entry per control node.

selection is the action’s realisation: "stochastic" corresponds to the realisation sample (a draw) and "deterministic" to mode (the argmax); a mixed strategy (stats) is not emitted here. Design: nesting-and-coupling.md N3.