ADMB Documentation  11.1.2393
 All Classes Files Functions Variables Typedefs Friends Defines
model2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: model2.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00007 #include <admodel.h>
00008 
00009  int stddev_params::num_stddev_params=0;
00010  int stddev_params::num_stddev_number_params=0;
00011 
00012 // this should be a resizeable array
00013 stddev_params* stddev_params::stddev_number_ptr[150];
00014 // this should be a resizeable array
00015 stddev_params* stddev_params::stddevptr[150];
00016 
00017   void stddev_params::add_to_list(void)
00018   {
00019     if (num_stddev_params>=150)
00020     {
00021       cerr << "This version of ADMB only supports " << num_stddev_params
00022            << " stddev_params." << endl;
00023       exit(1);
00024     }
00025     stddevptr[num_stddev_params++]= this; // this is the list of
00026   }
00027 
00028   void stddev_params::add_to_gui_list(void)
00029   {
00030     if (num_stddev_number_params>=150)
00031     {
00032       cerr << "This version of ADMB only supports " << num_stddev_params
00033            << " stddev_params." << endl;
00034       exit(1);
00035     }
00036     stddev_number_ptr[num_stddev_number_params++]= this; // this is the list of
00037   }
00038 
00039   ivector stddev_params::copy_all_number_offsets(void)
00040   {
00041     int ndv=stddev_params::num_stddev_number_calc();
00042     ivector no(1,ndv);
00043     for (int i=0;i<ndv;i++)
00044     {
00045       no(i+1)=stddev_number_ptr[i]->getindex();
00046     }
00047     return no;
00048   }
00049 
00050 
00051   int stddev_params::num_stddev_calc(void)
00052   {
00053     int nvar=0;
00054     for (int i=0;i<num_stddev_params;i++)
00055     {
00056       nvar+= (stddevptr[i])->size_count();
00057     }
00058     return nvar;
00059   }
00060 
00061   void stddev_params::setindex(int _index){;}
00062   int stddev_params::getindex(void){return 0;}
00063 
00064   int param_stddev_number::getindex(void)
00065   {
00066     return index;
00067   }
00068   void param_stddev_number::setindex(int _index)
00069   {
00070     index=_index;
00071   }
00072 
00073   void stddev_params::get_stddev_number_offset(void)
00074   {
00075     int offset=1;
00076     int ii=0;
00077     for (int i=0;i<num_stddev_params;i++)
00078     {
00079       if (stddevptr[i]==stddev_number_ptr[ii])
00080       {
00081         stddev_number_ptr[ii]->setindex(offset);
00082         if (++ii>=num_stddev_number_params) break;
00083       }
00084       offset+= (stddevptr[i])->size_count();
00085     }
00086   }
00087 
00088   int stddev_params::num_stddev_number_calc(void)
00089   {
00090     return stddev_params::num_stddev_number_params;
00091   }
00092 
00093   param_stddev_number::param_stddev_number() : named_dvariable() ,
00094     stddev_params()
00095   {
00096     add_to_list();
00097     add_to_gui_list();
00098     setindex(0);
00099   }
00100 
00101   int param_stddev_number::size_count(void)
00102   {
00103     return 1;
00104   }
00105 
00106   void param_stddev_number::set_dependent_variables(void)
00107   {
00108     #ifndef __ZTC__
00109     dvariable(*this) << dvariable(*this);
00110     #else
00111     *this << *this;
00112     #endif
00113   }
00114 
00115 
00116   void param_stddev_number::allocate(const char * _s)
00117   {
00118     named_dvariable::allocate(_s);
00119     stddev_params::allocate();
00120   }
00121 
00122   int param_stddev_vector::size_count(void)
00123   {
00124     return ::size_count(*this);
00125   }
00126 
00127   param_stddev_vector::param_stddev_vector(void) : named_dvar_vector() ,
00128     stddev_params()
00129   {
00130     add_to_list();
00131   }
00132 
00133   void param_stddev_vector::allocate(int imin,int imax,const char * s)
00134   {
00135     sd.allocate(imin,imax);
00136     named_dvar_vector::allocate(imin,imax,s);
00137     stddev_params::allocate();
00138   }
00139 
00140   void param_stddev_vector::set_dependent_variables(void)
00141   {
00142     dvar_vector(*this) << dvar_vector(*this);
00143   }
00144 
00145   param_stddev_matrix::param_stddev_matrix() : named_dvar_matrix() ,
00146     stddev_params()
00147   {
00148     add_to_list();
00149   }
00150 
00151   int param_stddev_matrix::size_count(void)
00152   {
00153     return ::size_count(*this);
00154   }
00155 
00156   void param_stddev_matrix::allocate(int rmin,int rmax,int cmin,int cmax,
00157     const char * s)
00158   {
00159     sd.allocate(rmin,rmax,cmin,cmax);
00160     named_dvar_matrix::allocate(rmin,rmax,cmin,cmax,s);
00161     stddev_params::allocate();
00162   }
00163 
00164   void param_stddev_matrix::set_dependent_variables(void)
00165   {
00166     dvar_matrix(*this) << dvar_matrix(*this);
00167   }
00168 
00169 
00170 /*
00171 dvar_vector& operator<<(const dvar_vector& v, const dvar_vector& w)
00172 {
00173   int mmin=v.indexmin();
00174   int mmax=v.indexmax();
00175   for (int i=mmin;i<=mmax;i++)
00176   {
00177     v[i] << w[i];
00178   }
00179   return v;
00180 }
00181 
00182 dvar_matrix& operator<<(const dvar_matrix& v, const dvar_matrix& w)
00183 {
00184   int mmin=v.rowmin();
00185   int mmax=v.rowmax();
00186   for (int i=mmin;i<=mmax;i++)
00187   {
00188     v[i] << w[i];
00189   }
00190   return v;
00191 }
00192 */
00193 
00194   const char * param_stddev_vector::label(void)
00195   {
00196     return model_name_tag::label().mychar();
00197   }
00198 
00199   const char * param_stddev_number::label(void)
00200   {
00201     return model_name_tag::label().mychar();
00202   }
00203 
00204   const char * param_stddev_matrix::label(void)
00205   {
00206     return model_name_tag::label().mychar();
00207   }
00208 
00209   /*
00210 class param_stddev_number: public named_dvariable , stddev_params
00211 {
00212   param_stddev_number& operator=(const prevariable&);
00213   param_stddev_number& operator = (CGNU_DOUBLE);
00214   void allocate(const char *s="UNNAMED");
00215   virtual int size_count(void); // get the number of active parameters
00216   virtual const char * label(void);
00217   param_stddev_number();
00218   friend class model_parameters;
00219   virtual void set_dependent_variables(void);
00220 };
00221 
00222 class param_stddev_matrix: public named_dvar_matrix , stddev_params
00223 {
00224   virtual int size_count(void);
00225   //virtual void read_value(void);
00226   virtual const char * label(void);
00227   void allocate(int rmin,int rmax,int cmin,int cmax,
00228     const char * s="UNNAMED");
00229   param_stddev_matrix(void);
00230   friend class model_parameters;
00231   virtual void set_dependent_variables(void);
00232 };
00233 */