infer-actively / pymdp

A Python implementation of active inference for Markov Decision Processes
MIT License
420 stars 83 forks source link

Error when using `stochastic` mode action sampling in case that `num_controls[f] = 1` #86

Closed conorheins closed 1 year ago

conorheins commented 1 year ago

Bug found by @SamGijsen:

Running "stochastic" action selection throws an error when using the current version. I believe it's because actions are sampled even if num_controls=1, in which case utils.sample() attempts to squeeze an array of size 1. Reverting to deterministic selection if num_controls==1 has fixed this for me. (control.sample_action() line 565 if action_selection == 'deterministic' or num_controls[factor_i]==1:) Happy to submit a PR if that's useful, otherwise I believe it's just this line of code.

Originally posted by @SamGijsen in https://github.com/infer-actively/pymdp/issues/82#issuecomment-1173743945

conorheins commented 1 year ago

This has now been fixed, please see https://github.com/infer-actively/pymdp/pull/90

Will close upon release of 0.0.6