Q-learning, a cornerstone of reinforcement learning, is the quest of an agent to master its environment by discerning the quality of its actions. Through iterative experiences, the agent constructs a map of rewards, forging paths to optimal outcomes.
Critic
- A
criticdoes not directly determine the action. - Given an actor , it evaluates how good is.
- There is an
actorcalled state value function- When using (to interact with
env), the cumulated reward is expected after visiting state .
- When using (to interact with
It literally just make a prediction. Having to look into the state , then yields a
scalar, .
Output of a critic depends on the evaluated actor.
Another Critic
- State-action value function
- When using actor , the cumulated reward is assessed after taking action a at state s
Policy is a network with parameter .
- Input: the observation of machine represented as a vector or a matrix.
- Output: each action corresponds to a neuron in output layer.
From the previous article, Trajectory . For every trajectory, its probability can be calculated ( given the parameters of the actor ):
depends on the behavior of the
environment, which can NOT be controlled.
Also, there is reward ,
The objective is to adjust to maximize . However, reward is a random variable (r.v.), due to the stochasticity of actor and environment (actor at a given state gives some random action , and so is environment). Expected Reward is calculated.
Policy Gradient
,
do not have to be differentiable, can even be a blackbox (Similar to GAN 🧐)
Note: (logarithmic derivative).
envcomponent in is not related to , therefore only do gradient on .
Intuitively, among ALL sampled data, at a certain state an action is to be executed ( is SOME
stateandactionpair within the trajectory) results in the trajectory . if certain pair results in some positive reward in the trajectory, then increase the likelihood of the pair and vice versa.
More Math
Cycles of data collection and model updates --- Policy is noted as (using existing agent to interact with the environment)
Using game as an example, in game play one , going through , , … results in , then for game play two (just change the superscript), etc. Using those data collected to calculate
Essentially, plug in ALL the pairs to calculate its
log probability, get thegradient, then multiply by a weight, which is the reward that is collected from a game play.
Extra Tips
Add a Baseline
- , its possible that is always positive.
- , according to the equation (and
explanationin the previous section), likelihood of shall increase if it provides a positive
Due to the nature of sampling (ONLY some pair can be sampled, therefore the probability of the un-sampled actions will decrease), a baseline term can be used.
Assign Suitable Credit
Instead of calculate the sum of rewards in the ENTIRE , it is BETTER to obtain the sum of rewards
after a certain action performed
Use represent the sum of rewards from time (where the action was performed) till the end of the game.
We can even take one step further by adding a discount factor for rewards on more future rewards on the current action , yields . It is reasonable because rewards collected not too long after an action should be weight MORE than later rewards.
Advantage Function
Eventually, becomes .
It measures how good it is if we take other than other actions at . indicates the nature that it goes through a network.