infer-actively / pymdp

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

Fix assertion when whether `num_controls` is consistent with actions enumerated in policy space #118

Closed conorheins closed 1 year ago

conorheins commented 1 year ago

In line 149 of agent.py, this assertion statement is used:

assert all([n_c == max_action for (n_c, max_action) in zip(self.num_controls, list(np.max(all_policies, axis =0)+1))]), "Maximum number of actions is not consistent with `num_controls`"

But sometimes certain actions will not be allowed (they will be pruned / absent in policies) and thus even when taking the maximum across all policies, you won't see the maximum action taken within a given control factor.

Therefore, @tverbele suggests to change this to

assert all([n_c >= max_action for (n_c, max_action) in zip(self.num_controls, list(np.max(all_policies, axis =0)+1))]), "Maximum number of actions is not consistent with `num_controls`"