Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Mismatch for observation state #40

Closed
Bala-1998 opened this issue Jan 8, 2024 · 2 comments
Closed

Type Mismatch for observation state #40

Bala-1998 opened this issue Jan 8, 2024 · 2 comments

Comments

@Bala-1998
Copy link

Please check this file for how I try to create and then use POMCPOW - https://github.com/Bala-1998/pomdp_jl/blob/main/discrete_drive_pomdp/drive_test_jl.ipynb

I have defined a structure for the observation as:

struct driveObservation
h::Int
r::Int
a::Int
end

and I have defined the observation model as this -

function POMDPs.observation(pomdp::drivePOMDP, act::Int64, state::driveState)
h, r, z, phi = state.h, state.r, state.z, state.phi
a = act
p_stop = human_policy(h, r, z)

# If the action to stop is taken by the robot, the human stops at a probability of p_stop this distribution needs to be returned for both stop action and go action.
if a == 0
    if r == 0 && h == 0
        return SparseCat([driveObservation(0,0,a), driveObservation(1,0,a)], [p_stop, 1-p_stop])
    else
        return Deterministic(1.0e-9)
    end
elseif a == 1
    if r  == 0 && h == 0
        return SparseCat([driveObservation(0,1,a), driveObservation(1,1,a)], [p_stop, 1-p_stop])
    else
        return Deterministic(1.0e-9)
    end
else
    return Deterministic(1.0e-9)
end

end

But when I try to solve using the pomcpow library, I get an error like this-
I get the following stack trace which has to do with driveObservation - MethodError: Cannot convert an object of type Float64 to an object of type driveObservation

Closest candidates are:
convert(::Type{T}, !Matched::T) where T
@ Base Base.jl:84
driveObservation(::Any, !Matched::Any, !Matched::Any)
@ Main ~/Fall23/aizen/pomdp_test/drive_test_jl.ipynb:2

Stacktrace:
[1] push!(a::Vector{driveObservation}, item::Float64)
@ Base ./array.jl:1118
[2] insert_obs_node!(t::BasicPOMCP.POMCPTree{Int64, driveObservation}, pomdp::drivePOMDP, ha::Int64, sp::driveState, o::Float64)
@ BasicPOMCP ~/.julia/packages/BasicPOMCP/ba47d/src/BasicPOMCP.jl:183
[3] simulate(p::POMCPPlanner{drivePOMDP, BasicPOMCP.SolvedPORollout{RandomPolicy{Random._GLOBAL_RNG, drivePOMDP, NothingUpdater}, NothingUpdater, Random._GLOBAL_RNG}, Random._GLOBAL_RNG}, s::driveState, hnode::BasicPOMCP.POMCPObsNode{Int64, driveObservation}, steps::Int64)
@ BasicPOMCP ~/.julia/packages/BasicPOMCP/ba47d/src/solver.jl:94
[4] search(p::POMCPPlanner{drivePOMDP, BasicPOMCP.SolvedPORollout{RandomPolicy{Random._GLOBAL_RNG, drivePOMDP, NothingUpdater}, NothingUpdater, Random._GLOBAL_RNG}, Random._GLOBAL_RNG}, b::SparseCat{Vector{driveState}, Vector{Float64}}, t::BasicPOMCP.POMCPTree{Int64, driveObservation}, info::Dict{Symbol, Any})
@ BasicPOMCP ~/.julia/packages/BasicPOMCP/ba47d/src/solver.jl:32
[5] action_info(p::POMCPPlanner{drivePOMDP, BasicPOMCP.SolvedPORollout{RandomPolicy{Random._GLOBAL_RNG, drivePOMDP, NothingUpdater}, NothingUpdater, Random._GLOBAL_RNG}, Random._GLOBAL_RNG}, b::SparseCat{Vector{driveState}, Vector{Float64}}; tree_in_info::Bool)
@ BasicPOMCP ~/.julia/packages/BasicPOMCP/ba47d/src/solver.jl:6
[6] action_info
@ BasicPOMCP ~/.julia/packages/BasicPOMCP/ba47d/src/solver.jl:1 [inlined]
[7] action(p::POMCPPlanner{drivePOMDP, BasicPOMCP.SolvedPORollout{RandomPolicy{Random._GLOBAL_RNG, drivePOMDP, NothingUpdater}, NothingUpdater, Random._GLOBAL_RNG}, Random._GLOBAL_RNG}, b::SparseCat{Vector{driveState}, Vector{Float64}})
@ BasicPOMCP ~/.julia/packages/BasicPOMCP/ba47d/src/solver.jl:19
[8] top-level scope
@ ~/Fall23/aizen/pomdp_test/drive_test_jl.ipynb:2

How Do I solve this method error mismatch?

@zsunberg
Copy link
Member

zsunberg commented Jan 9, 2024

You should return Deterministic(::driveObservation) instead of Deterministic(::Float64) from observation. Does that make sense?

@Bala-1998
Copy link
Author

Thank you! I was able to solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants