Learn R Programming

pomdp (version 1.0.0)

transition_matrix: Extract the Transition, Observation or Reward Information from a POMDP

Description

Converts the description of transition probabilities and observation probabilities in a POMDP into a list of matrices or a function.

Usage

transition_matrix(x, episode = 1, type = "matrix")

observation_matrix(x, episode = 1, type = "matrix")

reward_matrix(x, episode = 1, type = "matrix")

Arguments

x

A POMDP object.

episode

Episode used for time-dependent POMDPs (POMDP).

type

'matrix' or 'function' to get a list of matrices or a function.

Value

A list or a list of lists of matrices.

Details

See Details section in POMDP for details.

See Also

Other POMDP: POMDP(), plot_belief_space(), sample_belief_space(), simulate_POMDP(), solve_POMDP(), solve_SARSOP(), update_belief(), write_POMDP()

Examples

Run this code
# NOT RUN {
data("Tiger")

# List of |A| transition matrices. One per action in the from states x states
Tiger$transition_prob
transition_matrix(Tiger)

f <- transition_matrix(Tiger, type = "function")
args(f)
## listening does not change the tiger's position.
f("listen", "tiger-left", "tiger-left")

# List of |A| observation matrices. One per action in the from states x observations
Tiger$observation_prob
observation_matrix(Tiger)

# List of list of reward matrices. 1st level is action and second level is the
#  start state in the form end state x observation
Tiger$reward
reward_matrix(Tiger)

# Visualize transition matrix for action 'open-left'
library("igraph")
g <- graph_from_adjacency_matrix(transition_matrix(Tiger)$"open-left", weighted = TRUE)
edge_attr(g, "label") <- edge_attr(g, "weight")

igraph.options("edge.curved" = TRUE)
plot(g, layout = layout_on_grid, main = "Transitions for action 'open=left'")

## Use a function for the Tiger transition model
trans <- function(end.state, start.state, action) {
  ## listen has an identity matrix
  if(action == 'listen')
    if(end.state == start.state) return(1)
    else return(0)

  # other actions have a uniform distribution
  return(1/2)
}

Tiger$transition_prob <- trans
transition_matrix(Tiger)
# }

Run the code above in your browser using DataLab