Traj2SARS: Convert Trajectory to SARS

Description Usage Arguments Details Value Examples

View source: R/base.R

Description

The function Traj2SARS() converts a trajectory object to a SARS object.

Usage

1
Traj2SARS(traj, Interpreter, skip = 0)

Arguments

traj

a trajectory object (class = "Traj").

Interpreter

an interpreter function, see details.

skip

number of steps to skip over

Details

The interpreter function Interpreter(actions, observations) takes the history information up to certain time step, and outputs a list of (state, reward). Specifically, the history information is partial trajectory:

O_1, A_1, O_2, A_2, …, O_t, A_t, O_{t+1}

Value

a SARS object (class = "SARS")

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
observations <- list(0, -1, -1, 0, 1, 1)
actions <- list(-1, 1, 1, 0, -1)
traj <- Traj(observations, actions)
Interpreter <- function(actions, observations) {
n <- length(actions)
if (n > 0) {
  state <- c(observations[[n]], observations[[n + 1]])
  reward <- 1 - state[2]^2
} else {
  state <- reward <- NULL
}
return(list(state = state, reward = reward))
}
Traj2SARS(traj, Interpreter, skip = 1)

XiaoqiLu/PhD-Thesis documentation built on March 1, 2021, 10:49 a.m.