The actor-critic (AC) agent implements the advantage actor-critic (A2C) algorithm [1], which is a model-free, online, on-policy reinforcement learning method. The goal of this method is to optimize the policy (actor) directly and train a critic to estimate the return or future rewards.

For more information on the different types of reinforcement learning agents, see Reinforcement Learning Agents.

AC agents can be trained in environments with the following observation and action spaces.

Observation Space | Action Space |
---|---|

Continuous or discrete | Discrete |

During training, an AC 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.

To estimate the policy and value function, an AC agent maintains two function approximators:

Actor

*μ*(*S*) — The actor takes observation*S*and outputs the probabilities of taking each action in the action space when in state*S*.Critic

*V*(*S*) — The critic takes observation*S*and outputs the corresponding expectation of the discounted long-term reward.

When training is complete, the trained optimal policy is stored in actor
*μ*(*S*).

For more information on creating actors and critics for function approximation, see Create Policy and Value Function Representations.

To create an AC agent:

Create an actor representation object.

Create a critic representation object.

Specify agent options using the

`rlACAgentOptions`

function.Create the agent using the

`rlACAgent`

function.

For more information, see `rlACAgent`

and
`rlACAgentOptions`

.

AC agents use the following training algorithm. To configure the training algorithm,
specify options using `rlACAgentOptions`

.

Initialize the actor

*μ*(*S*) with random parameter values*θ*._{μ}Initialize the critic

*V*(*S*) with random parameter values*θ*._{V}For each training episode, generate

*N*experiences by following the current policy. The episode experience sequence consists of:$${S}_{0},{A}_{0},{R}_{1},{S}_{1},\dots ,{S}_{N-1},{A}_{N-1},{R}_{N},{S}_{N}$$

Here,

*S*is a state observation,_{t}*A*is an action taken from that state,_{t}*S*is the next state, and_{t+1}*R*is the reward received for moving from_{t+1}*S*to_{t}*S*._{t+1}When in state

*S*, the agent computes the probability of taking each action in the action space using_{t}*μ*(*S*) and randomly selects action_{t}*A*based on the probability distribution._{t}For each training episode that does not contain a terminal state,

*N*is equal to the`NumStepsToLookAhead`

option value. Otherwise,*N*is less than`NumStepsToLookAhead`

and*S*is the terminal state._{N}For each episode step

*t*= 1, 2, …,*N*compute the return*G*, which is the sum of the reward for that step and the discounted future reward. If_{t}*S*is a terminal state, the discounted future reward includes the discounted state value function, computed using the critic network_{N}*V*.$${G}_{t}={\displaystyle \sum _{k=t}^{N}\left({\gamma}^{k-t}{R}_{k}\right)}+b{\gamma}^{N-t+1}V\left({S}_{N}|{\theta}_{V}\right)$$

Here,

*b*is`0`

if*S*is a terminal state and_{N}`1`

otherwise.To specify the discount factor

*γ*, use the`DiscountFactor`

option.Accumulate the gradients for the actor network by following the policy gradient to maximize the expected discounted reward.

$$d{\theta}_{\mu}={\displaystyle \sum _{t=1}^{N}{\nabla}_{{\theta}_{\mu}}}\mathrm{ln}\mu \left({S}_{t}|{\theta}_{\mu}\right)\left({G}_{t}-V\left({S}_{t}|{\theta}_{V}\right)\right)$$

Here, $${G}_{t}-V\left({S}_{t}\right)$$ is the advantage function.

Accumulate the gradients for the critic network by minimizing the mean square error loss between the estimated value function

*V*() and the computed target return_{t}*G*across all_{t}*N*experiences. If the`EntropyLossWeight`

option is greater than zero, then additional gradients are accumulated to minimize the entropy loss function.$$d{\theta}_{V}={\displaystyle \sum _{t=1}^{N}{\nabla}_{{\theta}_{V}}}{\left({G}_{t}-V\left({S}_{t}|{\theta}_{V}\right)\right)}^{2}$$

Update the actor parameters by applying the gradients.

$${\theta}_{\mu}={\theta}_{\mu}+\alpha d{\theta}_{\mu}$$

Here,

*α*is the learning rate of the actor. Specify the learning rate when you create the actor representation by setting the`LearnRate`

option in the`rlRepresentationOptions`

object.Update the critic parameters by applying the gradients.

$${\theta}_{V}={\theta}_{V}+\beta d{\theta}_{V}$$

Here,

*β*is the learning rate of the critic. Specify the learning rate when you create the critic representation by setting the`LearnRate`

option in the`rlRepresentationOptions`

object.Repeat steps 3 through 8 for each training episode until training is complete.

For simplicity, this actor and critic updates in this algorithm show a gradient update
using basic stochastic gradient descent. The actual gradient update method depends on the
optimizer specified using `rlRepresentationOptions`

.

[1] Mnih, V, et al. "Asynchronous
methods for deep reinforcement learning," *International Conference on Machine
Learning*, 2016.

`rlACAgent`

| `rlACAgentOptions`

| `rlRepresentation`