Skip to content

Commit

Permalink
Version 08 compat (#29)
Browse files Browse the repository at this point in the history
* Fix trailing whitespace errors

* V0.8 compat

* Delete old require file

* Disable tests for v0.7 and enable vor v1.x
  • Loading branch information
lassepe authored and zsunberg committed Sep 17, 2019
1 parent 5522fe8 commit 44b494e
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ os:
- linux
# - osx
julia:
- 0.7
- 1.0
- 1
notifications:
email: false
after_success:
Expand Down
31 changes: 31 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name = "ParticleFilters"
uuid = "c8b314e2-9260-5cf8-ae76-3be7461ca6d0"
repo = "https://github.com/JuliaPOMDP/ParticleFilters.jl"
version = "0.4.0"

[deps]
POMDPModelTools = "08074719-1b2a-587c-a292-00f91cc44415"
POMDPPolicies = "182e52fb-cfd0-5e46-8c26-fd0667c990f4"
POMDPs = "a93abf59-7444-517b-a68a-c42f96afdd7d"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
POMDPs = "0.7.3, 0.8"
julia = "1"

[extras]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NBInclude = "0db19996-df87-5ea3-a455-e3a50d440464"
POMDPModels = "355abbd5-f08e-5560-ac9e-8b5f2592a0ca"
POMDPSimulators = "e0d0a172-29c6-5d4e-96d0-f262df5d01fd"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Reel = "71555da5-176e-5e73-a222-aebc6c6e4f2f"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DelimitedFiles", "Distributions", "LinearAlgebra", "NBInclude", "Plots", "POMDPModels", "POMDPSimulators", "Reel", "StaticArrays", "Test"]
5 changes: 0 additions & 5 deletions REQUIRE

This file was deleted.

2 changes: 0 additions & 2 deletions docs/src/beliefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ The following functions from the [POMDPs.jl distributions interface](http://juli
- [`rand`](@ref)
- [`pdf`](@ref)
- [`support`](@ref)
- [`sampletype`](@ref) (will be replaced with `Random.gentype`)
- [`mode`](@ref)
- [`mean`](@ref)

Expand All @@ -43,7 +42,6 @@ These functions provide access to the particles and weights in the beliefs (clic
POMDPs.rand
POMDPs.pdf
POMDPs.support
POMDPs.sampletype
POMDPs.mode
POMDPs.mean
n_particles
Expand Down
4 changes: 1 addition & 3 deletions src/ParticleFilters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ module ParticleFilters
using POMDPs
import POMDPs: pdf, mode, update, initialize_belief, support
import POMDPs: statetype, isterminal, observation
import POMDPs: generate_s
import POMDPs: action, value
import POMDPs: implemented
import POMDPs: sampletype

import POMDPModelTools: obs_weight
using StatsBase
Expand All @@ -15,7 +13,7 @@ using Statistics
using POMDPPolicies
using POMDPModelTools # for weighted_iterator

import Random: rand
import Random: rand, gentype
import Statistics: mean

export
Expand Down
1 change: 0 additions & 1 deletion src/beliefs.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
abstract type AbstractParticleBelief{T} end

sampletype(::Type{B}) where B<:AbstractParticleBelief{T} where T = T
Random.gentype(::Type{B}) where B<:AbstractParticleBelief{T} where T = T

########################
Expand Down
52 changes: 26 additions & 26 deletions src/policies.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#=
Implementation specific to using ParticleBeliefs with AlphaVectorPolicy from POMDPToolbox
these are more efficient than converting the ParticleBelief to a DiscreteBelief
=#

"""
Given a particle belief, return the unnormalized utility function that weights each state value by the weight of
the corresponding particle
unnormalized_util(p::AlphaVectorPolicy, b::AbstractParticleBelief)
"""
function unnormalized_util(p::AlphaVectorPolicy, b::AbstractParticleBelief)
util = zeros(n_actions(p.pomdp))
for (i, s) in enumerate(particles(b))
j = stateindex(p.pomdp, s)
util += weight(b, i)*getindex.(p.alphas, (j,))
end
return util
end

function action(p::AlphaVectorPolicy, b::AbstractParticleBelief)
util = unnormalized_util(p, b)
ihi = argmax(util)
return p.action_map[ihi]
end

value(p::AlphaVectorPolicy, b::AbstractParticleBelief) = maximum(unnormalized_util(p, b))/weight_sum(b)
#=
Implementation specific to using ParticleBeliefs with AlphaVectorPolicy from POMDPToolbox
these are more efficient than converting the ParticleBelief to a DiscreteBelief
=#

"""
Given a particle belief, return the unnormalized utility function that weights each state value by the weight of
the corresponding particle
unnormalized_util(p::AlphaVectorPolicy, b::AbstractParticleBelief)
"""
function unnormalized_util(p::AlphaVectorPolicy, b::AbstractParticleBelief)
util = p.pomdp |> actions |> length |> zeros
for (i, s) in enumerate(particles(b))
j = stateindex(p.pomdp, s)
util += weight(b, i)*getindex.(p.alphas, (j,))
end
return util
end

function action(p::AlphaVectorPolicy, b::AbstractParticleBelief)
util = unnormalized_util(p, b)
ihi = argmax(util)
return p.action_map[ihi]
end

value(p::AlphaVectorPolicy, b::AbstractParticleBelief) = maximum(unnormalized_util(p, b))/weight_sum(b)
4 changes: 2 additions & 2 deletions src/pomdps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function predict!(pm, m::POMDP, b, a, rng)
s = particle(b, i)
if !isterminal(m, s)
all_terminal = false
sp = generate_s(m, s, a, rng)
sp = gen(DDNOut(:sp), m, s, a, rng)
pm[i] = sp
end
end
Expand Down Expand Up @@ -68,7 +68,7 @@ function initialize_belief(up::BasicParticleFilter, d::D) where D
if ex isa MethodError
@warn("""
Suppressing MethodError in initialize_belief in ParticleFilters.jl. Please file an issue here:
https://github.com/JuliaPOMDP/ParticleFilters.jl/issues/new
The error was
Expand Down
4 changes: 2 additions & 2 deletions src/unweighted.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ function UnweightedParticleFilter(model, n::Integer; rng=Base.GLOBAL_RNG)
end

function update(up::UnweightedParticleFilter, b::ParticleCollection, a, o)
new = sampletype(b)[]
new = Random.gentype(b)[]
i = 1
while i <= up.n
s = particle(b, mod1(i, n_particles(b)))
sp, o_gen = generate_so(up.model, s, a, up.rng)
sp, o_gen = gen(DDNOut(:sp, :o), up.model, s, a, up.rng)
if o_gen == o
push!(new, sp)
end
Expand Down
12 changes: 0 additions & 12 deletions test/REQUIRE

This file was deleted.

2 changes: 1 addition & 1 deletion test/domain_specific_resampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ for bp in stepthrough(m, p2, up, "bp", max_steps=3)
@test bp isa ParticleCollection{LightDark1DState}
@test n_particles(bp) == n
end

end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ struct ContinuousPOMDP <: POMDP{Float64, Float64, Float64} end
rb2 = @inferred resample(rs, WeightedParticleBelief(particles(b), ones(n_particles(b))), MersenneTwister(3))
@test all(particles(rb1).==particles(rb2))
end

@testset "unweighted" begin
rng = MersenneTwister(47)
uf = UnweightedParticleFilter(p, 1000, rng)
ps = @inferred initialize_belief(uf, initialstate_distribution(p))
a = @inferred rand(rng, actions(p))
sp, o = @inferred generate_so(p, rand(rng, ps), a, rng)
sp, o = @inferred gen(DDNOut(:sp, :o), p, rand(rng, ps), a, rng)
bp = @inferred update(uf, ps, a, o)

wp1 = @inferred collect(weighted_particles(ParticleCollection([1,2])))
Expand Down

2 comments on commit 44b494e

@lassepe
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/3740

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" 44b494ebccf013d7894ac15bb273fec0435442fb
git push origin v0.4.0

Please sign in to comment.