ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
model2.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
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 
00096 param_stddev_number::param_stddev_number():
00097   named_dvariable(),
00098   stddev_params(),
00099   sd(0)
00100 {
00101   add_to_list();
00102   add_to_gui_list();
00103   setindex(0);
00104 }
00105 
00106   int param_stddev_number::size_count(void)
00107   {
00108     return 1;
00109   }
00110 
00111   void param_stddev_number::set_dependent_variables(void)
00112   {
00113     #ifndef __ZTC__
00114     dvariable(*this) << dvariable(*this);
00115     #else
00116     *this << *this;
00117     #endif
00118   }
00119 
00120 
00121   void param_stddev_number::allocate(const char * _s)
00122   {
00123     named_dvariable::allocate(_s);
00124     stddev_params::allocate();
00125   }
00126 
00127   int param_stddev_vector::size_count(void)
00128   {
00129     return ::size_count(*this);
00130   }
00131 
00132   param_stddev_vector::param_stddev_vector(void) : named_dvar_vector() ,
00133     stddev_params()
00134   {
00135     add_to_list();
00136   }
00137 
00138   void param_stddev_vector::allocate(int imin,int imax,const char * s)
00139   {
00140     sd.allocate(imin,imax);
00141     named_dvar_vector::allocate(imin,imax,s);
00142     stddev_params::allocate();
00143   }
00144 
00145   void param_stddev_vector::set_dependent_variables(void)
00146   {
00147     dvar_vector(*this) << dvar_vector(*this);
00148   }
00149 
00150   param_stddev_matrix::param_stddev_matrix() : named_dvar_matrix() ,
00151     stddev_params()
00152   {
00153     add_to_list();
00154   }
00155 
00156   int param_stddev_matrix::size_count(void)
00157   {
00158     return ::size_count(*this);
00159   }
00160 
00161   void param_stddev_matrix::allocate(int rmin,int rmax,int cmin,int cmax,
00162     const char * s)
00163   {
00164     sd.allocate(rmin,rmax,cmin,cmax);
00165     named_dvar_matrix::allocate(rmin,rmax,cmin,cmax,s);
00166     stddev_params::allocate();
00167   }
00168 
00169   void param_stddev_matrix::set_dependent_variables(void)
00170   {
00171     dvar_matrix(*this) << dvar_matrix(*this);
00172   }
00173 
00174 
00175 /*
00176 dvar_vector& operator<<(const dvar_vector& v, const dvar_vector& w)
00177 {
00178   int mmin=v.indexmin();
00179   int mmax=v.indexmax();
00180   for (int i=mmin;i<=mmax;i++)
00181   {
00182     v[i] << w[i];
00183   }
00184   return v;
00185 }
00186 
00187 dvar_matrix& operator<<(const dvar_matrix& v, const dvar_matrix& w)
00188 {
00189   int mmin=v.rowmin();
00190   int mmax=v.rowmax();
00191   for (int i=mmin;i<=mmax;i++)
00192   {
00193     v[i] << w[i];
00194   }
00195   return v;
00196 }
00197 */
00198 
00199   const char * param_stddev_vector::label(void)
00200   {
00201     return model_name_tag::label().mychar();
00202   }
00203 
00204   const char * param_stddev_number::label(void)
00205   {
00206     return model_name_tag::label().mychar();
00207   }
00208 
00209   const char * param_stddev_matrix::label(void)
00210   {
00211     return model_name_tag::label().mychar();
00212   }
00213 
00214   /*
00215 class param_stddev_number: public named_dvariable , stddev_params
00216 {
00217   param_stddev_number& operator=(const prevariable&);
00218   param_stddev_number& operator = (CGNU_DOUBLE);
00219   void allocate(const char *s="UNNAMED");
00220   virtual int size_count(void); // get the number of active parameters
00221   virtual const char * label(void);
00222   param_stddev_number();
00223   friend class model_parameters;
00224   virtual void set_dependent_variables(void);
00225 };
00226 
00227 class param_stddev_matrix: public named_dvar_matrix , stddev_params
00228 {
00229   virtual int size_count(void);
00230   //virtual void read_value(void);
00231   virtual const char * label(void);
00232   void allocate(int rmin,int rmax,int cmin,int cmax,
00233     const char * s="UNNAMED");
00234   param_stddev_matrix(void);
00235   friend class model_parameters;
00236   virtual void set_dependent_variables(void);
00237 };
00238 */