<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ting Qiao on Medium]]></title>
        <description><![CDATA[Stories by Ting Qiao on Medium]]></description>
        <link>https://medium.com/@tingq111011?source=rss-f0bf574a3eb8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*guOzn_whJFAYj31uXN2GUg@2x.jpeg</url>
            <title>Stories by Ting Qiao on Medium</title>
            <link>https://medium.com/@tingq111011?source=rss-f0bf574a3eb8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 03:43:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tingq111011/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[RL]Soft-RL: Maximum Entropy Reinforcement Learning as Probabilistic Inference]]></title>
            <link>https://tingq111011.medium.com/papers-soft-rl-maximum-entropy-reinforcement-learning-as-probabilistic-inference-85dd80d3b70e?source=rss-f0bf574a3eb8------2</link>
            <guid isPermaLink="false">https://medium.com/p/85dd80d3b70e</guid>
            <category><![CDATA[entropy]]></category>
            <category><![CDATA[soft]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[soft-actor-critic]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <dc:creator><![CDATA[Ting Qiao]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 13:44:03 GMT</pubDate>
            <atom:updated>2022-11-25T15:28:18.313Z</atom:updated>
            <content:encoded><![CDATA[<p>[RL]Soft-RL: Maximum Entropy Reinforcement Learning as Probabilistic Inference</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*Itpn8A_dWBoYgpUZgt7tSg.png" /></figure><p>The first book you read about Reinforcement Learning is likely the book Reinforcement Learning: An Introduction. In the book, dear Richard Sutton and Andrew Barto introduced reinforcement learning from the view of maximizing total <strong>Reward</strong> in very detail. The book explained reinforcement learning step by step:</p><ol><li>Multi-armed Bandits problems</li><li>How to build a Markov Decision Process(MDPs).</li><li>Using Dynamic Programming to solve the MDPs.</li><li>Using Monte-Carlo methods to avoid computing the state dynamic transition model.</li><li>Using Important Sampling to keep track of behavior and target policies.</li><li>Temporal Difference</li></ol><p>One of the key ideas behind this book is how to update state-action evaluation Q(s, a) and state evaluation V(s).</p><p>However, if we are modeling decision problems in Markov Decision Process, wouldn’t it be nice if we have everything in probability view? Moreover, using the probabilistic view can provide a way to model policy’s entropy. In other words, <strong>handling the exploration problem becomes more convenient</strong>. One extra problem, <strong>What is really a reward is defined as</strong>. The paper <a href="https://arxiv.org/abs/1805.00909"><strong>Reinforcement learning and control as probabilistic inference: Tutorial and review</strong></a><strong>(</strong><a href="https://arxiv.org/pdf/1805.00909.pdf"><strong>1805.00909.pdf (arxiv.org)</strong></a><strong>)</strong> written by Sergey Levine provided a different view.</p><p>To summarize, there are two advantages of using soft reinforcement learning:</p><ol><li>Dealt with Exploration problem by limiting the entropy of policy.</li><li>Define how a reward function should be like.</li></ol><h3>Part 1 Models.</h3><p>The goal of reinforcement learning is finding the optimal decisions to achieve certain goal. It requires each action selected at each step to be global optimal. For each state-action, such optimality is indicated by a probability “O” in the Probabilistic graphical model (PGMs) as (b) below.<strong> This probability is the probability of this state-action is the optimal choice. In other words, how good is this action at given state.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*kdtlh-kvxcIeIaSbyczX9Q.png" /><figcaption>(a): State Transition Graph: <strong>P(s’|s, a)</strong> (b). State transition and rewards. <strong>P(s’|s, a) and P(O|s, a)</strong></figcaption></figure><p><strong>And this optimality is directly connected with how to define rewards. </strong>Same as Sutton’s book, the goal is find a parametrized policy P(a|s,θ) that maximize the overall total rewards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*QF4__tuFmNIkttejtCPDTg.png" /><figcaption><strong>The definition of a reward for each state-action should be corresponding to how close it is to the optimal action.</strong></figcaption></figure><p>In order to find a way to find the optimal solution, or we say optimize the policy’s parameters to find the optimal solution, the transactions between the agent and environment is form as a trajectory. And the probability of forming such trajectory is shown as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBXuuEHqBcQl9261Uy5g9Q.png" /><figcaption>A trajectory is the product of “initial state probability P(s_1)” and “policy P(a_t|s_t,θ)” and “state transition probability p(s_{t+1}|s_t,a_t)”</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*C3yTeXB41VV5JzWfa2e7ZA.png" /><figcaption>Ant Direction Example InfoRL: Interpretable Reinforcement Learning using Information Maximization</figcaption></figure><p>Clearly, only having the trajectory is not enough. We need to connect rewards, or Optimality(O) here, to the trajectory.</p><p><strong>In order to connect the optimality variable with trajectory, they defined the relationship between optimality variables and a trajectory by conditioning the trajectory on the Optimality variables. Although we assume the trajectory and optimality variables are independent(if P(τ|O) is equals 0) for now, this relationship is not wrong.</strong></p><p><strong>Based on the Bayes Equation, P(τ|O) = P(τ,O)* 1/P(O) where P(O) is a constant prior, then we can introduce the optimality in trajectory. And our goal now is maximizing this optimality.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*lOwGHr7U0Ux0lzKT3nfgQQ.png" /></figure><p>As we can see, an very familiar term “Returns” become part of this equation. Actually, in a deterministic environment, where the state transition probability is 1. The rewards goal can be reduced to standard planning or trajectory optimization like what we saw in Sutton’s book.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*vjcu4d7IcKeDW3Dj8x0pmQ.png" /></figure><h3><strong>Part 2 Modelled by Message Passing (Dynamic Programming).</strong></h3><p>It caused me a little bit confusion about Message Passing at the beginning. However, when I look into it, it is honestly just passing Q and V values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*wEkWndAf2rsUNAVF9t0WGw.png" /></figure><p>For the future (i.e. time steps t:T), they defined the probability of having a set of optimal states as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*FzD0bg9UMNcIvgGul6_Szg.png" /></figure><p>And they defined the probability of having optimal state-action pair in the future as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*64pLC7a5aXVZB0yjvz8NFg.png" /></figure><p>If you are familiar with what is Q and V vales are, you may have a hint about what is these two probability linked with. But be aware that now it is just probabilities.</p><p>Remember there is a conversion between Q and V values in Sutton’s book.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*pLH8L6z_2xbgiqibH9196w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*ksttX0cbuchS2RuaDDvc9Q.png" /></figure><p>Now, does it still stands? Of course it is. The Q and V depends on each other, so does the messages β(s, a) and β(s). Firstly, let’s find a way to convert Q to V. <strong>Here, we must assume that s_t and a_t are independent, so P(s_t, a_t) = p(s_t)p(a_t).</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*LkaHOmzx6GWDlCB955MlJQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N3nhpN614NiN3YQiWuu4Ww.png" /><figcaption>It is equivalent to V = G(Q) like the upper right Equation.</figcaption></figure><p><strong>One thing worth to note is that, P(a_t|s_t) is not policy at all. It is just a constant prior. </strong>Secondly, let’s find a way to convert V to Q.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WVDcM7MhZ6_X8-K_qO7LA.png" /></figure><p>And it is proofed by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKKEZ0Hmcd76ebhepoDNuw.png" /></figure><p><strong>Introduce Policy:</strong></p><p>Firstly, based on the Markov Property, the overall optimal policy P(a_t|s_t, O_{1:T}) is not depends on the past(O_{1:t-1}), but only depends on the future(O(t:T)). Therefore, P(a_t|s_t, O_{1:T})=P(a_t|s_t, O_{t:T}).</p><p><strong>We can easily find the optimal policy who is proportional to the β(s, a) divided by the β(s). Using bayes’ rule in the third step.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*coJJFUmHsZbByXNe4t85ug.png" /></figure><p>As you can notice, the way of defining and updating the β(s, a) and the β(s) are quiet similar to how we update Q and V values in standard reinforcement learning. Here we consider the β(s, a) and the β(s) as probability. They should be bounded to [0,1]. However, our Q value and V values can be any number. Let’s take a compromise, and transfer β(s, a) and the β(s) into log-space, where the Q and V values are negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*Vqn01RGKWwfuB8g-EBS70Q.png" /></figure><p>In standard reinforcement learning, the policy is correlated with advantage function. In other words, how to choose the action is depending on the Q(s_t,a_t)-V(s_t).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*7bq4SvByklbAWWcRIYY9yw.png" /></figure><p>And the policy is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*A0Mg0prPZsPZZWzNRtWahQ.png" /></figure><p>And the conversion between Q and V still stands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*GquX18X2T4Luktf6zRak2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*ckn4OPEbWfYOIoyp-4a0qA.png" /></figure><p>Therefore the message passing backup in deterministic environment is :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*zDcqu75nxcyaNbvNbAtoaQ.png" /></figure><p><strong>Be aware that the above equations are assuming deterministic state transitions.</strong></p><h3><strong>Part 3 Define Inferencing Objective(KL Divergence)</strong></h3><p>Let’s find the original definition of a trajectory with a policy making decisions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qBXuuEHqBcQl9261Uy5g9Q.png" /><figcaption>A trajectory is the product of “initial state probability P(s_1)” and “policy P(a_t|s_t,θ)” and “state transition probability p(s_{t+1}|s_t,a_t)”</figcaption></figure><p>When the environment is deterministic,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*AVbU83F0wM61Ew47CgUB2g.png" /></figure><p>And then, Let’s recall the overall distribution with the optimality variables of the trajectory graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*lOwGHr7U0Ux0lzKT3nfgQQ.png" /></figure><p>And when the dynamic is deterministic, it can be simplified as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*vjcu4d7IcKeDW3Dj8x0pmQ.png" /></figure><p><strong>Now the thing should become clear. The policy is updated to find the optimal solution who is as close as possible to the Equation 4. We want this KL-Divergence to be as small as possible.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*sxBwy4CBNEnQVFn2C8FUow.png" /></figure><p>Minimizing such KL-Divergence can be re-written as maximizing the negative KL-Divergence:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iINyF_gT9GUoFNgldbv2kw.png" /></figure><p>Vola! That’s looks very very familiar if you have ever read the paper<strong>[</strong><a href="http://proceedings.mlr.press/v80/haarnoja18b"><strong>Soft actor-critic: Off-policy maximum entropy deep reinforcement learning with a stochastic actor</strong></a><strong>]. </strong><a href="http://proceedings.mlr.press/v80/haarnoja18b/haarnoja18b.pdf"><strong>haarnoja18b.pdf (mlr.press)</strong></a> <strong>It is the soft goal of reinforcement learning taking consideration of policy entropy.</strong></p><h3><strong>Stochastic<em>(I am not sure about this part, so I will just paste the original text, some one could enlighten me about it?)</em>:</strong></h3><p>The Soft-Bellman Updates for stochastic environment may introduce “Risk Seeking” behaviors. It is due to the soft-max operation in the last component in Equation 7 below. It will emphasize high-values and suppress low-values, even when high-value is unlikely to happen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n8Vhph4hIWETasedu31abQ.png" /></figure><p>For stochastic environment, where the state transition probability is not 1. <strong>The dynamic and initial state term does not cancel.</strong> We use the trajectory level of KL-Divergence:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*lOwGHr7U0Ux0lzKT3nfgQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UteNvzBdiihEhFyRphHUMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*sxBwy4CBNEnQVFn2C8FUow.png" /></figure><p>Where:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*895pesMhLxdEGTVcMD8cuQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*04yvzEISJ1EVpGOd_XHIQg.png" /></figure><h3><strong>Part 4 Variational Inference and Stochastic Dynamics.</strong></h3><p>Under stochastic dynamic assumption, the goal is still maximizing the negative KL-Divergence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8EbW-Sgs20ymXrqFPXUx2w.png" /></figure><p>However, now we are optimizing something similar to the standard reinforcement learning. Therefore, we need to find the backward messages like what we did in standard reinforcement learning. And then optimize the objective by dynamic programming.</p><p>The V(S_T) is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*nJXfjTolrjwcJtbTHYAP9Q.png" /></figure><p>Which is coherent with previous definitions of :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*9MeYZA8dfd7JAreNu6smAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*6yqc3bf36Do3FuqW7hrckA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*Vqn01RGKWwfuB8g-EBS70Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*64pLC7a5aXVZB0yjvz8NFg.png" /></figure><p>Therefore, we want to maximize the right hand side of Equation 12.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lj9Bw4s91lpokd-uLXJqeA.png" /></figure><p>Then the above equation 12 in the paper can be proofed by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*bE2KIY25L10-ZO40BzfSpA.png" /></figure><p><strong>It is a important equation which has also been used in the paper about Soft-Actor-Critic. However, in that paper, the proof is not given clearly.</strong></p><p>Apparently, In the KL-Divergence, when the</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*s8ld7stkRy-ArYPEOFBJjg.png" /></figure><p>The KL-Divergence becomes 0 and it is the minimal. <strong>Therefore, the optimal policy is for the KL-Divergence only:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*OLmCjKngAmhnYx0r1GlnAg.png" /></figure><p>However, the V(S_T) term in Equation12 is not dealt with!<strong> We can just add one extra term to maximize both.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZtWMKrMQ9znf4KYA9d9QCQ.png" /></figure><p>And the objective is rewritten as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J3nATEk5prqNNOastcRrbQ.png" /></figure><p>Here, these two assumption is hold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*McQS4W4rKcmQblhwv5ujvw.png" /></figure><h3>Variational Inference</h3><p>There is some intractable p(\tau):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p6W3cI-LX5IwraIK4yf00w.png" /></figure><p>We want to use some tractable approximator to approximate the intractable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/983/1*23Qy9BLb_MmUfRk7UR3HVQ.png" /></figure><p>Here, if the q(s1) is defined to be equal to p(s1), and the state transition dynamics and approximated dynamics q(s_t+1|s_t,a_t) is defined to be equal as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*MhWBWnkdQ1zRiARjnYb9XQ.png" /></figure><p>Then the q(\tau) here is exactly the \hat{p(\tau)}:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/68/1*rJKJwnY9on5wDdqiPZQxSQ.png" /></figure><p>Therefore, maximizing the variational lower bound in variational inferencing is trying to maximize the trajectory’s optimality log p(O_{1:T}), and this inequation is derived from Jensen’s inequality:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y7Pw02qDFUvG5ER3ZskejA.png" /></figure><p>Jensen’s Inequality:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*VtqdYFykPiP10wb1EgO4_Q.png" /></figure><p>For more detail, A recommended paper is:</p><h3><a href="http://approximateinference.org/2016/accepted/HoffmanJohnson2016.pdf">Elbo surgery: yet another way to carve up the variational evidence lower bound</a></h3><p>If we replace the p(O_{1:T, s_{1:T}, a_{1:T}}) with the definition of rewards. and q(a_t|s_t). Then optimizing the bound is equivalent to optimizing the soft objective equation we defined before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MixwrW99GTiK6DfCu0834Q.png" /></figure><p><strong>In the end of this paper, the author provided three soft algorithms, namely, Soft-Q learning, Soft-Actor-Critic, and Soft(Maximum Entropy) Policy Gradient. They are corresponding to the Value-based, Actor-Critic, and Policy Gradient in standard Reinforcement Learning.</strong></p><h3><strong>Part 5 Summary</strong></h3><p>I think the prior contribution of this paper is providing a different view of reinforcement learning. The author model the solutions of Markov Decision Process as Probability Inferencing. It bring several advantages:</p><ol><li>How to do exploration. The exploration here is depending on the rewards, which the policy is softly trained to approach.</li><li>How to define rewards. The rewards here is defined as the optimality. It is a negative number that can be converted to probability by exponential function.</li><li>Taking advantage of probability research which is considered to be more diverse and mature.</li></ol><p>In this paper, there are three ways to do the optimization:</p><ol><li>Message Passing: Just like what we did in standard reinforcement leanring.</li><li>Utilizing the KL-Divergence between optimal trajectories(where there are rewards) and policy trajectories(where there are parameterized policy).</li><li>Variational Lower Bound.</li></ol><p>Although this paper has been published in 2018, and only cited around 260 times for now. I still consider this paper is a very good review for probabilistic inferencing as reinforcement learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85dd80d3b70e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PILCO explanation]]></title>
            <link>https://tingq111011.medium.com/pilco-explanation-ef5b69f6349f?source=rss-f0bf574a3eb8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef5b69f6349f</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[model-based]]></category>
            <category><![CDATA[pilco]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[bayesian-machine-learning]]></category>
            <dc:creator><![CDATA[Ting Qiao]]></dc:creator>
            <pubDate>Sat, 05 Sep 2020 12:24:22 GMT</pubDate>
            <atom:updated>2022-11-25T15:29:20.179Z</atom:updated>
            <content:encoded><![CDATA[<h3>[RL]PILCO explanation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqNNRQVd7TZoAUD2soRb1w.jpeg" /></figure><p>PILCO is one of the most important Model-Based Reinforcement Learning algorithms draws a lot of attention from researchers. It is using Gaussian Process as the function approximation instead of mainstream Neural Networks. Then the loss function is back-propagated to update the parameters in the controller.</p><p>This algorithm was the PhD topic of the author <a href="https://deisenroth.cc/">Marc Deisenroth</a>. There are more related papers to explain the detail of the algorithm. I think PILCO offered a way to model the uncertainty of the world model, by using covariance matrices.</p><p>I am writing this blog based on the original paper[Deisenroth, M., &amp; Rasmussen, C. E. (2011)]. And the GitHub repository <a href="https://github.com/nrontsis/PILCO">https://github.com/nrontsis/PILCO</a></p><p>For nearly all the letters and symbols you can found corresponding variables in this repository.</p><p>Hope it will help on your research. Please bear with my English skills. I am trying to improve it.</p><p>Happy Hacking! ╭(●｀∀´●)╯╰(●’◡’●)╮</p><h3>Part 1. Gaussian Process.</h3><p>Here comes the PILCO, which is using the Gaussian Process(GP) as the world model. Before we get into the PILCO, we need to understand the Gaussian Process first.</p><p><strong>Point 1. Gaussian Process is a data-driven learning algorithm(</strong>function approximator<strong>)</strong></p><p>Instead of updating parameters of linear functions(like a neural network) to learn, GP do prediction based on how close the unknow points to known points. This distance is measured by a kernel.</p><p>Another name for these methods is non-parametric learning methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*GzJW2-GzIuI2jhKhF6dpDg.png" /><figcaption>Leclercq, F. (2018)</figcaption></figure><p><strong>Point 2. Gaussian Process generalize to unseen points with a kernel</strong></p><p>A kernel is a measure of how close two data points are. It is used as a covariance function in the Multivariate Gaussian distribution, which is used to model the input, i.e, describes the <a href="https://en.wikipedia.org/wiki/Covariance">covariance </a>of the Gaussian process random variables.</p><p>Commonly used kernels(From GPytorch library):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*wd6lIi1WebPIaROmOirl0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*l2DTmx4jHC4FwBF9NOZ75g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*ElTegUp1wYlPbjJaNNdGqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*AvrwdeU944-V69BEV6cKDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*67KooTkwnGALoJZPNo5rdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*QYof13ItDUVmj6zjQ1xouw.png" /></figure><p>If the data is a 2D data with shape (1,2), then the kernel shape should be (2, 2).</p><p><strong>Point 3. Gaussian Process Prediction Intuition</strong></p><p>In case you are confused, first thing first, there is <strong>no function between x and y</strong>. All GP need to predict a new data point is the distance of this new data to other known data. After it has such a distance measure, the predicted value will be linked with the corresponding y.</p><p>Intuition Example (<strong>Not how the GP works</strong>):</p><p>We know a corresponding:</p><p>when x = 1, y = 5</p><p>when x = 20, y =47</p><p>when x = 100, y = 207.</p><p>Now, we want to know what is y* = ?, when x* = 25 correspondings to.</p><p>First, we compute the distance in x space. We have distance (25–1 = 24), (25–20 = 5), (100–25 = 75). Total distance will be (24 + 5 + 75 = 104).</p><p>When we try to predict, we want to say that since the x* = 25 is closer to x=20, we would say, it is more likely that y* is close to 47. But I want to take consideration of other points. So one thing we can do is we can take the weighted sum of known <strong>ys</strong>. The weight is the inversed and normalized distances.</p><p>y* = 5 * ((104–24)/(2*104)) + 47 * ((104–5)/(2*104)) + 207* ((104–75)/(2*104)) = 53.15</p><p><strong>Gaussian Process is a distribution over functions. The weights are decided by the kernel. And the x will only affect the kernel i.e, weights. The predicted y is kinda like a weighted sum of known ys. There is no function link x and y.</strong></p><p>For Gaussian Process, a formal implication is the <strong>Multivariate Gaussian Theorem</strong>.</p><p>Assume the distribution of dependent variable Y is modelled by a Multivariate Gaussian Distribution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*eUy8etic3-1Oo7b2wuLeSg.png" /></figure><p>Where the K means the kernel for <strong>Xs </strong>in the known data.</p><p>Where the K* means the kernel for <strong>Xs</strong> in the known data and <strong>X*s</strong> in the unknown data.</p><p>Where the K** means the kernel for <strong>X*</strong> in the unknown data.</p><p>The <strong>Y* </strong>we want to predict is under the Gaussian Distribution with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*COJuUGBgy0DF6Ch4lXL-pQ.png" /></figure><p><strong>Point 4. Hyperparameters and training of Gaussian Process.</strong></p><p>As we can see from above, there is no “training” at all needed. The training of Gaussian Process is referred to <strong>update the hyperparameters</strong>(lengthscale, variance, likelihood) with the Maximum Likelihood Optimization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*fHEes5DbGsK707m_NKyPlg.png" /></figure><p>For an RBF kernel:</p><p>Lengthscale: the “l” in the formula</p><p>Output scale(variance): the “σf” in the first part</p><p>Noise(likelihood): the “σ n” in the second part, controls noise modelling.</p><blockquote>Higher “<strong>l</strong>” values lead to smoother functions and therefore to coarser approximations of the training data. Lower “<strong>l</strong>” values make functions more wiggly with wide confidence intervals between training data points. “<strong>σf</strong>” controls the vertical variation of functions drawn from the GP. This can be seen by the wide confidence intervals outside the training data region in the right figure of the second row. “<strong>σn”</strong> represents the amount of noise in the training data. Higher “<strong>σn”</strong> values make more coarse approximations which avoids overfitting to noisy data. — — — <a href="http://krasserm.github.io/2018/03/19/gaussian-processes/">http://krasserm.github.io/2018/03/19/gaussian-processes/</a></blockquote><p><strong>Point 5. Drawbacks</strong></p><ol><li>The (K*K^(-1)) is an inverse matrix, which will take O(n³) to compute.</li><li>Due to the fact that it is data-driven, the learning is offline.</li></ol><h3>Part 2 PILCO</h3><p>Now, Let’s get into PILCO.</p><p>In general, there are three parts involved in the PILCO.</p><p>(1). Gaussian Process World Model</p><p>(2). A Loss function that computes how far away a state is from the target.</p><p>(3). A controller that propose an action.</p><p>What we want is a controller that can achieve high rewards(or low loss function). That involves taking the derivative of the controller’s parameters with respect to the loss function. Taking such a derivative can be done automatically after we link everything up with mainstream off the shelf libraries like Tensorflow or Pytorch.</p><p>One thing worth to note in PILCO is that, instead of taking a specific value, function approximator<strong> takes the distribution</strong>. In other words, the system is processing distributions.</p><p><strong>Note: World model is different from transition probability.</strong></p><ol><li>The current state “x_{t-1}” and action “u_{t-1}” are concatenated to form the input.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/151/1*qcoduXT6vz9Rtt8cDQHyZw.png" /></figure><p>The model “f” will take such input, and predict the next state “x_t”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*C0emuvp7k43dkrL0_hb23Q.png" /></figure><p>2. The next state is under Gaussian Distribution. The distribution is defined by its’ mean and covariance. The world model is <strong>predicting the difference</strong> between current state “x_{t-1}” and “x{t}”, given action “u_t”. <strong>The covariance of the next state prediction is provided by the world model. It is indicating how sure the world model about this prediction.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*6cWinL3chvcaoAm4o0nCmw.png" /></figure><p>3. The kernel that the Gaussian Process is a squared exponential (SE) kernel. The “<strong>Λ</strong>” is the reciprocal of the lengthscale.</p><p>The alpha is the variance.</p><p>There is no noise term here for now. It is in the (7)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*y5bhyGOZfXvLYttyALeElA.png" /></figure><p>4. In the paper, they write out the Gaussian Process prediction as well. Which is similar to what we had above. The lower case k is the x for the points we want to predict. Noise term was taken consideration with “<strong>σε</strong>”.</p><p><strong>Remember, the β is defined as the (K + σ²εI)^-1 * y. It will show up in the code.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*6_gmCOQ7WB-mNQxqw6zH0Q.png" /></figure><p>5. Get the contribution of input states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/151/1*qcoduXT6vz9Rtt8cDQHyZw.png" /></figure><p>In order to predict next state <strong>x_t</strong>, <strong>the distribution of concatenated input </strong>p(x_{t−1}, u_{t−1}) is needed. Assume that such distribution is a Gaussian distribution. The mean of the concatenated state-action is easy to compute. Only the covariance is the hard part. We need covariance from both <strong>u </strong>and <strong>x</strong>. Then concatenate them into a big covariance matrix.</p><p>p(x, u) = N(0, cov[x_{t−1}, u_{t−1}])</p><p>However,<strong> the u_{t-1} distribution depends on controller p(u|x, θ)</strong>. To get the distribution of u_{t-1}, they integrate out the influence of state <strong>x. </strong>The state <strong>x’s</strong> covariance does not depend on anything, so we can just use it.</p><p>p(u) = ∫ p(x, u) dx = ∫ p(u|x, θ) * p(x) dx</p><p>6. With the world model “f”, we can compute the transition probability p(f(x_{t−1})|x_{t−1}).</p><p>The distribution of states difference ∆t is from the weighted sum of transition probability. We integrate out the random variable x_{t−1} to get the p(∆t).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*30f6dgHnC5OxsW_9rtxeEg.png" /></figure><p>Computing the exact predictive distribution p(∆t) in Eq. (9) is analytically intractable. Therefore, we approximate p(∆t) by a Gaussian using exact moment matching.</p><p>7. From difference to real next state.</p><p>For mean, we just add the difference. For covariance, cross-covariance is computed first, then added. The way fo computing cross-covariance is provided in another his paper[Deisenroth, M. P.(2010)].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*KKDLBoWO8qnfVg_6kb_Agg.png" /></figure><p>8. Mean prediction</p><p>Now it’s time to have a look at how to implement it. As the (9) shows, the current states &amp; action x^~_{t-1} are integrated out((13)). And the “mf” is the expectation from GP prediction, which is referred back to the <strong>β </strong>around equation (7). The “<strong>qa</strong>” here is equivalent to the k* transpose in the equation (7).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*6_gmCOQ7WB-mNQxqw6zH0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*9603UktZf65GoLkgbkFwVQ.png" /></figure><p>Here, for each dimension “a” in the output, it will have one GP corresponding to it. For example in the MountainCar, the state is position and velocity, actions are concatenated. The prediction is the next position and the next velocity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*Wkmn2BXKdNzHmnGsNmHxkw.png" /></figure><p>Further, for each entry in the kernel in the “<strong>qa</strong>” or <strong>k*</strong>, replace it with the kernel formula (6), it ends up with the formula from “<strong>x</strong>” to output “<strong>q</strong>”, no more <strong>k</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*y5bhyGOZfXvLYttyALeElA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*WO9ZnxEk_c-InvUao6VKQg.png" /></figure><p>9. Covariance Prediction</p><p>For the covariance matrix prediction, they distinguished between diagonal elements “<strong>aa</strong>” and off-diagonal elements “<strong>ab</strong>”. “<strong>a</strong>” and “<strong>b</strong>” are the row and column of the target covariance matrix.</p><p>t<strong>he law of iterated variances(from Wikipedia):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*g1nNqgU3GBruVzNfU2UQzg.png" /></figure><blockquote>We distinguish between diagonal elements and off-diagonal elements: Using t<strong>he law of iterated variances</strong>, we obtain for target dimensions a, b = 1, . . . , D</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*_ruhP9Wgu3GPiXFvMKvwGg.png" /></figure><blockquote>The off-diagonal terms do not contain the additional term Ex˜t−1 [covf [∆a, ∆b|x˜t−1]] because of the conditional independence assumption of the GP models: Different target dimensions do not covary for given x˜t−1.</blockquote><p>The computation of μ_a, μ_b are from the last section, the mean prediction.</p><p>Since the off-diagonal and diagonal will <strong>share the diagonal part</strong>, First we compute the terms that are common to both the diagonal and off-diagonal entries, with <strong>the law of iterated expectation(different law from above E(X) = E(E(X|Y)))</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/515/1*CiuLMMobHPjiqVyfEdaoTw.png" /></figure><p><strong>the law of iterated expectation(see the end for reference):</strong></p><blockquote>the probability of rain tomorrow can be calculated by considering both cases (it rained today/it did not rain today) in turn. To use specific numbers, suppose that</blockquote><blockquote>The probability of rain today is 70%</blockquote><blockquote>If it rains today, it will rain tomorrow with probability 30%</blockquote><blockquote>If it does not rain today, it will rain tomorrow with probability 90%</blockquote><blockquote>In this case, the probability of rain tomorrow is</blockquote><blockquote>0.7 * 0.3 + 0.3 * 0.9 = 0.21 + 0.27 = 0.48 =48%</blockquote><p>The math here is a little bit annoying. I need to do more Google.</p><p>╮(๑•́ ₃•̀๑)╭</p><p>Things should be more clear now. We would like to do the same thing as what we did for the mean prediction. Replacing the mean “<strong>m</strong>” with <strong>β, </strong>and then “<strong>k(or q)</strong>” with the kernel formula.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*w1sR52-BFFq0R6A5_Nz-dw.png" /></figure><p>Then for each entry of Q, use the kernel formula (6) to have the detail computation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*y5bhyGOZfXvLYttyALeElA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*Sr31p5rpJnhJt4iHMV6OXw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*MklbjqX6vEc3FshvDRkElA.png" /></figure><p>Now we get the σ_ab done. The rest of the Equation (17) can be done by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*-QBKKrDjbY5u3_1Cxylhiw.png" /></figure><p>10. Loss function (<strong>Policy Evaluation</strong>)</p><p>The loss function is defined with the difference between the state and the target state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*o37XAtwmbF9tV4bccDSpfw.png" /></figure><p>The policy is evaluated with the expected return. To do it, set the controller to evaluation mode, and then discover the distribution of the states. The expected return is computed with the weighted sum of the cost for each state and the state distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/497/1*0cdfgpOXxFuSC1gEgLW31w.png" /></figure><p>11. <strong>Policy Improvement</strong></p><p>After <strong>linking the world model and controller together to the loss function</strong>. The parameter of the controller can be updated by propagating the loss back to the controller parameters by <strong>the Chain Rule</strong>.</p><h3>References:</h3><p>Deisenroth, M., &amp; Rasmussen, C. E. (2011). PILCO: A model-based and data-efficient approach to policy search. In <em>Proceedings of the 28th International Conference on machine learning (ICML-11)</em> (pp. 465–472).</p><p>Leclercq, F. (2018). Bayesian optimization for likelihood-free cosmological inference. <em>Physical Review D</em>, <em>98</em>(6), 063511.</p><p>Ebden, M. (2008). Gaussian Processes for Regression: A Quick Introduction.[online] Available at:&lt; <a href="http://www./">http://www.</a> robots. ox. ac. uk/~ mebden/reports. <em>GPtutorial. pdf</em>.</p><p><em>Law of Iterated Expectation | Brilliant Math &amp; Science Wiki</em>. (2020). Brilliant. <a href="https://brilliant.org/wiki/law-of-iterated-expectation/">https://brilliant.org/wiki/law-of-iterated-expectation/</a></p><p>Deisenroth, M. P.(2010) Efficient Reinforcement Learning using Gaussian Processes. KIT Scientific Publishing, 2010. ISBN 978–3–86644–569–7.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef5b69f6349f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>