From 3218ebf2a38d4483e7af7dc2bd7f8697344ffd75 Mon Sep 17 00:00:00 2001 From: Jonathan Ehrenreich Laursen <112482257+Jonathan7773@users.noreply.github.com> Date: Sun, 6 Jul 2025 11:06:03 +0200 Subject: [PATCH 1/6] fix to pomdp action function --- src/pomdp/POMDP.jl | 109 +++++++++------------------------------------ 1 file changed, 21 insertions(+), 88 deletions(-) diff --git a/src/pomdp/POMDP.jl b/src/pomdp/POMDP.jl index d4086d8..a53be11 100644 --- a/src/pomdp/POMDP.jl +++ b/src/pomdp/POMDP.jl @@ -26,10 +26,10 @@ function action_pomdp!(agent::Agent, obs::Vector{Int64}) action_distribution = Vector{Distributions.Categorical}(undef, n_factors) #If there was a previous action - if !ismissing(agent.states["action"]) + if !isempty(agent.substruct.states.action) #Extract it - previous_action = agent.states["action"] + previous_action = agent.states.action # If it is not a vector, make it one if !(previous_action isa Vector) @@ -45,19 +45,18 @@ function action_pomdp!(agent::Agent, obs::Vector{Int64}) infer_states!(agent.substruct, obs) # If action is empty, update D vectors - if ismissing(agent.states["action"]) && !isnothing(agent.substruct.parameters.pD) - update_D!(agent.substruct) + if isempty(agent.substruct.states.action) && !isnothing(agent.substruct.parameters.pD) + update_D(agent.substruct) end # If learning of the B matrix is enabled and agent has a previous action - if !ismissing(agent.states["action"]) && !isnothing(agent.substruct.parameters.pB) - # Update Transition Matrix - update_B!(agent.substruct) + if !isempty(agent.substruct.states.action) && !isnothing(agent.substruct.parameters.pB) + update_B(agent.substruct) end # If learning of the A matrix is enabled if !isnothing(agent.substruct.parameters.pA) - update_A!(agent.substruct) + update_A(agent.substruct) end # Run policy inference @@ -83,18 +82,18 @@ function action_pomdp!(agent::Agent, obs::Tuple{Vararg{Int}}) obs = collect(obs) ### Get parameters - alpha = agent.substruct.parameters["alpha"] - n_factors = length(agent.substruct.settings["num_controls"]) + alpha = agent.substruct.parameters.alpha + n_factors = length(agent.substruct.settings._n_controls) # Initialize empty arrays for action distribution per factor action_p = Vector{Any}(undef, n_factors) action_distribution = Vector{Distributions.Categorical}(undef, n_factors) - #If there was a previous action - if !ismissing(agent.states["action"]) + #If there was a previous action + if !isempty(agent.substruct.states.action) #Extract it - previous_action = agent.states["action"] + previous_action = agent.states.action # If it is not a vector, make it one if !(previous_action isa Vector) @@ -111,24 +110,19 @@ function action_pomdp!(agent::Agent, obs::Tuple{Vararg{Int}}) infer_states!(agent.substruct, obs) # If action is empty and pD is not nothing, update D vectors - if ismissing(agent.states["action"]) && agent.substruct.pD !== nothing - qs_t1 = get_history(agent.substruct)["posterior_states"][1] - update_D!(agent.substruct, qs_t1) + if isempty(agent.substruct.states.action) && !isnothing(agent.substruct.parameters.pD) + + update_D(agent.substruct) end # If learning of the B matrix is enabled and agent has a previous action - if !ismissing(agent.states["action"]) && agent.substruct.pB !== nothing - - # Get the posterior over states from the previous time step - states_posterior = get_history(agent.substruct)["posterior_states"][end-1] - - # Update Transition Matrix - update_B!(agent.substruct, states_posterior) + if !isempty(agent.substruct.states.action) && !isnothing(agent.substruct.parameters.pB) + update_B(agent.substruct) end # If learning of the A matrix is enabled - if agent.substruct.pA !== nothing - update_A!(agent.substruct, obs) + if !isnothing(agent.substruct.parameters.pA) + update_A(agent.substruct) end # Run policy inference @@ -163,26 +157,17 @@ function action_pomdp!(aif::POMDPActiveInference, obs::Vector{Int64}) infer_states!(aif, obs) # If action is empty, update D vectors - if isempty(get_states(aif, "action")) && !isnothing(aif.parameters.pD) - # qs_t1 = get_history(aif, "qs_current")[end] - # update_D(aif, qs_t1) + if isempty(aif.states.action) && !isnothing(aif.parameters.pD) update_D(aif) end # If learning of the B matrix is enabled and agent has a previous action - if !isempty(get_states(aif, "action")) && !isnothing(aif.parameters.pB) - - # Get the posterior over states from the previous time step - # states_posterior = get_history(aif, "qs_current")[end-1] - - # Update Transition Matrix - # update_B(aif, states_posterior) + if !isempty(aif.states.action) && !isnothing(aif.parameters.pB) update_B(aif) end # If learning of the A matrix is enabled if !isnothing(aif.parameters.pA) - # update_A(aif, obs) update_A(aif) end @@ -202,58 +187,6 @@ function action_pomdp!(aif::POMDPActiveInference, obs::Vector{Int64}) return n_factors == 1 ? action_distribution[1] : action_distribution end -# function action_pomdp!(aif::AIF, obs::Vector{Int64}) - -# ### Get parameters -# alpha = aif.parameters["alpha"] -# n_factors = length(aif.settings["num_controls"]) - -# # Initialize empty arrays for action distribution per factor -# action_p = Vector{Any}(undef, n_factors) -# action_distribution = Vector{Distributions.Categorical}(undef, n_factors) - -# ### Infer states & policies - -# # Run state inference -# infer_states!(aif, obs) - -# # If action is empty, update D vectors -# if ismissing(get_states(aif)["action"]) && aif.pD !== nothing -# qs_t1 = get_history(aif)["posterior_states"][1] -# update_D!(aif, qs_t1) -# end - -# # If learning of the B matrix is enabled and agent has a previous action -# if !ismissing(get_states(aif)["action"]) && aif.pB !== nothing - -# # Get the posterior over states from the previous time step -# states_posterior = get_history(aif)["posterior_states"][end-1] - -# # Update Transition Matrix -# update_B!(aif, states_posterior) -# end - -# # If learning of the A matrix is enabled -# if aif.pA !== nothing -# update_A!(aif, obs) -# end - -# # Run policy inference -# infer_policies!(aif) - - -# ### Retrieve log marginal probabilities of actions -# log_action_marginals = get_log_action_marginals(aif) - -# ### Pass action marginals through softmax function to get action probabilities -# for factor in 1:n_factors -# action_p[factor] = softmax(log_action_marginals[factor] * alpha, dims=1) -# action_distribution[factor] = Distributions.Categorical(action_p[factor]) -# end - -# return n_factors == 1 ? action_distribution[1] : action_distribution -# end - function action_pomdp!(agent::Agent, obs::Int64) action_pomdp!(agent::Agent, [obs]) end \ No newline at end of file From 21216affd7f3ac20e28a4f7a11d68e13bc202f4f Mon Sep 17 00:00:00 2001 From: Peter Thestrup Waade Date: Wed, 19 Nov 2025 13:13:35 +0100 Subject: [PATCH 2/6] Add contributors section to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 03072ac..eb0beaa 100644 --- a/README.md +++ b/README.md @@ -97,3 +97,9 @@ infer_policies!(aif) sample_action!(aif) ```` + +## Contributors +- [@jonathan7773](https://github.com/Jonathan7773) – Developer +- [@samuelnehrer02](https://github.com/samuelnehrer02) – Developer +- [@PTWaade](https://github.com/PTWaade) – Developer +- [@John-Boik](https://github.com/John-Boik) – Developer From 0dc93026290be02b779c8941eca01fd063c3b936 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 02:10:05 +0000 Subject: [PATCH 3/6] :arrow_up: Bump actions/checkout from 4 to 6 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/CI_full.yml | 2 +- .github/workflows/CI_small.yml | 2 +- .github/workflows/Documenter.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI_full.yml b/.github/workflows/CI_full.yml index c939a76..e377baf 100644 --- a/.github/workflows/CI_full.yml +++ b/.github/workflows/CI_full.yml @@ -30,7 +30,7 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} diff --git a/.github/workflows/CI_small.yml b/.github/workflows/CI_small.yml index 870c007..33f161d 100644 --- a/.github/workflows/CI_small.yml +++ b/.github/workflows/CI_small.yml @@ -29,7 +29,7 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index f123d88..62ab588 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -19,7 +19,7 @@ jobs: name: Documentation runs-on: macOS-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: julia-actions/setup-julia@v2 with: version: '1' From 922b0b7720747f0fd397fd635a1da359862cd177 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Mar 2026 02:07:33 +0000 Subject: [PATCH 4/6] :arrow_up: Bump julia-actions/cache from 2 to 3 Bumps [julia-actions/cache](https://github.com/julia-actions/cache) from 2 to 3. - [Release notes](https://github.com/julia-actions/cache/releases) - [Commits](https://github.com/julia-actions/cache/compare/v2...v3) --- updated-dependencies: - dependency-name: julia-actions/cache dependency-version: '3' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/CI_full.yml | 2 +- .github/workflows/CI_small.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI_full.yml b/.github/workflows/CI_full.yml index e377baf..ff32730 100644 --- a/.github/workflows/CI_full.yml +++ b/.github/workflows/CI_full.yml @@ -35,7 +35,7 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v2 + - uses: julia-actions/cache@v3 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 diff --git a/.github/workflows/CI_small.yml b/.github/workflows/CI_small.yml index 33f161d..2375680 100644 --- a/.github/workflows/CI_small.yml +++ b/.github/workflows/CI_small.yml @@ -34,7 +34,7 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: julia-actions/cache@v2 + - uses: julia-actions/cache@v3 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 From 657345f6da1f80d0fcaf0ad40d9ad1b9fb38ba24 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 02:08:21 +0000 Subject: [PATCH 5/6] :arrow_up: Bump codecov/codecov-action from 5 to 6 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5 to 6. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v5...v6) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/CI_full.yml | 2 +- .github/workflows/CI_small.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI_full.yml b/.github/workflows/CI_full.yml index e377baf..f5a8c6e 100644 --- a/.github/workflows/CI_full.yml +++ b/.github/workflows/CI_full.yml @@ -39,7 +39,7 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v5 + - uses: codecov/codecov-action@v6 with: token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info diff --git a/.github/workflows/CI_small.yml b/.github/workflows/CI_small.yml index 33f161d..e3b76e5 100644 --- a/.github/workflows/CI_small.yml +++ b/.github/workflows/CI_small.yml @@ -38,7 +38,7 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v5 + - uses: codecov/codecov-action@v6 with: token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info \ No newline at end of file From c3de543533eab7b089d25ee2fbee1b734cfc2a2e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 02:08:29 +0000 Subject: [PATCH 6/6] :arrow_up: Bump julia-actions/setup-julia from 2 to 3 Bumps [julia-actions/setup-julia](https://github.com/julia-actions/setup-julia) from 2 to 3. - [Release notes](https://github.com/julia-actions/setup-julia/releases) - [Commits](https://github.com/julia-actions/setup-julia/compare/v2...v3) --- updated-dependencies: - dependency-name: julia-actions/setup-julia dependency-version: '3' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/CI_full.yml | 2 +- .github/workflows/CI_small.yml | 2 +- .github/workflows/Documenter.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI_full.yml b/.github/workflows/CI_full.yml index e377baf..c788c72 100644 --- a/.github/workflows/CI_full.yml +++ b/.github/workflows/CI_full.yml @@ -31,7 +31,7 @@ jobs: - x64 steps: - uses: actions/checkout@v6 - - uses: julia-actions/setup-julia@v2 + - uses: julia-actions/setup-julia@v3 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} diff --git a/.github/workflows/CI_small.yml b/.github/workflows/CI_small.yml index 33f161d..5bcb13b 100644 --- a/.github/workflows/CI_small.yml +++ b/.github/workflows/CI_small.yml @@ -30,7 +30,7 @@ jobs: - x64 steps: - uses: actions/checkout@v6 - - uses: julia-actions/setup-julia@v2 + - uses: julia-actions/setup-julia@v3 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index 62ab588..a72959f 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -20,7 +20,7 @@ jobs: runs-on: macOS-latest steps: - uses: actions/checkout@v6 - - uses: julia-actions/setup-julia@v2 + - uses: julia-actions/setup-julia@v3 with: version: '1' - uses: julia-actions/julia-buildpkg@v1