This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
194 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# mdp step simulator and stepthrough | ||
let | ||
mdp = GridWorld() | ||
solver = RandomSolver(MersenneTwister(2)) | ||
policy = solve(solver, mdp) | ||
sim = StepSimulator("s,sp,r,a", rng=MersenneTwister(3), max_steps=100) | ||
n_steps = 0 | ||
for (s, sp, r, a) in simulate(sim, mdp, policy) | ||
@test isa(s, state_type(mdp)) | ||
@test isa(sp, state_type(mdp)) | ||
@test isa(r, Float64) | ||
@test isa(a, action_type(mdp)) | ||
n_steps += 1 | ||
end | ||
@test n_steps <= 100 | ||
|
||
n_steps = 0 | ||
for s in stepthrough(mdp, policy, "s", rng=MersenneTwister(4), max_steps=100) | ||
@test isa(s, state_type(mdp)) | ||
n_steps += 1 | ||
end | ||
@test n_steps <= 100 | ||
end | ||
|
||
# pomdp step simulator and stepthrough | ||
let | ||
mdp = BabyPOMDP() | ||
policy = FeedWhenCrying() | ||
up = PrimedPreviousObservationUpdater(true) | ||
sim = StepSimulator("s,sp,r,a,b", rng=MersenneTwister(3), max_steps=100) | ||
n_steps = 0 | ||
for (s, sp, r, a, b) in simulate(sim, mdp, policy, up) | ||
@test isa(s, state_type(mdp)) | ||
@test isa(sp, state_type(mdp)) | ||
@test isa(r, Float64) | ||
@test isa(a, action_type(mdp)) | ||
@test isa(b, Bool) | ||
n_steps += 1 | ||
end | ||
@test n_steps == 100 | ||
|
||
n_steps = 0 | ||
for r in stepthrough(mdp, policy, "r", rng=MersenneTwister(4), max_steps=100) | ||
@test isa(r, Float64) | ||
@test r <= 0 | ||
n_steps += 1 | ||
end | ||
@test n_steps == 100 | ||
end | ||
|
||
# example from stepthrough documentation | ||
let | ||
pomdp = BabyPOMDP() | ||
policy = RandomPolicy(pomdp) | ||
|
||
for (s, a, o, r) in stepthrough(pomdp, policy, "s,a,o,r", max_steps=10) | ||
println("in state $s") | ||
println("took action $o") | ||
println("received observation $o and reward $r") | ||
end | ||
end |