EFEasVI: Tmaze - very simple, standard example for Active Inference#72
EFEasVI: Tmaze - very simple, standard example for Active Inference#72skoghoern wants to merge 28 commits intoReactiveBayes:mainfrom
Conversation
|
Thanks @skoghoern ! I'll check the PR in the coming weeks after some conference deadlines. I assigned myself such that it shows up on my to-do list. Appreciate the effort and the interest and I'll definitely get back to you! |
|
Sure, sounds good! Good luck with the deadlines - i'll keep an eye out for your comments later on:) |
Add a tutorial recreation of the paper A Message Passing Realization of Expected Free Energy Minimization by Wouter Nuijten, Mykola Lukashchuk, Thijs van de Laar and Bert de Vries
|
I've checked the example locally, nice work! The CI failure is unrelated and can be ignored |
|
Hey @skoghoern , Thanks for putting this together! It's great to see an accessible example of the paper However, there are some significant deviations from the paper's core logic. Specifically, replacing dynamic factor nodes with static pre-computations is a move I'm not sure is 100% correct. I’ve noted the key areas that need to be reverted/fixed below: 1. Notation ConsistencyTo stay consistent with the paper and RxInfer standards, let's standardize:
2. The "Invariance" Shortcut & Static PriorsIn your
3. Ambiguity LogicTechnically, you could precompute the ambiguity term as long as the observation model ( Overall, this is a massive contribution to the |
… and examples.rxinfer.com
Changes: - Polished tone in the first cell of the notebook - Changed the mathematical notation for random variables from = to ~ - Created a new version of the graph, with all the proper equality nodes and an attention to the data that is given in the first iteration.
…rch truncation specification
…e_RxInfer_Examples_B Cross reference rx infer examples b
the just in-memory check should be enough
|
Hi @wouterwln ,
Mathematical Proofs for Static Precomputation(Using bold for random variables/distributions and lowercase for specific samples/states)
Theorem: If the transition matrix Proof: By definition, if the transition matrix is invariant to the previous state, the inner Shannon entropy evaluates to a constant Substituting By the law of total probability, Because
A similar logic applies to the epistemic prior over states: In the T-maze, we factorize the hidden states into a time-varying agent location and a time-invariant reward location: This resolves into: Given the agent knows the observation matrix
graph TD
Root[Knowledge of Parameters] --> Known[Agent knows parameters]
Root --> Learn[Agent needs to learn parameters]
Known --> Invariant[Matrices are invariant to previous state/other state <br><i>e.g., T-maze</i>]
Known --> Dependent[Dependent on previous state <br><i>e.g., Stochastic maze</i>]
e.g. we could position this examle as a "simplified starting point" and then link to meditans #73 more comprehensive, general tutorial for advanced use cases? Obv. this is just a suggestion given my limited understanding, and either way i’m happy to update the tutorial in whatever direction you feel serves the project best. p.s.: on a related note, have you considered the possibility of adapting GraphPPL/RxInfer/RMP to allow passing beliefs from previous VMP iterations? Technically, since these are stored (when including keep_each(), it could be a powerful addition. |
…_ReloadBug fix: on make docs-serve, page was constantly refreshing. Now not.
Add EFE Minimization via Message Passing notebook
|
Hi @wouterwln , I’ve now submitted a major overhaul of the tutorial! I included two versions of the t-maze: one as you requested and another one where i explored a different implementation: While looking into generalizing the implementation, I noticed your marginal storage approach works perfectly for the current scenarios. However, not being 100% sure whether there could be edge cases/models (e.g. hierarchical loopy graphs) in which the outgoing messages from the custom factor nodes could be triggered several times during one VMP iteration itself, where marginals might have been updated inbetween the computations of the rules, making convergence even more difficult. To explore this, I implemented your original version in the main file and added a second file that handles epistemic prior updates via the callback system. Key Changes in the Callback Approach
Observations on ConvergenceI ran some tests to see where the agent breaks (fails to explore the cue field) and found some interesting quirks depending on the
My hypothesis is that the shorter the loop, the higher the risk of VMP convergence issues disrupting exploration. Let me know what you think and we can decide on one version to upload. |
|
[EDIT]: just saw that the difference was only due, because i hadnt updated the local EFEasVFE repo with the correct state-transition tensor (corrected in this commit). Using the same state-transition tensor the both implementations are equal in their results. (adding free_energy analysis we can see a pattern that free energy plateaus when VMP_iter == Planning horizon for H=[3,6]: where we can observe that the posterior for the first action u[1] of the planning horizon changes from South=3 ("correct"), to North=1 ("wrong") beginning in the VMP_iteration==H. e.g. here again for planning horizon H=6 the posteriors of u[1] for several VMP iterations:
i will try to analyze the reason further in the upcoming days. would be very interesting to find out why this happens, whether this is a general pattern, and if it might generalize to other loopy models as well. |
|
Hey @skoghoern, thanks for the revision! The example now looks really cool and really really good, many thanks! One question: There seem to be 2 notebooks in your repo: |
|
hi wouter, thanks for the feedback, it was also much inspired by @meditans :)
no, only one of them is necessary. |
…Inference_-_Planning_as_Message_Passing_callback.ipynb
|
Decided to use original implementation, as it is more intuitive and doesnt need future adaption since callbacks are being currently changed (deleted |
adapted the code from @wouterwln in EFEasVFE to make a first example of the standard tmaze.
(epistemic priors are currently overengineered with helper functions but maybe allow users to test, whether they can reuse it for their own transition matrices.
interestingly even though the helper functions return fixed vectors to the categorical, using the p-vector directly in the standard definition doesnt lead to the same results (there seems to be an interference with the message-passing-optimization)).
running make.jl for the new folder returned: