# Intuition of PG

Comparison to maximum likelihood

Policy gradient:

$$
\nabla\_\theta J(\theta)
\=\frac{1}{N}\sum\_{i=1}^N
\left\[
\left(\sum\_{t=1}^T \nabla\_\theta \log\pi\_\theta (a\_{i,t}|s\_{i,t})     \right)
\left(\sum\_{t=1}^T r(s\_{i,t},a\_{i,t})    \right)
\right]
\= \frac{1}{N}\sum\_i^N \nabla\_\theta \log \pi\_\theta (\tau\_i)r(\tau\_i)
$$

Maximum likelihood:

$$
\nabla\_\theta J\_{ML}(\theta)
\=\frac{1}{N}\sum\_{i=1}^N
\left(\sum\_{t=1}^T \nabla\_\theta \log\pi\_\theta (a\_{i,t}|s\_{i,t})     \right)
\=\frac{1}{N}\sum\_{i=1}^N \nabla\_\theta \log \pi\_\theta (\tau\_i)
$$

The only difference is that policy gradient update formula has a weight of $$r(\tau)$$, which means good stuff(with high reward sum) is made more likely but bad stuff(with low reward sum) is made less likely. To conclude, this algorithm simply formalizes the notion of "trial and error".


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://drdh.gitbook.io/rl/deep-rl-course/policy-gradient/intuition-of-pg.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
