Created
October 27, 2019 22:42
-
-
Save msaroufim/04b5f6884846a2dbcaff6d36c38867de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/JuliaML/Reinforce.jl/blob/master/examples/mountain_car.jl | |
using Reinforce | |
using Reinforce.MountainCarEnv: MountainCar | |
using Plots | |
gr() | |
# Deterministic policy that is solving the problem | |
mutable struct BasicCarPolicy <: Reinforce.AbstractPolicy end | |
Reinforce.action(policy::BasicCarPolicy, r, s, A) = s.velocity < 0 ? 1 : 3 | |
# Environment setup | |
env = MountainCar() | |
function episode!(env, π = RandomPolicy()) | |
ep = Episode(env, π) | |
for (s, a, r, s′) in ep | |
gui(plot(env)) | |
end | |
ep.total_reward, ep.niter | |
end | |
# Main part | |
R, n = episode!(env, BasicCarPolicy()) | |
println("reward: $R, iter: $n") | |
# This one can be really long... | |
R, n = episode!(env, RandomPolicy()) | |
println("reward: $R, iter: $n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment