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

Add convert_s function #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

yangyou95
Copy link

It seems like there is no convert_s() function for the LaserTag problem.
Adding a convert_s() function, transforming a LTState to a vector.

add convert_s function
@yangyou95 yangyou95 changed the title Update LaserTag.jl Add convert_s function Dec 13, 2022
@codecov
Copy link

codecov bot commented Dec 17, 2022

Codecov Report

Base: 68.23% // Head: 67.62% // Decreases project coverage by -0.60% ⚠️

Coverage data is based on head (c18fa55) compared to base (60b14f6).
Patch coverage: 0.00% of modified lines in pull request are covered.

❗ Current head c18fa55 differs from pull request most recent head da28f02. Consider uploading reports for the commit da28f02 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
- Coverage   68.23%   67.62%   -0.61%     
==========================================
  Files          10       10              
  Lines         447      451       +4     
==========================================
  Hits          305      305              
- Misses        142      146       +4     
Impacted Files Coverage Δ
src/LaserTag.jl 72.72% <0.00%> (-7.28%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@zsunberg zsunberg left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the contribution! As in the rocksample PR, can you add a test?

Please also see my inline comment.

Finally, as in rocksample, it would be great to add the convert_s for the opposite direction.

src/LaserTag.jl Outdated
@@ -143,6 +143,11 @@ function POMDPs.reward(p::LaserTagPOMDP, s::LTState, a::Int, sp::LTState)
end
end

# add a function to transform a LTState to a vector
function POMDPs.convert_s(T::Type{<:AbstractArray}, s::LTState, p::LaserTagPOMDP)
return convert(T, vcat(s.robot, s.opponent, [s.terminal]))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return convert(T, vcat(s.robot, s.opponent, [s.terminal]))
return convert(T, vcat(s.robot, s.opponent, s.terminal))

I don't think you need to create a vector with s.terminal in it. That will cause an additional allocation.

(additionally, I think vcat itself might cause an allocation, which is disappointing. You might be able to eliminate all allocations with StaticArrays, but that might take a bit of learning. There are many tools to track allocations including BenchmarkTools.@btime

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the info!

Copy link
Member

@zsunberg zsunberg left a comment

Choose a reason for hiding this comment

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

@yangyou95 if you would like to finish this PR - that would be helpful! I added one suggestion to avoid allocating an array, but the most important change still needed is to add tests! Let me know if you need pointers on how to do this!

src/LaserTag.jl Outdated

# transform a vector to a LTState
function POMDPs.convert_s(T::Type{LTState}, v::AbstractArray{Float64}, p::LaserTagPOMDP)
return LTState([v[1], v[2]], [v[3], v[4]], v[5])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return LTState([v[1], v[2]], [v[3], v[4]], v[5])
return LTState(Coord(v[1], v[2]), Coord(v[3], v[4]), v[5])

Copy link
Author

Choose a reason for hiding this comment

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

Hello @zsunberg! Sorry, I totally forgot this change after Xmas... I updated and pushed it! Hope what did is correct.
Pls let me know if everything is ok.

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

Successfully merging this pull request may close these issues.

2 participants