REINFORCE Williams, 1992 directly learns a parameterized policy, π, which maps states to probability distributions over actions.
Starting with random parameter values, the agent uses this policy to act in an environment and receive rewards. After an episode has finished, the "goodness" of each action, represented by, f(τ), is calculated using the episode trajectory. The parameters of the policy are then updated in a direction which makes good actions (f(τ)>0) more likely, and bad actions (f(τ)<0) less likely. Good actions are reinforced, bad actions are discouraged.
The agent then uses the updated policy to act in the environment, and the training process repeats.
REINFORCE is an on policy algorithm. Only data that is gathered using the current policy can be used to update the parameters. Once the policy parameters have been updated all previous data gathered must be discarded and the collection process started again with the new policy.
There are a number of different approaches to calculating f(τ). Method 3, outlined below, is common. It captures the idea that the absolute quality of the actions matters less than their quality relative to some baseline. One option for a baseline is the average of f(τ) over the training data (typically one episode trajectory).
Algorithm: REINFORCE with baseline
Initialize weights θ, learning rate αfor each episode (trajectory) τ={s0,a0,r0,s1,⋯,rT}∼πθfor t=0 to T doθ←θ+αf(τ)t∇θlogπθ(at∣st)end forend for
action_policy string specifying which policy to use to act. For example, "Categorical" (for discrete action spaces), "Normal" (for continuous actions spaces with one dimension), or "default" to automatically switch between the two depending on the environment.