actor-critic (ac) agents
you can use the actor-critic (ac) agent, which uses a model-free, online, on-policy reinforcement learning method, to implement actor-critic algorithms, such as a2c and a3c. the goal of this agent is to optimize the policy (actor) directly and train a critic to estimate the return or future rewards [1].
for more information on the different types of reinforcement learning agents, see reinforcement learning agents.
actor-critic agents can be trained in environments with the following observation and action spaces.
observation space | action space |
---|---|
discrete or continuous | discrete or continuous |
actor-critic agents use the following actor and critics.
critic | actor |
---|---|
value function critic v(s), which you create using | stochastic policy actor π(s), which you create using (for discrete action spaces) or (for continuous action spaces) |
during training, an actor-critic agent:
estimates probabilities of taking each action in the action space and randomly selects actions based on the probability distribution.
interacts with the environment for multiple steps using the current policy before updating the actor and critic properties.
if the useexplorationpolicy
option of the agent is set to
false
the action with maximum likelihood is always used in sim
and . as a result, the simulated agent and generated policy
behave deterministically.
if the useexplorationpolicy
is set to true
the
agent selects its actions by sampling its probability distribution. as a result the policy is
stochastic and the agent explores its observation space.
this option affects only simulation and deployment; it does not affect training.
actor and critic function approximators
to estimate the policy and value function, an actor-critic agent maintains two function approximators.
actor π(a|s;θ) — the actor, with parameters θ, outputs the conditional probability of taking each action a when in state s as one of the following:
discrete action space — the probability of taking each discrete action. the sum of these probabilities across all actions is 1.
continuous action space — the mean and standard deviation of the gaussian probability distribution for each continuous action.
critic v(s;ϕ) — the critic, with parameters ϕ, takes observation s and returns the corresponding expectation of the discounted long-term reward.
for more information on creating actors and critics for function approximation, see create policies and value functions.
during training, the agent tunes the parameter values in θ. after training, the parameters remain at their tuned value and the trained actor function approximator is stored in π(a|s).
agent creation
you can create an actor-critic agent with default actor and critics based on the observation and action specifications from the environment. to do so, perform the following steps.
create observation specifications for your environment. if you already have an environment interface object, you can obtain these specifications using
getobservationinfo
.create action specifications for your environment. if you already have an environment interface object, you can obtain these specifications using
getactioninfo
.if needed, specify the number of neurons in each learnable layer or whether to use an lstm layer. to do so, create an agent initialization option object using .
if needed, specify agent options using an
rlacagentoptions
object.create the agent using an
rlacagent
object.
alternatively, you can create actor and critic and use these objects to create your agent. in this case, ensure that the input and output dimensions of the actor and critic match the corresponding action and observation specifications of the environment.
create an actor using an (for discrete action spaces) or an (for continuous action spaces) object.
create a critic using an object.
specify agent options using an
rlacagentoptions
object.create the agent using an
rlacagent
object.
for more information on creating actors and critics for function approximation, see create policies and value functions.
training algorithm
actor-critic agents use the following training algorithm. to configure the training
algorithm, specify options using an rlacagentoptions
object.
initialize the actor π(a|s;θ) with random parameter values θ.
initialize the critic v(s;ϕ) with random parameter values ϕ.
generate n experiences by following the current policy. the episode experience sequence is
here, st is a state observation, at is an action taken from that state, st 1 is the next state, and rt 1 is the reward received for moving from st to st 1.
when in state st, the agent computes the probability of taking each action in the action space using π(a|st;θ) and randomly selects action at based on the probability distribution.
ts is the starting time step of the current set of n experiences. at the beginning of the training episode, ts = 1. for each subsequent set of n experiences in the same training episode, ts = ts n.
for each training episode that does not contain a terminal state, n is equal to the
numstepstolookahead
option value. otherwise, n is less thannumstepstolookahead
and sn is the terminal state.for each episode step t = ts, ts 1, …, ts n, compute the return gt, which is the sum of the reward for that step and the discounted future reward. if sts n is not a terminal state, the discounted future reward includes the discounted state value function, computed using the critic network v.
here, b is
0
if sts n is a terminal state and1
otherwise.to specify the discount factor γ, use the
discountfactor
option.compute the advantage function dt.
accumulate the gradients for the actor network by following the policy gradient to maximize the expected discounted reward.
accumulate the gradients for the critic network by minimizing the mean squared error loss between the estimated value function v (st;ϕ) and the computed target return gt across all n experiences. if the
entropylossweight
option is greater than zero, then additional gradients are accumulated to minimize the entropy loss function.update the actor parameters by applying the gradients.
here, α is the learning rate of the actor. specify the learning rate when you create the actor by setting the
learnrate
option in therlactoroptimizeroptions
property within the agent options object.update the critic parameters by applying the gradients.
here, β is the learning rate of the critic. specify the learning rate when you create the critic by setting the
learnrate
option in therlcriticoptimizeroptions
property within the agent options object.repeat steps 3 through 9 for each training episode until training is complete.
for simplicity, the actor and critic updates in this algorithm description show a
gradient update using basic stochastic gradient descent. the actual gradient update method
depends on the optimizer you specify using in the rloptimizeroptions
object
assigned to the rlcriticoptimizeroptions
property.
references
[1] mnih, volodymyr, adrià puigdomènech badia, mehdi mirza, alex graves, timothy p. lillicrap, tim harley, david silver, and koray kavukcuoglu. “asynchronous methods for deep reinforcement learning.” arxiv:1602.01783 [cs], february 4, 2016..