[ADMB Users] sorted minimizer display?

dave fournier davef at otter-rsch.com
Tue Aug 20 08:27:28 PDT 2013


Well this is a bit complicated because there are various loops where the 
function and
gradient are calculated and various function minimizers.  What I would 
do is to
compile my code with debug info and but a breakpoint in the 
userfunction. Then
a stack trace will find where you are.  In my case df1b2qnm.cpp around 
line 185.
the loop looks like



   while (fmc.ireturn>=0)
       {
         fmc.fmin(f,x,g);
         if (fmc.ireturn>0)
         {
           dvariable vf=0.0;
           vf=initial_params::reset(dvar_vector(x));
           *objective_function_value::pobjfun=0.0;
           pre_userfunction();
           vf+=*objective_function_value::pobjfun;
           f=value(vf);
           gradcalc(nvar,g);
         }
       }

To make it simple lets print out every function evaluation.

   ofstream ofs("stuff");

   while (fmc.ireturn>=0)
       {
         fmc.fmin(f,x,g);
         if (fmc.ireturn>0)
         {
           dvariable vf=0.0;
           vf=initial_params::reset(dvar_vector(x));
           *objective_function_value::pobjfun=0.0;
           pre_userfunction();
           vf+=*objective_function_value::pobjfun;
           f=value(vf);
           gradcalc(nvar,g);

           printstuff(f,x,g,ofs);
         }
       }

void printstuff(double f,const dvector& x,const dvector& g,const 
ofstream& ofs)
{
    int n=g.indexmax();
    dmatrix TS(1,2,1,n);

    TS(1).fill_seqadd(1,1);
    TS(2)=fabs(g);

     dmatrix S=trans(TS);

     S=sort(S,2);

    ivector index=ivector(column(S,1));   // can use index to print out 
what you want

    for (int i=n;i>=n;i--)
    {
        ofs << x(ind(i)) << " " << g(ind(i)) << endl;
    }

This is probably in decreasing order









More information about the Users mailing list