From cbff8470c08e3dc95d99baee4b209aeaa2e82778 Mon Sep 17 00:00:00 2001 From: Tomas Omasta Date: Thu, 13 May 2021 14:36:01 +0200 Subject: [PATCH 1/4] replaced convert methods with initialize_belief --- src/pbvi.jl | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/pbvi.jl b/src/pbvi.jl index 8add4b8..61ec8a7 100644 --- a/src/pbvi.jl +++ b/src/pbvi.jl @@ -35,21 +35,6 @@ end ==(a::AlphaVec, b::AlphaVec) = (a.alpha,a.action) == (b.alpha, b.action) Base.hash(a::AlphaVec, h::UInt) = hash(a.alpha, hash(a.action, h)) -convert(::Type{Array{Float64, 1}}, d::BoolDistribution, pomdp) = [1 - d.p, d.p] -convert(::Type{Array{Float64, 1}}, d::DiscreteUniform, pomdp) = [pdf(d, stateindex(pomdp, s)) for s in states(pomdp)] -convert(::Type{Array{Float64, 1}}, d::SparseCat, pomdp) = d.probs - -convert(::Type{Array{Float64, 1}}, d::InStageDistribution{DiscreteUniform}, m::FixedHorizonPOMDPWrapper) = vec([pdf(d, s) for s in states(m)]) - -function convert(::Type{Array{Float64, 1}}, d::InStageDistribution{BoolDistribution}, m::FixedHorizonPOMDPWrapper) - if stage(d) == 1 - append!([1 - d.d.p[1], d.d.p[1]], zeros(length(states(m)) - 2)) - else - append!(append!(zeros((stage(d) - 1) * length(stage_states(m, 1))), [1 - d.d.p[1], d.d.p[1]]), zeros((horizon(m) - stage(d) + 1) * length(stage_states(m, 1)))) - end -end - - function _argmax(f, X) return X[argmax(map(f, X))] end @@ -197,7 +182,7 @@ function solve(solver::PBVISolver, pomdp::POMDP) Γ = [fill(α_init, length(S)) for a in A] #init belief, if given distribution, convert to vector - init = convert(Array{Float64, 1}, initialstate(pomdp), pomdp) + init = initialize_belief(DiscreteUpdater(pomdp), initialstate(pomdp)).b B = [DiscreteBelief(pomdp, init)] Bs = Set([init]) From 61e470ea451deac9ef3e6636fd792b2a973cf201 Mon Sep 17 00:00:00 2001 From: Tomas Omasta Date: Thu, 13 May 2021 18:57:38 +0200 Subject: [PATCH 2/4] Removed convert tests --- test/runtests.jl | 43 ++----------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 45889a7..a5a9302 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,50 +3,11 @@ using POMDPModels using POMDPs using SARSOP using BeliefUpdaters -using POMDPModelTools: Deterministic -using POMDPSimulators: RolloutSimulator +using POMDPModelTools +using POMDPSimulators using FiniteHorizonPOMDPs - using PointBasedValueIteration -@testset "Convert test" begin - @testset "Infinite Horizon POMDP tests" begin - tigerPOMDP = TigerPOMDP() - babyPOMDP = BabyPOMDP() - minihallwayPOMDP = MiniHallway() - - @test convert(Array{Float64, 1}, initialstate(tigerPOMDP), tigerPOMDP) == [0.5, 0.5] - @test convert(Array{Float64, 1}, initialstate(babyPOMDP), babyPOMDP) == [1., 0.] - @test convert(Array{Float64, 1}, initialstate(minihallwayPOMDP), minihallwayPOMDP) == append!(fill(1/12, 12), zeros(1)) - end - - @testset "Finite Horizon POMDP tests" begin - @testset "Finite Horizon POMDP initial state convert tests" begin - tigerPOMDP = fixhorizon(TigerPOMDP(), 1) - babyPOMDP = fixhorizon(BabyPOMDP(), 1) - minihallwayPOMDP = fixhorizon(MiniHallway(), 1) - - @test convert(Array{Float64, 1}, initialstate(tigerPOMDP), tigerPOMDP) == [0.5, 0.5, 0., 0.] - @test convert(Array{Float64, 1}, initialstate(babyPOMDP), babyPOMDP) == [1., 0., 0., 0.] - @test convert(Array{Float64, 1}, initialstate(minihallwayPOMDP), minihallwayPOMDP) == append!(fill(1/12, 12), zeros(14)) - end - - @testset "Finite Horizon POMDP other than initial stage distribution tests" begin - tigerPOMDP = fixhorizon(TigerPOMDP(), 2) - babyPOMDP = fixhorizon(BabyPOMDP(), 2) - minihallwayPOMDP = fixhorizon(MiniHallway(), 2) - - tigerbelief = FiniteHorizonPOMDPs.InStageDistribution(FiniteHorizonPOMDPs.distribution(initialstate(tigerPOMDP)), 2) - babybelief = FiniteHorizonPOMDPs.InStageDistribution(FiniteHorizonPOMDPs.distribution(initialstate(babyPOMDP)), 2) - minihallwaybelief = FiniteHorizonPOMDPs.InStageDistribution(FiniteHorizonPOMDPs.distribution(initialstate(minihallwayPOMDP)), 2) - - @test convert(Array{Float64, 1}, tigerbelief, tigerPOMDP) == [0., 0., 0.5, 0.5, 0., 0.] - @test convert(Array{Float64, 1}, babybelief, babyPOMDP) == [0., 0., 1., 0., 0., 0.] - @test convert(Array{Float64, 1}, minihallwaybelief, minihallwayPOMDP) == append!(append!(zeros(13), fill(1/12, 12)), zeros(14)) - end - end -end - @testset "Comparison with SARSOP" begin pomdps = [TigerPOMDP(), BabyPOMDP(), MiniHallway()] From d9ddc87556c93f98b3c2000e614d2626b3b50a16 Mon Sep 17 00:00:00 2001 From: Tomas Omasta Date: Thu, 13 May 2021 19:04:55 +0200 Subject: [PATCH 3/4] replace vector with DiscreteBelief --- src/pbvi.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pbvi.jl b/src/pbvi.jl index 61ec8a7..80bfb71 100644 --- a/src/pbvi.jl +++ b/src/pbvi.jl @@ -182,9 +182,9 @@ function solve(solver::PBVISolver, pomdp::POMDP) Γ = [fill(α_init, length(S)) for a in A] #init belief, if given distribution, convert to vector - init = initialize_belief(DiscreteUpdater(pomdp), initialstate(pomdp)).b - B = [DiscreteBelief(pomdp, init)] - Bs = Set([init]) + init = initialize_belief(DiscreteUpdater(pomdp), initialstate(pomdp)) + B = [init] + Bs = Set([init.b]) if solver.verbose println("Running PBVI solver on $(typeof(pomdp)) problem with following settings:\n max_iterations = $(solver.max_iterations), ϵ = $(solver.ϵ), verbose = $(solver.verbose)\n+----------------------------------------------------------+") end From d122b63b7875d30d000980d06c366871c15c087f Mon Sep 17 00:00:00 2001 From: Tomas Omasta Date: Thu, 13 May 2021 19:15:50 +0200 Subject: [PATCH 4/4] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3add5de..b91294d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PointBasedValueIteration" uuid = "835c131e-675f-4498-8e2c-c054c75556e1" authors = ["Dominik Straub and Tomáš Omasta "] -version = "0.2.0" +version = "0.2.1" [deps] BeliefUpdaters = "8bb6e9a1-7d73-552c-a44a-e5dc5634aac4"