Contents
- I. Basic Concepts
- 1.1 Terminology
- 1.2 Randomness in Reinforcement Learning
- 1.3 How Reinforcement Learning Controls the agent
- II. Value Learning Deep Q-Network(DQN)
- III. Policy Learning
- IV. Actor-Crictic
- V. Monte Carlo Tree Search
- 5.1 Basic Idea
- 5.2 Process
- VI. Continuous Control
- 6.1 Deterministic Policy Gradient (DPG)
- 6.2 Stochastic Policies for Continuous Control
I. Basic Concepts
1.1 Terminology
(1) State: A state can be understood as the current condition of the environment.
(2) Action: An action is a behavior performed by the agent.
(3) Policy: A policy is a function used to make decisions given an observed state. It is usually expressed as , where is the action and is the state. The goal of reinforcement learning is to learn a policy function, which is usually represented as a probability density function.
(4) Reward: A reward defines how rewards are given and has an important effect on the outcome of reinforcement learning.
(5) State Transition: A state transition represents the probability that, when the agent performs an action in the current state, the environment may randomly transition to a particular next state. It is usually expressed as .
(6) Return: The return is also known as the accumulation of future rewards and is usually expressed as .
(7) Discounted Return: The discounted return accounts for the discounting effect on future rewards, represented by the discount rate . It is usually expressed as .
(8) Action-Value Function: The action-value function represents the expected return that the agent can obtain for a given state and action. It is usually expressed as . The action-value function under the optimal policy is expressed as . The action-value function can be used to evaluate the quality of the current action.
(9) State-Value Function: The state-value function represents the expected return under the policy function for a given state. It is usually expressed as . The state-value function can tell us how good or bad the current state is.
(10) Cross Entropy: Cross entropy is used to measure the difference between two probability distributions and is usually expressed as . When the two probability distributions are the same, cross entropy reaches its minimum value.
1.2 Randomness in Reinforcement Learning
(1) Randomness of Action
Because an action is randomly sampled according to the policy function, the agent may take any action in the policy. Although these actions have different probabilities, the action itself is random.
(2) Randomness of State transitions
Suppose the agent has performed an action. The environment will randomly sample according to the probabilities and produce the next state.
1.3 How Reinforcement Learning Controls the agent
(1) If a policy function is available
- Given an observed state
- Use the policy function to randomly sample from all possible actions
(2) If the optimal action-value function is available
- Given an observed state
- Select the action by maximizing
II. Value Learning Deep Q-Network(DQN)
reflects the sum of future rewards. Therefore, to determine the value of , and because it is a random variable, we can take the expectation of , leaving only the two variables and .
To further eliminate the policy function , we can maximize over , denoted by
This parameter tells us that, regardless of the situation in which action is taken, the expected value is at most .
Goal: Complete the task (maximize the total return) Problem: If is known, then the best action is , because indicates how good or bad it is for the agent to select action a in state s Challenge: We do not know
(1) What Is DQN
We use the neural network to approximate , where w is the parameter to approximate, s is the input, and a is the output that scores all actions.

Given the currently observed state , DQN takes as input, scores all actions, and selects the action with the highest score as .
After the agent performs action , the environment changes. The state transition function randomly samples a new state , and the environment also tells us a return . This is the key to training DQN.
(2) How to Train DQN
The conventional network training process is as follows:
- First, make a prediction of the task outcome
- Obtain the target after completing the task
- Calculate the loss
- Calculate the gradient
- Update the parameter
However, this approach requires the entire task to be completed before the parameters can be updated. To begin updating the parameters after completing only part of the task, Temporal Difference Learning (TD algorithm) was introduced. The process is as follows:
- First, make a prediction of the task outcome
- After performing part of the task, predict the task outcome again as . At this point, includes the completed part and a prediction of the remaining part, so it is more reliable than
- Calculate the loss
- Calculate the gradient
- Update the parameter
In deep reinforcement learning, this is represented by the following equation:
The expected sum of future rewards is the reward that has actually been observed plus the expected future rewards at time t+1.
- First, make the prediction
- Obtain the TD target
- Calculate the loss
- Perform gradient descent

(3) Experience Replay
Previously, we used online gradient descent to update , thereby reducing the TD errer .
We define an experience transition as . The traditional approach discards each transition after using it, which wastes experience. In addition, the traditional approach ignores correlations between different experiences.
Store the most recent n transitions in a replay buffer. When new experience arrives, delete the old transition.
- Randomly sample a transition from the buffer each time
- Calculate the TD error
- Calculate the gradient
- Perform stochastic gradient descent (in practice, minibatch SGD is generally used, sampling multiple transitions at once)
Prioritized Experience Replay: To address nonuniform data, importance sampling can be used instead of uniform sampling. Sampling can be based on the TD error: the larger the error, the higher the probability that the transition will be sampled.
Learning Rate Scaling: If a transition has a high sampling probability, its learning rate should be set relatively low.
Updating the TD error: If a transition has never been used, set its TD error to the maximum value. Update the TD error while training DQN.
III. Policy Learning
The policy function is a probability density function. For each given state , the policy function draws an optimal action to be performed.
Ideally, we could list all states and actions and calculate the probabilities between every state and action.
In practice, however, there are countless states, so it is impossible to record the action corresponding to every state. Function approximation is therefore required. A neural network is generally used for approximation, namely the policy network
The state-value function can tell us whether the current situation is good or bad. When the state is known, it can also determine whether the policy is good. The better the policy, the larger is and the higher the task completion success rate. can be expressed as:
Replace the policy function with a neural network to obtain:
Given state , the better the policy function, the larger the value function. We can therefore consider changing the neural network parameter to increase . Based on this idea, we can take the expectation:
The better the policy network, the larger is. To change , we use the policy gradient algorithm.
- Observe state
- Update the policy using gradient ascent, because we want the value function to be as large as possible.
For discrete actions, use
For continuous actions, use

IV. Actor-Crictic
The state-value function is defined as follows:
Policy network (produces actions):
- Use the neural network to approximate the policy function
- Here, is the parameter to train
Value network (produces evaluation criteria):
- Use the neural network to approximate the value function
- Here, is the parameter to train
Therefore, the state-value function can be written as
Training the policy network and value network simultaneously is called the Actor-Critic Method. The general steps are as follows:
- Observe the current state
- According to the policy function , randomly sample the action
- Perform action and observe the new state and return
- Update the value network parameter using the TD algorithm
- Update the policy network parameter using the policy gradient algorithm
During training, the policy network and value network must be trained simultaneously, with the value network scoring the policy network. After training is complete, the value network is no longer needed; only the policy network is required to generate actions.
V. Monte Carlo Tree Search
5.1 Basic Idea
The idea behind Monte Carlo Tree Search is that people must look many steps ahead, consider every possible situation in the future, and select the optimal action to perform.
- If I choose to perform action at this point
- How will the environment’s feedback change over the coming period
- Based on this environmental change, I will then perform action
- How will the environment change at that point
If an agent can enumerate all possibilities until the task is complete, the task will certainly have a high success rate.
5.2 Process
(1) Selection
Select an action based on its score (an imagined action that is not actually performed);
First, calculate the score for every possible action :
Here, is the action value calculated by Monte Carlo Tree Search is the trained policy network; the better the action, the higher the policy score is, for the given environment state , the number of times action has been selected so far. If the same action has been explored too many times, the denominator of this term will increase.
(2) Expansion
Imagine updating the environment;
(3) Evaluation
Evaluate the state-value score and return , and set the action score to ;
(4) Backup
Update the action value using the action score :
Average the state values of all subsequent steps.
VI. Continuous Control
In practical reinforcement learning, the action space may be discrete (for example, controlling a game character to move up, down, left, or right), or the actions may be continuous (robotic arm joint control).
For discrete control, classification can be used directly to obtain a onehot vector. Each element of the vector represents the score for performing that action, which is used to determine which action should be performed. In continuous control, however, the action space is infinite-dimensional, so this approach cannot be applied directly to continuous control.
A relatively conventional solution is to discretize the action space, but this approach also has problems. For example, for a robotic arm with 6 degrees of freedom, even if each degree of freedom is discretized into 360 points, the entire action space contains points. This causes the curse of dimensionality and makes training very difficult.
There are therefore two ways to implement continuous control:
- Deterministic policy network
- Stochastic policy network
6.1 Deterministic Policy Gradient (DPG)
Consider a robotic arm with only 2 degrees of freedom. The base has a motion range of (0,180), and the robotic arm has a motion range of (0,360). Therefore, the robotic arm’s action space is the continuous set , and an action is a two-dimensional vector.
DPG is an Actor-Critic method
- There is a policy network that controls the agent’s motion and makes decision a based on state s; Use the policy network to output a deterministic action a based on the input state s. Here, action a is the robot’s two-dimensional action vector.
- There is a value network that does not control the agent. It scores action a based on state s, thereby guiding improvements to the policy network. Use the value network with state s and action a as inputs. It outputs a real number value as the evaluation of the action. The better the action, the larger the value.
The principle of DPG is therefore to train these two networks.

(1) Value Network Training
- Obtain a training data transition each time
- Use the value network to predict the action value at the current time t:
- Use the value network to predict the action value at the next time t+1: , where . This action is not the action actually performed by the agent; is used only to update the value network.
- Calculate the TD error: , where the second term is the TD Target. One part is the reward actually observed, while the other part is the value network’s own prediction. Because we believe that the second term is closer to the actual situation than alone because it includes the real reward from this step, we want to approach the TD Target, which means making the TD error as small as possible.
- Perform gradient descent to update w:
There is a problem here. When calculating the TD error , a bootstrapping problem can occur. That is, if the initial value is overestimated or underestimated, the TD target will also be overestimated or underestimated and will propagate back to the value network itself, causing the overestimation or underestimation to persist. The solution is to use different neural networks to calculate the TD Target, namely Target Networks.
- Obtain a training data transition each time
- Use the value network to predict the action value at the current time t:
- Use the value network to predict the action value at the next time t+1: , where is the Target policy network used in place of the policy network. Its network structure is exactly the same as the policy network, but its parameters are different. is the Target value network. It has the same structure as the value network but different parameters.
(2) Policy Network Training
Training the policy network requires the value network to evaluate how good or bad the action is, thereby guiding improvements to the policy network.
In other words, update the policy network parameter so that the value network considers the action to be better. That is, improve to make the value as large as possible.
Given state s, the policy network outputs a deterministic action a, and if the value network is also deterministic, the output value is deterministic.
Therefore, the problem only requires changing to increase the value q. In other words, calculate the gradient of with respect to , then use gradient ascent to update so that increases. This gradient is called the Deterministic Policy Gradient DPG.
Here, , then perform gradient ascent
The detailed steps for jointly training the policy network and value network are as follows:
- The policy network makes a decision:
- Calculate the output of the value network:
- Use DPG to update the policy network:
- Use the Target networks and to calculate
- Calculate the TD error:
- Update the value network:
- Update the Target networks’ parameters: , , where is a hyperparameter
6.2 Stochastic Policies for Continuous Control
First, consider stochastic-policy continuous control with a degree of freedom equal to 1, meaning that all actions are real numbers.
Let represent the mean and represent the standard deviation. Both are functions of state s.
Use the probability density function of the normal distribution as the policy function:
The same applies to the d-dimensional case, where the action is a d-dimensional vector.
Let vector represent the mean and vector represent the standard deviation. Both are functions of state s.
Use a special normal distribution as the policy function:
However, we do not know and , so we do not know the policy function.
We can therefore use neural networks to approximate and , where
Take the logarithm of the policy function to turn the product into a sum, obtaining the auxiliary neural network . Calculate the gradient of f with respect to the parameters in the convolutional and fully connected layers, then use it to update the parameters through backpropagation.

References:
- Shusen Wang. Reinforcement Learning Course (YouTube)
Comments