Skip to content

Commit a8f9374

Browse files
authored
Merge pull request #8 from Omastto1/master
Replaced convert methods
2 parents 2e89f7f + d122b63 commit a8f9374

File tree

3 files changed

+6
-60
lines changed

3 files changed

+6
-60
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PointBasedValueIteration"
22
uuid = "835c131e-675f-4498-8e2c-c054c75556e1"
33
authors = ["Dominik Straub <straub@psychologie.tu-darmstadt.de> and Tomáš Omasta <tomom@email.cz>"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
77
BeliefUpdaters = "8bb6e9a1-7d73-552c-a44a-e5dc5634aac4"

src/pbvi.jl

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ end
3535
==(a::AlphaVec, b::AlphaVec) = (a.alpha,a.action) == (b.alpha, b.action)
3636
Base.hash(a::AlphaVec, h::UInt) = hash(a.alpha, hash(a.action, h))
3737

38-
convert(::Type{Array{Float64, 1}}, d::BoolDistribution, pomdp) = [1 - d.p, d.p]
39-
convert(::Type{Array{Float64, 1}}, d::DiscreteUniform, pomdp) = [pdf(d, stateindex(pomdp, s)) for s in states(pomdp)]
40-
convert(::Type{Array{Float64, 1}}, d::SparseCat, pomdp) = d.probs
41-
42-
convert(::Type{Array{Float64, 1}}, d::InStageDistribution{DiscreteUniform}, m::FixedHorizonPOMDPWrapper) = vec([pdf(d, s) for s in states(m)])
43-
44-
function convert(::Type{Array{Float64, 1}}, d::InStageDistribution{BoolDistribution}, m::FixedHorizonPOMDPWrapper)
45-
if stage(d) == 1
46-
append!([1 - d.d.p[1], d.d.p[1]], zeros(length(states(m)) - 2))
47-
else
48-
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))))
49-
end
50-
end
51-
52-
5338
function _argmax(f, X)
5439
return X[argmax(map(f, X))]
5540
end
@@ -197,9 +182,9 @@ function solve(solver::PBVISolver, pomdp::POMDP)
197182
Γ = [fill(α_init, length(S)) for a in A]
198183

199184
#init belief, if given distribution, convert to vector
200-
init = convert(Array{Float64, 1}, initialstate(pomdp), pomdp)
201-
B = [DiscreteBelief(pomdp, init)]
202-
Bs = Set([init])
185+
init = initialize_belief(DiscreteUpdater(pomdp), initialstate(pomdp))
186+
B = [init]
187+
Bs = Set([init.b])
203188

204189
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
205190

test/runtests.jl

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,11 @@ using POMDPModels
33
using POMDPs
44
using SARSOP
55
using BeliefUpdaters
6-
using POMDPModelTools: Deterministic
7-
using POMDPSimulators: RolloutSimulator
6+
using POMDPModelTools
7+
using POMDPSimulators
88
using FiniteHorizonPOMDPs
9-
109
using PointBasedValueIteration
1110

12-
@testset "Convert test" begin
13-
@testset "Infinite Horizon POMDP tests" begin
14-
tigerPOMDP = TigerPOMDP()
15-
babyPOMDP = BabyPOMDP()
16-
minihallwayPOMDP = MiniHallway()
17-
18-
@test convert(Array{Float64, 1}, initialstate(tigerPOMDP), tigerPOMDP) == [0.5, 0.5]
19-
@test convert(Array{Float64, 1}, initialstate(babyPOMDP), babyPOMDP) == [1., 0.]
20-
@test convert(Array{Float64, 1}, initialstate(minihallwayPOMDP), minihallwayPOMDP) == append!(fill(1/12, 12), zeros(1))
21-
end
22-
23-
@testset "Finite Horizon POMDP tests" begin
24-
@testset "Finite Horizon POMDP initial state convert tests" begin
25-
tigerPOMDP = fixhorizon(TigerPOMDP(), 1)
26-
babyPOMDP = fixhorizon(BabyPOMDP(), 1)
27-
minihallwayPOMDP = fixhorizon(MiniHallway(), 1)
28-
29-
@test convert(Array{Float64, 1}, initialstate(tigerPOMDP), tigerPOMDP) == [0.5, 0.5, 0., 0.]
30-
@test convert(Array{Float64, 1}, initialstate(babyPOMDP), babyPOMDP) == [1., 0., 0., 0.]
31-
@test convert(Array{Float64, 1}, initialstate(minihallwayPOMDP), minihallwayPOMDP) == append!(fill(1/12, 12), zeros(14))
32-
end
33-
34-
@testset "Finite Horizon POMDP other than initial stage distribution tests" begin
35-
tigerPOMDP = fixhorizon(TigerPOMDP(), 2)
36-
babyPOMDP = fixhorizon(BabyPOMDP(), 2)
37-
minihallwayPOMDP = fixhorizon(MiniHallway(), 2)
38-
39-
tigerbelief = FiniteHorizonPOMDPs.InStageDistribution(FiniteHorizonPOMDPs.distribution(initialstate(tigerPOMDP)), 2)
40-
babybelief = FiniteHorizonPOMDPs.InStageDistribution(FiniteHorizonPOMDPs.distribution(initialstate(babyPOMDP)), 2)
41-
minihallwaybelief = FiniteHorizonPOMDPs.InStageDistribution(FiniteHorizonPOMDPs.distribution(initialstate(minihallwayPOMDP)), 2)
42-
43-
@test convert(Array{Float64, 1}, tigerbelief, tigerPOMDP) == [0., 0., 0.5, 0.5, 0., 0.]
44-
@test convert(Array{Float64, 1}, babybelief, babyPOMDP) == [0., 0., 1., 0., 0., 0.]
45-
@test convert(Array{Float64, 1}, minihallwaybelief, minihallwayPOMDP) == append!(append!(zeros(13), fill(1/12, 12)), zeros(14))
46-
end
47-
end
48-
end
49-
5011
@testset "Comparison with SARSOP" begin
5112
pomdps = [TigerPOMDP(), BabyPOMDP(), MiniHallway()]
5213

0 commit comments

Comments
 (0)