infer-actively / pymdp

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

A matrix stub bug #39

Closed conorheins closed 2 years ago

conorheins commented 2 years ago

Hi, Will this new method fix the error I get with A-Matrix and B-Matrix examples?


AssertionError Traceback (most recent call last)

in ----> 1 A = utils.convert_A_stub_to_ndarray(A_stub, model_labels) ~\pymdp\core\utils.py in convert_A_stub_to_ndarray(A_stub, model_labels) 490 for g, modality_name in enumerate(model_labels['observations'].keys()): 491 A[g] = A_stub.loc[modality_name].to_numpy().reshape(num_obs[g], *num_states) --> 492 assert (A[g].sum(axis=0) == 1.0).all(), 'A matrix not normalized! Check your initialization....\n' 493 494 return A AssertionError: A matrix not normalized! Check your initialization.... or unrelated? Thanks _Originally posted by @osaaso3 in https://github.com/infer-actively/pymdp/issues/26#issuecomment-876492249_
conorheins commented 2 years ago

Just a reference to the comment in #26 . Has been fixed

conorheins commented 2 years ago

Hi @osasso3, I fixed this in the latest merge to main - basically, there were some missing arguments to read_A_matrix due to a recent change in the argument structure of that function. I also tried to make the code more clear, that if you choose to create your own A matrix in excel, you have to first write the empty 'stub' to your local storage, and then fill it out (using e.g. MS Excel), and then load it back in. There's also an option of loading in a pre-loaded A matrix (stored in my_a_matrix.xlsx), and finally there's the option to just create the A matrix directly in Python (using indexing operations in pandas).