<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/174221</link>
    <title>MATLAB Central Newsreader - Have fminunc show the gradient?</title>
    <description>Feed for thread: Have fminunc show the gradient?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 12 Aug 2008 18:54:02 -0400</pubDate>
      <title>Have fminunc show the gradient?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/174221#448767</link>
      <author>David Doria</author>
      <description>I have been looking through the help for a long while and&lt;br&gt;
cant seem to find how to make fminunc display the gradient&lt;br&gt;
at each iteration - maybe I am just missing it??&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
Dave</description>
    </item>
    <item>
      <pubDate>Thu, 14 Aug 2008 20:58:02 -0400</pubDate>
      <title>Re: Have fminunc show the gradient?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/174221#449205</link>
      <author>Marcelo Marazzi</author>
      <description>Dave,&lt;br&gt;
&lt;br&gt;
See the output function in the doc, which provides a number of &lt;br&gt;
optimization quantities at each iteration, e.g. the gradient in&lt;br&gt;
fminunc:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/f19175.html#f11022&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/f19175.html#f11022&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
-Marcelo&lt;br&gt;
&lt;br&gt;
David Doria wrote:&lt;br&gt;
&amp;gt; I have been looking through the help for a long while and&lt;br&gt;
&amp;gt; cant seem to find how to make fminunc display the gradient&lt;br&gt;
&amp;gt; at each iteration - maybe I am just missing it??&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Dave</description>
    </item>
    <item>
      <pubDate>Thu, 14 Aug 2008 21:34:01 -0400</pubDate>
      <title>Re: Have fminunc show the gradient?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/174221#449215</link>
      <author>David Doria</author>
      <description>Ah, great - that does the trick - although I was expecting&lt;br&gt;
something a bit more built in.. so I don't have to write my&lt;br&gt;
own output function, I could just toggle what the built in&lt;br&gt;
output function outputs!&lt;br&gt;
&lt;br&gt;
Thanks!&lt;br&gt;
&lt;br&gt;
Dave</description>
    </item>
    <item>
      <pubDate>Fri, 15 Aug 2008 13:06:02 -0400</pubDate>
      <title>Re: Have fminunc show the gradient?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/174221#449296</link>
      <author>David Doria</author>
      <description>Ok, now I would like to see the hessian that it calculates&lt;br&gt;
at every step... I don't see this in the OptimValues list...&lt;br&gt;
is there a way to get at it?&lt;br&gt;
&lt;br&gt;
Dave</description>
    </item>
    <item>
      <pubDate>Fri, 15 Aug 2008 20:41:48 -0400</pubDate>
      <title>Re: Have fminunc show the gradient?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/174221#449397</link>
      <author>Marcelo Marazzi</author>
      <description>There is a built-in plot function that plots the norm of the gradient.&lt;br&gt;
&lt;br&gt;
One way to run it is to open the optimtool, and select FIrst Order &lt;br&gt;
Optimality under Plot Functions. There is a way to run this from the &lt;br&gt;
command line as well.&lt;br&gt;
&lt;br&gt;
I assume you're using the medium-scale algorithm. This algorithm&lt;br&gt;
does not compute the Hessian, but rather a so-called quasi-Newton&lt;br&gt;
approximation to the inverse of the Hessian. This matrix is only&lt;br&gt;
an approximation (often crude), and to the inverse of the Hessian&lt;br&gt;
(not to the Hessian itself), so it's not made available via the&lt;br&gt;
output function - typically it's not useful.&lt;br&gt;
&lt;br&gt;
The output function gives you access to each iterate x; you can&lt;br&gt;
compute the Hessian (or an approximation to it via finite differences)&lt;br&gt;
at x inside the output function.&lt;br&gt;
&lt;br&gt;
-Marcelo&lt;br&gt;
&lt;br&gt;
David Doria wrote:&lt;br&gt;
&amp;gt; Ok, now I would like to see the hessian that it calculates&lt;br&gt;
&amp;gt; at every step... I don't see this in the OptimValues list...&lt;br&gt;
&amp;gt; is there a way to get at it?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Dave</description>
    </item>
    <item>
      <pubDate>Tue, 08 Jun 2010 21:40:21 -0400</pubDate>
      <title>Re: Have fminunc show the gradient?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/174221#752773</link>
      <author>Ceren </author>
      <description>Hi! &lt;br&gt;
Thanks for the help, it was very useful! I have a related question: Is it possible to save the gradient so that I can see it in the workspace, rather than just display it for each iteration? I defined it as an output of outfun by:&lt;br&gt;
&lt;br&gt;
function [stop,Y] = outfun(x, optimValues, state) &lt;br&gt;
stop=false;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;switch state&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;case 'iter'&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Y(optimValues.iteration+1,:)=optimValues.gradient'&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;otherwise&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
But still could not save it in the workspace. I'd appreciate any help!&lt;br&gt;
Thanks&lt;br&gt;
&lt;br&gt;
Marcelo Marazzi &amp;lt;mREMOVEmaALLraCAPITALSzzi@mathworks.com&amp;gt; wrote in message &amp;lt;g84pmc$rle$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; There is a built-in plot function that plots the norm of the gradient.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; One way to run it is to open the optimtool, and select FIrst Order &lt;br&gt;
&amp;gt; Optimality under Plot Functions. There is a way to run this from the &lt;br&gt;
&amp;gt; command line as well.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I assume you're using the medium-scale algorithm. This algorithm&lt;br&gt;
&amp;gt; does not compute the Hessian, but rather a so-called quasi-Newton&lt;br&gt;
&amp;gt; approximation to the inverse of the Hessian. This matrix is only&lt;br&gt;
&amp;gt; an approximation (often crude), and to the inverse of the Hessian&lt;br&gt;
&amp;gt; (not to the Hessian itself), so it's not made available via the&lt;br&gt;
&amp;gt; output function - typically it's not useful.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The output function gives you access to each iterate x; you can&lt;br&gt;
&amp;gt; compute the Hessian (or an approximation to it via finite differences)&lt;br&gt;
&amp;gt; at x inside the output function.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -Marcelo&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; David Doria wrote:&lt;br&gt;
&amp;gt; &amp;gt; Ok, now I would like to see the hessian that it calculates&lt;br&gt;
&amp;gt; &amp;gt; at every step... I don't see this in the OptimValues list...&lt;br&gt;
&amp;gt; &amp;gt; is there a way to get at it?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Dave</description>
    </item>
  </channel>
</rss>

