transition_graph: Transition Graph

View source: R/transition_graph.R

transition_graphR Documentation

Transition Graph

Description

Returns the transition model as an igraph object.

Usage

transition_graph(
  x,
  action = NULL,
  episode = NULL,
  epoch = NULL,
  state_col = NULL,
  simplify_transitions = TRUE
)

Arguments

x

object of class POMDP or MDP.

action

the name or id of an action or a set of actions. Bey default the transition model for all actions is returned.

episode, epoch

Episode or epoch used for time-dependent POMDPs. Epochs are internally converted to the episode using the model horizon.

state_col

colors used to represent the states.

simplify_transitions

logical; combine parallel transition arcs into a single arc.

Details

The transition model of a POMDP/MDP is a Markov Chain. This function extracts the transition model as an igraph object.

Value

returns the transition model as an igraph object.

See Also

Other POMDP: POMDP_accessors, POMDP(), plot_belief_space(), projection(), regret(), sample_belief_space(), simulate_POMDP(), solve_POMDP(), solve_SARSOP(), update_belief(), value_function(), write_POMDP()

Other MDP: MDP(), POMDP_accessors, simulate_MDP(), solve_MDP()

Examples

data("Tiger")

g <- transition_graph(Tiger)
g

library(igraph)
plot(g)

# plot with a fixed layout and curved edges
plot(g,
 layout = rbind(c(-1, 0), c(1, 0)), rescale = FALSE,
 edge.curved = curve_multiple_directed(g, .8),
 edge.loop.angle = -pi / 4,
 vertex.size = 60
 )

## Use visNetwork (if installed)
if(require(visNetwork)) {

g_vn <- toVisNetworkData(g)
nodes <- g_vn$nodes
edges <- g_vn$edges

# add manual layout
nodes$x <- c(-1, 1) * 200
nodes$y <- 0

visNetwork(nodes, edges)  %>%  
  visNodes(physics = FALSE) %>% 
  visEdges(smooth = list(type = "curvedCW", roundness = .6), arrows = "to")
} 
 
## Plot an individual graph for each actions
for (a in Tiger$actions) {
 g <- transition_graph(Tiger, action = a)

 plot(g,
  layout = rbind(c(-1, 0), c(1, 0)), rescale = FALSE,  
  edge.curved = curve_multiple_directed(g, .8),
  edge.loop.angle = cumsum(which_loop(g)) *  (-pi / 8),
  vertex.size = 60
 )
}

pomdp documentation built on Sept. 9, 2023, 1:07 a.m.