Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/policies/q_based_policies/learners/abstract_learner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ Base.show(io::IO, p::AbstractLearner) =
AbstractTrees.print_tree(io, StructTree(p), get(io, :max_depth, 10))

function RLBase.update!(
p::AbstractLearner,
L::AbstractLearner,
t::AbstractTrajectory,
e::AbstractEnv,
s::AbstractStage
)
end

function RLBase.update!(
L::AbstractLearner,
t::AbstractTrajectory,
e::AbstractEnv,
s::PreActStage
)
update!(L, t)
end
22 changes: 17 additions & 5 deletions src/policies/tabular_random_policy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export TabularRandomPolicy
Use a `Dict` to store action distribution.
"""
Base.@kwdef struct TabularRandomPolicy{S,T, R} <: AbstractPolicy
table::Dict{S,T} = Dict{Int, Float32}()
table::Dict{S,T} = Dict{Any, Vector{Float32}}()
rng::R = Random.GLOBAL_RNG
end

Expand All @@ -19,7 +19,7 @@ function RLBase.prob(p::TabularRandomPolicy, ::ExplicitStochastic, env::Abstract
if current_player(env) == chance_player(env)
prob(env)
else
p(DETERMINISTIC, env) # treat it just like a normal one
prob(p, DETERMINISTIC, env) # treat it just like a normal one
end
end

Expand All @@ -41,11 +41,23 @@ function RLBase.prob(t::TabularRandomPolicy, ::MinimalActionSet, env::AbstractEn
end
end

function RLBase.prob(t::TabularRandomPolicy, env::AbstractEnv, action::Int)
prob(t, state(env))[action]
function RLBase.prob(t::TabularRandomPolicy, env::AbstractEnv, action)
prob(t, env, action_space(env), action)
end

function RLBase.prob(t::TabularRandomPolicy{S}, state::S, action::Int) where S
function RLBase.prob(t::TabularRandomPolicy, env::AbstractEnv, action_space, action)
prob(t, env)[findfirst(==(action), action_space)]
end

function RLBase.prob(t::TabularRandomPolicy, env::AbstractEnv, action_space::Base.OneTo, action)
prob(t, env)[action]
end

# function RLBase.prob(t::TabularRandomPolicy, env::AbstractEnv, action_space::ZeroTo, action)
# prob(t, env)[action+1]
# end

function RLBase.prob(t::TabularRandomPolicy, state, action)
# assume table is already initialized
t.table[state][action]
end
Expand Down