diff --git a/.github/workflows/CI_full.yml b/.github/workflows/CI_full.yml index c939a76..0653497 100644 --- a/.github/workflows/CI_full.yml +++ b/.github/workflows/CI_full.yml @@ -30,16 +30,16 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 + - uses: actions/checkout@v6 + - uses: julia-actions/setup-julia@v3 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 - - 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 870c007..5c3dfcf 100644 --- a/.github/workflows/CI_small.yml +++ b/.github/workflows/CI_small.yml @@ -29,16 +29,16 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 + - uses: actions/checkout@v6 + - uses: julia-actions/setup-julia@v3 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 - - uses: codecov/codecov-action@v5 + - uses: codecov/codecov-action@v6 with: token: ${{ secrets.CODECOV_TOKEN }} files: lcov.info \ No newline at end of file diff --git a/.github/workflows/Documenter.yml b/.github/workflows/Documenter.yml index f123d88..a72959f 100644 --- a/.github/workflows/Documenter.yml +++ b/.github/workflows/Documenter.yml @@ -19,8 +19,8 @@ jobs: name: Documentation runs-on: macOS-latest steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 + - uses: actions/checkout@v6 + - uses: julia-actions/setup-julia@v3 with: version: '1' - uses: julia-actions/julia-buildpkg@v1 diff --git a/README.md b/README.md index 5fda33a..6b29746 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 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