[ADMB Users] likelihood profile for elements in vector?

dave fournier davef at otter-rsch.com
Sat Sep 18 15:49:57 PDT 2010


You can do just about anything in C++.
Define a class likeprof_vector in  the GLOBALS_SECTION
You may have to move some things in the header file to make them
public.  also this was originally done on dos with 8+3 file names so 
keep them short
or they may get truncated.

DATA_SECTION

PARAMETER_SECTION
   init_number logR1
   init_number logR2
   sdreport_number avgR
  !!CLASS likeprof_vector xx(1,20,"my")      // vector of 20 
likeprof_numbers
   sdreport_number R1
   sdreport_number R2
   objective_function_value f
PROCEDURE_SECTION
   R1=exp(logR1);
   R2=exp(logR2);
   avgR=(R1+R2)/2.0;
   f=100*square(logR1+logR2);
   f+=square(R1);
   f+=square(R2);
   for (int i=1;i<=20;i++)
   {
     xx(i)=i*R1;
   }


GLOBALS_SECTION
   #include <admodel.h>
   class likeprof_vector
   {
       int index_min;
       int index_max;
       param_likeprof_number * v;
   public:
       int indexmin(){ return index_min;}
       int indexmax(){ return index_max;}
       param_likeprof_number& operator () (int i) {return v[i];}
       likeprof_vector(int lb,int ub,const char * la)
       {
           index_min=lb;
           index_max=ub;
           v=new  param_likeprof_number[index_max-index_min+1];
           v-=index_min;
           for (int i=index_min;i<=index_max;i++)
           {
             adstring label=la + adstring("_") + str(i);
             (*this)(i).allocate(label);
           }
        }
         ~likeprof_vector()
        {
           v+=index_min;
           delete [] v;
           v=0;
        }
   };
                                                                                                                     51,1          Bot




More information about the Users mailing list