Jekyll2017-12-09T04:05:16+00:00http://www.breloff.com/tbreloff.github.ioThoughts from my quest for Artificial General IntelligenceHow about Software 1.5 instead?2017-12-08T00:00:00+00:002017-12-08T00:00:00+00:00http://www.breloff.com/software-one-point-five<p>I recently read <a href="https://medium.com/@karpathy/software-2-0-a64152b37c35">Andrej Karpathy’s recent blog post</a> proclaiming that we are entering an era of “Software 2.0”, where traditional approaches to developing software (a team of human developers writing code in their programming language of choice… i.e. v1.0) will become less prevalent and important.</p>
<p>Instead, the world will be run by neural networks. Why not? They’re really great at recognizing objects in images, winning at board games, and even writing movie scripts. (Well <a href="https://www.theguardian.com/technology/2016/jun/10/artificial-intelligence-screenplay-sunspring-silicon-valley-thomas-middleditch-ai">maybe not movie scripts</a>.)</p>
<p>I can’t decide if he’s being naive or if we should be scared (no… not from an army of infinitely intelligent super-robots).</p>
<h2 id="is-he-naive">Is he naive?</h2>
<p>Neural networks are very powerful. There’s no question. But human software engineers do more than just pattern match inputs into outputs. In software development, it’s not enough to produce correct outputs 99% of the time (though even that is seemingly unachievable for most complex tasks). Imagine if your bank deposits only landed in the right account 99% of the time. Or if an air traffic control tower only assured your plane would land safely 99% of the time.</p>
<p>There are too many tasks that require near-certain guarantees on performance. And most importantly, many of those tasks require full human understanding of the processes and algorithms which determine the outcome. This is something we simply cannot expect from end-to-end neural (statistical) models.</p>
<p>I think he’s naive for claiming that statistical modeling can replace good ol’ fashion software engineering.</p>
<h2 id="should-we-be-scared">Should we be scared?</h2>
<p>Neural networks are fragile, complicated, opaque, compute-heavy, and easily tricked. They are simultaneously hard to understand and easy for bad actors to manipulate. But… they get some amazing results in certain domains (most notably sensorial tasks like vision, hearing, and speech).</p>
<p>Humans are gullible animals. We have implicit biases, and constantly change the facts to match our understanding of the world. In a world filled with Software 2.0, where the software programs are written by statistical models, the output of that software will start to look like magic. So much so that people will start to believe that it <strong>is</strong> magic.</p>
<p>Throughout history, people have been happy to worship and serve a power greater than them. What if people start to believe in <strong>computing magic</strong>, and trust important life decisions to a statistical model? Insurance companies might deny your coverage because a neural network told them a procedure wouldn’t help you. Employers will discriminate based on expected performance. Police will monitor and arrest people through statistical profiling, predicting crime that hasn’t yet happened. Courts will prosecute and sentence based on expectations of repeat offense.</p>
<p>You might be saying… “This is already happening!” I know. I think we should be scared of relying on statistical models without properly accounting for their biases and shortcomings.</p>
<h2 id="its-both">It’s both.</h2>
<p>Just like the spreading IoT time bomb, placing blind trust in Software 2.0 is a trojan horse. We let it into our lives without full understanding, and it puts us at risk in ways we can’t realize.</p>
<p>The path forward is in developing human-led technology. Building machines that can help and advise, but do not assert full control. We shouldn’t worship a machine, and we shouldn’t put our blind trust in statistical methods. Humans are more than just pattern matchers. We can transfer our experience to new environments. We can plan and reason, without having to fail at a task millions of times first.</p>
<p>Instead of rushing to Software 2.0, lets view neural networks in proper context: they are models, not magic.</p>Tom BreloffI recently read Andrej Karpathy’s recent blog post proclaiming that we are entering an era of “Software 2.0”, where traditional approaches to developing software (a team of human developers writing code in their programming language of choice… i.e. v1.0) will become less prevalent and important.Plots: Past, Present, and Future2017-12-02T00:00:00+00:002017-12-02T00:00:00+00:00http://www.breloff.com/plots-past-present-future<p>Earlier this year, I backed away from the Julia community to pursue a full time opportunity with the exciting AI startup <a href="https://www.elementalcognition.com/">Elemental Cognition</a> as a senior engineer. Elemental Cognition was founded by <a href="https://en.wikipedia.org/wiki/David_Ferrucci">Dave Ferrucci</a>, the AI visionary that led the original IBM Watson team to <a href="http://www.nytimes.com/2011/02/17/science/17jeopardy-watson.html?pagewanted=all">victory in Jeopardy</a>. We’re a small team (though we’re hiring!) of talented and passionate researchers and engineers, some of whom were instrumental in the success of Watson, working to build machines with common sense and reasoning (thought partners, if you will). It’s incredibly interesting, but it also doesn’t leave time for hobbies.</p>
<p>In this post I wanted to provide some perspective on the Plots project, from origin to today, as well as to speculate on its future. If you have further questions about this project (or any of my other open source efforts), please use the public forums (Github, Discourse, Gitter, Slack) to seek help from other users and developers, as I have very little capacity to answer emails or messages sent directly to me. (Not to mention I probably won’t have the most up to date answer!)</p>
<h2 id="past">Past</h2>
<p>I spent my career in finance building custom visualization software to analyze and monitor my trading and portfolios. When I started using Julia, the visualization options were not exciting. Most available packages were slow, lacking features, or cumbersome to use (or all of those things). As both the primary designer <strong>and</strong> user of my software in my previous roles, I knew a better approach was possible.</p>
<p>In 2015, early in my Julia experience, I created <a href="https://github.com/tbreloff/Qwt.jl">Qwt.jl</a>, a Julia interface to a slightly customized wrapper of the Qwt visualization framework. I used it primarily to analyze trading simulations and watch networks of spiking neurons fire. It was (IMO) a massive step up in cleanliness and usability compared to my experiences doing visualization in Python, C++, and Java. I am a nut for convenience, and made sure all the defaults were set such that 90% of the time they were exactly what I wanted. Qwt.jl could be thought of as the design inspiration for the API of Plots.</p>
<p>In August of 2015, a bunch of devs in the Julia community (most of which had “competing” visualization packages) set up the JuliaPlot (note the missing “s”) organization to discuss the state of Julia visualization. We all agreed that the community was too fragmented but most thought it was too hard a problem to tackle properly. Each package had many strengths and weaknesses, and there was large difference in supported feature sets and API style.</p>
<p>I laid out a rough plan for “one interface to rule them all”. It was not well received, with the biggest objection that it wasn’t likely to be successful. People, after all, have very different preferences in naming, styles, and requirements. It would be impossible to please enough people enough of the time to make the time investment worthwhile. Now, telling me something is impossible is an effective way to motivate me. I pushed the <a href="https://github.com/JuliaPlots/Plots.jl/tree/f222dd845869a5f16cf9116f5b2802033dfe0fc0">initial commits of Plots</a> that weekend.</p>
<h2 id="present">Present</h2>
<p>Plots (and the larger JuliaPlots ecosystem) has been (again, IMO) a wildly successful project. Is it perfect? Of course not. Nothing is. There are precompilation issues, unsatisfying customization of legends, minimal interactivity, and more. But it has received a large following of loyal users and (much more important) dedicated contributors and maintainers.</p>
<p>Sadly, I don’t have the ability to work on the project, as described above. In fact, I bet you can guess when I joined Elemental Cognition given my Github activity:</p>
<p><img src="/images/github_activity_2017.png" alt="" /></p>
<p>However, even though I’ve backed away from the project, it is in good hands with many people invested in its continued success. Looking at the <a href="https://github.com/JuliaPlots/Plots.jl/graphs/contributors">list of contributors to Plots</a> (64 people at the time of writing this post) and the graph of commits (below), it seems very clear that this is an active and passionate community of Julia visualizers that care about the success of the ecosystem.</p>
<p><img src="/images/github_commits_plots.png" alt="" /></p>
<p>In fact, this graph seems to show that activity has <strong>risen</strong> since I handed over responsibility of the organization to the <a href="https://github.com/orgs/JuliaPlots/people">JuliaPlots team</a>. I reason that my departure gave other members the courage to take a more active role, before which their contributions were not as aggressive and passionate.</p>
<p>The design of <a href="https://github.com/JuliaPlots/RecipesBase.jl">RecipesBase</a> and the <a href="http://docs.juliaplots.org/latest/recipes/">recipes concept</a> has ensured that, even if something better comes along to replace the Plots core, things like StatPlots, PlotRecipes, and many other custom recipes can still be used. This is a motivating idea when deciding whether to invest time in a project… knowing that a contributed recipe can outlast the plotting package it was designed for. This is a primary reason that I expect JuliaPlots to remain active and vibrant.</p>
<h2 id="future">Future</h2>
<p>There are many ways to make visualization in Julia better. We need better compilation performance, fewer bugs, better support for interactive workflows, more complete documentation, as well as countless other issues. The number of things that can be improved is a testament to how insanely difficult it is to build a visualization platform. It’s perfectly natural to have 10 different solutions, because there are 1,000 different ways to look at a dataset. How could one solution possibly cover everything?</p>
<p>During (and after) JuliaCon 2016, <a href="https://github.com/SimonDanisch">Simon Danisch</a> and I had a bunch of brainstorming sessions diving into how we could improve the core Plots engine. These conversations were mostly centered around strategies to support better performance and interactivity in the Plots API and core loop. We also wanted to give backends more control over lazily recomputing attributes and data, and optional updates to subparts of the visualization (when few things have changed). The goal was marrying extreme flexibility with extreme performance (similar to the goal of Julia itself).</p>
<p>I <strong>hope</strong> that Simon’s latest project <a href="https://github.com/SimonDanisch/Makie.jl">MakiE</a> is the realization of those ideas and goals. I would consider it a big success if he could replace the core of Plots with a new engine, without losing any of the flexibility and features that currently exist. Of course, it will be a ridiculously massive effort to achieve feature-parity without tapping into recipes framework and the Plots API. So my skepticism rests on the question of whether the existing concepts can be mapped into a MakiE engine. I wish Simon the best of luck!</p>
<p>Aside from large rebuilds, there is some low-hanging fruit to a better ecosystem, some of which will be helped by things like “Pkg3” and other core Julia improvements. Also, the (eventual) release of Julia 1.0 will bring a wave of new development effort to fill in the gaps and add missing features.</p>
<p>All things told, I have high hopes for the future of Julia and especially the visualization, data science, and machine learning sub-communities within. I hope to find my way back to the language someday!</p>Tom BreloffEarlier this year, I backed away from the Julia community to pursue a full time opportunity with the exciting AI startup Elemental Cognition as a senior engineer. Elemental Cognition was founded by Dave Ferrucci, the AI visionary that led the original IBM Watson team to victory in Jeopardy. We’re a small team (though we’re hiring!) of talented and passionate researchers and engineers, some of whom were instrumental in the success of Watson, working to build machines with common sense and reasoning (thought partners, if you will). It’s incredibly interesting, but it also doesn’t leave time for hobbies.Learning without Backpropagation: Intuition and Ideas (Part 2)2016-12-03T00:00:00+00:002016-12-03T00:00:00+00:00http://www.breloff.com/no-backprop-part2<p>In <a href="/no-backprop">part one</a>, we peeked into the rabbit hole of backprop-free network training with asymmetric random feedback. In this post, we’ll jump into the rabbit hole with both feet. First I’ll demonstrate how it is possible to learn by “gradient” descent with <strong>zero-derivative activations</strong>, where <strong>learning by backpropagation is impossible</strong>. The technique is a modification of Direct Feedback Alignment. Then I’ll review several different (but unexpectedly related) research directions: targetprop, e-prop, and synthetic gradients, which set up my ultimate goal: efficient training of arbitrary recurrent networks.</p>
<h2 id="direct-feedback-alignment">Direct Feedback Alignment</h2>
<p>In recent research from <a href="https://arxiv.org/abs/1609.01596" title="Direct Feedback Alignment Provides Learning in Deep Neural Networks (Nøkland 2016)">Arild Nøkland</a>, he explores extensions to random feedback (see <a href="/no-backprop">part one</a>) that avoid backpropagating error signals sequentially through the network. Instead, he proposes Direct Feedback Alignment (DFA) and Indirect Feedback Alignment (IFA) which connect the final error layer directly to earlier hidden layers through random feedback connections. Not only are they more convenient for error distribution, but they are more biologically plausible as there is no need for weight symmetry <strong>or</strong> feedback paths that match forward connectivity. A quick tutorial on the method:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/AZ0emAUIkw0" frameborder="0" allowfullscreen=""></iframe>
<h2 id="learning-through-flat-activations">Learning through flat activations</h2>
<p>In this post, we’re curious whether we can use a surrogate gradient algorithm that will handle threshold activations. <a href="https://arxiv.org/abs/1609.01596" title="Direct Feedback Alignment Provides Learning in Deep Neural Networks (Nøkland 2016)">Nøkland</a> connects the direct feedback connections from the transformation output error gradient to the “layer output”, which in this case is the <strong>output of the activation functions</strong>. However, we want to use activation functions with zero derivative, so even with direct feedback the gradients would be zeroed during propagation through the activations.</p>
<p>To get around this issue, we modify DFA to instead connect the error layer directly to the <strong>inputs of the activations</strong>, instead of the outputs. The result is that we have affine transformations which can learn to connect latent input ($h_{i-1}$ from earlier layers) to a projection of output error ($B_i \nabla y$) into the space of $h_i$, <strong>before</strong> applying the threshold nonlinearity. The effect of the application of a nonlinear activation is “handled” by the progressive re-learning of later network layers. Effectively, each layer <strong>learns how to align their inputs with a fixed projection of the error</strong>. The hope is that, by aligning layer input with final error gradients, we can <strong>project the inputs to a space that is useful for later layers</strong>. Learning happens in parallel, and later layers eventually learn to adjust to the learning that happens in the earlier layers.</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/KwHG3O8ttcc" frameborder="0" allowfullscreen=""></iframe>
<h2 id="mnist-with-modified-dfa">MNIST with Modified DFA</h2>
<p>Reusing the approach in <a href="/JuliaML-and-Plots">an earlier post on JuliaML</a>, we will attempt to learn neural network parameters both with backpropagation and our modified DFA method. The combination of Plots and JuliaML makes digging into network internals and building custom learning algorithms super-simple, and the DFA learning algorithm was fairly quick to implement. The full notebook can be found <a href="https://github.com/tbreloff/notebooks/blob/master/juliaml_mnist_nobackprop.ipynb">here</a>. To ease understanding, I’ve created a video to review the notebook, method, and preliminary results:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/CCcFznBBElA" frameborder="0" allowfullscreen=""></iframe>
<p>Nice animations can be built using the super-convenient animation facilities of <a href="https://juliaplots.github.io">Plots</a>:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/cFOmmMKn_Gc" frameborder="0" allowfullscreen=""></iframe>
<h2 id="target-propagation">Target Propagation</h2>
<p>The concept of Target Propagation (targetprop) goes back to <a href="http://link.springer.com/chapter/10.1007/978-3-642-82657-3_24" title="Learning Process in an Asymmetric Threshold (LeCun 1987)">LeCun 1987</a>, but has recently been explored in depth in <a href="https://arxiv.org/abs/1407.7906" title="How Auto-Encoders Could Provide Credit Assignment in Deep Networks via Target Propagation (Bengio 2014)">Bengio 2014</a>, <a href="https://arxiv.org/abs/1412.7525" title="Difference Target Propagation (Lee et al 2014)">Lee et al 2014</a>, and <a href="https://arxiv.org/abs/1502.04156" title="Towards Biologically Plausible Deep Learning (Bengio et al 2015)">Bengio et al 2015</a>. The intuition is simple: instead of focusing solely on the “forward-direction” model ($y = f(x)$), we also try to fit the “backward-direction” model ($x = g(y)$). $f$ and $g$ form an auto-encoding relationship; $f$ is the <strong>encoder</strong>, creating a latent representation and predicted outputs given inputs $x$, and $g$ is the <strong>decoder</strong>, generating input representations/samples from latent/output variables.</p>
<p><a href="https://arxiv.org/abs/1407.7906" title="How Auto-Encoders Could Provide Credit Assignment in Deep Networks via Target Propagation (Bengio 2014)">Bengio 2014</a> iteratively adjusts weights to push latent outputs $h_i$ towards the <strong>targets</strong>. The final layer adjusts towards useful final targets using the output gradients as a guide:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\hat{h}_i &= g_i (\hat{h}_{i+1}) \nonumber \\
\Delta \hat{h}_M &= -\eta \frac{\partial L}{\partial y_M} \nonumber
\end{align} %]]></script>
<p><a href="https://arxiv.org/abs/1412.7525" title="Difference Target Propagation (Lee et al 2014)">Difference Target Propagation</a> makes a slight adjustment to the update, and attempts to learn auto-encoders which fulfill:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\hat{h}_i - h_i &= g_i (\hat{h}_{i+1}) - g_i (h_{i+1}) \nonumber
\end{align} %]]></script>
<p>Finally, <a href="https://arxiv.org/abs/1502.04156" title="Towards Biologically Plausible Deep Learning (Bengio et al 2015)">Bengio et al 2015</a> extend targetprop to a Bayesian/generative setting, in which they attempt to reduce divergence between generating distributions p and q, such that the pair of conditionals form a denoising auto-encoder:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
h_i &\sim p (h_i | \hat{h}_{i+1}) \nonumber \\
h_i &\sim q (h_i | \hat{h}_{i-1}) \nonumber
\end{align} %]]></script>
<p>Targetprop (and its variants/extensions) is a nice alternative to backpropagation. There is still sequential forwards and backwards passes through the layers, however we:</p>
<ul>
<li>avoid the issues of vanishing and exploding gradients, and</li>
<li>focus on the role of intermediate layers: creating latent representations of the input which are useful in the context of the target values.</li>
</ul>
<h2 id="equilibrium-propagation">Equilibrium Propagation</h2>
<p><a href="https://arxiv.org/abs/1602.05179" title="Equilibrium Propagation: Bridging the Gap Between Energy-Based Models and Backpropagation (Scellier and Bengio 2016)">Equilibrium Propagation</a> (e-prop) is a relatively new approach which (I’m not shy to admit) I’m still trying to get my head around. As I understand, it uses an iterative process of perturbing components towards improved values and allowing the network dynamics to settle into a new equilibrium. The proposed algorithm alternates between phases of “learning” in a forward and backward direction, though it is a departure from the simplicity of backprop and optimization.</p>
<p>The concepts are elegant, and it offers many potential advantages for efficient learning of very complex networks. However it will be a long time before those efficiencies are realized, given the trend towards massively parallel GPU computations. I’ll follow this line of research with great interest, but I don’t expect it to be used in a production setting in the near future.</p>
<h2 id="synthetic-gradients">Synthetic Gradients</h2>
<p>A <a href="https://arxiv.org/abs/1608.05343" title="Decoupled Neural Interfaces using Synthetic Gradients (Jaderberg et al 2016)">recent paper</a> from DeepMind takes an interesting approach. What if we use complex models to estimate useful surrogate gradients for our layers? Their focus is primarily from the perspective of “unlocking” (i.e. parallelizing) the forward, backward, and update steps of a typical backpropagation algorithm. However they also offer the possibility of estimating (un-truncated) Backpropagation Through Time (BPTT) gradients, which would be a big win.</p>
<p>Layers output to a local model, called a Decoupled Neural Interface. This local model estimates the value of the backpropagated gradient that would be used for updating the parameters of that layer, estimated using only the layer outputs and target vectors. If you’re like me, you noticed the similarity to DFA in modeling the relationship of the local layer and final targets in order to choose a search direction which is useful for improving the final network output.</p>
<h2 id="what-next">What next?</h2>
<p>I think the path forward will be combinations and extensions of the ideas presented here. Like synthetic gradients and direct feedback, I think we should be attempting to find reliable alternatives to backpropagation which are:</p>
<ul>
<li>Highly parallel</li>
<li>Asymmetric</li>
<li>Local in time and space</li>
</ul>
<p>Obviously they must still enable learning, and efficient/simple solutions are preferred. I like the concept of synthetic gradients, but wonder if they are optimizing the wrong objective. I like direct feedback, but wonder if there are alternate ways to initialize or update the projection matrices ($B_1, B_2, …$). Combining the concepts, can we add non-linearities to the error projections (direct feedback) and learn a more complex (and hopefully more useful) layer?</p>
<p>There is a lot to explore, and I think we’re just at the beginning. I, for one, am happy that I chose the red pill.</p>Tom BreloffIn part one, we peeked into the rabbit hole of backprop-free network training with asymmetric random feedback. In this post, we’ll jump into the rabbit hole with both feet. First I’ll demonstrate how it is possible to learn by “gradient” descent with zero-derivative activations, where learning by backpropagation is impossible. The technique is a modification of Direct Feedback Alignment. Then I’ll review several different (but unexpectedly related) research directions: targetprop, e-prop, and synthetic gradients, which set up my ultimate goal: efficient training of arbitrary recurrent networks.Learning without Backpropagation: Intuition and Ideas (Part 1)2016-11-22T00:00:00+00:002016-11-22T00:00:00+00:00http://www.breloff.com/no-backprop<p>For the last 30 years, artificial neural networks have overwhelmingly been trained by a technique called backpropagation. This method is correct, intuitive, and easy to implement in both software and hardware (with specialized routines available for GPU computing). However, there are downsides to the method. It can cause practical instabilities in the learning process due to vanishing and exploding gradients. It is inherently sequential in design; one must complete a full sequential forward pass before computing a loss, after which you can begin your sequential backward pass. This sequential requirement makes parallelizing large networks (in space and/or time) difficult. Finally, it may be too conservative of a method to achieve our true goal: optimizing out-of-sample global loss. For these reasons, we explore the possibility of learning networks without backpropagation.</p>
<h2 id="backpropagation">Backpropagation</h2>
<p>Backpropagation is fairly straightforward, making use of some basic calculus (partial derivatives and the chain rule), and matrix algebra. Its goal: to measure the effect of internal parameters of a model on the final loss (or cost) of our objective. This value is called the <strong>gradient</strong> of our parameters with respect to the <strong>loss</strong>. For input x, target y, model f, and model parameters $\theta$:</p>
<script type="math/tex; mode=display">\nabla_\theta = \frac{\partial L(f(x,\theta), y)}{\partial \theta} = \frac{\partial L}{\partial \theta} = \frac{\partial L}{\partial f} \frac{\partial f}{\partial \theta}</script>
<p>For a quick review of the backpropagation method, see this short video:</p>
<iframe width="560" height="315" src="https://www.youtube.com/embed/qD4YR8MgOs8" frameborder="0" allowfullscreen=""></iframe>
<h2 id="the-symmetry-of-the-forward-and-backward-pass">The symmetry of the forward and backward pass</h2>
<p>For a commonly used linear transformation:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
y &= w x + b \nonumber \\
\theta &= \{w, b\} \nonumber
\end{align} %]]></script>
<p>we typically multiply the backpropagated gradient by the <strong>transpose of the weight matrix</strong>: $w^T$. This is the mathematically correct approach to computing the exact gradient:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\nabla_w &= \nabla_y x^T \nonumber \\
\nabla_b &= \nabla_y \nonumber \\
\nabla_x &= w^T \nabla_y \nonumber
\end{align} %]]></script>
<p>All was right with the world, until I read <a href="https://arxiv.org/abs/1411.0247?" title="Lillicrap et al: Random feedback weights support learning in deep neural networks (2014)">Random feedback weights support learning in deep neural networks</a>. In it, Lillicrap et al describe how you can replace $w^T$ with <strong>a random and fixed matrix</strong> $B$ during the backward pass so that:</p>
<script type="math/tex; mode=display">\nabla_x = B \nabla_y</script>
<p>And the network will still learn. WTF?! How could you possibly learn something from random feedback? It was as if I was no longer Mr. Anderson, but instead some dude sitting in goo with tubes coming out of my body. Why did I just choose the red pill?</p>
<p><img src="https://media.licdn.com/mpr/mpr/shrinknp_800_800/AAEAAQAAAAAAAAQSAAAAJDJmMjgwNjU1LWFmYzMtNDM5Ny1hZjUwLWQ5NjBlNWUzYzc4Nw.jpg" alt="" /></p>
<p>To gain intuition about how random feedback can still support learning, I had to step back and consider the function of neural nets. First there are many <strong>exactly equivalent</strong> formulations of a neural net. Just reorder the nodes of the hidden layers (and the corresponding rows of the weight matrix and bias vector and the columns of downstream weights), and you’ll get the exact same output. If you also allow small offsetting perturbations in the weights and biases, the final output will be relatively close (in the non-rigorous sense). There are countless ways to alter the parameters in order to produce effectively equivalent models.</p>
<p>Intuitively we may think that we are optimizing a function like:</p>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20537722/2c43a9f0-b0bc-11e6-90ad-8a14d2714b12.gif" alt="" /></p>
<p>But in reality, we are optimizing a function like:</p>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20537708/1560c1a0-b0bc-11e6-947c-7600cfc96446.gif" alt="" /></p>
<p>Vanilla backpropagation optimizes towards the surface valley (local minimum) closest to the initial random weights. Random feedback first randomly picks a valley and instead optimizes towards that. In the words of <a href="https://arxiv.org/abs/1411.0247?" title="Lillicrap et al: Random feedback weights support learning in deep neural networks (2014)">Lillicrap et al</a>:</p>
<blockquote>
<p>The network learns how to learn – it gradually discovers how to use B, which then allows effective modification of the hidden units. At first, the updates to the hidden layer are not helpful, but they quickly improve by an implicit feedback process that alters W so that $e^T W B e > 0$.</p>
</blockquote>
<p>We implicitly learn how to make W approximately symmetric with B before searching for the local minimum. Wow.</p>
<h2 id="relationship-to-dropout">Relationship to Dropout</h2>
<p>Trying to intuit random feedback felt similar to my process of understanding <a href="https://www.cs.toronto.edu/~hinton/absps/JMLRdropout.pdf" title="Srivastava et al: Dropout: A Simple Way to Prevent Neural Networks from Overfitting (2014)">Dropout</a>. In a nutshell, Dropout simulates an ensemble model of $2^n$ sub-models, each composed of a subset of the nodes of the original network. It <strong>avoids overfitting by spreading the responsibility</strong>. Except it’s not a real ensemble (where models are typically learned independently), but instead some sort of co-learned ensemble. The net effect is a less powerful, but usually more general, network. The explanation I see for why Dropout is beneficial is frequently: “<strong>it prevents co-adaption of latent features</strong>”. Put another way, it prevents a network from acquiring weights that force a dependence between latent (hidden) features.</p>
<p>In backpropagation, the gradients of early layers can vanish or explode unless the weights and gradients of later layers are highly controlled. In a sense, we see <strong>co-adaption of weights across layers</strong>. The weights of earlier layers are highly dependent on the weights of later layers (and vice-versa). Dropout reduces co-adaption from <strong>intra-layer neurons</strong>, and random feedback may help reduce co-adaption from <strong>inter-layer weights</strong>.</p>
<h2 id="benefits-of-breaking-the-symmetry">Benefits of breaking the symmetry</h2>
<p>Some will claim that random feedback is more biologically-plausible, and this is true. However the real benefit comes from breaking the fragile dependence of early-layer weight updates from later-layer weights. The construction of the fixed feedback matrices ${B_1, B_2, …, B_M}$ can be managed as additional hyperparameters and have the potential to stabilize the learning process.</p>
<h2 id="next">Next</h2>
<p>Random feedback is just the tip of the iceberg when it comes to backprop-free learning methods (though random feedback is more a slight modification of backprop). In part 2, I’ll review more research directions that have been explored, and highlight some particularly interesting recent methods which I intend on extending and incorporating into the <a href="/JuliaML-and-Plots">JuliaML</a> ecosystem.</p>Tom BreloffFor the last 30 years, artificial neural networks have overwhelmingly been trained by a technique called backpropagation. This method is correct, intuitive, and easy to implement in both software and hardware (with specialized routines available for GPU computing). However, there are downsides to the method. It can cause practical instabilities in the learning process due to vanishing and exploding gradients. It is inherently sequential in design; one must complete a full sequential forward pass before computing a loss, after which you can begin your sequential backward pass. This sequential requirement makes parallelizing large networks (in space and/or time) difficult. Finally, it may be too conservative of a method to achieve our true goal: optimizing out-of-sample global loss. For these reasons, we explore the possibility of learning networks without backpropagation.JuliaML Transformations: Internal Design2016-11-21T00:00:00+00:002016-11-21T00:00:00+00:00http://www.breloff.com/transformations-video-internals<p>In this video post, I expand on my <a href="/transformations">introduction to Transformations</a> and show the core idea behind the design: namely that each transformation has a black-box representation of input, output, and (optionally) parameters which are vectors in contiguous storage. Julia’s excellent type system and efficient array views allow for very convenient and intuitive structures.</p>
<hr />
<iframe width="560" height="315" src="https://www.youtube.com/embed/yscT_P0k-Bs" frameborder="0" allowfullscreen=""></iframe>
<p>For questions, comments, or if you’re interested in collaborating, please join the <a href="https://gitter.im/JuliaML/chat">JuliaML Gitter chat</a>.</p>Tom BreloffIn this video post, I expand on my introduction to Transformations and show the core idea behind the design: namely that each transformation has a black-box representation of input, output, and (optionally) parameters which are vectors in contiguous storage. Julia’s excellent type system and efficient array views allow for very convenient and intuitive structures.Plots Tutorial: Ecosystem and Pipeline2016-11-21T00:00:00+00:002016-11-21T00:00:00+00:00http://www.breloff.com/plots-video<p>Plots is a complex and powerful piece of software, with features and functionality that many probably don’t realize. In this video tutorial, I try to explain where Plots fits into the Julia landscape and how Plots turns a simple command into a beautiful visualization.</p>
<hr />
<iframe width="560" height="315" src="https://www.youtube.com/embed/Iof7Ccm8UiM" frameborder="0" allowfullscreen=""></iframe>
<p>If you have questions or want to request video tutorials on other topics, <a href="https://gitter.im/tbreloff/Plots.jl">come chat</a>.</p>Tom BreloffPlots is a complex and powerful piece of software, with features and functionality that many probably don’t realize. In this video tutorial, I try to explain where Plots fits into the Julia landscape and how Plots turns a simple command into a beautiful visualization.Online Layer Normalization: Derivation of Analytical Gradients2016-11-15T00:00:00+00:002016-11-15T00:00:00+00:00http://www.breloff.com/layernorm<p><a href="https://arxiv.org/abs/1607.06450">Layer Normalization</a> is a technique developed by Ba, Kiros, and Hinton for normalizing neural network layers as a whole (as opposed to Batch Normalization and variants which normalize per-neuron). In this post I’ll show my derivation of analytical gradients for Layer Normalization using an online/incremental weighting of the estimated moments for the layer.</p>
<hr />
<h3 id="background-and-notation">Background and Notation</h3>
<p>Training deep neural networks (and likewise recurrent networks which are deep through time) with gradient descent has been a difficult problem, partially (mostly) due to the issue of <a href="http://www.jmlr.org/proceedings/papers/v28/pascanu13.pdf">vanishing and exploding gradients</a>. One solution is to normalize layer activations, and learn the skew (b) and scale (g) as part of the learning algorithm. Online layer normalization can be summed up as learning parameter arrays <strong>g</strong> and <strong>b</strong> in the learnable transformation:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
y &= g \odot z + b \\
where: z_o &= \frac{a_o - \mu_t}{\sigma_t} \\
a_o &= \sum_i{w_{oi} x_i} \\
\mu_t &= \alpha_t (\frac{1}{D} \sum_p{a_p}) + (1-\alpha_t) \mu_{t-1} \\
\sigma_t &= \alpha_t \sqrt{\frac{1}{D-1} \sum_p{(a_o - \mu_t)^2}} + (1-\alpha_t) \sigma_{t-1}
\end{align} %]]></script>
<p>The vector <strong>a</strong> is the input to our <strong>LayerNorm</strong> layer and the result of a <strong>Linear</strong> transformation of <strong>x</strong>. We keep a running mean ($\mu_t$) and standard deviation ($\sigma_t$) of <strong>a</strong> using a time-varying weighting factor ($\alpha_t$).</p>
<h3 id="derivation">Derivation</h3>
<p>Due mostly to LaTeX-laziness, I present the derivation in scanned form. A PDF version can be found <a href="/images/layernorm/layernorm_derivation.pdf">here</a>.</p>
<p><img src="/images/layernorm/layernorm-0.png" alt="" /></p>
<p><img src="/images/layernorm/layernorm-1.png" alt="" /></p>
<p><img src="/images/layernorm/layernorm-2.png" alt="" /></p>
<p><img src="/images/layernorm/layernorm-3.png" alt="" /></p>
<p><img src="/images/layernorm/layernorm-4.png" alt="" /></p>
<p><img src="/images/layernorm/layernorm-5.png" alt="" /></p>
<h3 id="summary">Summary</h3>
<p>Layer normalization is a nice alternative to batch or weight normalization. With this derivation, we can include it as a standalone <a href="/transformations">learnable transformation</a> as part of a larger network. In fact, this is already accessible using the <code class="highlighter-rouge">nnet</code> convenience constructor in Transformations:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">using</span> <span class="n">Transformations</span>
<span class="n">nin</span><span class="x">,</span> <span class="n">nout</span> <span class="o">=</span> <span class="mi">3</span><span class="x">,</span> <span class="mi">5</span>
<span class="n">nhidden</span> <span class="o">=</span> <span class="x">[</span><span class="mi">4</span><span class="x">,</span><span class="mi">5</span><span class="x">,</span><span class="mi">4</span><span class="x">]</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">nnet</span><span class="x">(</span><span class="n">nin</span><span class="x">,</span> <span class="n">nout</span><span class="x">,</span> <span class="n">nhidden</span><span class="x">,</span> <span class="x">:</span><span class="n">relu</span><span class="x">,</span> <span class="x">:</span><span class="n">logistic</span><span class="x">,</span> <span class="n">layernorm</span> <span class="o">=</span> <span class="n">true</span><span class="x">)</span>
</code></pre></div></div>
<p>Network:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Chain{Float64}(
Linear{3-->4}
LayerNorm{n=4, mu=0.0, sigma=1.0}
relu{4}
Linear{4-->5}
LayerNorm{n=5, mu=0.0, sigma=1.0}
relu{5}
Linear{5-->4}
LayerNorm{n=4, mu=0.0, sigma=1.0}
relu{4}
Linear{4-->5}
LayerNorm{n=5, mu=0.0, sigma=1.0}
logistic{5}
)
</code></pre></div></div>Tom BreloffLayer Normalization is a technique developed by Ba, Kiros, and Hinton for normalizing neural network layers as a whole (as opposed to Batch Normalization and variants which normalize per-neuron). In this post I’ll show my derivation of analytical gradients for Layer Normalization using an online/incremental weighting of the estimated moments for the layer.Transformations: Modular tensor computation graphs in Julia2016-11-14T00:00:00+00:002016-11-14T00:00:00+00:00http://www.breloff.com/transformations<p>In this post I’ll try to summarize my design goals with the <a href="https://github.com/JuliaML/Transformations.jl">Transformations</a> package for the <a href="https://github.com/JuliaML">JuliaML ecosystem</a>. Transformations should be seen as a modular and higher-level approach to building complex tensor computation graphs, similar to those you may build in TensorFlow or Theano. The major reason for designing this package from the ground up lies in the flexibility of a pure-Julia implementation for new research paths. If you want to apply convolutional neural nets to identify cats in pictures, this is not the package for you. My focus is in complex, real-time, and incremental algorithms for learning from temporal data. I want the ability to track learning progress in real time, and to build workflows and algorithms that don’t require a gpu server farm.</p>
<hr />
<h3 id="what-is-a-tensor-computation-graph">What is a tensor computation graph?</h3>
<p>A <strong>computation graph</strong>, or data flow graph, is a representation of math equations using a directed graph of nodes and edges. Here’s a simple example using Mike Innes’ cool package <a href="https://github.com/MikeInnes/DataFlow.jl">DataFlow</a>. I’ve built a <a href="https://github.com/JuliaML/Transformations.jl/blob/master/src/scratch/flow.jl">recipe</a> for converting DataFlow graphs to <a href="/Graphs">PlotRecipes graphplot</a> calls. See the <a href="https://github.com/tbreloff/notebooks/blob/master/transformations.ipynb">full notebook</a> for complete Julia code.</p>
<p>We’ll compute $f(x) = w * x + b$:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">g</span> <span class="o">=</span> <span class="nd">@flow</span> <span class="n">f</span><span class="x">(</span><span class="n">x</span><span class="x">)</span> <span class="o">=</span> <span class="n">w</span> <span class="o">*</span> <span class="n">x</span> <span class="o">+</span> <span class="n">b</span>
<span class="n">plot</span><span class="x">(</span><span class="n">g</span><span class="x">)</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20271931/657d34d8-aa5a-11e6-81f7-80973266c16e.png" alt="" /></p>
<p>The computation graph is a <strong>graphical representation of the flow of mathematical calculations</strong> to compute a function. Follow the arrows, and do the operations on the inputs. First we multiply w and x together, then we add the result with b. The result of the addition is our output of the function f.</p>
<p>When x/w/b are numbers, this computation flow is perfectly easy to follow. But when they are <a href="https://en.wikipedia.org/wiki/Tensor">tensors</a>, the graph is much more complicated. Here’s the same example for a 1D, 2-element version where w is a 2x2 weight matrix and x and b are 2x1 column vectors:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">plot</span><span class="x">(</span><span class="nd">@flow</span> <span class="n">f</span><span class="x">(</span><span class="n">x</span><span class="x">)</span> <span class="o">=</span> <span class="n">out</span><span class="x">(</span><span class="n">w11</span><span class="o">*</span><span class="n">x1</span> <span class="o">+</span> <span class="n">w12</span><span class="o">*</span><span class="n">x2</span> <span class="o">+</span> <span class="n">b1</span><span class="x">,</span> <span class="n">w21</span><span class="o">*</span><span class="n">x1</span> <span class="o">+</span> <span class="n">w22</span><span class="o">*</span><span class="n">x2</span> <span class="o">+</span> <span class="n">b2</span><span class="x">))</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20272655/96fd0978-aa5c-11e6-9274-ce279d63960b.png" alt="" /></p>
<p>Already this computational graph is getting out of hand. A <strong>tensor computation graph</strong> simply re-imagines the vector/matrix computations as the core units, so that the first representation ($f(x) = w * x + b$) is used to represent the tensor math which does a matrix-vector multiply and a vector add.</p>
<h3 id="transformation-graphs">Transformation Graphs</h3>
<p>Making the jump from computation graph to tensor computation graph was a big improvement in complexity and understanding of the underlying operations. This improvement is the core of frameworks like TensorFlow. But we can do better. In the same way a matrix-vector product</p>
<script type="math/tex; mode=display">(W*x)_i = \sum_j W_{ij} x_j</script>
<p>can be represented as simply the vector $Wx$, we can treat the <strong>tensor transformation</strong> $f(x) = wx + b$ as a black box function which takes input vector (x) and produces output vector (f(x)). Parameter nodes (w/b) are considered <strong>learnable parameters</strong> which are internal to the <strong>learnable transformation</strong>. The new <strong>transformation graph</strong> looks like:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">plot</span><span class="x">(</span><span class="nd">@flow</span> <span class="n">f</span><span class="x">(</span><span class="n">x</span><span class="x">)</span> <span class="o">=</span> <span class="n">affine</span><span class="x">(</span><span class="n">x</span><span class="x">))</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20273571/d5014132-aa5f-11e6-8953-a17d6ebad1d2.png" alt="" /></p>
<p>Quite the improvement! We have created a modular, black-box representation of our affine transformation, which takes a vector input, multiplies by weight vector and adds a bias vector, producing a vector output:</p>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20273883/edfaa236-aa60-11e6-9c6c-9e8c8945201b.png" alt="" /></p>
<p>And here’s the comparison for a basic recurrent network:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">g</span> <span class="o">=</span> <span class="nd">@flow</span> <span class="k">function</span><span class="nf"> net</span><span class="x">(</span><span class="n">x</span><span class="x">)</span>
<span class="n">hidden</span> <span class="o">=</span> <span class="n">relu</span><span class="x">(</span> <span class="n">Wxh</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">Whh</span><span class="o">*</span><span class="n">hidden</span> <span class="o">+</span> <span class="n">bh</span> <span class="x">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">logistic</span><span class="x">(</span> <span class="n">Why</span><span class="o">*</span><span class="n">hidden</span> <span class="o">+</span> <span class="n">Wxy</span><span class="o">*</span><span class="n">x</span> <span class="o">+</span> <span class="n">by</span> <span class="x">)</span>
<span class="k">end</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20276999/d2f9b1aa-aa6c-11e6-9ae6-9004f87abb8d.png" alt="" />
<img src="https://cloud.githubusercontent.com/assets/933338/20277271/ddc70276-aa6d-11e6-94d6-50d9a6921075.png" alt="" /></p>
<h3 id="but-tensorflow">But… TensorFlow</h3>
<p>The unfortunate climate of ML/AI research is: “TensorFlow is love, TensorFlow is life”. If it can’t be built into a TF graph, it’s not worth researching. I think we’re in a bit of a deep learning hype bubble at the moment. Lots of time and money is poured into hand-designed networks with (sometimes arbitrary) researcher-chosen hyperparameters and algorithms. Your average high school student can install and build a neural network to perform quite complex and impressive models. But this is not the path to human-level intelligence. You <strong>could</strong> represent the human brain by a fully connected deep recurrent neural network with a billion neurons and a quintillion connections, but I don’t think NVIDIA has built that GPU yet.</p>
<p>I believe that researchers need a more flexible framework to build, test, and train complex approaches. I want to make it easy to explore spiking neural nets, dynamically changing structure, evolutionary algorithms, and anything else that may get us closer to human intelligence (and beyond). See my <a href="/Efficiency-is-key">first post on efficiency</a> for a little more background on my perspective. JuliaML is my playground for exploring the future of AI research. TensorFlow and competitors are solutions to a very specific problem: gradient-based training of static tensor graphs. We need to break the cycle that research should only focus on solutions that fit (or can be hacked into) this paradigm. Transformations (the Julia package) is a generalization of tensor computation that should be able to support other paradigms and new algorithmic approaches to learning, though the full JuliaML design is one which empowers researchers to approach the problem from any perspective they see fit.</p>Tom BreloffIn this post I’ll try to summarize my design goals with the Transformations package for the JuliaML ecosystem. Transformations should be seen as a modular and higher-level approach to building complex tensor computation graphs, similar to those you may build in TensorFlow or Theano. The major reason for designing this package from the ground up lies in the flexibility of a pure-Julia implementation for new research paths. If you want to apply convolutional neural nets to identify cats in pictures, this is not the package for you. My focus is in complex, real-time, and incremental algorithms for learning from temporal data. I want the ability to track learning progress in real time, and to build workflows and algorithms that don’t require a gpu server farm.Visualizing Graphs in Julia using Plots and PlotRecipes2016-11-11T00:00:00+00:002016-11-11T00:00:00+00:00http://www.breloff.com/Graphs<p>In this short post, I hope to introduce you to basic visualization of graphs (nodes connected by edges) when using <a href="https://github.com/tbreloff/Plots.jl">Plots</a> in Julia. The intention is that Visualizing a graph is as simple as inputting the connectivity structure, and optionally setting a ton of attributes that define the layout, labeling, colors, and more. Nodes are markers, and edges are lines. With this understanding, we can apply common Plots attributes as we see fit.</p>
<hr />
<h3 id="setup">Setup</h3>
<p>First, you’ll want to get a working setup of <a href="https://github.com/tbreloff/Plots.jl">Plots</a> and <a href="https://github.com/JuliaPlots/PlotRecipes.jl">PlotRecipes</a>:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># for pkg in ("Plots","PlotRecipes")</span>
<span class="c"># Pkg.add(pkg)</span>
<span class="c"># Pkg.checkout(pkg)</span>
<span class="c"># end</span>
<span class="n">using</span> <span class="n">PlotRecipes</span>
<span class="c"># we'll use the PyPlot backend, and set a couple defaults</span>
<span class="n">pyplot</span><span class="x">(</span><span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="x">,</span> <span class="n">size</span><span class="o">=</span><span class="x">(</span><span class="mi">800</span><span class="x">,</span><span class="mi">400</span><span class="x">))</span>
</code></pre></div></div>
<h3 id="type-trees">Type Trees</h3>
<p>For our example, we’re going to build a graph of the type hierarchy for a Julia abstract type. We will look at the Integer abstraction, and view it at the center of all supertypes and subtypes of Integer. You can view this demo as <a href="https://github.com/tbreloff/notebooks/blob/master/types_demo.ipynb">a Jupyter notebook</a>.</p>
<p>First, we’ll create a vector of our chosen type (Integer) and all its supertypes (Real, Number, and Any):</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">T</span> <span class="o">=</span> <span class="n">Integer</span>
<span class="n">sups</span> <span class="o">=</span> <span class="x">[</span><span class="n">T</span><span class="x">]</span>
<span class="n">sup</span> <span class="o">=</span> <span class="n">T</span>
<span class="k">while</span> <span class="n">sup</span> <span class="o">!=</span> <span class="kt">Any</span>
<span class="n">sup</span> <span class="o">=</span> <span class="n">supertype</span><span class="x">(</span><span class="n">sup</span><span class="x">)</span>
<span class="n">unshift!</span><span class="x">(</span><span class="n">sups</span><span class="x">,</span><span class="n">sup</span><span class="x">)</span>
<span class="k">end</span>
</code></pre></div></div>
<p>Next we will build the graph connectivity and node labels. <code class="highlighter-rouge">source</code> and <code class="highlighter-rouge">destiny</code> are lists of integers representing the indices in the edge connections of “source” to “destination”.</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">n</span> <span class="o">=</span> <span class="n">length</span><span class="x">(</span><span class="n">sups</span><span class="x">)</span>
<span class="n">nodes</span><span class="x">,</span> <span class="n">source</span><span class="x">,</span> <span class="n">destiny</span> <span class="o">=</span> <span class="n">copy</span><span class="x">(</span><span class="n">sups</span><span class="x">),</span> <span class="n">collect</span><span class="x">(</span><span class="mi">1</span><span class="x">:</span><span class="n">n</span><span class="o">-</span><span class="mi">1</span><span class="x">),</span> <span class="n">collect</span><span class="x">(</span><span class="mi">2</span><span class="x">:</span><span class="n">n</span><span class="x">)</span>
<span class="k">function</span><span class="nf"> add_subs</span><span class="o">!</span><span class="x">(</span><span class="n">T</span><span class="x">,</span> <span class="n">supidx</span><span class="x">)</span>
<span class="k">for</span> <span class="n">sub</span> <span class="k">in</span> <span class="n">subtypes</span><span class="x">(</span><span class="n">T</span><span class="x">)</span>
<span class="n">push!</span><span class="x">(</span><span class="n">nodes</span><span class="x">,</span> <span class="n">sub</span><span class="x">)</span>
<span class="n">subidx</span> <span class="o">=</span> <span class="n">length</span><span class="x">(</span><span class="n">nodes</span><span class="x">)</span>
<span class="n">push!</span><span class="x">(</span><span class="n">source</span><span class="x">,</span> <span class="n">supidx</span><span class="x">)</span>
<span class="n">push!</span><span class="x">(</span><span class="n">destiny</span><span class="x">,</span> <span class="n">subidx</span><span class="x">)</span>
<span class="n">add_subs!</span><span class="x">(</span><span class="n">sub</span><span class="x">,</span> <span class="n">subidx</span><span class="x">)</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="n">add_subs!</span><span class="x">(</span><span class="n">T</span><span class="x">,</span> <span class="n">n</span><span class="x">)</span>
<span class="n">names</span> <span class="o">=</span> <span class="n">map</span><span class="x">(</span><span class="n">string</span><span class="x">,</span> <span class="n">nodes</span><span class="x">)</span>
</code></pre></div></div>
<p>Now we will use the connectivity (<code class="highlighter-rouge">source</code> and <code class="highlighter-rouge">destiny</code>) and the node labels (<code class="highlighter-rouge">names</code>) to visualize the graphs.</p>
<h3 id="graphplot">graphplot</h3>
<p>The <code class="highlighter-rouge">graphplot</code> method is a <a href="https://juliaplots.github.io/recipes/">user recipe</a> defined in <a href="https://github.com/JuliaPlots/PlotRecipes.jl">PlotRecipes</a>. It accepts many different inputs to describe the graph structure:</p>
<ul>
<li><code class="highlighter-rouge">source</code> and <code class="highlighter-rouge">destiny</code> lists, with optional <code class="highlighter-rouge">weights</code> for weighted edges</li>
<li><code class="highlighter-rouge">adjlist</code>: a vector of int-vectors, describing the connectivity from each node</li>
<li><code class="highlighter-rouge">adjmat</code>: an adjacency matrix</li>
<li><code class="highlighter-rouge">LightGraphs.Graph</code>: if LightGraphs is installed</li>
</ul>
<p>We will use the source/destiny/weights method in this post. Lets see what it looks like without overriding default settings:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">graphplot</span><span class="x">(</span><span class="n">source</span><span class="x">,</span> <span class="n">destiny</span><span class="x">)</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20223068/c233d0b2-a805-11e6-8e0a-44f85b45f71b.png" alt="" /></p>
<hr />
<p>Cool. Now lets add names to the nodes. Notice that the nodes take on a hexagonal shape and expand to fix the text. There are a few additional attributes you can try: <code class="highlighter-rouge">fontsize</code>, <code class="highlighter-rouge">nodeshape</code>, and <code class="highlighter-rouge">nodesize</code>.</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">graphplot</span><span class="x">(</span><span class="n">source</span><span class="x">,</span> <span class="n">destiny</span><span class="x">,</span> <span class="n">names</span><span class="o">=</span><span class="n">names</span><span class="x">)</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20221332/e93254ec-a7fe-11e6-8ced-0e941a5bf588.png" alt="" /></p>
<hr />
<p>We can also change the layout of the nodes by:</p>
<ul>
<li>using one of the built-in algorithms (spectral, stress, or tree)</li>
<li>extending with <a href="https://github.com/JuliaGraphs/NetworkLayout.jl">NetworkLayout</a></li>
<li>passing an arbitrary layout function to the <code class="highlighter-rouge">func</code> keyword</li>
<li>overriding the x/y/z coordinates yourself (<code class="highlighter-rouge">graphplot(..., x=x, y=y)</code>).</li>
</ul>
<p>As there’s a clear hierarchy to our graph, lets use the tree method:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">graphplot</span><span class="x">(</span><span class="n">source</span><span class="x">,</span> <span class="n">destiny</span><span class="x">,</span> <span class="n">names</span><span class="o">=</span><span class="n">names</span><span class="x">,</span> <span class="n">method</span><span class="o">=</span><span class="x">:</span><span class="n">tree</span><span class="x">)</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20221351/fbce7e50-a7fe-11e6-831d-b64a63d56275.png" alt="" /></p>
<hr />
<p>The tree layout allows the additional setting of the <code class="highlighter-rouge">root</code> of the tree. Lets make the graph flow from left to right:</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">graphplot</span><span class="x">(</span><span class="n">source</span><span class="x">,</span> <span class="n">destiny</span><span class="x">,</span> <span class="n">names</span><span class="o">=</span><span class="n">names</span><span class="x">,</span> <span class="n">method</span><span class="o">=</span><span class="x">:</span><span class="n">tree</span><span class="x">,</span> <span class="n">root</span><span class="o">=</span><span class="x">:</span><span class="n">left</span><span class="x">)</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20221362/0601b9f0-a7ff-11e6-9f65-85368911f5c8.png" alt="" /></p>
<hr />
<p>All too easy. Finally, lets give it some color. Remember that we’re building a generic Plots visualization, where nodes are markers and edges are line segments. For more info on Plots, please read through <a href="https://juliaplots.github.io/">the documentation</a>.</p>
<div class="language-julia highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">weights</span> <span class="o">=</span> <span class="n">linspace</span><span class="x">(</span><span class="mi">1</span><span class="x">,</span><span class="mi">2</span><span class="x">,</span><span class="n">length</span><span class="x">(</span><span class="n">source</span><span class="x">))</span>
<span class="n">graphplot</span><span class="x">(</span><span class="n">source</span><span class="x">,</span> <span class="n">destiny</span><span class="x">,</span> <span class="n">weights</span><span class="x">,</span>
<span class="n">names</span> <span class="o">=</span> <span class="n">names</span><span class="x">,</span> <span class="n">method</span> <span class="o">=</span> <span class="x">:</span><span class="n">tree</span><span class="x">,</span>
<span class="n">l</span> <span class="o">=</span> <span class="x">(</span><span class="mi">2</span><span class="x">,</span> <span class="n">cgrad</span><span class="x">()),</span> <span class="c"># apply the default color gradient to the line (line_z values taken from edge weights)</span>
<span class="n">m</span> <span class="o">=</span> <span class="x">[</span><span class="n">node</span><span class="o">==</span><span class="n">T</span> <span class="o">?</span> <span class="x">:</span><span class="n">orange</span> <span class="x">:</span> <span class="x">:</span><span class="n">steelblue</span> <span class="k">for</span> <span class="n">node</span> <span class="k">in</span> <span class="n">nodes</span><span class="x">]</span> <span class="c"># node colors</span>
<span class="x">)</span>
</code></pre></div></div>
<p><img src="https://cloud.githubusercontent.com/assets/933338/20221372/0efabb7e-a7ff-11e6-83ee-65cb176641f7.png" alt="" /></p>
<h3 id="summary">Summary</h3>
<p>Visualizing graphs with PlotRecipes is pretty simple, and it’s easy to customize to your hearts content, thanks to the flexibility of Plots. In a future post, I’ll use this functionality to view and visualize neural networks using my (work in progress) efforts within <a href="https://github.com/JuliaML">JuliaML</a> and <a href="https://github.com/tbreloff">other projects</a>.</p>Tom BreloffIn this short post, I hope to introduce you to basic visualization of graphs (nodes connected by edges) when using Plots in Julia. The intention is that Visualizing a graph is as simple as inputting the connectivity structure, and optionally setting a ton of attributes that define the layout, labeling, colors, and more. Nodes are markers, and edges are lines. With this understanding, we can apply common Plots attributes as we see fit.Deep Reinforcement Learning with Online Generalized Advantage Estimation2016-10-06T00:00:00+00:002016-10-06T00:00:00+00:00http://www.breloff.com/DeepRL-OnlineGAE<p>Deep Reinforcement Learning, or Deep RL, is a really hot field at the moment. If you haven’t heard of it, pay attention. Combining the power of reinforcement learning and deep learning, it is being used to play complex games better than humans, control driverless cars, optimize robotic decisions and limb trajectories, and much more. And we haven’t even gotten started… Deep RL has far reaching applications in business, finance, health care, and many other fields which could be improved with better decision making. It’s the closest (practical) approach we have to <a href="https://en.wikipedia.org/wiki/Artificial_general_intelligence">AGI</a>. Seriously… how cool it that? In this post, I’ll rush through the basics and terminology in standard reinforcement learning (RL) problems, then review and extend work in Policy Gradient and Actor-Critic methods to derive an online variant of <a href="https://arxiv.org/abs/1506.02438">Generalized Advantage Estimation</a> (GAE) using eligibility traces, which can be used to learn optimal policies for our Deep RL agents.</p>
<hr />
<h3 id="background-and-terminology">Background and Terminology</h3>
<div class="imgcenter">
<img src="https://cloud.githubusercontent.com/assets/933338/20276214/5dd8bc66-aa69-11e6-99c6-81e4a43b4afe.png" /><br />
<em>The RL loop: state, action, reward</em>
</div>
<p>The RL framework: An <strong>agent</strong> senses the current <strong>state</strong> (s) of its <strong>environment</strong>. The agent takes an <strong>action</strong> (a), selected from the <strong>action set</strong> (A), using <strong>policy</strong> (π), and receives an immediate <strong>reward</strong> (r), with the goal of receiving large future <strong>return</strong> (R).</p>
<p>That’s it. Everything else is an implementation detail. The above paragraph can be summed up with the equations below, where $\sim$ means that we randomly sample a value from a probability distribution, and the current discrete time-step is $t$.</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
a_t &\sim \pi(a_t \mid s_t) \\
a_t &\in A_t \\
r_t, s_{t+1} &\sim p(r_t, s_{t+1} \mid s_t, a_t) \\
\tau_t &= \{ s_t, a_t, r_t, s_{t+1}, a_{t+1}, r_{t+1}, ~ ... \} \\
\tau &= \tau_0 \\
R(\tau_t) &= \sum_{l=0}^\infty{\gamma^l r_{t+l}}
\end{align} %]]></script>
<p>The policy is some function (usually parameterized, sometimes differentiable) which uses the full history of experience of the agent to choose an action after presentation of the new state of the environment. For simplicity, we’ll only consider discrete-time episodic environments, though most of this could be extended or approximated for continuous, infinite-horizon scenarios. We will also only consider the function approximation case, where we will approximate policies and value functions using neural networks that are parameterized by a vector of learnable weights $Θ$.</p>
<p>The difficulty of reinforcement learning, as compared to other sub-fields of machine learning, is the <strong>Credit Assignment Problem</strong>. This is the problem that there are many many actions which lead to any given reward (and many rewards resulting from a single action), and it’s not easy to pick out the “important actions” which led to the good (or bad) reward. With infinite resources and enough samples, the statistics will reveal the truth, but we’d like to make sure an algorithm converges in our lifetime.</p>
<p><img src="https://theclickercenterblog.files.wordpress.com/2015/05/rat-lever-press-cartoon.png" alt="" /></p>
<hr />
<h3 id="approaches-to-rl">Approaches to RL</h3>
<p>The goal with all reinforcement learners is to learn a good policy which will take the best actions in order to generate the highest return. This can be accomplished a few different ways.</p>
<p>Value iteration, temporal difference (TD) learning, and Q-learning approximate the value of states $V(s_t)$ or state-action pairs $Q(s_t, a_t)$, and use the “surprise” from incorrect value estimates to update a policy. These methods can be more flexible for learning off-policy, but can be difficult to apply effectively for continuous action spaces (such as robotics).</p>
<p>An alternative approach, called Policy Gradient methods, model a direct mapping from states to actions. With a little math, one can compute the effect of a parameter $\theta_i$ on the future cumulative returns of the policy. Then to improve our policy, we “simply” adjust our parameters in a direction that will increase the return. In truth, what we’re doing is increasing the probability of choosing good actions, and decreasing the probability of choosing bad actions.</p>
<p>I put “simply” in quotes because, although the math is reasonably straightforward, there are a few practical hurdles to overcome to be able to learn policies effectively. Policy gradient methods can be applied to a wide range of problems, with both continuous and discrete action spaces. In the next section we’ll see a convenient theorem that makes the math of computing parameter gradients tractable.</p>
<p>We can combine value iteration and policy gradients using a framework called Actor-Critic. In this, we maintain an <strong>actor</strong> which typically uses a policy gradient method, and a <strong>critic</strong>, which typically uses some sort of value iteration. The actor never sees the actual reward. Instead, the critic intercepts the rewards from the trajectory and critiques the chosen actions of the actor. This way, the noisy (and delayed) reward stream can be smoothed and summarized for better policy updates. Below, we will assume an Actor-Critic approach, but we will focus only on how to update the parameters of the actor.</p>
<hr />
<h3 id="policy-gradient-theorem">Policy Gradient Theorem</h3>
<p>I’d like to briefly review a “trick” which makes policy gradient methods tractable: the <a href="https://webdocs.cs.ualberta.ca/~sutton/papers/SMSM-NIPS99.pdf" title="Sutton et al: Policy Gradient Methods for Reinforcement Learning with Function Approximation (2000)">Policy Gradient Theorem</a>. If we assume there is some mapping of any state/action pair to a real-valued return:</p>
<script type="math/tex; mode=display">f: S \times A \rightarrow \mathbb{R} \\
x \in (S,A) \\
R = f(x)</script>
<p>then we’d like to compute the gradient of $\theta$ with respect to the expected total return $E_x[f(x)]$:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\nabla_\theta E_x[f(x)] &= \frac{\partial E_x[f(x)]}{\partial \theta} \\
& = \nabla_\theta \int f(x) ~ p(x \mid \theta) ~ dx \\
& = \int f(x) ~ \nabla_\theta p(x \mid \theta) ~ \frac{p(x \mid \theta)}{p(x \mid \theta)} ~ dx \\
& = \int f(x) ~ \nabla_\theta log ~ p(x \mid \theta) ~ p(x \mid \theta) ~ dx \\
& = E_x[f(x) ~ \nabla_\theta log ~ p(x \mid \theta)]
\end{align} %]]></script>
<p>We bring the gradient inside the integral and divide by the probability to get the gradient of log probability (grad-log-prob) term, along with a well-formed expectation. This trick means we don’t actually need to compute the integral equation in order to estimate the total gradient. Additionally, it’s much easier to take the gradient of a log as it decomposes into a sum of terms. This is important, because we only need to sample rewards and compute $\nabla_\theta log ~ p(x \mid \theta)$, which is <strong>dependent solely on our policy and the states/rewards that we see</strong>. There’s no need to understand or estimate the transition probability distribution of the underlying environment! (this is called “model-free reinforcement learning”.) Check out <a href="https://www.youtube.com/watch?v=oPGVsoBonLM">John Schulman’s lectures</a> for a great explanation and more detail.</p>
<hr />
<h3 id="improvements-to-the-policy-gradient-formula">Improvements to the policy gradient formula</h3>
<p>Now we have this easy-to-calculate formula to estimate the gradient, so we can just plug in the formulas and feed it into a gradient descent optimization, and we’ll magically learn optimal parameters… right? Right?!?</p>
<p>Sadly, due to weak correlation of actions to rewards resulting from the credit assignment problem, our gradient estimates will be extremely weak and noisy (the signal to noise ratio will be small, and variance of the gradient will be high), and convergence will take a while (unless it diverges).</p>
<p>One improvement we can make is to realize that, when deciding which actions to select, we only care about the <strong>relative difference in state-action values</strong>. Suppose we’re in a really awesome state, and no matter what we do we’re destined to get a reward of at least 100, but there’s a single action which would allow us to get 101. In this case we care only about that difference: <script type="math/tex">101 - 100 = 1</script>.</p>
<p>This is the intuition behind the <strong>advantage function</strong> $A^\pi(s,a)$ for a policy $\pi$. It is defined as the difference between the <strong>state-action value function</strong> $Q^\pi(s,a)$ and the <strong>state value function</strong> $V^\pi(s)$:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
V^\pi(s_t) &= E^\pi[R(\tau_t) \mid s_t] \\
Q^\pi(s_t, a_t) &= E^\pi[R(\tau_t) \mid s_t, a_t] \\
A^\pi(s_t, a_t) &= Q^\pi(s_t, a_t) - V^\pi(s_t)
\end{align} %]]></script>
<p>Going back to the policy gradient formula, we <a href="https://webdocs.cs.ualberta.ca/~sutton/papers/SMSM-NIPS99.pdf" title="Sutton et al: Policy Gradient Methods for Reinforcement Learning with Function Approximation (2000)">can subtract a zero-expectation <strong>baseline</strong></a> $b_t(s_t)$ from our score function $f(x)$ without changing the expectation. If we choose the score function to be the state-action value function $Q^\pi(s,a)$, and the baseline to be the state value function $V^\pi(s)$, then the policy gradient $g$ is of the form:</p>
<script type="math/tex; mode=display">\begin{align}
g = E[\sum_{t=0}^\infty{A^\pi(s_t, a_t) ~ \nabla_\theta log ~ \pi^\theta(a_t \mid s_t)}]
\end{align}</script>
<p>The intuition with this formula is that we wish to increase the probability of better-than-average actions, and decrease the probability of worse-than-average actions. We use a discount factor $\gamma$ to control the impact of our value estimation. With $\gamma$ near 0, we will approximate the next-step return. With $\gamma$ near 1, we will approximate the sum of all future rewards. If episodes are very long (or infinite), we may need $\gamma < 1$ for tractibility/convergence.</p>
<p>This formula is an example of an Actor-Critic algorithm, where the policy $\pi$ (the <strong>actor</strong>) adjusts its parameters by using the “advice” of a <strong>critic</strong>. In this case we use an estimate of the advantage to critique our policy choices.</p>
<hr />
<h3 id="generalized-advantage-estimator-gae">Generalized Advantage Estimator (GAE)</h3>
<p><a href="https://arxiv.org/abs/1506.02438" title="Schulman et al: High-Dimensional Continuous Control using Generalized Advantage Estimation (2015)">Schulman et al</a> use a discounted sum of TD residuals:</p>
<script type="math/tex; mode=display">\begin{align}
\delta_t^V = r_t + \gamma V(s_{t+1}) - V(s_t)
\end{align}</script>
<p>and compute an estimator of the k-step discounted advantage:</p>
<script type="math/tex; mode=display">\begin{align}
\hat{A}_t^{(k)} = \sum_{l=0}^{k-1}{\gamma^l \delta_{t+l}^V}
\end{align}</script>
<p>Note: it seems that equation 14 from their paper has an incorrect subscript on $\delta$.</p>
<p>They define their generalized advantage estimator (GAE) as the weighted average of the advantage estimators above, which reduce to a sum of discounted TD residuals:</p>
<script type="math/tex; mode=display">\begin{align}
\hat{A}_t^{GAE(\gamma,\lambda)} = \sum_{l=0}^\infty{(\gamma\lambda)^l \delta_{t+l}^V}
\end{align}</script>
<p>This generalized estimator of the advantage function allows a trade-off of bias vs variance using the parameter $0 \leq \lambda \leq 1$, similar to <a href="http://webdocs.cs.ualberta.ca/~sutton/papers/sutton-88-with-erratum.pdf" title="Sutton: Learning to Predict by the Methods of Temporal Differences (1988)">TD(λ)</a>. For $\lambda = 0$, the problem reduces to the (unbiased) TD(0) function. As we increase $\lambda$ towards 1, we reduce the variance of our estimator but increase the bias.</p>
<hr />
<h3 id="online-gae">Online GAE</h3>
<p>We’ve come a long way. We now have a low(er)-variance approximation to the true policy gradient. In github speak: <code class="highlighter-rouge">:tada:</code> But for problems I care about (for example high frequency trading strategies), it’s not very practical to compute forward-looking infinite-horizon returns before performing a gradient update step.</p>
<p>In this section, I’ll derive an online formula which is equivalent to the GAE policy gradient above, but which uses <strong>eligibility traces</strong> of the inner gradient of log probabilities to <strong>compute a gradient estimation on every reward, as it arrives</strong>. Not only will this prove to be more efficient, but there will be a massive savings in memory requirements and compute resources, at the cost of a slightly more complex learning process. (Luckily, <a href="/JuliaML-and-Plots">I code in Julia</a>)</p>
<p>Notes: See <a href="http://lasa.epfl.ch/publications/uploadedFiles/Waw13.pdf" title="Wawrzyński et al: Autonomous reinforcement learning with experience replay (2013)">Wawrzyński et al</a> for an alternate derivation. These methods using eligibility traces are closely related to <a href="http://www-anw.cs.umass.edu/~barto/courses/cs687/williams92simple.pdf" title="Williams: Simple Statistical Gradient-Following Algorithms for Connectionist Reinforcement Learning (1992)">REINFORCE</a>.</p>
<p>Lets get started. We are trying to reorganize the many terms of the policy gradient formula so that the gradient is of the form: $g = E^\pi[\sum_{t=0}^\infty{r_t \psi_t}]$, where $\psi_t$ can depend only on the states, actions, and rewards that occurred <strong>before</strong> (or immediately after) the arrival of $r_t$. We will solve for an online estimator of the policy gradient $\hat{g}$:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\hat{g} &= \sum_{t=0}^\infty{\hat{A}_t^{GAE(\gamma,\lambda)} ~ \nabla_\theta log ~ \pi^\theta(a_t \mid s_t)} \\
& = \sum_{t=0}^\infty{ \nabla_\theta log ~ \pi^\theta(a_t \mid s_t) ~ \sum_{l=0}^\infty{(\gamma\lambda)^l \delta_{t+l}^V}}
\end{align} %]]></script>
<p>In order to simplify the derivation, I’ll introduce the following shorthand:</p>
<script type="math/tex; mode=display">\begin{align}
\nabla_t := \nabla_\theta log ~ \pi^\theta(a_t \mid s_t)
\end{align}</script>
<p>and then expand the sum:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\hat{g} &= \nabla_0 (\delta_0^V + (\gamma\lambda)\delta_1^V + (\gamma\lambda)^2\delta_2^V + ~ ... ) \nonumber \\
& ~~ + \nabla_1 (\delta_1^V + (\gamma\lambda)\delta_2^V + (\gamma\lambda)^2\delta_3^V + ~ ... ) \\
& ~~ + \nabla_2 (\delta_2^V + (\gamma\lambda)\delta_3^V + (\gamma\lambda)^2\delta_4^V + ~ ... ) \nonumber \\
& ~~ + ~ ... \nonumber
\end{align} %]]></script>
<p>and collect the $\delta_t^V$ terms:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\hat{g} &= \delta_0^V \nabla_0 \nonumber \\
& ~~ + \delta_1^V ( \nabla_1 + (\gamma\lambda)\nabla_0 ) \\
& ~~ + \delta_2^V ( \nabla_2 + (\gamma\lambda)\nabla_1 + (\gamma\lambda)^2\nabla_0 ) \nonumber \\
& ~~ + ~ ... \nonumber
\end{align} %]]></script>
<p>and summarize:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\hat{g} &= \sum_{t=0}^\infty{\delta_t^V \sum_{l=0}^t{(\gamma\lambda)^l \nabla_{t-l}}}
\end{align} %]]></script>
<p>If we define our eligibility trace as the inner sum in that equation:</p>
<script type="math/tex; mode=display">\begin{align}
\epsilon_t := \sum_{l=0}^t{(\gamma\lambda)^l \nabla_{t-l}}
\end{align}</script>
<p>and convert to a recursive formula:</p>
<script type="math/tex; mode=display">% <![CDATA[
\begin{align}
\epsilon_0 &:= \nabla_0 \\
\epsilon_t &:= (\gamma\lambda) \epsilon_{t-1} + \nabla_t
\end{align} %]]></script>
<p>then we have our online generalized advantage estimator for the policy gradient:</p>
<script type="math/tex; mode=display">\begin{align}
\hat{g} = \sum_{t=0}^\infty{\delta_t^V \epsilon_t}
\end{align}</script>
<p>So at each time-step, we compute the gradient term $\hat{g}_t = \delta_t^V \epsilon_t$ as the product of the TD(0) error from our critic and the accumulated log-prob gradients of our policy. We could update our parameters online at the end of each episode, or at each step, or in batches, or using some sort of smoothing method.</p>
<hr />
<h3 id="summary">Summary</h3>
<p>In this post I covered some basic terminology, and summarized the theorems and formulas that comprise Generalized Advantage Estimation. We extended GAE to the online setting in order to give us more flexibility when computing parameter updates. The hyperparameter <strong>$\gamma$ allows us to control our trust in the value estimation</strong>, while the hyperparameter <strong>$\lambda$ allows us to assign more credit to recent actions</strong>.</p>
<p>In future posts, I intend to demonstrate how to use formulas 26-28 in practical algorithms to solve problems in robotic simulation and other complex environments. If you need help solving difficult problems with data, or if you see mutual benefit in collaboration, please don’t hesitate to get in touch.</p>Tom BreloffDeep Reinforcement Learning, or Deep RL, is a really hot field at the moment. If you haven’t heard of it, pay attention. Combining the power of reinforcement learning and deep learning, it is being used to play complex games better than humans, control driverless cars, optimize robotic decisions and limb trajectories, and much more. And we haven’t even gotten started… Deep RL has far reaching applications in business, finance, health care, and many other fields which could be improved with better decision making. It’s the closest (practical) approach we have to AGI. Seriously… how cool it that? In this post, I’ll rush through the basics and terminology in standard reinforcement learning (RL) problems, then review and extend work in Policy Gradient and Actor-Critic methods to derive an online variant of Generalized Advantage Estimation (GAE) using eligibility traces, which can be used to learn optimal policies for our Deep RL agents.