{"id":115,"date":"2017-07-10T12:28:55","date_gmt":"2017-07-10T19:28:55","guid":{"rendered":"http:\/\/blogs.reed.edu\/projectproject\/?p=115"},"modified":"2017-07-20T17:12:22","modified_gmt":"2017-07-21T00:12:22","slug":"level-sets-the-gradient-and-gradient-flow","status":"publish","type":"post","link":"https:\/\/blogs.reed.edu\/projectproject\/2017\/07\/10\/level-sets-the-gradient-and-gradient-flow\/","title":{"rendered":"Level Sets, the Gradient, and Gradient Flow"},"content":{"rendered":"<h6><\/h6>\n<h6><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-415 aligncenter\" src=\"http:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/image.jpeg0001.jpg\" alt=\"\" width=\"864\" height=\"487\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/image.jpeg0001.jpg 1920w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/image.jpeg0001-300x169.jpg 300w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/image.jpeg0001-768x432.jpg 768w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/image.jpeg0001-1024x576.jpg 1024w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/image.jpeg0001-1200x675.jpg 1200w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/h6>\n<p>Level sets, the gradient, and gradient flow are methods of extracting specific features of a surface. You&#8217;ve heard of level sets and the gradient in vector calculus class \u2013 level sets show slices\u00a0of a surface and the gradient shows a sort of 2D &#8220;slope&#8221; of a surface. These measurements are useful\u00a0on their own, but they hint at something else, something more abstract. The gradient vectors are perpendicular to the level sets, so\u00a0will always be direction the &#8220;slope&#8221;\u00a0of a point toward another point on another level set. But how would you represent that? The answer is the concept of\u00a0<em>gradient flow<\/em>. Read more to learn about how these three standard measurements fit together to <em>flow<\/em> along a surface, much like a liquid or rolling\u00a0object.<br \/>\n<!--more--><\/p>\n<h6>Level\u00a0Sets<\/h6>\n<p>Consider a function [latex] f : \\mathbb{R}^2 \\rightarrow \\mathbb{R}. [\/latex] If you were to graph this as a 3D plot, you can visualize how this would turn out to be a cone-like surface, with the small end at 0. This represents the solutions to this equation in three variables. What happens when we want the solutions in two variables, instead? The goal would be to obtain the solutions to this equation at a certain\u00a0<em>level, <\/em>meaning\u00a0at a constant value for one of the variables. Let&#8217;s choose [latex]z[\/latex]. The level set of such a function for a given\u00a0[latex]z[\/latex] is\u00a0$$ \\{ (x,y) \\in \\mathbb{R}^2 \\mid \\ f(x,y)=z \\}. $$ For\u00a0example, let&#8217;s say \u00a0[latex]f:(x,y) \\mapsto x^2+y^2[\/latex]. Now we need to pick a few [latex]z[\/latex]-levels to show the level sets at, say [latex]z\\in\\{0,1,2,3,4\\}[\/latex]. These level sets turn out to be<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-133 aligncenter\" src=\"http:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levelsets1-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levelsets1-300x300.jpg 300w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levelsets1-150x150.jpg 150w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levelsets1.jpg 360w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>where the circle radius is\u00a0increasing with [latex]z[\/latex]-level.\u00a0All of these level sets turn out to be circles, with one exception being the point at [latex](0,0)[\/latex] \u2013 the only solution to\u00a0[latex]x^2+y^2=0[\/latex]. Why are the level sets circles when [latex]z&gt;0[\/latex]? An examination of our function shows that, when you solve for\u00a0[latex]f[\/latex]&#8217;s level set at [latex]z[\/latex], you get an equation of the form [latex]x^2 + y^2 = z[\/latex], which is the equation for a circle with radius\u00a0[latex]\\sqrt{z}[\/latex]. This explains why the circles are getting bigger, but at a decreasing rate; the circle radius is increasing at the rate\u00a0[latex]\\frac{1}{2\\sqrt{z}}[\/latex]. This is an extremely simple example, but it demonstrates level curves, and some following concepts very clearly.<\/p>\n<p>So what are level curves showing? The graph above may have reminded you of something \u2013 a contour (or topographical) map of a landscape. Essentially the level sets are the contour lines on a map of a surface. They are\u00a0cross-sections through the surface, in this case at specific\u00a0[latex]z[\/latex]-levels.<\/p>\n<h6>The Gradient<\/h6>\n<p>The <em>gradient<\/em> of a scalar function records its partial derivatives throughout its domain. For example, consider a function [latex]f:\\mathbb{R}^2 \\rightarrow \\mathbb{R}[\/latex]. Then, $$ \\nabla f : (x,y) \\mapsto \\left ( \\frac{\\partial f}{\\partial x}(x,y), \\frac{\\partial f}{\\partial y}(x,y) \\right ) $$ is a function [latex]\\mathbb{R}^2\\to \\mathbb{R}^2[\/latex].<\/p>\n<p>Let&#8217;s take a new function [latex]g: (x,y) \\mapsto x^2-y^2[\/latex] as an example. Since the gradient has range [latex]\\mathbb{R}^2[\/latex], we can use a vector plot to visualize it, with the level sets for [latex]z\\in \\{-5,-4,\\ldots,4,5\\}[\/latex] in the background:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-143 aligncenter\" src=\"http:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient1-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient1-300x300.jpg 300w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient1-150x150.jpg 150w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient1.jpg 360w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>What are these gradient arrows representing? It turns out that these arrows show, at each point, which direction yields the largest increase\u00a0in the value of [latex]g[\/latex]; the magnitude gives the rate of increase. If you are curious, this is a depiction of [latex]f:(x,y)\\mapsto x^2+y^2[\/latex]&#8217;s gradient:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-145 aligncenter\" src=\"http:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient2-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient2-300x300.jpg 300w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient2-150x150.jpg 150w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/gradient2.jpg 360w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<h6>Gradient Flow<\/h6>\n<p>These level curves and gradient vector fields are slowly building an outline of\u00a0a\u00a0surface in [latex] \\mathbb{R}^3[\/latex]. However,\u00a0we are still lacking a way of connecting the curves and the arrows. How\u00a0would one <em>follow<\/em>\u00a0the vectors\u00a0to\u00a0get\u00a0from one level curve to the next? With this ability, you could\u00a0<em>flow<\/em>\u00a0across continuously-spaced level curves.<\/p>\n<p>The features we aim to achieve are:<\/p>\n<ul>\n<li>The\u00a0flow&#8217;s points are solutions to the original function \u2013 the flow with be on\u00a0the surface;<\/li>\n<li>The flow&#8217;s derivative is the gradient \u2013 the flow will follow the gradient vectors.<\/li>\n<\/ul>\n<p>For a point [latex](x,y)[\/latex] in the domain of a function [latex]f:\\mathbb{R}^2\\to\\mathbb{R}[\/latex], the\u00a0curve that starts at [latex](x,y)[\/latex] and accomplishes this flow is [latex]\\gamma_{(x,y)} :\\mathbb{R} \\rightarrow \\mathbb{R}^2\u00a0[\/latex] such that\u00a0$$ \\begin{align} \\gamma_{(x,y)}(0) &amp;= (x,y), \\\\ \\gamma_{(x,y)}^\\prime(t)\u00a0&amp;= \\nabla f (\\gamma_{(x,y)} (t)). \\end{align}$$ As you can see, [latex]\\gamma[\/latex]&#8217;s derivative will follow the gradient and\u00a0[latex]\\gamma[\/latex] will be centered around a point of &#8220;origin&#8221; where the flow\u00a0<em>flows<\/em> from. What does\u00a0[latex]\\gamma[\/latex] look like? Let&#8217;s consider gradient flows\u00a0for our usual functions $$ \\begin{align} f(x,y) &amp;= \u00a0x^2 + y^2, \\\\ g(x,y) &amp;= x^2 &#8211; y^2. \\end{align} $$ [latex]\\gamma_{(x,y)}[\/latex] of [latex]f[\/latex] needs to be a function\u00a0where $$\\begin{align} \\gamma_{(x,y)}(t) &amp;\\mapsto (x^\\prime, y^\\prime), \\\\ \\gamma_{(x,y)}(0) &amp;= (x,y), \\\\ \\gamma_{(x,y)}^\\prime &amp;= \\nabla f (x^\\prime, y^\\prime) \\\\ &amp;= (2 x^\\prime, 2 y^\\prime). \\end{align} $$ Solve this differential equation and you get\u00a0$$ \\gamma_{(x,y)} = (x e^{2t}, y e^{2t}). $$<\/p>\n<p>What does [latex]\\gamma[\/latex]\u00a0<em>look<\/em> like? Below are the usual level curves and gradient vector field, and now with the flow lines in green starting at some blue points on the unit circle\u00a0(we let [latex]t \\in [-0.75,0.75][\/latex]:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-167 aligncenter\" src=\"http:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows1-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows1-300x300.jpg 300w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows1-150x150.jpg 150w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows1.jpg 360w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>And for [latex]g[\/latex], with the same parameters:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-168 aligncenter\" src=\"http:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows2-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows2-300x300.jpg 300w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows2-150x150.jpg 150w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/flows2.jpg 360w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>So we have produced gradient flows, and they join the\u00a0level curves. But what exactly are we visualizing here? One way to think about it is noting that since the gradient is the direction of steepest ascent in the [latex]z[\/latex]-direction, the reverse of the flow is the path of an object as it rolls on the surface, starting from a high place and rolling down to a lower place (in the exact opposite direction as the gradient vectors point).<\/p>\n<h6>To 3D<\/h6>\n<p>I&#8217;ve been showing you 2D pictures of curves and arrows, but the functions that we have been considering are inherently 3D in nature. The functions [latex]f,g[\/latex] from above can be visualized as the following parabaloid and saddle surface,\u00a0respectively:<\/p>\n<div id='gallery-1' class='gallery galleryid-115 gallery-columns-2 gallery-size-full'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"392\" src=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/parabaloid-1.jpg\" class=\"attachment-full size-full\" alt=\"\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/parabaloid-1.jpg 360w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/parabaloid-1-276x300.jpg 276w\" sizes=\"auto, (max-width: 360px) 85vw, 360px\" \/>\n\t\t\t<\/div><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"284\" src=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_hyperbaloid-2.jpg\" class=\"attachment-full size-full\" alt=\"\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_hyperbaloid-2.jpg 360w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_hyperbaloid-2-300x237.jpg 300w\" sizes=\"auto, (max-width: 360px) 85vw, 360px\" \/>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n\n<p>These shouldn&#8217;t be surprising visuals. The level curves, being cross-sections through the surfaces at specified [latex]z[\/latex]-levels, are only 2D, but they can be fit into this 3D depiction by simply setting the level curves&#8217;s [latex]z[\/latex]-coordinate to its respective [latex]z[\/latex]-level, highlighted in black:<\/p>\n<div id='gallery-2' class='gallery galleryid-115 gallery-columns-2 gallery-size-full'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"424\" src=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_parabaloid.jpg\" class=\"attachment-full size-full\" alt=\"\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_parabaloid.jpg 360w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_parabaloid-255x300.jpg 255w\" sizes=\"auto, (max-width: 360px) 85vw, 360px\" \/>\n\t\t\t<\/div><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon landscape'>\n\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"324\" src=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_hyperbaloid-1.jpg\" class=\"attachment-full size-full\" alt=\"\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_hyperbaloid-1.jpg 360w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/levels3D_hyperbaloid-1-300x270.jpg 300w\" sizes=\"auto, (max-width: 360px) 85vw, 360px\" \/>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n\n<p>And finally, the same sort of process can be applied to the flow. We want to preserve the\u00a0[latex]x,y[\/latex] coordinates of the flow, but we need to decide at what [latex]z[\/latex]-coordinate to put each point on the flow. The natural choice\u00a0is the following function: $$ \\textit{flow}_{(x,y)}:t\\mapsto ( \\gamma_{(x,y)}(t), f( \\gamma_{(x,y)} (t)) ). $$ There are too many parentheses, but essentially this function plots the flow\u00a0from before, and assigns its [latex]z[\/latex]-coordinate to be the value of the original function at the [latex](x^\\prime , y^\\prime )[\/latex] point that [latex]\\gamma[\/latex] returns (as a function of [latex]t[\/latex], of course). Here are our two favorite functions fully rendered with level (black) and 3D\u00a0flow lines (orange):<\/p>\n<div id='gallery-3' class='gallery galleryid-115 gallery-columns-2 gallery-size-full'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"343\" height=\"377\" src=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/parabaloid_complete.jpg\" class=\"attachment-full size-full\" alt=\"\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/parabaloid_complete.jpg 343w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/parabaloid_complete-273x300.jpg 273w\" sizes=\"auto, (max-width: 343px) 85vw, 343px\" \/>\n\t\t\t<\/div><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"360\" height=\"411\" src=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/hyperbaloid_complete.jpg\" class=\"attachment-full size-full\" alt=\"\" srcset=\"https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/hyperbaloid_complete.jpg 360w, https:\/\/blogs.reed.edu\/projectproject\/files\/2017\/07\/hyperbaloid_complete-263x300.jpg 263w\" sizes=\"auto, (max-width: 360px) 85vw, 360px\" \/>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n\n<p>For each, the flow lines originate at points on the [latex]1[\/latex]-level set, and we let [latex]t[\/latex] vary through a large enough interval for the flow lines to fill up the surface. If you imagine looking at these 3D-structures from above, you can confirm that they match the previous 2D graphs. In the parabaloid, you can see that the flow lines converge at the critical point [latex]z=0[\/latex], where the level set is a single point. This makes sense intuitively; an object would roll down the slope to the bottom, and come to rest.<\/p>\n<p>As for the saddle, none of the pictured flow lines stop at the critical point (the center of the saddle at [latex]z=0[\/latex]). There are, in fact, exactly four flow lines that would stop there (they are clearly\u00a0visible in the 2D depiction in <em>Gradient Flow<\/em>); the paucity of flow lines going through [latex]g[\\latex]&#8217;s critical point makes that point\u00a0<em>unstable<\/em>, a feature I will return to later if this project heads towards Morse theory.<\/p>\n<p>Mathematica code for the above models: <a href=\"https:\/\/drive.google.com\/file\/d\/0B35H0BdFgL2eWUJzZC1zbGVoblE\/view?usp=sharing\">GradientFlow.nb<\/a><\/p>\n<h6>Printing<\/h6>\n<p>In the\u00a0<em>To 3D<\/em> section, I displayed\u00a0various 3D models of the concepts I explained. Though these 2D projections on your computer screen are very helpful, physical 3D models can offer a more intuitive and clear expression of the truly 3D surfaces that are concerned. Especially with more complicated models, 3D printing gains a huge advantage of being relatively uncluttered and easily manipulatable.<\/p>\n<p>I am currently working on printing a few different models, and will have updates on their progress in the next two weeks. In the meantime, check out\u00a0my next article on 3D printing!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Level sets, the gradient, and gradient flow are methods of extracting specific features of a surface. You&#8217;ve heard of level sets and the gradient in vector calculus class \u2013 level sets show slices\u00a0of a surface and the gradient shows a sort of 2D &#8220;slope&#8221; of a surface. These measurements are useful\u00a0on their own, but they &hellip; <a href=\"https:\/\/blogs.reed.edu\/projectproject\/2017\/07\/10\/level-sets-the-gradient-and-gradient-flow\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Level Sets, the Gradient, and Gradient Flow&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1573,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[28,29,30,24,25,23,22,7,27,26],"class_list":["post-115","post","type-post","status-publish","format-standard","hentry","category-vector-calc","tag-3d-modeling","tag-3d-printing","tag-3d-visualization","tag-gradient","tag-gradient-flow","tag-level-curves","tag-level-sets","tag-math","tag-multivariable-calculus","tag-vector-calculus"],"_links":{"self":[{"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/posts\/115","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/users\/1573"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":79,"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/posts\/115\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.reed.edu\/projectproject\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}