Created
October 29, 2018 18:14
-
-
Save zsunberg/f1f9d8bd57fa8e75eb493439d0790c09 to your computer and use it in GitHub Desktop.
Procedure to generate a transition matrix from an MDP
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
using POMDPs | |
using POMDPModelTools | |
function transition_matrix_a_s_sp(mdp::MDP) | |
na = n_actions(mdp) | |
ns = n_states(mdp) | |
mat = zeros(na, ns, ns) # this should be sparse | |
for a in actions(mdp) | |
ai = actionindex(mdp, a) | |
for s in states(mdp) | |
si = stateindex(mdp, s) | |
if !isterminal(mdp, s) # if terminal, the transition probabilities are all just zero | |
td = transition(mdp, s, a) | |
for (sp, p) in weighted_iterator(td) | |
if p > 0.0 | |
spi = stateindex(mdp, sp) | |
mat[ai, si, spi] = p | |
end | |
end | |
end | |
end | |
end | |
return mat | |
end | |
using POMDPModels | |
@show m = SimpleGridWorld() | |
@show transition_matrix_a_s_sp(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment