[ADMB Users] Application of 'sort' function to variables

kvk fromdustreturned at gmail.com
Mon Apr 26 15:51:41 PDT 2010


I'll have to study this a bit, and I'll get it working. Thank you!

On Apr 26, 2:36 pm, dave fournier <ot... at otter-rsch.com> wrote:
> As I said it is not too difficult to extend the
> sort function to a dvar_matrix. I would use a dmatrix and sort that
> keeping track of the where the rows end up.
> something like this.
>
> GLOBALS_SECTION
>   #include <admodel.h>
>   dvar_matrix sort(const dvar_matrix & M, int ic)
>   {
>     int rmin=M.indexmin();
>     int rmax=M.indexmax();
>     int cmin=M(rmin).indexmin();
>     int cmax=M(rmax).indexmax();
>     if (ic<cmin || ic>cmax)
>     {
>       cerr << "column index out of bounds in sort" << endl;
>       ad_exit(1);
>     }
>     dmatrix CM(rmin,rmax,cmin,cmax+1);
>     int i;
>     for (i=rmin;i<=rmax;i++)
>     {
>       CM(i)(cmin,cmax)=value(M(i));
>       CM(i,cmax+1)=i;   // keep track of the rows
>     }
>     dmatrix SCM=sort(CM,ic);
>     dvector ind=column(SCM,cmax+1);
>     dvar_matrix SM(rmin,rmax,cmin,cmax);
>     for (i=rmin;i<=rmax;i++)
>     {
>       SM(i)=M(ind(i));
>     }
>     return SM;
>   }
>
> --
> _______________________________________________
> Users mailing list
> Us... at admb-project.orghttp://lists.admb-project.org/mailman/listinfo/users
>
> --
> You received this message because you are subscribed to the Google Groups "admb-users" group.
> To post to this group, send email to admb-users at googlegroups.com.
> To unsubscribe from this group, send email to admb-users+unsubscribe at googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/admb-users?hl=en.



More information about the Users mailing list