Performs an action in a state and returns the new state and reward.
Usage
act(model, state, action, fast = FALSE, ...)
# S3 method for class 'MDPModel'
act(model, state, action = NULL, fast = FALSE, ...)
# S3 method for class 'MDPSample'
act(model, state, action, fast = FALSE, ...)Arguments
- model
an MDP model.
- state
the current state.
- action
the chosen action. If the action is not specified (
NULL) and the MDP model contains a policy, then the action is chosen according to the policy.- fast
logical; if
TRUEthen extra state id to label conversions are avoided.- ...
if action is unspecified, then the additional parameters are passed on to
action()to determine the action using the model's policy.
See also
Other MDP:
MDP(),
absorbing_states(),
action_state_helpers,
available_actions(),
find_reachable_states(),
reachable_states(),
sample_MDP(),
sample_MDP.MDPSample(),
start,
transition_graph(),
transition_matrix(),
unreachable_states()
Other MDPSample:
MDPSample(),
absorbing_states(),
action_state_helpers,
reachable_states(),
sample_MDP.MDPSample(),
solve_MDP_PG(),
start
Examples
data(Maze)
act(Maze, "s(1,3)", "right")
#> $reward
#> [1] 0.96
#>
#> $state_prime
#> [1] s(1,4)
#> 11 Levels: s(1,1) s(2,1) s(3,1) s(1,2) s(3,2) s(1,3) s(2,3) s(3,3) ... s(3,4)
#>
# solve the maze and then ask for actions using the policy
sol <- solve_MDP(Maze)
act(sol, "s(1,3)")
#> $reward
#> [1] 0.96
#>
#> $state_prime
#> [1] s(1,4)
#> 11 Levels: s(1,1) s(2,1) s(3,1) s(1,2) s(3,2) s(1,3) s(2,3) s(3,3) ... s(3,4)
#>
# make the policy in sol epsilon-soft and ask 10 times for the action
replicate(10, act(sol, "s(1,3)", epsilon = .2))
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
#> reward 0.96 -0.04 0.96 0.96 0.96 0.96 -0.04 -0.04 0.96
#> state_prime s(1,4) s(2,3) s(1,4) s(1,4) s(1,4) s(1,4) s(2,3) s(1,3) s(1,4)
#> [,10]
#> reward -0.04
#> state_prime s(1,3)