Skip to content

Deep reinforcement learning and decision models · Method reference · DRL005 · Algorithm

Advantage actor–critic: A2C/A3C family

Learn a stochastic policy and a state-value baseline together, using estimated advantage to reduce policy-gradient variance. A3C uses asynchronous workers; A2C denotes a synchronous batched counterpart.

Explained here Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

Documented in the Academy only. There's no Set up button.

Availability
Explained here
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Learn a stochastic policy and a state-value baseline together, using estimated advantage to reduce policy-gradient variance. A3C uses asynchronous workers; A2C denotes a synchronous batched counterpart. They are grouped here because the central actor–critic objective is shared.

Question / hypotheses

Which policy updates increase expected return while a learned baseline estimates state value? The critic supports variance reduction and bootstrapping; it is not an independent ground-truth reward estimator.

Architecture / computational structure

A shared or separate encoder feeds policy logits or continuous-action distribution parameters and a scalar value head. Workers collect short rollouts, compute n-step returns/advantages, and update actor and critic; a recurrent state can summarize observation histories. A3C workers may use stale local weights.

Assumptions

Policy gradients require correctly computed action log probabilities and returns from the intended behavior policy. On-policy sampling restricts reuse of old trajectories. State representation, termination masks, and reward scale must be consistent across workers; asynchronous updates complicate reproducibility.

Formula / computational definition

L=−E[log⁡πθ(at∣st)A^t]+cVE[(Vϕ(st)−R^t)2]−cHE[H(πθ)]\mathcal L=-\mathbb E[\log\pi_\theta(a_t\mid s_t)\widehat A_t]+c_V\mathbb E[(V_\phi(s_t)-\widehat R_t)^2]-c_H\mathbb E[\mathcal H(\pi_\theta)]. Treat advantage and return targets as fixed in the corresponding actor/critic gradient steps.

Parameters and notation

Learned quantities are actor and critic weights, optionally a shared encoder and recurrent state model. Hyperparameters include rollout length, discount, value-loss weight, entropy coefficient, number of environments/workers, learning rate, gradient clipping, and advantage-estimation convention.

Fitting, fine-tuning, and adaptation

For a related task, transfer the encoder and policy where action semantics match; refit the critic for the new reward. Start with a frozen encoder baseline, then unfreeze at a smaller learning rate. Collect fresh on-policy rollouts after each material policy change.

How to use and calibrate

Compare return and interaction efficiency across seeds, recording synchronous versus asynchronous execution. Monitor policy entropy, advantage scale, critic explained variance, and rollout freshness. A low value loss with poor exploratory coverage does not establish a useful controller.

Example application

Run several simulated navigation environments to train a shared policy. The paired example evaluates actor, critic, and entropy terms for a minibatch of supplied probabilities and returns; worker orchestration and neural gradient updates are outside its scope.

Interpretation / pitfalls

Watch out

An entropy bonus can delay deterministic exploitation, and an inaccurate critic can bias bootstrapped advantages. A2C synchronization and A3C asynchronous scheduling are operationally different. Neither is an offline-RL method merely because its rollout data are temporarily stored.

Python and R code examples

Scope: computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. Dependencies/validation: Python with NumPy executed successfully; base R not executed. Targets and supplied network outputs are ordinary arrays here, so this does not validate automatic-differentiation boundaries.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop. · needs numpy

import numpy as np
policy=np.array([[.7,.3],[.2,.8]]); actions=np.array([0,1]); advantages=np.array([1.,-.5])
value=np.array([.4,.8]); returns=np.array([1.4,.3])
actor=-np.mean(np.log(policy[np.arange(2),actions])*advantages)
critic=np.mean((value-returns)**2); entropy=-np.mean(np.sum(policy*np.log(policy),axis=1))
loss=actor+.5*critic-.01*entropy; print(actor,critic,entropy,loss)
R

Component demo, not a trained model — computational component described in the application subsection; not a complete estimator, neural trainer, or environment loop.

policy <- matrix(c(.7,.3,.2,.8),2,byrow=TRUE); actions <- c(1,2); advantages <- c(1,-.5)
value <- c(.4,.8); returns <- c(1.4,.3)
actor <- -mean(log(policy[cbind(1:2,actions)])*advantages)
critic <- mean((value-returns)^2); entropy <- -mean(rowSums(policy*log(policy)))
loss <- actor+.5*critic-.01*entropy; print(c(actor,critic,entropy,loss))

Sources

From the CodeSplash reference, entry DRL005.