<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 13-08-20 11:25 AM, Ian Taylor - NOAA
Federal wrote:<br>
<br>
What's wrong with you people! I was just trying to illustrate a
few ideas about printing out<br>
the variables sorted by gradient magnitude. The function minimizer
only prints out the values<br>
at an iteration. If you want to see the values for each function
evaluation you need to do<br>
something a bit different. What I posted is a simple way to do
this. Obviously it needs a bit of dressing up.<br>
<br>
If you don't like my ideas you are certainly welcome to do
something else (assuming you ever get the time<br>
of course).<br>
<br>
<br>
<br>
<br>
</div>
<blockquote
cite="mid:CAOUH9r4w10uo+pv5s+JypPkCPi=kWsCqwrnDtC64nBqYGmHTvQ@mail.gmail.com"
type="cite">
<div dir="ltr">I don't see that I was conflating things nor that
it's too complicated (though Dave would surely know better).
<div><br>
</div>
<div>As noted in <a moz-do-not-send="true"
href="http://www.admb-project.org/redmine/issues/109">the
Redmine Issue</a>, the file <a moz-do-not-send="true"
href="http://admb-project.org/documentation/api/fmm__disp_8cpp_source.html">fmm_disp.cpp</a>
is what currently displays the gradient values during the
minimization process. If this is not the ideal time to
calculate gradient values, then we've been looking at the
wrong numbers all along. If it is indeed the right time, one
option would be to revise fmm_disp.cpp to display them in an
alternative order as John suggests. Another (or parallel)
option would be to add a section to fmm_disp.cpp to write the
same values to a file which could be sorted in any order.
Presumably writing to a file would slow things down slightly,
so you would want it as an option, not the default behavior.</div>
<div><br>
</div>
<div>Currently you can redirect all the command window text to a
file and then parse this file to get the gradient info.
However, the 3-column format for the gradients makes this
slightly more tedious than it has to be.</div>
<div><br>
</div>
<div>-Ian</div>
<div><br>
</div>
<div><br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Tue, Aug 20, 2013 at 8:27 AM, dave
fournier <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:davef@otter-rsch.com" target="_blank">davef@otter-rsch.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Well this is a bit complicated because there are various
loops where the function and<br>
gradient are calculated and various function minimizers.
What I would do is to<br>
compile my code with debug info and but a breakpoint in
the userfunction. Then<br>
a stack trace will find where you are. In my case
df1b2qnm.cpp around line 185.<br>
the loop looks like<br>
<br>
<br>
<br>
while (fmc.ireturn>=0)<br>
{<br>
fmc.fmin(f,x,g);<br>
if (fmc.ireturn>0)<br>
{<br>
dvariable vf=0.0;<br>
vf=initial_params::reset(dvar_vector(x));<br>
*objective_function_value::pobjfun=0.0;<br>
pre_userfunction();<br>
vf+=*objective_function_value::pobjfun;<br>
f=value(vf);<br>
gradcalc(nvar,g);<br>
}<br>
}<br>
<br>
To make it simple lets print out every function
evaluation.<br>
<br>
ofstream ofs("stuff");<br>
<br>
while (fmc.ireturn>=0)<br>
{<br>
fmc.fmin(f,x,g);<br>
if (fmc.ireturn>0)<br>
{<br>
dvariable vf=0.0;<br>
vf=initial_params::reset(dvar_vector(x));<br>
*objective_function_value::pobjfun=0.0;<br>
pre_userfunction();<br>
vf+=*objective_function_value::pobjfun;<br>
f=value(vf);<br>
gradcalc(nvar,g);<br>
<br>
printstuff(f,x,g,ofs);<br>
}<br>
}<br>
<br>
void printstuff(double f,const dvector& x,const
dvector& g,const ofstream& ofs)<br>
{<br>
int n=g.indexmax();<br>
dmatrix TS(1,2,1,n);<br>
<br>
TS(1).fill_seqadd(1,1);<br>
TS(2)=fabs(g);<br>
<br>
dmatrix S=trans(TS);<br>
<br>
S=sort(S,2);<br>
<br>
ivector index=ivector(column(S,1)); // can use index
to print out what you want<br>
<br>
for (int i=n;i>=n;i--)<br>
{<br>
ofs << x(ind(i)) << " " <<
g(ind(i)) << endl;<br>
}<br>
<br>
This is probably in decreasing order
<div class="HOEnZb">
<div class="h5"><br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a moz-do-not-send="true"
href="mailto:Users@admb-project.org" target="_blank">Users@admb-project.org</a><br>
<a moz-do-not-send="true"
href="http://lists.admb-project.org/mailman/listinfo/users"
target="_blank">http://lists.admb-project.org/mailman/listinfo/users</a><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
<br>
</body>
</html>