{"id":513,"date":"2026-06-20T21:29:12","date_gmt":"2026-06-20T13:29:12","guid":{"rendered":"https:\/\/arkdoc.cc\/?p=513"},"modified":"2026-06-20T21:39:45","modified_gmt":"2026-06-20T13:39:45","slug":"lecture-policy-gradient","status":"publish","type":"post","link":"https:\/\/arkdoc.cc\/index.php\/2026\/06\/20\/lecture-policy-gradient\/","title":{"rendered":""},"content":{"rendered":"\n<div class=\"custom-html-post tex2jax_process\">\n\n<h1 id=\"lecture-policy-gradient\">Lecture: Policy Gradient<\/h1>\n<p>For simplicity, let us first consider a one-step decision-making\nprocess (also known as a contextual bandit).<\/p>\n<h4 id=\"problem-setup\">Problem Setup<\/h4>\n<p>Let <span class=\"math inline\">\\(s \\in \\set S\\)<\/span> be the state\nvector of the environment, and let <span class=\"math inline\">\\(a \\in\n\\set A\\)<\/span> be the action taken by the agent. The reward function is\ndenoted by <span class=\"math inline\">\\(r(a,s)\\)<\/span>. The agent\u2019s\nbehavior is characterized by a policy, which is conveniently represented\nas a conditional probability distribution, <span class=\"math inline\">\\(\\pi(a \\mid s)\\)<\/span>, specifying the probability\nof selecting each action <span class=\"math inline\">\\(a\\)<\/span> given a\nstate <span class=\"math inline\">\\(s\\)<\/span>. The objective is to find\nthe optimal policy <span class=\"math inline\">\\(\\pi^*\\)<\/span> that\nmaximizes the expected reward: <span class=\"math display\">\\[%R(\\pi \\mid\ns)\nR(\\pi) = \\mathbb{E}_{s\\sim p_0}\\mathbb{E}_{a\\sim \\pi(\\cdot | s)} [r(a,s)] = \\sum_{s,a}\np_\\pi(a, s) r(a,s),\\]<\/span> where <span class=\"math inline\">\\(p_0\\)<\/span> denotes the distribution of states,\nand we have <span class=\"math inline\">\\(p_{\\pi}(a,s)\\)<\/span> denotes\nthe joint distribution of <span class=\"math inline\">\\((a,s)\\)<\/span>\nwhen policy <span class=\"math inline\">\\(\\pi\\)<\/span> is used: <span class=\"math display\">\\[p_\\pi(a,s) = \\pi(a\\mid s) p_0(s).\\]<\/span>\nTypically, <span class=\"math inline\">\\(p_0\\)<\/span> is unknown to us,\nbut observed through a collection of data <span class=\"math inline\">\\(\\{s^{(i)}\\}\\)<\/span> drawn from <span class=\"math inline\">\\(p_0\\)<\/span>.<\/p>\n<div class=\"center\">\n\n<\/div>\n<h4 id=\"policy-gradient\">Policy Gradient<\/h4>\n<p>In practice, the policy <span class=\"math inline\">\\(\\pi(a \\mid s) =\n\\pi_\\theta(a \\mid s)\\)<\/span> is parameterized by a function with\nparameter <span class=\"math inline\">\\(\\theta\\)<\/span>. Assume the\nstate-action space <span class=\"math inline\">\\(\\mathcal S \\times\n\\mathcal A\\)<\/span> is finite or accountable, the gradient of the\nexpected reward with respect to <span class=\"math inline\">\\(\\theta\\)<\/span> is <span class=\"math display\">\\[\\begin{align}\n\\nabla_\\theta R(\\textcolor{blue}{\\pi_\\theta})\n&amp; =  \\nabla_\\theta \\left ( \\sum_{s,a} p_0(s) \\textcolor{blue}{\\pi_\\theta(a \\mid\ns)} r(a, s)  \\right ) \\notag \\\\\n&amp; = \\sum_{s,a} p_0(s) \\textcolor{blue}{\\nabla_\\theta \\pi_\\theta(a \\mid s)} r(a,\ns)  \\notag \\\\\n&amp; = \\sum_{s,a} p_0(s) \\textcolor{blue}{\\pi_\\theta(a \\mid s)}\\textcolor{blue}{ \\frac{\n\\nabla_\\theta \\pi_\\theta(a \\mid s) }{\\pi_\\theta(a \\mid s)} } r(a, s)\n\\notag \\\\\n&amp; = \\mathbb{E}_{\\textcolor{blue}{p_{\\pi_\\theta}}} \\left[ r(a, s) \\textcolor{blue}{\\nabla_\\theta\n\\log \\pi_\\theta(a \\mid s)} \\right], \\notag\n\\end{align}\\]<\/span> where the parts depending on <span class=\"math inline\">\\(\\theta\\)<\/span> are highlighted, and we use the\nlog-derivative trick <span class=\"math inline\">\\(\\nabla_\\theta \\log \\pi =\n\\nabla_\\theta \\pi_\\theta \/ \\pi_\\theta\\)<\/span>. This allows us to\nexpress the derivative of an expectation with respect to a distribution\nas the expectation of the reward weighted by <span class=\"math inline\">\\(\\nabla_\\theta \\log \\pi_\\theta(a \\mid s)\\)<\/span>.<\/p>\n<h4 id=\"reward-baseline\">Reward Baseline<\/h4>\n<p>For any policy <span class=\"math inline\">\\(\\pi^\\theta\\)<\/span>, it is\neasy to prove the following identity: <span class=\"math display\">\\[\\mathbb{E}_{a\\sim \\pi_\\theta(\\cdot|s)}[\\nabla_\\theta \\log\n\\pi_\\theta(a\\mid s)] =0,~~~~~ \\forall s,~\\theta.\\]<\/span><\/p>\n<p>Hence, we can generalize the gradient formula above to <span class=\"math display\">\\[\\begin{align}\n\\label{equ:pcgrad2}\n\\nabla_\\theta  R(\\pi_\\theta )\n&amp; = \\mathbb{E}_{p_{\\pi_\\theta}}  \\left [  (r(a,s) &#8211;\n\\textcolor{magenta}{v(s)})  \\textcolor{blue}{\\nabla_\\theta  \\log  \\pi_\\theta (a\\mid s)}  \\right ],\n\\end{align}\\]<\/span> where <span class=\"math inline\">\\(v(s)\\)<\/span> is\n<em>any<\/em> function that does not depend on the action <span class=\"math inline\">\\(a\\)<\/span>. The choice of <span class=\"math inline\">\\(v\\)<\/span> does not alter the expectation of the\nformula, but a proper choice of <span class=\"math inline\">\\(v\\)<\/span>\ncan reduce the variance of the mean estimation given empirical\nobservations.<\/p>\n<p>One common choice of baseline is <span class=\"math inline\">\\(v(s) =\n\\mathbb{E}_{a\\sim \\pi_\\theta(\\cdot|s)}[r(a,s)]\\)<\/span>, in which case the\ndifference <span class=\"math inline\">\\(r(a,s) &#8211; v(s)\\)<\/span> is known\nas the <em>advantage function<\/em>: <span class=\"math display\">\\[A(a, s)\n= r(a,s) &#8211; v(s).\\]<\/span> A positive value <span class=\"math inline\">\\(A(a,s) &gt; 0\\)<\/span> (respectively, negative\n<span class=\"math inline\">\\(&lt;0\\)<\/span>) indicates that the action\n<span class=\"math inline\">\\(a\\)<\/span> performs above (respectively,\nbelow) the average.<\/p>\n<h4 id=\"on-policy-estimation\">On-Policy Estimation<\/h4>\n<p>In practice, given observations <span class=\"math inline\">\\(\\{s^{(i)}\\}\\)<\/span> drawn from <span class=\"math inline\">\\(p_0\\)<\/span> and <span class=\"math inline\">\\(a^{(i)} \\sim \\pi^\\theta(\\cdot|s^{(i)})\\)<\/span>\ndrawn from the ongoing policy <span class=\"math inline\">\\(\\pi^\\theta\\)<\/span>, the gradient can be estimated\nby <span class=\"math display\">\\[\\begin{align}\n\\label{equ:onpolicyestimate}\n\\nabla_\\theta  R(\\pi_\\theta )\n\\approx \\frac{1}{n}\\sum_{i=1}^n  \nA^{(i)} \\nabla_\\theta  \\log  \\pi_\\theta (a^{(i)} \\mid s^{(i)}),~~~~~~\nA^{(i)} =  A(a^{(i)}, s^{(i)}).\n\\end{align}\\]<\/span> The gradient ascent update, also known as\nREINFORCE, <span class=\"math display\">\\[\\theta\\gets \\theta + \\epsilon\n\\nabla_\\theta  R(\\pi_\\theta ).\\]<\/span> Intuitively, the gradient <span class=\"math inline\">\\(\\nabla_\\theta \\log \\pi_\\theta (a^{(i)} \\mid\ns^{(i)})\\)<\/span> for data points <span class=\"math inline\">\\((a^{(i)},\ns^{(i)})\\)<\/span> with positive advantages <span class=\"math inline\">\\(A^{(i)} &gt; 0\\)<\/span> is positively weighted,\nincreasing the probability <span class=\"math inline\">\\(\\pi_\\theta(a \\mid\ns)\\)<\/span> during gradient ascent. Conversely, for data points with\nnegative advantages, the gradient is negatively weighted, decreasing the\nprobability.<\/p>\n<h4 id=\"connection-to-weighted-mle\">Connection to Weighted MLE<\/h4>\n<p>Assuming the data <span class=\"math inline\">\\(\\{a^{(i)},\ns^{(i)}\\}\\)<\/span> are fixed, the policy gradient <span class=\"math inline\">\\(\\nabla_\\theta R(\\pi_\\theta)\\)<\/span> coincides with\nthe gradient of the <span class=\"math inline\">\\(A^{(i)}\\)<\/span>-weighted log-likelihood function:\n<span class=\"math display\">\\[\\ell(\\pi_\\theta) = \\frac{1}{n} \\sum_{i=1}^n\nA^{(i)} \\log \\pi_\\theta(a^{(i)} \\mid s^{(i)}).\\]<\/span> This aligns with\nthe intuition of maximizing <span class=\"math inline\">\\(\\log \\pi(a \\mid\ns)\\)<\/span> for data points with large (and positive) <span class=\"math inline\">\\(A^{(i)}\\)<\/span>, while minimizing the\nlog-likelihood for negative <span class=\"math inline\">\\(A^{(i)}\\)<\/span>.<\/p>\n<p>The key difference, however, is that the data <span class=\"math inline\">\\(\\{a^{(i)}, s^{(i)}\\}\\)<\/span> are drawn from the\npolicy <span class=\"math inline\">\\(\\pi_\\theta\\)<\/span> and thus depend\non the current parameter <span class=\"math inline\">\\(\\theta\\)<\/span>. As\n<span class=\"math inline\">\\(\\theta\\)<\/span> is updated during policy\noptimization, the data must either be regenerated or reweighted to\nreflect changes in <span class=\"math inline\">\\(\\pi_\\theta\\)<\/span>. In\ncontrast, maximum likelihood estimation assumes the data are fixed.<\/p>\n<p>Hence, policy optimization can be viewed as an adaptively weighted\nmaximum likelihood estimation (MLE), where the weights (<span class=\"math inline\">\\(A^{(i)}\\)<\/span>) are adjusted across iterations\nusing newly generated data.<\/p>\n<h4 id=\"off-policy-estimation-via-importance-sampling\">Off-Policy\nEstimation via Importance Sampling<\/h4>\n<p>The gradient estimation in <a href=\"#equ:onpolicyestimate\" data-reference-type=\"eqref\" data-reference=\"equ:onpolicyestimate\">[equ:onpolicyestimate]<\/a> is\n<em>on-policy<\/em>, because the actions <span class=\"math inline\">\\(a\\)<\/span> must be drawn from the current policy\n<span class=\"math inline\">\\(\\pi_\\theta(\\cdot | s)\\)<\/span>. This does\nnot yield efficient use of data as new actions must be rolled out once\nthe policy is updated, and data from different policies cannot be used.\nIn comparison, <em>off-policy<\/em> methods allow us to leverage actions\nfrom different policies.<\/p>\n<p>One common approach to off-policy estimation is importance sampling.\nAssume that the data <span class=\"math inline\">\\(\\{a^{(i)},\ns^{(i)}\\}\\)<\/span> are drawn from a <em>behavior policy<\/em> <span class=\"math inline\">\\(\\pi^{\\mathtt{data}}\\)<\/span>. Using importance\nsampling, we have<\/p>\n<p><span class=\"math display\">\\[\\begin{align*}\n\\nabla_\\theta R(\\pi_\\theta)  \n&amp; = \\mathbb{E}_{p_{\\pi^{\\texttt{data}}}}\n\\left[\\frac{\\pi_\\theta(a|s)}{\\pi^{\\mathtt{data}}(a|s)} A(a,s)\n\\nabla_\\theta \\log \\pi_\\theta (a \\mid s) \\right] \\\\\n&amp; \\approx \\frac{1}{z} \\sum_{i=1}^n\nw^{(i)} A^{(i)}  \\nabla_\\theta \\log \\pi_\\theta (a^{(i)} \\mid s^{(i)}),\n~~~~~\n\\end{align*}\\]<\/span> where <span class=\"math inline\">\\(w^{(i)}\\)<\/span>\nis the importance weight: <span class=\"math display\">\\[w^{(i)} =\n\\frac{\\pi_\\theta(a^{(i)}|s^{(i)})}{\\pi^{\\mathtt{data}}(a^{(i)}|s^{(i)})},\\]<\/span>\nand the normalization constant <span class=\"math inline\">\\(z\\)<\/span> is\noften taken as <span class=\"math inline\">\\(z = \\sum_i\nw^{(i)}\\)<\/span>.<\/p>\n<div class=\"cremark\">\n<p>In RL, <em>on-policy methods<\/em> update the policy using data\ncollected from the current policy itself. <em>Off-policy methods<\/em>\nlearn from data collected under a different policy, allowing reuse of\npast experiences and improving sample efficiency, but at the cost of a\ndistribution mismatch between the behavior policy <span class=\"math inline\">\\(\\pi^{\\text{data}}\\)<\/span> and the target policy\n<span class=\"math inline\">\\(\\pi_\\theta\\)<\/span>. <em>Offline RL<\/em> is\nthe case of off-policy learning where training relies entirely on a\nfixed dataset with no further interaction.<\/p>\n<\/div>\n\n\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Lecture: Policy Gradient For simplicity, let us first c &hellip; <a href=\"https:\/\/arkdoc.cc\/index.php\/2026\/06\/20\/lecture-policy-gradient\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\"><\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-513","post","type-post","status-publish","format-standard","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/posts\/513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/comments?post=513"}],"version-history":[{"count":3,"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/posts\/513\/revisions"}],"predecessor-version":[{"id":516,"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/posts\/513\/revisions\/516"}],"wp:attachment":[{"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/media?parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/categories?post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arkdoc.cc\/index.php\/wp-json\/wp\/v2\/tags?post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}