ADMB Documentation  11.1.1916
 All Classes Files Functions Variables Typedefs Friends Defines
admodel.h
Go to the documentation of this file.
00001 /*
00002  * $Id: admodel.h 1878 2014-04-09 00:56:26Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 #ifndef _ADMODEL_H_
00046 #define _ADMODEL_H_
00047 
00048 #define USE_SHARE_FLAGS
00049 //#define DO_PROFILE
00050 #define __MINI_MAX__
00051 #if defined(__GNUC__) && (__GNUC__ < 3)
00052   #pragma interface
00053 #endif
00054 
00055 #define BIG_INIT_PARAMS
00056 
00057 #if defined(USE_LAPLACE)
00058   class laplace_approximation_calculator;
00059   void cleanup_laplace_stuff(laplace_approximation_calculator *);
00060 #endif
00061 
00062 #include <fvar.hpp>
00063 #if defined(USE_ADPVM)
00064 #  include <adpvm2.h>
00065 #endif
00066 
00067 //#include <d4arr.hpp>
00068 #include <cifstrem.h>
00069 
00070 #include <adstring.hpp>
00071 class init_xml_doc;
00072 
00073 #if !defined(_MSC_VER)
00074   #include <unistd.h>
00075 #endif
00076 
00077 //#define _ADSTD_ std::
00078 #define param_matrix named_dvar_matrix
00079 #define param_vector named_dvar_vector
00080 #define param_number named_dvariable
00081 #define param_3array named_dvar3_array
00082 #define param_4array named_dvar4_array
00083 #define param_5array named_dvar5_array
00084 #define param_6array named_dvar6_array
00085 #define param_7array named_dvar7_array
00086 
00087 #define SPparam_matrix SPnamed_dvar_matrix
00088 #define SPparam_vector SPnamed_dvar_vector
00089 #define SPparam_number SPnamed_dvariable
00090 #define SPparam_3array SPnamed_dvar3_array
00091 #define SPparam_4array SPnamed_dvar4_array
00092   double mfexp(CGNU_DOUBLE );
00093   dvariable mfexp(const prevariable& v1);
00094   dvar_vector mfexp(const dvar_vector&);
00095   dvector mfexp(const dvector&);
00096 
00097   class param_init_bounded_number_vector;
00098   class model_parameters;
00099   extern int AD_gaussflag;
00100 
00101   extern function_minimizer * pfm;
00102   extern int traceflag;
00103   extern int ADqd_flag;
00104 /*
00105  void set_value_inv(const dvariable& x, const dvector& v, const int& ii);
00106  void set_value_inv(const dvar_matrix& x, const dvector& v, const int& ii);
00107  void set_value_inv(const dvar_vector&, const dvector&, const int &ii);
00108  void set_value_inv(const dvariable& u, const dvector& x, const int& ii,
00109    CGNU_DOUBLE fmin, CGNU_DOUBLE fmax);
00110  void set_value_inv(const dvar_matrix& u, const dvector& x, const int& ii,
00111   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
00112  void set_value_inv(const dvar3_array& u, const dvector& x, const int& ii,
00113   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
00114  void set_value_inv(const dvar3_array& u, const dvector& x, const int& ii);
00115 */
00116 
00117   void copy_value_to_vector(const prevariable& x, const dvector& v,
00118     const int& ii);
00119   void copy_value_to_vector(const dvar_vector& x, const dvector& v,
00120     const int& ii);
00121   void copy_value_to_vector(const dvar_matrix& x, const dvector& v,
00122     const int& ii);
00123   void copy_value_to_vector(const dvar3_array& x, const dvector& v,
00124     const int& ii);
00125 
00126   void restore_value_from_vector(const prevariable& x, const dvector& v,
00127     const int& ii);
00128   void restore_value_from_vector(const dvar_vector& x, const dvector& v,
00129     const int& ii);
00130   void restore_value_from_vector(const dvar_matrix& x, const dvector& v,
00131     const int& ii);
00132   void restore_value_from_vector(dvar3_array& x, const dvector& v,
00133     const int& ii);
00134 
00139 class AD_matherror
00140 {
00141 public:
00142 #if defined (_BORLANDC_)
00143   exception * err;
00144   AD_matherror(exception * _err) : err(_err) {;}
00145 #endif
00146 #if defined (_MSC_VER)
00147   _exception * err;
00148   AD_matherror(_exception * _err) : err(_err) {;}
00149 #endif
00150 };
00151 
00152 class model_data;
00153 
00158 class label_class
00159 {
00160   const char * name;
00161   friend ostream& operator<<(const ostream& s, const label_class& lc);
00162   friend class model_name_tag;
00163 public:
00164   const char * mychar(void) { return name;}
00165   label_class(const char * s){name=s;}
00166 };
00167 
00172 class model_name_tag
00173 {
00174 protected:
00175   adstring name;
00176   //friend ostream& operator<<(const ostream& os, const model_name_tag& mnt);
00177 public:
00178   model_name_tag(void){;}
00179   void allocate(const char * s);
00180   label_class label(void){return (char*)(name);}
00181   const char * get_name(void) { return name;}
00182 };
00183 
00188 class named_dvar_vector : public dvar_vector, public model_name_tag
00189 {
00190 protected:
00191   named_dvar_vector(void) : dvar_vector(), model_name_tag() {;}
00192   named_dvar_vector& operator=(const dvar_vector& m);
00193   named_dvar_vector& operator=(const dvector& m);
00194   named_dvar_vector& operator = (CGNU_DOUBLE m);
00195   named_dvar_vector& operator=(const prevariable& m);
00196   friend class model_parameters;
00197   void allocate(int mmin,int mmax,const char * s);
00198   void allocate(const char * s);
00199 };
00200 
00205 class equality_constraint_vector : public named_dvar_vector
00206 {
00207 protected:
00208   equality_constraint_vector(void);
00209   equality_constraint_vector& operator=(const dvar_vector& m);
00210   equality_constraint_vector& operator=(const dvector& m);
00211   equality_constraint_vector& operator = (CGNU_DOUBLE m);
00212   equality_constraint_vector& operator=(const prevariable& m);
00213   friend class model_parameters;
00214   void allocate(int mmin,int mmax,const char * s);
00215 };
00216 
00221 class inequality_constraint_vector : public named_dvar_vector
00222 {
00223 protected:
00224   inequality_constraint_vector(void);
00225   inequality_constraint_vector& operator=(const dvar_vector& m);
00226   inequality_constraint_vector& operator=(const dvector& m);
00227   inequality_constraint_vector& operator = (CGNU_DOUBLE m);
00228   inequality_constraint_vector& operator=(const prevariable& m);
00229   friend class model_parameters;
00230   void allocate(int mmin,int mmax,const char * s);
00231 };
00232 
00237 class dll_param_vector : public named_dvar_vector
00238 {
00239   double * pd;
00240 public:
00241   ~dll_param_vector();
00242   void allocate(double *_pd,int mmin,int mmax,const char * s);
00243   dll_param_vector& operator=(const dvar_vector& m);
00244   dll_param_vector& operator=(const dvector& m);
00245   dll_param_vector& operator = (CGNU_DOUBLE m);
00246   dll_param_vector& operator=(const prevariable& m);
00247 };
00248 
00253 class named_dvariable : public dvariable, public model_name_tag
00254 {
00255   //named_dvariable& operator=(const dvariable& m);
00256 protected:
00257   named_dvariable(void) : dvariable(), model_name_tag() {;}
00258   void allocate(const char * s);
00259   named_dvariable& operator=(const prevariable& m);
00260   named_dvariable& operator = (CGNU_DOUBLE m);
00261   friend class model_parameters;
00262 };
00263 
00268 class dll_param_number : public named_dvariable
00269 {
00270   double * pd;
00271 protected:
00272   //named_dvariable(void) : dvariable(), model_name_tag() {;}
00273   void allocate(double *_d,const char * s);
00274   dll_param_number& operator=(const prevariable& m);
00275   dll_param_number& operator = (CGNU_DOUBLE m);
00276   virtual ~dll_param_number();
00277   friend class model_parameters;
00278 };
00279 
00284 class named_dvar_matrix : public dvar_matrix, public model_name_tag
00285 {
00286 protected:
00287   named_dvar_matrix(void) : dvar_matrix(), model_name_tag() {;}
00288   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00289   void allocate(int rmin,int rmax,const char * s);
00290   void allocate(const char * s);
00291   //void allocate(int rmin,int rmax,int,const ivector&,
00292     //const char * s);
00293   void allocate(int rmin,int rmax,const index_type&,const index_type&,
00294     const char * s);
00295 public:
00296   named_dvar_matrix& operator = (CGNU_DOUBLE m);
00297   named_dvar_matrix& operator=(const dmatrix& m);
00298   named_dvar_matrix& operator=(const dvar_matrix& m);
00299   named_dvar_matrix& operator=(const dvariable& m);
00300   friend class model_parameters;
00301 };
00302 
00307 class dll_param_matrix : public named_dvar_matrix
00308 {
00309   double * pd;
00310 public:
00311   //named_dvar_matrix(void) : dvar_matrix(), model_name_tag() {;}
00312   void allocate(double * ,int rmin,int rmax,int cmin,int cmax,const char * s);
00313   void allocate(double * ,int rmin,int rmax,const index_type&
00314      ,const index_type& ,const char * s);
00315   dll_param_matrix& operator=(const dvariable& m);
00316   dll_param_matrix & operator = (const double m);
00317   dll_param_matrix& operator=(const dmatrix& m);
00318   dll_param_matrix& operator=(const dvar_matrix& m);
00319   virtual ~dll_param_matrix();
00320 };
00321 
00326 class named_dvar3_array : public dvar3_array, public model_name_tag
00327 {
00328 protected:
00329   named_dvar3_array(void) : dvar3_array(), model_name_tag() {;}
00330  void allocate(const ad_integer& sl,const ad_integer& sh,
00331   const index_type& nrl,const index_type& nrh,const index_type& ncl,
00332     const index_type& nch,const char * s="UNNAMED");
00333   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00334     const char * s="UNNAMED");
00335 
00336   void allocate(int hsl,int hsu,int rmin,int rmax,const char * s="UNNAMED");
00337   void allocate(int hsl,int hsu,const index_type& rmin,const index_type& rmax,
00338     const char * s="UNNAMED");
00339   void allocate(int hsl,int hsu,const char * s="UNNAMED");
00340   void allocate(const char * s="UNNAMED");
00341 
00342 
00343   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00344                 int cmin, int cmax, const char *s = "UNNAMED");
00345   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00346     int cmin,int cmax,const char * s="UNNAMED");
00347   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00348     int cmin,int cmax,const char * s="UNNAMED");
00349   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00350     int cmax,const char * s="UNNAMED");
00351   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00352                 const ivector& cmax, const char *s = "UNNAMED");
00353   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00354                 const ivector& cmax, const char *s = "UNNAMED");
00355   named_dvar3_array& operator=(const dvar3_array& m);
00356   named_dvar3_array& operator=(const d3_array& m);
00357   friend class model_parameters;
00358 };
00359 
00364 class named_dvar4_array : public dvar4_array, public model_name_tag
00365 {
00366 protected:
00367   named_dvar4_array(void) : dvar4_array(), model_name_tag() {;}
00368   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00369   int cmin,int cmax,const char * s);
00370   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00371     const index_type&,const index_type&,const index_type&,const index_type&,
00372     const char *s);
00373 
00374   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00375     const index_type&,const index_type&,const char *s);
00376 
00377   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00378     const char *s);
00379   void allocate(ad_integer,ad_integer,const char *s);
00380   void allocate(const char *s);
00381 
00382   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00383     const char * s);
00384   void allocate(int hhsl,int hhsu,int hsl,int hsu,const char * s);
00385   void allocate(int hhsl,int hhsu,const char * s);
00386 
00387   named_dvar4_array& operator=(const dvar4_array& m);
00388   named_dvar4_array& operator=(const d4_array& m);
00389   friend class model_parameters;
00390 };
00391 
00396 class named_dvar5_array : public dvar5_array, public model_name_tag
00397 {
00398 protected:
00399   named_dvar5_array(void) : dvar5_array(), model_name_tag() {;}
00400   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00401   int cmin,int cmax,
00402   int l5,int u5,
00403   const char * s);
00404 
00405   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00406     const index_type& hsl,const index_type& hsu,
00407     const index_type& sl,const index_type& sh,
00408     const index_type& nrl,const index_type& nrh,
00409     const index_type& ncl,const index_type& nch,
00410     const char * s);
00411 
00412   named_dvar5_array& operator=(const dvar5_array& m);
00413   named_dvar5_array& operator=(const d5_array& m);
00414   friend class model_parameters;
00415 };
00416 
00421 class named_dvar6_array : public dvar6_array, public model_name_tag
00422 {
00423 protected:
00424   named_dvar6_array(void) : dvar6_array(), model_name_tag() {;}
00425   void allocate(int hhsl,int hhsu,
00426     int hsl,int hsu,
00427     int rmin,int rmax,
00428     int cmin,int cmax,
00429     int l5,int u5,
00430     int l6,int u6,
00431     const char * s);
00432 
00433   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00434     const index_type& hsl,const index_type& hsu,
00435     const index_type& sl,const index_type& sh,
00436     const index_type& nrl,const index_type& nrh,
00437     const index_type& ncl,const index_type& nch,
00438     const index_type& l5,const index_type& u5,
00439     const char * s);
00440 
00441   named_dvar6_array& operator=(const dvar6_array& m);
00442   named_dvar6_array& operator=(const d6_array& m);
00443   friend class model_parameters;
00444 };
00445 
00450 class named_dvar7_array : public dvar7_array, public model_name_tag
00451 {
00452 protected:
00453   named_dvar7_array(void) : dvar7_array(), model_name_tag() {;}
00454   void allocate(
00455     int hhsl,int hhsu,
00456     int hsl,int hsu,
00457     int rmin,int rmax,
00458     int cmin,int cmax,
00459     int l5,int u5,
00460     int l6,int u6,
00461     int l7,int u7,
00462     const char * s);
00463 
00464   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00465     const index_type& hsl,const index_type& hsu,
00466     const index_type& sl,const index_type& sh,
00467     const index_type& nrl,const index_type& nrh,
00468     const index_type& ncl,const index_type& nch,
00469     const index_type& l5,const index_type& u5,
00470     const index_type& l6,const index_type& u6,
00471     const char * s);
00472 
00473   named_dvar7_array& operator=(const dvar7_array& m);
00474   named_dvar7_array& operator=(const d7_array& m);
00475   friend class model_parameters;
00476 };
00477 
00482 class named_dvector : public dvector, public model_name_tag
00483 {
00484 protected:
00485   named_dvector(void) : dvector(), model_name_tag() {;}
00486   void allocate(int mmin,int mmax,const char * s);
00487   void allocate(const char * s);
00488   void allocate(int mmin, const ivector& mmax, const char *s);
00489   named_dvector& operator=(const dvector& m);
00490   named_dvector& operator = (CGNU_DOUBLE m);
00491   friend class model_data;
00492 };
00493 
00498 class named_ivector : public ivector, public model_name_tag
00499 {
00500 protected:
00501   named_ivector(void) : ivector(), model_name_tag() {;}
00502   void allocate(int mmin,int mmax,const char * s);
00503 };
00504 
00509 class named_dmatrix : public dmatrix, public model_name_tag
00510 {
00511 protected:
00512   named_dmatrix(void) : dmatrix(), model_name_tag() {;}
00513   void allocate(int rmin,int rmax,const char * s);
00514   void allocate(const char * s);
00515   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00516   void allocate(int rmin,int rmax,const ivector& cmin,int cmax,const char * s);
00517   void allocate(int rmin,int rmax,const ivector& cmin,const ivector& cmax,
00518     const char * s);
00519   void allocate(int rmin,int rmax,int cmin,const ivector& cmax,const char * s);
00520   named_dmatrix& operator=(const dmatrix& m);
00521   named_dmatrix& operator = (CGNU_DOUBLE m);
00522 };
00523 
00528 class named_imatrix : public imatrix, public model_name_tag
00529 {
00530 protected:
00531   named_imatrix(void) : imatrix(), model_name_tag() {;}
00532   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00533   void allocate(int rmin, int rmax, const index_type& cmin,
00534                 const index_type& cmax, const char *s);
00535   named_imatrix& operator=(const imatrix& m);
00536   named_imatrix& operator=(const int& m);
00537 };
00538 
00543 class named_d3_array : public d3_array, public model_name_tag
00544 {
00545 protected:
00546   named_d3_array(void) : d3_array(), model_name_tag() {;}
00547   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00548     const char * s);
00549   void allocate(int hsl, int hsu, const index_type& rmin,
00550                 const index_type& rmax, const index_type& cmin,
00551                 const index_type& cmax, const char *s);
00552   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00553     int cmin,int cmax,const char * s);
00554   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00555     int cmin,int cmax,const char * s);
00556   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00557     int cmin,int cmax,const char * s);
00558   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00559     int cmax, const char * s);
00560   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00561                 const ivector& cmax, const char *s);
00562   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00563                 const ivector& cmax, const char *s);
00564   named_d3_array& operator=(const d3_array& m);
00565 
00566   void allocate(int hsl,int hsu,const index_type& rmin,const index_type& rmax,
00567     const char * s);
00568   void allocate(int hsl,int hsu,int rmin,int rmax,const char * s);
00569   void allocate(int hsl,int hsu,const char * s);
00570   void allocate(const char * s);
00571 };
00572 
00577 class named_i3_array : public i3_array, public model_name_tag
00578 {
00579 protected:
00580   named_i3_array(void) : i3_array(), model_name_tag() {;}
00581   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00582     const char * s);
00583   void allocate(int hsl, int hsu, const index_type& rmin,
00584                 const index_type& rmax, const index_type& cmin,
00585                 const index_type& cmax, const char *s);
00586   named_i3_array& operator=(const i3_array& m);
00587 };
00588 
00593 class named_d4_array : public d4_array, public model_name_tag
00594 {
00595 protected:
00596   named_d4_array(void) : d4_array(), model_name_tag() {;}
00597   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00598     const index_type&,const index_type&,const index_type&,const index_type&,
00599     const char * s);
00600   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00601     int rmax,int cmin,int cmax,const char * s);
00602 
00603   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00604     int rmax,const char * s);
00605   void allocate(int hhsl,int hhsu,int hsl,int hsu,const char * s);
00606   void allocate(int hhsl,int hhsu,const char * s);
00607   void allocate(const char * s);
00608 
00609   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00610     const index_type&,const index_type&,const char * s);
00611   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00612     const char * s);
00613   void allocate(ad_integer,ad_integer,const char * s);
00614 
00615 
00616   named_d4_array& operator=(const d4_array& m);
00617 };
00618 
00623 class named_d5_array : public d5_array, public model_name_tag
00624 {
00625 protected:
00626   named_d5_array(void) : d5_array(), model_name_tag() {;}
00627   void allocate(int l5,int u5,int hhsl,int hhsu,int hsl,int hsu,int rmin,
00628     int rmax,int cmin,int cmax,const char * s);
00629   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00630     const index_type& hsl,const index_type& hsu, const index_type& sl,
00631     const index_type& sh,const index_type& nrl,const index_type& nrh,
00632     const index_type& ncl,const index_type& nch,const char * s);
00633 
00634   named_d5_array& operator=(const d5_array& m);
00635 };
00636 
00641 class named_d6_array : public d6_array, public model_name_tag
00642 {
00643 protected:
00644   named_d6_array(void) : d6_array(), model_name_tag() {;}
00645   void allocate(int l6,int u6,int l5,int u5,int hhsl,int hhsu,int hsl,
00646     int hsu,int rmin,int rmax,int cmin,int cmax,const char * s);
00647   void allocate(const ad_integer& l6,const ad_integer& u6,
00648     const index_type& l5,const index_type& u5,
00649     const index_type& hhsl,const index_type& hhsu,
00650     const index_type& hsl,const index_type& hsu,
00651     const index_type& sl,const index_type& sh,
00652     const index_type& nrl,const index_type& nrh,
00653     const char * s);
00654 
00655   named_d6_array& operator=(const d6_array& m);
00656 };
00657 
00662 class named_d7_array : public d7_array, public model_name_tag
00663 {
00664 protected:
00665   named_d7_array(void) : d7_array(), model_name_tag() {;}
00666   void allocate(int l7,int u7,int l6,int u6,int l5,int u5,int hhsl,
00667     int hhsu,int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00668     const char * s);
00669   void allocate(const ad_integer& l7,const ad_integer& u7,
00670     const index_type& l6,const index_type& u6,
00671     const index_type& l5,const index_type& u5,
00672     const index_type& hhsl,const index_type& hhsu,
00673     const index_type& hsl,const index_type& hsu,
00674     const index_type& sl,const index_type& sh,
00675     const index_type& nrl,const index_type& nrh,
00676     const char * s);
00677 
00678   named_d7_array& operator=(const d7_array& m);
00679 };
00680 
00681 
00682 class function_minimizer;
00683 
00684 #if defined(USE_ADPVM)
00685 
00689 class pvm_params
00690 {
00691   static pvm_params * varsptr[]; // this should be a resizeable array
00692   static int num_pvm_params;
00693   static const int maxnum_pvm_params;
00694   void add_to_list(void);
00695   virtual void send_to_slaves(void)=0;
00696   virtual void get_from_master(void)=0;
00697 public:
00698   static void pvm_params::send_all_to_slaves(void);
00699   static void pvm_params::get_all_from_master(void);
00700   void allocate(const char *);
00701   void allocate(void);
00702 };
00703 
00708 class pvm_number : public pvm_params
00709 {
00710 public:
00711   virtual void send_to_slaves(void);
00712   virtual void get_from_master(void);
00713   dvector v;
00714   double d;
00715   operator double();
00716   void assign(const dvector&);
00717   void assign(double);
00718 };
00719 
00724 class pvm_int : public pvm_params
00725 {
00726 public:
00727   virtual void send_to_slaves(void);
00728   virtual void get_from_master(void);
00729   ivector v;
00730   int d;
00731   operator int();
00732   void assign(const ivector&);
00733   void assign(int);
00734 };
00735 #endif // #if defined(USE_ADPVM)
00736 
00737 class initial_params;
00738 typedef initial_params* pinitial_params;
00739 typedef void* ptovoid;
00743 class adlist_ptr
00744 {
00745   ptovoid * ptr;
00746   int current_size;
00747   int current;
00748   void resize(void);
00749   void add_to_list(void* p);
00750 public:
00751   adlist_ptr(int init_size);
00752   ~adlist_ptr();
00753 
00754   void initialize();
00755 
00756   pinitial_params& operator[](int i);
00757 
00758   friend class initial_params;
00759 };
00760 
00761 #if defined(USE_SHARE_FLAGS)
00762 
00767   class shareinfo
00768   {
00769     index_type * sflags;
00770     index_type * original_sflags;
00771     index_type * aflags;
00772     index_type * invflags;
00773     i3_array * bmap;
00774     int dimension;
00775     int maxshare;
00776     int current_phase;
00777   public:
00778     void get_inv_matrix_shared( int _cf);
00779     void get_inv_vector_shared( int _cf);
00780     int & get_maxshare(void) { return maxshare; }
00781     i3_array & get_bmap(void);
00782     int & get_dimension(void){ return dimension;}
00783     index_type * get_original_shareflags(void);
00784     index_type * get_shareflags(void);
00785     int& get_current_phase(void);
00786     index_type * get_activeflags(void);
00787     index_type * get_invflags(void);
00788     void set_shareflags(const index_type& sf);
00789     void set_original_shareflags(const index_type& sf);
00790     void reset_shareflags(const index_type& sf);
00791     void set_activeflags(const index_type& af);
00792     void set_bmap(const i3_array& af);
00793     void reset_bmap(const i3_array& af);
00794     void set_invflags(const index_type& af);
00795     shareinfo(const index_type& sf,const index_type& af);
00796     ~shareinfo();
00797   };
00798 #endif
00799 
00804 class initial_params
00805 {
00806 protected:
00807 #if defined(USE_SHARE_FLAGS)
00808   shareinfo * share_flags;
00809 #endif
00810   virtual ~initial_params();
00811   int active_flag;
00812   int initial_value_flag;
00813   double initial_value;
00814   double scalefactor;
00815 public:
00816 #if defined(USE_SHARE_FLAGS)
00817   virtual void setshare(const index_type& sf,const index_type& af);
00818   virtual void shared_set_value_inv(const dvector&,const int&);
00819   virtual void shared_set_value(const dvar_vector&,const int&,
00820     const dvariable& pen);
00821   virtual int shared_size_count(void); // get the number of active parameters
00822 #endif
00823   double get_scalefactor();
00824   void set_scalefactor(const double);
00825 #if !defined(BIG_INIT_PARAMS)
00826   static initial_params  varsptr[]; // this should be a resizeable array
00827 #else
00828   static adlist_ptr varsptr; // this should be a resizeable array
00829 #endif
00830   static int num_initial_params;
00831   static const int max_num_initial_params;
00832   static int straight_through_flag;
00833   static int num_active_initial_params;
00834   static int max_number_phases;
00835   static int current_phase;
00836   static int restart_phase;
00837   static int sd_phase;
00838   static int mc_phase;
00839   static int mceval_phase;
00840   int phase_start;
00841   int phase_save;
00842   int phase_stop;
00843   virtual void set_random_effects_active();
00844   void restore_phase_start(void);
00845   virtual void set_random_effects_inactive();
00846   virtual void set_only_random_effects_active();
00847   virtual void set_only_random_effects_inactive();
00848   virtual void set_value(const dvar_vector&, const int&,
00849     const dvariable& pen) = 0;
00850   virtual void dev_correction(const dmatrix&, const int&) = 0;
00851   void set_initial_value(double x);
00852   double get_initial_value(void);
00853   void set_phase_start(int x);
00854   int get_phase_start(void);
00855   static void set_all_simulation_bounds(const dmatrix& symbds);
00856   static void set_all_simulation_bounds(const dmatrix& symbds, const dvector&);
00857   static void get_jacobian_value(const dvector& y, const dvector& jac);
00858   static int correct_for_dev_objects(const dmatrix &H);
00859   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii) = 0;
00860   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
00861   //  const int& ii) = 0;
00862   virtual void set_value_inv(const dvector&, const int&) = 0;
00863   virtual void add_value(const dvector&, const int&) = 0;
00864   virtual void add_value(const dvector&, const dvector&, const int&,
00865     const double&, const dvector&) = 0;
00866   virtual void get_jacobian(const dvector&, const dvector&, const int&) = 0;
00867   //virtual void check_tightness(const dvector&, const int&) = 0;
00868   virtual void copy_value_to_vector(const dvector&, const int&) = 0;
00869   virtual void restore_value_from_vector(const dvector&, const int&) = 0;
00870   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00871   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
00872     const int& ii)=0;
00873   virtual void mc_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00874   virtual void curv_scale(const dvector& d, const dvector& x,
00875     const int& ii) = 0;
00876   virtual void hess_scale(const dvector& d, const dvector& x,
00877     const int& ii) = 0;
00878   virtual int size_count(void)=0; // get the number of active parameters
00879   virtual void save_value(void)=0; // save the objects value in a ascii file
00880   virtual void bsave_value(void)=0; // save the objects value in a binary file
00881   virtual void save_value(const ofstream& ofs, int prec) = 0;
00882   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
00883     int& offset) = 0;
00884   //virtual void bsave_value(const uostream& ofs) = 0;
00885     virtual const char * label()=0;
00886   void allocate(int _phase_start);
00887   void set_active_flag(void);
00888   void set_inactive_flag(void);
00889   friend int active(const initial_params& ip);
00890   static adstring get_reportfile_name(void);
00891   initial_params(void);
00892   static void xinit(const dvector& x); // get the number of active parameters
00893   // get the number of active parameters
00894   static void xinit_all(const dvector& x);
00895   static void save_all(const ofstream& _ofs,int prec,const dvector&g);
00896   // get the number of active parameters
00897   static void set_active_random_effects(void);
00898   // get the number of active parameters
00899   static void set_active_only_random_effects(void);
00900   // get the number of active parameters
00901   static void set_inactive_only_random_effects(void);
00902   // get the number of active parameters
00903   static void set_inactive_random_effects(void);
00904   // get the number of active parameters
00905   static void restore_start_phase(void);
00906   static void xinit1(const dvector& x, const dvector& g);
00907   //save all initial parameter values in a vector
00908   static void copy_all_values(const dvector& x, const int& ii);
00909   //get ivalues for all active parameters from a vector
00910   static void restore_all_values(const dvector& x, const int& ii);
00911   // get the number of active parameters
00912   static dvariable reset(const dvar_vector& x);
00913   // get the number of active parameters
00914   static dvariable reset(const dvector& x);
00915   static dvariable reset1(const dvar_vector& x, const dvector& g);
00916   // get the number of active parameters
00917   static dvariable reset(const dvar_vector& x, const dvector& pen);
00918   // get the number of active parameters
00919   static dvariable reset_all(const dvar_vector& x,const dvector& pen);
00920   static int nvarcalc(void);
00921   static int nvarcalc_all(void);
00922   static int num_active_calc(void);
00923   static int stddev_scale(const dvector& d, const dvector& x);
00924   static int stddev_vscale(const dvar_vector& d,const dvar_vector& x);
00925   static int montecarlo_scale(const dvector& d, const dvector& x);
00926   static int stddev_curvscale(const dvector& d, const dvector& x);
00927   static void read(void);
00928   static void save(void);
00929   static void save(const ofstream& ofs, int prec);
00930   static void restore(const ifstream& ifs);
00931   static void add_random_vector(const dvector& x);
00932   static void add_random_vector(const dvector& y, const dvector& x,
00933     const double& ll, const dvector& diag);
00934   virtual void restore_value(const ifstream& ifs) = 0;
00935   virtual void add_to_list(void);
00936 #if defined(USE_ADPVM)
00937   virtual void pvm_pack(void)=0;
00938   virtual void pvm_unpack(void)=0;
00939 #endif
00940 
00941   friend class function_minimizer;
00942 };
00943 
00944 void pvm_pack(const dvar_vector&);
00945 void pvm_unpack(const dvar_vector&);
00946 void pvm_pack(const prevariable&);
00947 void pvm_unpack(const prevariable&);
00948 void pvm_pack(const dvar_matrix&);
00949 void pvm_unpack(const dvar_matrix&);
00950 
00955 class param_init_vector: public named_dvar_vector , public initial_params
00956 {
00957 public:
00958 #if defined(USE_SHARE_FLAGS)
00959   virtual void setshare(const index_type& sf,const index_type& af);
00960   virtual void shared_set_value_inv(const dvector&,const int&);
00961   virtual void shared_set_value(const dvar_vector&,const int&,
00962     const dvariable& pen);
00963   virtual int shared_size_count(void); // get the number of active parameters
00964 #endif
00965   virtual void dev_correction(const dmatrix& H, const int& ii);
00966   virtual const char * label(void);
00967   param_init_vector();
00968 #if defined(USE_ADPVM)
00969   void pvm_pack(void){::pvm_pack(*this);}
00970   void pvm_unpack(void){::pvm_unpack(*this);}
00971 #endif
00972 private:
00973   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
00974   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
00975   //  const int& ii);
00976   virtual void add_value(const dvector&, const dvector&, const int&,
00977     const double&, const dvector&);
00978   virtual void add_value(const dvector&, const int&);
00979   virtual void get_jacobian(const dvector&, const dvector&, const int&);
00980   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
00981     const int& ii);
00982 
00983   virtual void set_value(const dvar_vector& x, const int& ii,
00984     const dvariable& pen);
00985   virtual void set_value_inv(const dvector& x, const int& ii);
00986   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00987   virtual void restore_value_from_vector(const dvector&, const int&);
00988   virtual int size_count(void);
00989   virtual void sd_scale(const dvector& d, const dvector& x, const int&);
00990   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
00991   virtual void curv_scale(const dvector& d, const dvector& x,const int&);
00992   virtual void hess_scale(const dvector&, const dvector&, const int&){}
00993   virtual void save_value(void);
00994   virtual void bsave_value(void);
00995   virtual void save_value(const ofstream& ofs, int prec);
00996   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
00997     int& offset);
00998   virtual void restore_value(const ifstream& ifs);
00999   void report_value(void);
01000   //virtual void read_value(void);
01001   void allocate(int imin,int imax,int phasestart=1,const char * s="UNNAMED");
01002   void allocate(const ad_integer& imin,const ad_integer& imax,
01003     const ad_integer& phasestart=1,const char * s="UNNAMED");
01004   void allocate(int imin,int imax,const char * s="UNNAMED");
01005 #if defined(USE_SHARE_FLAGS)
01006   void allocate(int imin,int imax,const ivector& ishare,
01007     const char * s="UNNAMED");
01008 #endif
01009   friend class model_parameters;
01010   friend class param_init_vector_vector;
01011 public:
01012   param_init_vector& operator = (const dvector&);
01013   param_init_vector& operator = (const dvar_vector&);
01014   param_init_vector& operator = (const prevariable&);
01015   param_init_vector& operator = (const double&);
01016 };
01017 
01022 class dll_param_init_vector: public param_init_vector
01023 {
01024   double * pd;
01025 public:
01026   dll_param_init_vector& operator = (const dvector&);
01027   dll_param_init_vector& operator = (const dvar_vector&);
01028   dll_param_init_vector& operator = (const prevariable&);
01029   dll_param_init_vector& operator = (const double&);
01030   void allocate(double * _pd,int imin,int imax,
01031     int phasestart=1,const char * s="UNNAMED");
01032   void allocate(double * _pd,int imin,int imax,
01033     const char * s="UNNAMED");
01034 
01035   virtual ~dll_param_init_vector();
01036   friend class model_parameters;
01037 };
01038 
01043 class param_init_bounded_vector: public named_dvar_vector,public initial_params
01044 {
01045   virtual void* parent_this(void){return this;}
01046 public:
01047   double get_minb(void);
01048   void set_minb(double b);
01049   double get_maxb(void);
01050   void set_maxb(double b);
01051 protected:
01052   double minb;
01053   double maxb;
01054   param_init_bounded_vector();
01055 private:
01056   virtual void dev_correction(const dmatrix&, const int&);
01057   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01058   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01059     const int& ii);
01060   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01061   //  const int& ii);
01062   virtual void add_value(const dvector&, const dvector&, const int&,
01063     const double&, const dvector&);
01064   virtual void add_value(const dvector&, const int&);
01065   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01066   virtual void set_value(const dvar_vector& x, const int& ii,
01067     const dvariable& pen);
01068   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01069   virtual void restore_value_from_vector(const dvector&, const int&);
01070   virtual void set_value_inv(const dvector& x, const int& ii);
01071   virtual int size_count(void);
01072   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01073   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01074   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01075   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01076   void allocate(int imin,int imax,double _minb,double _maxb,
01077     int phasestart=1, const char * name="UNNAMED");
01078   void allocate(int imin,int imax,double _minb,double _maxb,
01079     const char * name="UNNAMED");
01080  //void param_init_bounded_vector::allocate(const ad_integer& imin,
01081    //const ad_integer& imax,const ad_double& _minb,const ad_double& _maxb,
01082    //const ad_integer& phase_start,const char * s);
01083   friend class model_parameters;
01084   friend class param_init_bounded_vector_vector;
01085   virtual const char * label(void);
01086   virtual void save_value(const ofstream& ofs, int prec);
01087   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
01088     int& offset);
01089   virtual void restore_value(const ifstream& ifs);
01090   virtual void save_value(void);
01091   virtual void bsave_value(void);
01092   void report_value(void);
01093   //virtual void read_value(void);
01094 public:
01095   param_init_bounded_vector& operator = (const dvector&);
01096   param_init_bounded_vector& operator = (const dvar_vector&);
01097   param_init_bounded_vector& operator = (const prevariable&);
01098   param_init_bounded_vector& operator = (const double&);
01099 #if defined(USE_ADPVM)
01100   void pvm_pack(void){::pvm_pack(*this);}
01101   void pvm_unpack(void){::pvm_unpack(*this);}
01102 #endif
01103 };
01104 
01109 class dll_param_init_bounded_vector: public param_init_bounded_vector
01110 {
01111   double * pd;
01112 public:
01113   void allocate(double * _pd,int imin,int imax,double _minb,double _maxb,
01114     int phasestart=1, const char * name="UNNAMED");
01115   void allocate(double * _pd,int imin,int imax,double _minb,double _maxb,
01116     const char * name="UNNAMED");
01117   ~dll_param_init_bounded_vector();
01118 };
01119 
01124 class param_init_bounded_dev_vector: public param_init_bounded_vector
01125 {
01126   virtual void set_value(const dvar_vector& x, const int& ii,
01127     const dvariable& pen);
01128   virtual void dev_correction(const dmatrix& H, const int& ii);
01129 public:
01130   param_init_bounded_dev_vector& operator = (const dvar_vector& m);
01131   param_init_bounded_dev_vector& operator = (const dvector& m);
01132   param_init_bounded_dev_vector& operator = (const prevariable& m);
01133   param_init_bounded_dev_vector& operator = (const double& m);
01134 };
01135 
01140 class param_init_number: public named_dvariable , public initial_params
01141 {
01142   virtual void dev_correction(const dmatrix&, const int&);
01143   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01144 
01145 #if defined(USE_ADPVM)
01146   void pvm_pack(void){::pvm_pack(*this);}
01147   void pvm_unpack(void){::pvm_unpack(*this);}
01148 #endif
01149 
01150 //  virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01151 //    const int& ii);
01152   virtual void add_value(const dvector&, const dvector&, const int&,
01153     const double&, const dvector&);
01154   virtual void add_value(const dvector&, const int&);
01155   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01156   virtual void set_value(const dvar_vector& x, const int& ii,
01157     const dvariable& pen);
01158   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01159   virtual void restore_value_from_vector(const dvector&, const int&);
01160   virtual void set_value_inv(const dvector& x, const int& ii);
01161   virtual int size_count(void);
01162   virtual void save_value(const ofstream& ofs, int prec);
01163   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
01164     int& offset);
01165   virtual void restore_value(const ifstream& ifs);
01166   virtual void save_value(void);
01167   virtual void bsave_value(void);
01168   void report_value(void);
01169   virtual const char * label(void);
01170   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01171   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01172   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01173   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01174   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01175     const int& ii);
01176   //virtual void read_value(void);
01177 protected:
01178   void allocate(int phase_start=1,const char *s="UNNAMED");
01179   void allocate(const char *s="UNNAMED");
01180   void allocate(init_xml_doc&, const char *s="UNNAMED");
01181   friend class model_parameters;
01182   friend class param_init_number_vector;
01183   param_init_number();
01184   param_init_number& operator = (CGNU_DOUBLE m);
01185   param_init_number& operator=(const prevariable& m);
01186 };
01187 
01192 class dll_param_init_number: public param_init_number
01193 {
01194   double * pd;
01195 public:
01196   void allocate(double * pd,int phase_start=1,const char *s="UNNAMED");
01197   void allocate(double *pd,const char *s="UNNAMED");
01198   virtual ~dll_param_init_number();
01199   dll_param_init_number& operator = (CGNU_DOUBLE m);
01200   dll_param_init_number& operator=(const prevariable& m);
01201 };
01202 
01203 //forward declaration
01204 class data_vector;
01211 class param_init_bounded_number: public param_init_number
01212 {
01213 public:
01214   double get_minb(void);
01215   void set_minb(double b);
01216   double get_maxb(void);
01217   void set_maxb(double b);
01218 protected:
01219   double minb;
01220   double maxb;
01221   void allocate(double _minb,double _maxb,int phase_start=1,
01222     const char * s="UNNAMED");
01223   void allocate(double _minb,double _maxb,const char * s="UNNAMED");
01224   // Added by Steve Martell for using input data for allocation.
01225   void allocate(const data_vector& v,const char * s="UNNAMED");
01226   void allocate(init_xml_doc&, const char * s="UNNAMED");
01227 
01228 public:
01229 #if defined(USE_ADPVM)
01230   void pvm_pack(void){::pvm_pack(*this);}
01231   void pvm_unpack(void){::pvm_unpack(*this);}
01232 #endif
01233   param_init_bounded_number();
01234 private:
01235   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01236 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01237 //  const int& ii);
01238   virtual void add_value(const dvector&, const dvector&, const int&,
01239     const double&, const dvector&);
01240   virtual void add_value(const dvector&, const int&);
01241   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01242   virtual void set_value(const dvar_vector& x, const int& ii,
01243     const dvariable& pen);
01244   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01245   virtual void restore_value_from_vector(const dvector&, const int&);
01246   virtual void set_value_inv(const dvector& x, const int& ii);
01247   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01248   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01249   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01250   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01251   virtual const char * label(void);
01252   void report_value(void);
01253   param_init_bounded_number& operator = (CGNU_DOUBLE m);
01254   param_init_bounded_number& operator=(const prevariable& m);
01255   friend class model_parameters;
01256   friend class param_init_bounded_number_vector;
01257   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01258     const int& ii);
01259 };
01260 
01265 class dll_param_init_bounded_number: public param_init_bounded_number
01266 {
01267   double * pd;
01268 public:
01269   void allocate(double * _pd,double _minb,double _maxb,int phase_start=1,
01270     const char * s="UNNAMED");
01271   void allocate(double* _pd,double _minb, double _maxb,const char* s="UNNAMED");
01272 public:
01273   virtual ~dll_param_init_bounded_number();
01274   void report_value(void);
01275 };
01276 
01281 class param_init_matrix: public named_dvar_matrix,public initial_params
01282 {
01283 #if defined(USE_SHARE_FLAGS)
01284   virtual void shared_set_value_inv(const dvector& x,const int& ii);
01285   virtual int shared_size_count(void); // get the number of active parameters
01286   virtual void shared_set_value(const dvar_vector&,const int&,
01287     const dvariable& pen);
01288 #endif
01289   virtual void dev_correction(const dmatrix&, const int&);
01290   virtual void set_simulation_bounds(const dmatrix& symbds,const int& ii);
01291 #if defined(USE_ADPVM)
01292   void pvm_pack(void){::pvm_pack(*this);}
01293   void pvm_unpack(void){::pvm_unpack(*this);}
01294 #endif
01295 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01296 //  const int& ii);
01297   virtual void add_value(const dvector&, const dvector&, const int&,
01298     const double&, const dvector&);
01299   virtual void add_value(const dvector&, const int&);
01300   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01301 public:
01302   virtual void set_value(const dvar_vector& x, const int& ii,
01303     const dvariable& pen);
01304   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01305   virtual void restore_value_from_vector(const dvector&, const int&);
01306   virtual void set_value_inv(const dvector& x, const int& ii);
01307   virtual int size_count(void);
01308   virtual void save_value(void);
01309   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
01310     int& offset);
01311   virtual void bsave_value(void);
01312   virtual void save_value(const ofstream& ofs, int prec);
01313   virtual void restore_value(const ifstream& ifs);
01314   void report_value(void);
01315   //virtual void read_value(void);
01316   virtual const char * label(void);
01317   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01318   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01319   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01320   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01321   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01322     const int& ii);
01323 
01324 public:
01325   void allocate(int rmin,int rmax,int cmin,int cmax,
01326     int phase_start=1,const char * = "UNNAMED");
01327 #if defined(USE_SHARE_FLAGS)
01328   //void allocate(int rmin,int rmax,int cmin,int cmax, const imatrix& jshare,
01329   // const char * = "UNNAMED");
01330   virtual void setshare(const index_type& sf,const index_type& af);
01331 #endif
01332   void allocate(int rmin,int rmax,int cmin,int cmax,
01333     const char * = "UNNAMED");
01334  void allocate(const ad_integer& imin,const ad_integer&imax,
01335    const index_type& imin2,const index_type& imax2,
01336    const ad_integer& phase_start, const char * s);
01337   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01338                 const index_type& cmin, const index_type& cmax,
01339                 const char * = "UNNAMED");
01340   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01341                 const index_type& cmin, const index_type& cmax,
01342                 int phase_start = 1, const char * = "UNNAMED");
01343   param_init_matrix(void);
01344   param_init_matrix& operator = (const dmatrix& m);
01345   param_init_matrix& operator = (const dvar_matrix& m);
01346   param_init_matrix& operator = (const dvariable& m);
01347   param_init_matrix& operator = (const double& m);
01348 };
01349 
01354 class dll_param_init_matrix: public param_init_matrix
01355 {
01356   double * d;
01357 public:
01358   void allocate(double* _d,int rmin,int rmax,int cmin,int cmax,
01359     int phase_start=1,const char * = "UNNAMED");
01360   void allocate(double * _d,int rmin,int rmax,int cmin,int cmax,
01361     const char * = "UNNAMED");
01362   virtual ~dll_param_init_matrix();
01363   dll_param_init_matrix(){d=NULL;}
01364   dll_param_init_matrix& operator = (const dmatrix& m);
01365   dll_param_init_matrix& operator = (const dvar_matrix& m);
01366   dll_param_init_matrix& operator = (const dvariable& m);
01367   dll_param_init_matrix& operator = (const double& m);
01368 };
01369 
01374 class param_init_bounded_matrix: public param_init_matrix
01375 {
01376 public:
01377   double get_minb(void);
01378   void set_minb(double b);
01379   double get_maxb(void);
01380   void set_maxb(double b);
01381 protected:
01382   double minb;
01383   double maxb;
01384   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01385 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01386 //  const int& ii);
01387   virtual void add_value(const dvector&, const dvector&, const int&,
01388     const double&, const dvector&);
01389   virtual void add_value(const dvector&, const int&);
01390   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01391 public:
01392 #if defined(USE_ADPVM)
01393   void pvm_pack(void){::pvm_pack(*this);}
01394   void pvm_unpack(void){::pvm_unpack(*this);}
01395 #endif
01396   virtual void set_value(const dvar_vector& x, const int& ii,
01397     const dvariable& pen);
01398 #if defined(USE_SHARE_FLAGS)
01399   virtual void shared_set_value_inv(const dvector&,const int&);
01400   virtual void shared_set_value(const dvar_vector&,const int&,
01401     const dvariable& pen);
01402 #endif
01403   virtual void set_value_inv(const dvector& x, const int& ii);
01404   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01405   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01406   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01407   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01408   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01409     const int& ii);
01410 
01411 public:
01412  void allocate(const ad_integer& imin,
01413    const ad_integer& imax, const ad_integer& imin2,
01414    const ad_integer& imax2, const ad_double& _bmin,
01415    const ad_double& _bmax, const ad_integer& phase_start,
01416    const char * s);
01417 
01418   param_init_bounded_matrix(void);
01419   void allocate(int rmin,int rmax,int cmin,int cmax,
01420     double _minb,double _maxb,
01421     int phase_start=1,const char * = "UNNAMED");
01422   void allocate(int rmin,int rmax,int cmin,int cmax,
01423     double _minb,double _maxb,const char * = "UNNAMED");
01424 
01425   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01426     const index_type& cmin,
01427                 const index_type& cmax, double _minb, double _maxb,
01428                 const char * = "UNNAMED");
01429   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01430     const index_type& cmin,
01431                 const index_type& cmax, double _minb, double _maxb,
01432                 int phase_start = 1, const char * = "UNNAMED");
01433 };
01434 
01439 class data_int : public model_name_tag
01440 {
01441 protected:
01442   int val;
01443   data_int& operator=(const int);
01444   void allocate(int n,const char * s="UNNAMED");
01445   void allocate(const char * s="UNNAMED");
01446   void allocate(init_xml_doc&, const char * s="UNNAMED");
01447   friend class model_data;
01448   friend class model_parameters;
01449   friend int operator + (int n,data_int v);
01450   friend int operator + (data_int v,int n);
01451   friend int operator + (data_int v,data_int n);
01452 public:
01453   operator int() {return val;}
01454 #if !defined (__BORLANDC__)
01455   //operator const int() const {return val;}
01456 #endif
01457   virtual ~data_int(){;}
01458 };
01459 
01464 class named_adstring : public adstring, public model_name_tag
01465 {
01466 protected:
01467   void allocate(const char * s1,const char * s="UNNAMED");
01468   void operator = (const adstring&);
01469   void operator = (const char *);
01470 };
01471 
01476 class named_line_adstring : public line_adstring, public model_name_tag
01477 {
01478 protected:
01479   void allocate(const char * s1,const char * s="UNNAMED");
01480   void operator = (const adstring&);
01481   void operator = (const char *);
01482 };
01483 
01488 class init_adstring: public named_adstring
01489 {
01490 public:
01491   void allocate(const char * s="UNNAMED");
01492 };
01493 
01498 class init_line_adstring: public named_line_adstring
01499 {
01500 public:
01501   void allocate(const char * s="UNNAMED");
01502 };
01503 
01508 class dll_named_adstring : public named_adstring
01509 {
01510   char ** d;
01511 public:
01512   void allocate(char ** ps1,const char * s="UNNAMED");
01513   void operator = (const adstring&);
01514   void operator = (const char *);
01515   ~dll_named_adstring();
01516   dll_named_adstring(void){d=NULL;}
01517 };
01518 
01523 class dll_data_int : public data_int
01524 {
01525 public:
01526   int *pi;
01527   void allocate(int *_pi,const char * s);
01528   virtual ~dll_data_int();
01529 };
01530 
01535 class data_matrix : public named_dmatrix
01536 {
01537 public:
01538   data_matrix(void) : named_dmatrix() {;}
01539   data_matrix& operator=(const dmatrix& m);
01540   data_matrix& operator=(const double& m);
01541 private:
01542   void allocate(int rmin,int rmax,int cmin,int cmax,
01543     const char * = "UNNAMED");
01544   void allocate(int rmin, int rmax, const ivector& cmin, const ivector& cmax,
01545     const char * = "UNNAMED");
01546   void allocate(int rmin, int rmax, const ivector& cmin, int cmax,
01547     const char * = "UNNAMED");
01548   void allocate(int rmin, int rmax, int cmin, const ivector& cmax,
01549     const char * = "UNNAMED");
01550   void allocate(init_xml_doc&, const char * = "UNNAMED");
01551   friend class model_data;
01552 };
01553 
01558 class dll_data_matrix : public data_matrix
01559 {
01560   double * d;
01561 public:
01562   void allocate(double * _d,int rmin,int rmax,int cmin,int cmax,
01563     const char * _s = "UNNAMED");
01564   virtual ~dll_data_matrix();
01565   dll_data_matrix& operator=(const dmatrix &m);
01566   dll_data_matrix& operator=(const double &m);
01567 };
01568 
01573 class data_3array : public named_d3_array
01574 {
01575 public:
01576   data_3array(void) : named_d3_array() {;}
01577 private:
01578   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
01579     const char * ="UNNAMED");
01580   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
01581     int cmin,int cmax,const char * ="UNNAMED");
01582   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
01583     int cmin,int cmax,const char * ="UNNAMED");
01584   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
01585     int cmin,int cmax,const char * ="UNNAMED");
01586   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
01587     int cmax, const char * ="UNNAMED");
01588   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
01589                 const ivector& cmax, const char * ="UNNAMED");
01590   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
01591                 const ivector& cmax, const char * ="UNNAMED");
01592   void allocate(int hsl,int hsu, const index_type& rmin, const index_type& rmax,
01593     const index_type& cmin, const index_type& cmax, const char * ="UNNAMED");
01594   friend class model_data;
01595 };
01596 
01601 class dll_data_3array : public data_3array
01602 {
01603   double * d;
01604 public:
01605   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
01606     int cmin,int cmax,const char * _s = "UNNAMED");
01607   dll_data_3array& operator=(const d3_array &);
01608   virtual ~dll_data_3array();
01609   friend class model_data;
01610 };
01611 
01616 class data_3iarray : public named_i3_array
01617 {
01618   data_3iarray(void) : named_i3_array() {;}
01619   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
01620     const char * ="UNNAMED");
01621   void allocate(int hsl, int hsu,const index_type& rmin, const index_type& rmax,
01622     const index_type& cmin, const index_type& cmax, const char * ="UNNAMED");
01623   friend class model_data;
01624 };
01625 
01630 class data_5array : public named_d5_array
01631 {
01632   data_5array(void) : named_d5_array() {;}
01633   void allocate(int hhsl,int hhsu,
01634     int hhhsl,int hhhsu,
01635     int hsl,int hsu,int rmin,int rmax,
01636     int cmin,int cmax,const char * ="UNNAMED");
01637   void allocate(ad_integer hhhsl, ad_integer hhhsu, const index_type& hhsl,
01638     const index_type& hhsu, const index_type& hsl, const index_type& hsu,
01639     const index_type& rmin, const index_type& rmax, const index_type& cmin,
01640     const index_type& cmax, const char * ="UNNAMED");
01641   friend class model_data;
01642 };
01643 
01648 class data_4array : public named_d4_array
01649 {
01650   data_4array(void) : named_d4_array() {;}
01651   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
01652     int cmin,int cmax,const char * ="UNNAMED");
01653   void allocate(ad_integer hhsl, ad_integer hhsu, const index_type& hsl,
01654     const index_type& hsu, const index_type& rmin, const index_type& rmax,
01655     const index_type& cmin, const index_type& cmax, const char * ="UNNAMED");
01656   friend class model_data;
01657 };
01658 
01663 class data_imatrix : public named_imatrix
01664 {
01665   data_imatrix(void) : named_imatrix() {;}
01666   void allocate(int rmin,int rmax,int cmin,int cmax,const char * ="UNNAMED");
01667   void allocate(int rmin, int rmax, const index_type&, const index_type& cmax,
01668     const char * ="UNNAMED");
01669   friend class model_data;
01670 };
01671 
01676 class data_vector : public named_dvector
01677 {
01678 public:
01679   data_vector& operator=(const dvector& m);
01680   data_vector& operator = (CGNU_DOUBLE m);
01681   data_vector(void) : named_dvector() {;}
01682 private:
01683   void allocate(int imin,int imax,const char * ="UNNAMED");
01684   void allocate(int imin, const ivector& imax, const char * ="UNNAMED");
01685   void allocate(init_xml_doc&, const char * ="UNNAMED");
01686   friend class model_data;
01687 };
01688 
01693 class dll_data_vector : public data_vector
01694 {
01695 public:
01696   double * pd;
01697   void allocate(double * pd,int imin,int imax,const char * ="UNNAMED");
01698   void allocate(double *pd, int imin, const ivector& imax,
01699     const char * ="UNNAMED");
01700   virtual ~dll_data_vector();
01701   dll_data_vector& operator = (const dvector& x);
01702   dll_data_vector& operator = (const double& x);
01703 };
01704 
01709 class data_ivector : public named_ivector
01710 {
01711 public:
01712   data_ivector(void) : named_ivector() {;}
01713 private:
01714   void allocate(int imin,int imax,const char * ="UNNAMED");
01715   friend class model_data;
01716 };
01717 
01722 class data_number : public model_name_tag
01723 {
01724 protected:
01725   double val;
01726   void allocate(const char * ="UNNAMED");
01727 public:
01728   void report_value(void);
01729   operator double() {return val;}
01730   double& value(void) {return val;}
01731   void initialize(void) {val=0.0;}
01732   friend class model_data;
01733   data_number & operator=(const double& m);
01734 };
01735 
01740 class dll_data_number : public data_number
01741 {
01742 public:
01743   double * pd;
01744   void allocate(double *_pd,const char * s);
01745   virtual ~dll_data_number();
01746   dll_data_number & operator=(const double& m);
01747 };
01748 
01749 typedef dvariable (model_parameters::*PMF) (const dvariable&);
01750 typedef dvariable (model_parameters::*PMFI) (const dvariable&,int n);
01751 typedef dvariable (model_parameters::*PMFVI) (const dvar_vector&,int n);
01752 typedef void (model_parameters::*PMFVIV4) (const dvar_vector&,int n,
01753   dvariable& f1, const dvariable& f2, const dvariable& f3, const dvariable& f4);
01754 
01755 #if defined(USE_LAPLACE)
01756   class init_df1b2vector;
01757   class df1b2vector;
01758   class df1b2variable;
01759 #endif
01760 
01765 class function_minimizer
01766 {
01767 public:
01768   static int bad_step_flag;
01769   static int likeprof_flag;
01770   static int first_hessian_flag;
01771   static int test_trust_flag;
01772   static int random_effects_flag;
01773   dmatrix * negdirections;
01774   static int negative_eigenvalue_flag;
01775 #if defined(USE_LAPLACE)
01776   static int inner_opt_flag;
01777   static int inner_opt(void);
01778   laplace_approximation_calculator * lapprox;
01779   dvector * multinomial_weights;
01780   void set_multinomial_weights(dvector&d);
01781   //init_df1b2vector* py;
01782   virtual void AD_uf_inner(void);
01783   virtual void AD_uf_outer(void);
01784   virtual void user_function(void);
01785   void pre_user_function(void);
01786   //void df1b2_pre_user_function(void);
01787   //virtual void user_function(const init_df1b2vector& x,df1b2variable& f);
01788   //static int hesstype;
01789   //int set_hessian_type(int);
01790   void hess_routine_noparallel_randomeffects(void);
01791   void other_separable_stuff_begin(void);
01792   void other_separable_stuff_end(void);
01793   void begin_df1b2_funnel(void){;}
01794   void setup_quadprior_calcs(void){;}
01795   void end_df1b2_funnel(void){;}
01796   void get_function_difference(void);
01797   void start_get_importance_sampling_comnponent(void);
01798   void end_get_importance_sampling_comnponent(void);
01799 #endif
01800   int spminflag;
01801   int repeatminflag;
01802   int mcmc2_flag;
01803   int robust_hybrid_flag;
01804   int ifn;
01805   int maxfn;
01806   int iprint;
01807   double crit;
01808   int imax;
01809   double dfn;
01810   int iexit;
01811   int ihflag;
01812   int ihang;
01813   int scroll_flag;
01814   int maxfn_flag;
01815   int quit_flag;
01816   double min_improve;
01817   void pre_userfunction(void);
01818   virtual void userfunction(void)=0;
01819   virtual void allocate(void){;}
01820   static named_dvar_vector * ph;
01821   static named_dvar_vector * pg;
01822 protected:
01823   double ffbest;
01824 private:
01825   gradient_structure * pgs;
01826   adstring_array param_labels;
01827   ivector param_size;
01828 protected:
01829   void report_function_minimizer_stats(void){;}
01830   virtual void report(const dvector& gradients){;};
01831   static dvector convergence_criteria;
01832   static dvector maximum_function_evaluations;
01833   static int sd_flag;
01834   static adstring user_data_file;
01835   static adstring user_par_file;
01836   static int have_constraints;
01837 public:
01838   virtual dvariable user_randeff(const dvar_vector& x);
01839   virtual dvar_vector user_dfrandeff(const dvar_vector& x);
01840   virtual dvar_matrix user_d2frandeff(const dvar_vector& x);
01841   void limited_memory_quasi_newton(const independent_variables&,int);
01842   void limited_memory_quasi_newton(const independent_variables&,int,int);
01843   void limited_memory_quasi_newton(double& f, const independent_variables&,
01844     int, int, int,double);
01845   function_minimizer(long int sz=0L);
01846   void likeprof_routine(double global_min);
01847   virtual ~function_minimizer();
01848   virtual void other_calculations(void){;}
01849   virtual void final_calcs(void){;}
01850   virtual void minimize(void);
01851   virtual void constraints_minimize(void);
01852   virtual void between_phases_calculations(void){;}
01853   void computations(int argc,char * argv[]);
01854   void computationsx(int argc,char * argv[]);
01855   void computations1(int argc,char * argv[]);
01856   void computations_np(int argc,char * argv[]);
01857   void computations(void);
01858   void hess_routine(void);
01859   void hess_routine_noparallel(void);
01860   void hess_routine_master(void);
01861   void hess_routine_slave(void);
01862   void constraint_report(void);
01863   void pvm_slave_likeprof_routine(void);
01864   void pvm_master_function_evaluation_profile(double& f,
01865     independent_variables& x,const dvector & g,int nvar,int iprof,double weight,
01866     double new_value);
01867   void pvm_slave_prof_minimize(int underflow_flag);
01868   void pvm_master_prof_minimize(int iprof, double sigma,
01869     double new_value, const double& _fprof, const int underflow_flag,
01870     double global_min, const double& _penalties,
01871     const double& _final_weight);
01872   //void pvm_master_function_evaluation_profile(double& f,
01873    // independent_variables& x,dvector & g,int nvar,int iprof);
01874   void pvm_slave_function_evaluation(void);
01875   void pvm_slave_function_evaluation_no_derivatives(void);
01876   void pvm_slave_function_evaluation_noder(void);
01877   void pvm_master_function_evaluation_no_derivatives(double& f,
01878     independent_variables& x,int nvar);
01879   void pvm_master_function_evaluation(double& f,
01880     independent_variables& x,const dvector & g,int nvar);
01881   dmatrix dep_hess_routine(const dvariable& dep);
01882   void top_mcmc_routine(int,int,double,int);
01883   void mcmc_routine(int,int,double,int);
01884   void sgibbs_mcmc_routine(int,int,double,int);
01885   void hybrid_mcmc_routine(int,int,double,int);
01886   double pvm_master_get_monte_carlo_value(int nvar,
01887     const dvector& x);
01888   void pvm_slave_get_monte_carlo_value(int nvar);
01889   void mcmc_eval(void);
01890   //void hess_routine_and_constraint(int);
01891   void hess_routine_and_constraint(int iprof, const dvector& g,
01892     dvector& fg);
01893   dmatrix diag_hess_routine(void);
01894   void hess_inv(void);
01895   void depvars_routine(void);
01896   void sd_routine(void);
01897   int ef_(double * f, double * x);
01898   int constrained_minimization2(int _n,int _nh, int _ng,dvector& __x);
01899   static int constraint_exit_number;
01900   void get_bigS(int ndvar,int nvar1,int nvar,
01901     dmatrix& S,dmatrix& BS,dvector& scale);
01902 
01903 #ifdef CURVE_CORRECT
01904   void constraint_hess_routine(int ip);
01905   void get_curvature_correction_factors(int ip,
01906     dvector& g, const int underflow_flag, const dvector& eigenvals,
01907     dvector& curvcor);
01908 #endif
01909   double projected_jacobian(const dvector& g, const dvector& xscale);
01910 
01911   dvariable random_effects_maximization(const dvar_vector& v);
01912   void prof_minimize_re(int iprof, double sigma,
01913     double new_value, const double& fprof, const int underflow_flag,
01914     double global_min, const double& penalties, const double& final_weight);
01915   void prof_minimize(int iprof, double sigma,
01916     double new_value, const double& fprof, const int underflow_flag,
01917     double global_min, const double& penalties, const double& final_weight);
01918   void begin_gauss_hermite_stuff(void);
01919   void begin_funnel_stuff(void);
01920   void end_gauss_hermite_stuff(void);
01921 
01922   void prof_hess_routine(int ip,double new_value,double final_weight);
01923 
01924   void quasi_newton_minimizer1(int nvar,double _crit,
01925     double& f, const independent_variables& x,const dvector& g);
01926 
01927   double hess_determinant(int underflow_flag);
01928 
01929 #ifndef CURVE_CORRECT
01930   void normalize_posterior_distribution(double udet,
01931     const dvector& siglevel, const ofstream& ofs2, int num_pp,
01932     const dvector& all_values, const dmatrix& actual_value, double global_min,
01933     int offset, const dmatrix& lprof, const dmatrix& ldet, const dmatrix& xdist,
01934     const dmatrix& penalties);
01935   //  dmatrix& penalties, const hdmatrix& lg_jacob);
01936 #else
01937   void normalize_posterior_distribution(double udet,
01938     const dvector& siglevel, const ofstream& ofs2, int num_pp,
01939     const dvector& all_values, const dmatrix& actual_value,
01940     double global_min,
01941     int offset, const dmatrix& lprof, const dmatrix& ldet,
01942     const dmatrix& xdist,
01943     const d3_array& eigenvals,d3_array& curvcor);
01944 #endif
01945   void get_particular_grad(int iprof, int nvar, const dvector& fg,
01946     const dvector& g);
01947   double projected_hess_determinant(const dvector& g, const int underflow_flag,
01948     const dvector& xscale, const double& ln_det_proj_jac);
01949 //  double projected_hess_determinant(const dvector& fg, const dvector& g,
01950   //const int underflow_flag, const dvector& xscale,
01951   // const double& ln_det_proj_jac);
01952   double projected_hess_determinant(const dvector& g,const int underflow_flag);
01953   double projected_hess_determinant(const dmatrix& hh, const dvector& g,
01954     const int underflow_flag);
01955  //double projected_hess_determinant(const dvector& g, const int underflow_flag,
01956     //dvector& xscale, const double& ln_det_proj_jac);
01957 
01958   double projected_hess_determinant(const dvector& fg, const dvector& g,
01959     const int underflow_flag, const dvector& curvscale, const dvector& xscale,
01960     double& ln_det_proj_jac, const double& tmp, const dmatrix& hesses);
01961   double diag_projected_hess_determinant(const dvector& g,
01962     const int underflow_flag, dmatrix& dh);
01963     double unrestricted_hess_determinant(void);
01964   void monte_carlo_routine(void);
01965   double get_monte_carlo_value(int nvar, const independent_variables& x);
01966   double get_monte_carlo_value(int nvar, const independent_variables& x,
01967     dvector& g);
01968   double get_hybrid_monte_carlo_value(int nvar,const independent_variables& x,
01969     dvector& g);
01970   void mcmc_computations(void);
01971   void pvm_slave_mcmc_computations(void);
01972   void pvm_master_mcmc_computations(void);
01973   double get_monte_carlo_value(int nvar, const dvector& x);
01974   void sob_routine(int nmcmc,double dscale,int restart_flag);
01975   void sobol_importance_routine(int nmcmc,int iseed0,double dscale,
01976   int restart_flag);
01977   void pvm_master_mcmc_routine(int nmcmc,int iseed0,double dscale,
01978     int restart_flag);
01979 #if defined(USE_ADPVM)
01980   void pvm_slave_mcmc_routine(void);
01981 #else
01982   void pvm_slave_mcmc_routine(void) {}
01983 #endif
01984   void trust_region_update(int nvar,int _crit,
01985     independent_variables& x,const dvector& _g,const double& _f);
01986 
01987   void multint4(int n, const dvar_vector& a, const dvar_vector& b,
01988     const dvar_vector& h, double al, int m, const dvariable& e,
01989     const dvariable& aint1, const dvariable& aint2, dvariable& aint3,
01990     const dvariable& aint4, const int& key, PMFVIV4 f);
01991 
01992   void multint(int n, const dvar_vector& a, const dvar_vector& b,
01993     const dvar_vector& h, double al, int m, const dvariable& e,
01994     const dvariable& aint, const int& key, PMFVI f);
01995 
01996   virtual void set_runtime(void);
01997   virtual void set_runtime_maxfn(const char *);
01998   virtual void set_runtime_crit(const char *);
01999   dvariable adromb(PMF,double a,double b,int ns=9);
02000   dvariable adromb(PMF, const dvariable& a, double b, int ns = 9);
02001   dvariable adromb(PMF, const dvariable& a, const dvariable& b, int ns = 9);
02002   dvariable adromb(PMF, double a, const dvariable& b, int ns = 9);
02003 
02004   dvariable adrombo(PMF,double a,double b,int ns=9);
02005   dvariable adrombo(PMF, const dvariable& a, double b, int ns = 9);
02006   dvariable adrombo(PMF, const dvariable& a, const dvariable& b, int ns = 9);
02007   dvariable adrombo(PMF, double a, const dvariable& b,int ns = 9);
02008 
02009   dvariable trapzd(void*,double a,double b,int n);
02010   dvariable trapzd(PMF,double a,double b,int n);
02011   dvariable trapzd(PMF, double a, const dvariable& b, int n);
02012   dvariable trapzd(PMF, const dvariable& a, double b, int n);
02013   dvariable trapzd(PMF, const dvariable& a, const dvariable& b, int n);
02014 
02015   dvariable midpnt(PMF,double a,double b,int n);
02016   dvariable midpnt(PMF, double a, const dvariable& b, int n);
02017   dvariable midpnt(PMF, const dvariable& a, double b, int n);
02018   dvariable midpnt(PMF, const dvariable& a, const dvariable& b, int n);
02019 
02020   virtual void * mycast() { return (void*)this;}
02021 
02022   void neldmead(int n, dvector& _start, dvector& _xmin, double *ynewlo,
02023     double reqmin, double delta,int *icount, int *numres, int *ifault);
02024   void adamoeba(const dmatrix& p, const dvector& y, int ndim, double ftol,
02025      int maxfn);
02026   void set_initial_simplex(const dmatrix& p, const dvector& y, int nvar,
02027     const dvector& x, double delta);
02028   double amxxx(const dmatrix& p, const dvector& y, const dvector& psum,
02029     int ndim, int ihi, double fac);
02030   friend class equality_constraint_vector;
02031   friend class inequality_constraint_vector;
02032   void quasi_newton_block(int nvar,int crit,independent_variables& x,
02033     const dvector& g,const double& f);
02034   void limited_memory_quasi_newton_block(int nvar,int _crit,
02035     independent_variables& x,const dvector& _g,const double& _f,
02036     int nsteps);
02037 
02038 #if defined(USE_LAPLACE)
02039   void function_evaluation_block_pvm_slave_random_effects(int nvar,int _crit,
02040     independent_variables& x,const dvector& g,const double& f);
02041   void quasi_newton_block_pvm_master_random_effects(int nvar,int _crit,
02042     independent_variables& x,const dvector& g,const double& f);
02043   void function_evaluation_block_pvm_slave_random_effects(void);
02044   void hess_routine_random_effects(void);
02045 #endif
02046   void quasi_newton_block_pvm_master(int nvar,int _crit,
02047     independent_variables& x,const dvector& g,const double& f);
02048   void hess_routine_noparallel_random_effects(void);
02049 #if defined(USE_ADPVM)
02050   void function_evaluation_block_pvm_slave(void);
02051   void hess_routine_slave_random_effects(void);
02052 #endif
02053   dvariable do_gauss_hermite_integration(void);
02054   dvariable do_gauss_hermite_integration_multi(void);
02055   void end_df1b2_funnel_stuff(void);
02056 };
02057 
02058 cifstream& operator>>(const cifstream& s, const param_init_number& x);
02059 cifstream& operator>>(const cifstream& s, const param_init_vector& v);
02060 cifstream& operator>>(const cifstream& s, const param_init_matrix& m);
02061 ostream& operator<<(const ostream& s, const label_class& lc);
02062 
02067 class stddev_params
02068 {
02069 public:
02070   // this should be a resizeable array
02071   static stddev_params * stddevptr[150];
02072   // this should be a resizeable array
02073   static stddev_params * stddev_number_ptr[150];
02074   static void get_all_sd_values(const dvector& x, const int& ii);
02075   static int num_stddev_params;
02076   static int num_stddev_number_params;
02077   static ivector copy_all_number_offsets(void);
02078   void allocate(void){;};
02079   static int num_stddev_calc(void);
02080   static int num_stddev_number_calc(void);
02081   static void get_stddev_number_offset(void);
02082 public:
02083   stddev_params(void){;}
02084   virtual void setindex(int);
02085   virtual int getindex(void);
02086   virtual int size_count(void)=0; // get the number of active parameters
02087   virtual void set_dependent_variables(void)=0;
02088   virtual void copy_value_to_vector(const dvector&,const int&) = 0;
02089   virtual void get_sd_values(const dvector& x, const int& ii) = 0;
02090   //get the number of active parameters
02091   static void copy_all_values(const dvector& x, const int& ii);
02092   //get the number of active parameters
02093   static void copy_all_number_values(const dvector& x, const int& ii);
02094   virtual void add_to_list(void);
02095   virtual void add_to_gui_list(void);
02096   virtual const char * label()=0;
02097   friend class function_minimizer;
02098 };
02099 
02104 class likeprof_params
02105 {
02106   double stepsize;
02107   int    stepnumber;
02108 protected:
02109 public:
02110   static likeprof_params * likeprofptr[500]; // this should be a
02111                                                // resizeable array
02112   static int num_likeprof_params;
02113   void allocate(void){;};
02114   static int num_stddev_calc(void);
02115 public:
02116   likeprof_params(void);
02117   virtual void add_to_list(void);
02118   virtual const char * label()=0;
02119   virtual dvariable variable(void)=0;
02120   virtual double& get_sigma(void)=0;
02121   virtual double get_value(void)=0;
02122   double get_stepsize(void);
02123   int get_stepnumber(void);
02124   void set_stepsize(double);
02125   void set_stepnumber(int);
02126   friend class function_minimizer;
02127 };
02128 
02133 class param_stddev_vector: public named_dvar_vector , stddev_params
02134 {
02135   dvector sd;
02136     virtual int size_count(void); // get the number of active parameters
02137     virtual const char * label(void);
02138     param_stddev_vector();
02139     void allocate(int imin,int imax,const char * s="UNNAMED");
02140     virtual void set_dependent_variables(void);
02141     friend class model_parameters;
02142     virtual void copy_value_to_vector(const dvector& x, const int& ii);
02143     virtual void get_sd_values(const dvector& x, const int& ii);
02144   param_stddev_vector& operator=(const dvar_vector& m);
02145   param_stddev_vector& operator=(const dvector& m);
02146   param_stddev_vector& operator = (CGNU_DOUBLE m);
02147 };
02148 
02153 class param_stddev_number: public named_dvariable , public stddev_params
02154 {
02155   double sd;
02156   int index;
02157   void allocate(const char *s="UNNAMED");
02158   virtual void setindex(int);
02159   virtual int getindex(void);
02160   virtual int size_count(void); // get the number of active parameters
02161   virtual const char * label(void);
02162   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02163   virtual void get_sd_values(const dvector& x, const int& ii);
02164 protected:
02165   param_stddev_number();
02166   friend class model_parameters;
02167   virtual void set_dependent_variables(void);
02168   param_stddev_number& operator=(const prevariable&);
02169   param_stddev_number& operator = (CGNU_DOUBLE);
02170 };
02171 
02176 class param_likeprof_number: public param_stddev_number ,
02177     public likeprof_params
02178 {
02179     double sigma;
02180     void allocate(const char *s="UNNAMED");
02181     virtual int size_count(void); // get the number of active parameters
02182     virtual const char * label(void);
02183     virtual double& get_sigma(void){return sigma;}
02184     virtual double get_value(void){return value(*this);}
02185     //void copy_value_to_vector(const dvector& x, const int& ii);
02186     virtual dvariable variable(void){ return dvariable(*this);}
02187     param_likeprof_number();
02188     friend class model_parameters;
02189 public:
02190     param_likeprof_number& operator=(const prevariable&);
02191     param_likeprof_number& operator = (CGNU_DOUBLE);
02192 };
02193 
02198 class param_stddev_matrix: public named_dvar_matrix , stddev_params
02199 {
02200   dmatrix sd;
02201     virtual int size_count(void);
02202     //virtual void read_value(void);
02203     virtual const char * label(void);
02204     void allocate(int rmin,int rmax,int cmin,int cmax,
02205     const char * s="UNNAMED");
02206   param_stddev_matrix(void);
02207   friend class model_parameters;
02208   virtual void set_dependent_variables(void);
02209   virtual void get_sd_values(const dvector& x, const int& ii);
02210   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02211   param_stddev_matrix& operator = (CGNU_DOUBLE m);
02212   param_stddev_matrix& operator=(const dmatrix& m);
02213   param_stddev_matrix& operator=(const dvar_matrix& m);
02214 };
02215 
02220 class adpvm_slave_args
02221 {
02222   char ** argv;
02223   int num_args;
02224   ivector length_args;
02225 public:
02226   int counter;
02227   char * operator () (int);
02228   operator char ** ();
02229   void operator -- (void);
02230   adpvm_slave_args(int num_args,int len_args);
02231   adpvm_slave_args(int num_args,const ivector& len_args);
02232   ~adpvm_slave_args();
02233   int get_num_args(void);
02234 };
02235 
02236 void strcpy(const adpvm_slave_args& a,const char * s);
02237 class adpvm_manager;
02238 
02243   class objective_function_value : public named_dvariable
02244   {
02245   public:
02246     static objective_function_value * pobjfun;
02247     static double fun_without_pen;
02248     static double gmax;
02249     objective_function_value();
02250     objective_function_value& operator=(const prevariable& v);
02251     objective_function_value& operator = (CGNU_DOUBLE v);
02252   };
02253 
02254   int withinbound(int lb,int n,int ub);
02255 
02256 double cumd_cauchy(const double& x);
02257 double density_cauchy(const double& x);
02258 double log_density_cauchy(const double& x);
02259 double inv_cumd_cauchy(const double& x);
02260 
02261 double cumd_mixture(const double& x);
02262 double inv_cumd_mixture(const double& y);
02263 double cumd_mixture_02(const double& x);
02264 double inv_cumd_mixture_02(const double& y);
02265 
02266 #if defined _ADM_HIGHER_ARRAYS__
02267 
02272 class param_init_matrix: public named_dvar_matrix,public initial_params
02273 {
02274   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
02275 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
02276 //  const int& ii);
02277   virtual void add_value(const dvector&, const dvector&, const int&,
02278     const double&, const dvector&);
02279   virtual void add_value(const dvector&, const int&);
02280   virtual void get_jacobian(const dvector&, const dvector&, const int&);
02281 public:
02282   virtual void set_value(const dvar_vector& x, const int& ii,
02283     const dvariable& pen);
02284   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02285   virtual void restore_value_from_vector(const dvector&, const int&);
02286   virtual void set_value_inv(const dvector& x, const int& ii);
02287   virtual int size_count(void);
02288   virtual void save_value(void);
02289   virtual void bsave_value(void);
02290   virtual void save_value(const ofstream& ofs, int prec);
02291   virtual void restore_value(const ifstream& ifs);
02292   void report_value(void);
02293   //virtual void read_value(void);
02294   virtual const char * label(void);
02295   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
02296   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
02297   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
02298   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){;};
02299 
02300 public:
02301   void allocate(int rmin,int rmax,int cmin,int cmax,
02302     int phase_start=1,const char * = "UNNAMED");
02303   void allocate(int rmin,int rmax,int cmin,int cmax,
02304     const char * = "UNNAMED");
02305   param_init_matrix(void);
02306   param_init_matrix& operator = (const dmatrix& m);
02307   param_init_matrix& operator = (const dvar_matrix& m);
02308   param_init_matrix& operator = (const dvariable& m);
02309   param_init_matrix& operator = (const double& m);
02310 };
02311 #endif // #if defined _ADM_HIGER_ARRAYS__
02312 
02317 class param_init_d3array: public named_dvar3_array,public initial_params
02318 {
02319 public:
02320 #if defined(USE_SHARE_FLAGS)
02321   virtual void setshare(const index_type& sf,const index_type& af);
02322   virtual void shared_set_value_inv(const dvector&,const int&);
02323   virtual void shared_set_value(const dvar_vector&,const int&,
02324     const dvariable& pen);
02325   virtual int shared_size_count(void); // get the number of active parameters
02326 #endif
02327 
02328   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
02329     const int& ii);
02330   virtual void dev_correction(const dmatrix&, const int&);
02331   virtual void curv_scale(const dvector& d, const dvector& x, const int& ii);
02332   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
02333 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
02334 //  const int& ii);
02335   virtual void add_value(const dvector&, const dvector&, const int&,
02336     const double&, const dvector&);
02337   virtual void add_value(const dvector&, const int&);
02338   virtual void get_jacobian(const dvector&, const dvector&, const int&);
02339   virtual void set_value(const dvar_vector& x, const int& ii,
02340     const dvariable& pen);
02341   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02342   virtual void restore_value_from_vector(const dvector&,const int&);
02343   virtual void set_value_inv(const dvector& x, const int& ii);
02344   virtual int size_count(void);
02345   virtual void save_value(void);
02346   virtual void bsave_value(void);
02347   virtual void save_value(const ofstream& ofs, int prec);
02348   virtual void restore_value(const ifstream& ifs);
02349   void report_value(void);
02350   //virtual void read_value(void);
02351   virtual const char * label(void);
02352   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
02353   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
02354   virtual void hess_scale(const dvector& d, const dvector& x, const  int& ii);
02355 
02356 public:
02357 #if defined(USE_ADPVM)
02358   virtual void pvm_pack(void) { cerr << "Error" << endl; ad_exit(1);}
02359   virtual void pvm_unpack(void) { cerr << "Error" << endl; ad_exit(1);}
02360 #endif
02361 
02362   void allocate(const ad_integer& sl,const ad_integer& sh,
02363     const index_type& nrl,const index_type& nrh,
02364     const index_type& ncl,const index_type& nch,const char * s="UNNAMED");
02365 
02366   void allocate(const ad_integer& sl,const ad_integer& sh,
02367     const index_type& nrl,const index_type& nrh,
02368     const index_type& ncl,const index_type& nch,int phase_start=1,
02369     const char * s="UNNAMED");
02370 
02371   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
02372     int phase_start=1,const char * = "UNNAMED");
02373   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
02374     const char * = "UNNAMED");
02375   param_init_d3array(void);
02376 };
02377 
02382 class dll_param_init_d3array: public param_init_d3array
02383 {
02384   double * d;
02385 public:
02386   void allocate(double* _d,int hmin,int hmax,
02387     int rmin,int rmax,int cmin,int cmax,
02388     int phase_start=1,const char * = "UNNAMED");
02389   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
02390     int cmin,int cmax,const char * = "UNNAMED");
02391   virtual ~dll_param_init_d3array();
02392   dll_param_init_d3array(){d=NULL;}
02393   dll_param_init_d3array& operator=(const d3_array&);
02394   dll_param_init_d3array& operator=(const dvar3_array&);
02395 };
02396 
02401 class dll_param_d3array: public named_dvar3_array
02402 {
02403   double * d;
02404 public:
02405   void allocate(double* _d,int hmin,int hmax,
02406     int rmin,int rmax,int cmin,int cmax,
02407     int phase_start=1,const char * = "UNNAMED");
02408   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
02409     int cmin,int cmax,const char * = "UNNAMED");
02410   virtual ~dll_param_d3array();
02411   dll_param_d3array(){d=NULL;}
02412   dll_param_d3array& operator=(const d3_array&);
02413   dll_param_d3array& operator=(const dvar3_array&);
02414 };
02415 
02416 
02417 //double set_value_mc(const double& x, CGNU_DOUBLE fmin, CGNU_DOUBLE fmax);
02418 
02419 void set_value_mc(const dvar_vector& x, const dvar_vector& v, const int& ii,
02420   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
02421 
02422 double set_value_inv_mc(double v,double fmin,double fmax);
02423 
02424 double set_value_inv_mc(const prevariable& v, double fmin, double fmax);
02425 
02426 void set_value_inv_mc(const dvar_vector& x, const dvector& v, const int& ii,
02427   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
02428 
02429 //double set_value_inv_mc(const dvector&, const dvector& x, int ii, double minb,
02430 //  double maxb);
02431 
02432 double set_value_mc(double z,double min,double max);
02433 double ndfboundp( double x, double fmin, double fmax,const double& fpen);
02434 double ndfboundp_mc( double x, double fmin, double fmax,const double& fpen);
02435 
02436 void copy_value_from_vector(const double& _sd,const dvector& x,const int & _ii);
02437 void copy_value_from_vector(const dvector& _sd,const dvector& x,
02438   const int & _ii);
02439 void copy_value_from_vector(const dmatrix& _sd,const dvector& x,
02440   const int & _ii);
02441 
02442 dvector bounded_multivariate_normal(int nvar, const dvector& a1,
02443   const dvector& b1, dmatrix& ch, const double& _wght,
02444   const random_number_generator & rng);
02445 
02446 void bounded_multivariate_normal_mcmc(int nvar, const dvector& a1,
02447   const dvector& b1, dmatrix& ch, const double& wght, const dvector& y,
02448   const random_number_generator & rng);
02449 
02450 void bounded_multivariate_uniform_mcmc(int nvar, const dvector& a1,
02451   const dvector& b1, dmatrix& ch, const double& wght, const dvector& y,
02452   const random_number_generator & rng);
02453 
02454 dvector bounded_multivariate_normal(int nvar, const dvector& a1,
02455   const dvector& b1, dmatrix& ch, const double& lprob,
02456   random_number_generator &rng);
02457 
02458 dvector bounded_multivariate_normal_sobol(int nvar, const dvector& a1,
02459   const dvector& b1, dmatrix& ch, const double& lprob,
02460   const random_number_generator &rng);
02461 
02462 dvector probing_bounded_multivariate_normal(int nvar, const dvector& a1,
02463   const dvector& b1, dmatrix& ch, const double& lprob, double pprobe,
02464   const random_number_generator &rng);
02465 
02466 dvector bounded_multivariate_uniform(int nvar, const dvector& a1,
02467   const dvector& b1, dmatrix& ch, const double& lprob,
02468   random_number_generator &rng);
02469 
02470 dvector bounded_robust_multivariate_normal(int nvar, const dvector& a1,
02471   const dvector& b1, dmatrix& ch, const dmatrix& ch3, double contaminant,
02472   const double& _wght, random_number_generator &rng);
02473 
02474 void probing_bounded_multivariate_normal_mcmc(int nvar, const dvector& a1,
02475   const dvector& b1, dmatrix& ch, const double& wght, const dvector& v,
02476   double pprobe, const random_number_generator &rng);
02477 
02478 /*
02479 int option_match(int argc,char * argv[], const char * string);
02480 int option_match(int argc,char * argv[], const char * string, const int& nopt);
02481 int option_match(char * s, const char * string, const int& _nopt);
02482 int option_match(char * s, const char * string);
02483 */
02484 
02485 double inv_cumd_exp(double x);
02486 double cumd_exp(double x);
02487 
02488 double ffmax(double a,double b);
02489 double ffmin(double a,double b);
02490 
02491 void check_datafile_pointer(void * p);
02492 
02493 adstring get_reportfile_name(void);
02494 
02495 void ad_make_code_reentrant(void);
02496 
02497 char** parse_dll_options(char *pname, const int& argc,
02498   char * dll_options);
02499 
02500 void parse_dll_options(char *pname, const int& argc, char *dll_options,
02501   char *** pargv);
02502 
02503 char** no_dll_options(char *pname, const int& argc);
02504 
02505 void cleanup_argv(int nopt,char *** pa);
02506 
02507 void get_sp_printf(void);
02508 
02509 void do_dll_housekeeping(int argc,char ** argv);
02510 
02511 void adwait(double);
02512 
02513 int ad_get_commandline_option(const char *option_label, const int &option_value,
02514   const char * error_message);
02515 
02520  class param_init_vector_vector
02521  {
02522    param_init_vector * v;
02523    int index_min;
02524    int index_max;
02525    double_index_type * it;
02526 
02527  public:
02528   void set_scalefactor(double s);
02529   void set_scalefactor(const dvector& s);
02530   dvector get_scalefactor(void);
02531 
02532 #if defined(OPT_LIB)
02533    param_init_vector& operator [] (int i) { return v[i];}
02534    param_init_vector& operator () (int i) { return v[i];}
02535    prevariable operator () (int i,int j) { return v[i][j];}
02536 #else
02537    param_init_vector& operator [] (int i);
02538    param_init_vector& operator () (int i);
02539    prevariable operator () (int i,int j);
02540 #endif
02541 
02542    void allocate(int min1,int max1,const index_type& min,
02543      const index_type& max,const index_type& phase_start,
02544      const char * s);
02545 
02546    void allocate(int min1,int max1,const index_type& min,
02547      const index_type& max,const char * s);
02548 
02549    param_init_vector_vector();
02550    int allocated(void) { return (v!=NULL); }
02551    int indexmin(void) {return (index_min);}
02552    int indexmax(void) {return (index_max);}
02553    ~param_init_vector_vector();
02554    void set_initial_value(const double_index_type& it);
02555    void deallocate(void);
02556  };
02557 
02562  class param_init_bounded_vector_vector
02563  {
02564    param_init_bounded_vector * v;
02565    int index_min;
02566    int index_max;
02567    double_index_type * it;
02568  public:
02569   void set_scalefactor(double s);
02570   void set_scalefactor(const dvector& s);
02571   dvector get_scalefactor(void);
02572   param_init_bounded_vector_vector();
02573 #if defined(OPT_LIB)
02574    param_init_bounded_vector& operator [] (int i) { return v[i];}
02575    param_init_bounded_vector& operator () (int i) { return v[i];}
02576    prevariable operator () (int i,int j) { return v[i][j];}
02577 #else
02578    param_init_bounded_vector& operator [] (int i);
02579    param_init_bounded_vector& operator () (int i);
02580    prevariable operator () (int i,int j);
02581 #endif
02582 
02583    void allocate(int min1,int max1,
02584      const index_type& min,
02585      const index_type& max,
02586      const double_index_type& dmin,
02587      const double_index_type& dmax,
02588      const index_type& phase_start,
02589      const char * s);
02590 
02591    void allocate(int min1,int max1,
02592      const index_type& min,
02593      const index_type& max,
02594      const double_index_type& dmin,
02595      const double_index_type& dmax,
02596      const char * s);
02597 
02598    int allocated(void) { return (v!=NULL); }
02599    int indexmin(void) {return (index_min);}
02600    int indexmax(void) {return (index_max);}
02601    ~param_init_bounded_vector_vector();
02602    void deallocate(void);
02603    void set_initial_value(const double_index_type& it);
02604  };
02605 
02610  class param_init_matrix_vector
02611  {
02612    param_init_matrix * v;
02613    int index_min;
02614    int index_max;
02615    double_index_type * it;
02616  public:
02617   param_init_matrix_vector();
02618   void set_scalefactor(double s);
02619   void set_scalefactor(const dvector& s);
02620   dvector get_scalefactor(void);
02621 
02622 #if defined(OPT_LIB)
02623    param_init_matrix& operator [] (int i) { return v[i];}
02624    param_init_matrix& operator () (int i) { return v[i];}
02625    dvar_vector& operator () (int i,int j) { return v[i][j];}
02626    prevariable operator () (int i,int j,int k) { return v[i](j,k);}
02627 #else
02628    param_init_matrix& operator [] (int i);
02629    param_init_matrix& operator () (int i);
02630    dvar_vector& operator () (int i,int j);
02631    prevariable operator () (int i,int j,int k);
02632 #endif
02633    void allocate(int min0,int max0,const index_type& min,
02634      const index_type& max,const index_type& min1,
02635      const index_type& max1,const index_type& phase_start,
02636      const char * s);
02637 
02638    void allocate(int min0,int max0,const index_type& min,
02639      const index_type& max,const index_type& min1,
02640      const index_type& max1,const char * s);
02641 
02642    int allocated(void) { return (v!=NULL); }
02643    int indexmin(void) {return (index_min);}
02644    int indexmax(void) {return (index_max);}
02645    ~param_init_matrix_vector();
02646    void set_initial_value(const double_index_type& it);
02647    void deallocate(void);
02648  };
02649 
02654  class param_init_bounded_matrix_vector
02655  {
02656    param_init_bounded_matrix * v;
02657    int index_min;
02658    int index_max;
02659    double_index_type * it;
02660  public:
02661   void set_scalefactor(double s);
02662   void set_scalefactor(const dvector& s);
02663   dvector get_scalefactor(void);
02664   param_init_bounded_matrix_vector();
02665 
02666    void allocate(int min1,int max1,
02667      const index_type& min, const index_type& max, const index_type& min2,
02668      const index_type& max2, const double_index_type& dmin2,
02669      const double_index_type& dmax2, const index_type& phase_start,
02670      const char * s);
02671 
02672    void allocate(int min1,int max1,
02673      const index_type& min, const index_type& max, const index_type& min2,
02674      const index_type& max2, const double_index_type& dmin2,
02675      const double_index_type& dmax2,const char * s);
02676 
02677 #if defined(OPT_LIB)
02678    param_init_bounded_matrix& operator [] (int i) { return v[i];}
02679    param_init_bounded_matrix& operator () (int i) { return v[i];}
02680    dvar_vector& operator () (int i,int j) { return v[i][j];}
02681    prevariable operator () (int i,int j,int k) { return v[i](j,k);}
02682 #else
02683    param_init_bounded_matrix& operator [] (int i);
02684    param_init_bounded_matrix& operator () (int i);
02685    dvar_vector& operator () (int i,int j);
02686    prevariable operator () (int i,int j,int k);
02687 #endif
02688 
02689    int allocated(void) { return (v!=NULL); }
02690    int indexmin(void) {return (index_min);}
02691    int indexmax(void) {return (index_max);}
02692    ~param_init_bounded_matrix_vector();
02693    void set_initial_value(const double_index_type& it);
02694    void deallocate(void);
02695  };
02696 
02701  class param_init_number_vector
02702  {
02703    param_init_number * v;
02704    int index_min;
02705    int index_max;
02706    double_index_type * it;
02707  public:
02708   void set_scalefactor(double s);
02709   void set_scalefactor(const dvector& s);
02710   dvector get_scalefactor(void);
02711   param_init_number_vector();
02712 
02713 #if defined(OPT_LIB)
02714    param_init_number& operator [] (int i) { return v[i];}
02715    param_init_number& operator () (int i) { return v[i];}
02716 #else
02717    param_init_number& operator [] (int i);
02718    param_init_number& operator () (int i);
02719 #endif
02720 
02721    void allocate(int min1,int max1,const index_type& phase_start,
02722      const char * s);
02723 
02724    void allocate(int min1,int max1,const char * s);
02725 
02726    int allocated(void) { return (v!=NULL); }
02727    int indexmin(void) {return (index_min);}
02728    int indexmax(void) {return (index_max);}
02729    ~param_init_number_vector();
02730    void set_initial_value(const double_index_type& it);
02731    void deallocate(void);
02732  };
02733 
02741  class data_matrix;
02742  class param_init_bounded_number_vector
02743  {
02744    param_init_bounded_number * v;
02745    int index_min;
02746    int index_max;
02747    double_index_type * it;
02748  public:
02749   void set_scalefactor(double s);
02750   void set_scalefactor(const dvector& s);
02751   dvector get_scalefactor(void);
02752   param_init_bounded_number_vector();
02753 
02754 #if defined(OPT_LIB)
02755    param_init_bounded_number& operator [] (int i) { return v[i];}
02756    param_init_bounded_number& operator () (int i) { return v[i];}
02757 #else
02758    param_init_bounded_number& operator [] (int i);
02759    param_init_bounded_number& operator () (int i);
02760 #endif
02761 
02762    void allocate(int min1,int max1,const double_index_type & bmin,
02763      const double_index_type & bmax,const index_type& phase_start,
02764      const char * s);
02765 
02766    void allocate(int min1,int max1,const double_index_type & bmin,
02767      const double_index_type & bmax,const char * s);
02768 
02769    // Added by Steve Martell, Jan 18, 2014.
02770    void allocate(const data_matrix &m, const char *s);
02771 
02772    int allocated(void) { return (v!=NULL); }
02773    int indexmin(void) {return (index_min);}
02774    int indexmax(void) {return (index_max);}
02775    ~param_init_bounded_number_vector();
02776    void set_initial_value(const double_index_type& it);
02777    void deallocate(void);
02778  };
02779   extern int traceflag;
02780   void tracing_message(int traceflag,const char *s,int *pn);
02781   void tracing_message(int traceflag,const char *s,double *pn);
02782   void set_gauss_covariance_matrix(const dll_data_matrix& m);
02783   void set_gauss_covariance_matrix(const dmatrix& m);
02784   void set_covariance_matrix(const dll_data_matrix& m);
02785   void set_covariance_matrix(const dmatrix& m);
02786 
02787   //ostream& operator<<(const ostream&, const param_init_number_vector);
02788   //ostream& operator<<(const ostream&, const param_init_bounded_number_vector);
02789   //ostream& operator<<(const ostream&, const param_init_vector_vector);
02790   //ostream& operator<<(const ostream&, const param_init_bounded_vector_vector);
02791   //ostream& operator<<(const ostream&, const param_init_matrix_vector);
02792   //ostream& operator<<(const ostream&, const param_init_bounded_matrix_vector);
02793 
02798   class vector_kludge : public dvar_vector
02799   {
02800     public:
02801      vector_kludge(const param_init_number_vector &);
02802      vector_kludge(const param_init_bounded_number_vector &);
02803   };
02808   class matrix_kludge : public dvar_matrix
02809   {
02810     public:
02811      matrix_kludge(const param_init_vector_vector &);
02812      matrix_kludge(const param_init_bounded_vector_vector &);
02813   };
02814 
02815 class ad_comm;
02816 
02821 class adpvm_manager
02822 {
02823   adstring_array slave_names;
02824   adpvm_slave_args * slave_argv;
02825 public:
02826   struct pvmhostinfo *hostp;
02827   int nhost;
02828   int mode;  // 1 = master 2 = slave
02829   int copy;
02830   int slave_number;
02831   int narch;
02832   imatrix id;
02833   int num_slave_processes;
02834   ivector num_per_host;
02835   int start_slave_processes(const ad_comm& mp);
02836   imatrix slave_assignments;
02837   adtimer tm;
02838   int timing_flag;
02839   void master_slave_variable_interface(const ad_comm& mp);
02840   void master_slave_variable_interface(void);
02841   void get_variable_values_from_master(void);
02842   void send_variable_values_to_slaves(void);
02843   adpvm_manager(int);
02844   ~adpvm_manager();
02845 #  if defined(USE_LAPLACE)
02846       int start_slave_processes_for_random_effects(const ad_comm& mp);
02847 #  endif
02848 };
02849 
02850 void send_dmatrix_to_slaves(const dmatrix&  x,ivector& jmin,ivector& jmax);
02851 dvariable receive_f_from_slaves(void);
02852 void send_x_to_slaves(const dvar_vector& x);
02853 void send_dvector_to_slaves(const dvector& x);
02854 void send_dvector_to_master(const dvector& x);
02855 void send_dmatrix_to_master(const dmatrix& x);
02856 dvar_vector get_x_from_master(void);
02857 dvector get_dvector_from_master(void);
02858 dmatrix get_dmatrix_from_master(void);
02859 void send_f_to_master(const dvariable& x);
02860 void send_int_to_master(int i);
02861 dvar_matrix get_f_from_slaves();
02862 d3_array get_dmatrix_from_slaves();
02863 d3_array get_dmatrix_from_slaves(const imatrix& flags);
02864 dmatrix get_dvector_from_slaves();
02865 void admaster_slave_variable_interface(const ad_comm& mp);
02866 void admaster_slave_variable_interface(void);
02867 int get_int_from_master(void);
02868 imatrix get_int_from_slaves(void);
02869 void send_int_to_slaves(int  x);
02870 void send_int_to_slaves(const ivector& x);
02871 int check_pvm_message(int i,int j);
02872 void read_covariance_matrix(const dmatrix& S, int nvar, int& hbf,
02873   dvector& sscale);
02874 
02875 dvector value(const param_init_number_vector& t);
02876 dvector value(const param_init_bounded_number_vector& t);
02877 //dvector value(const param_init_bounded_number_matrix& t);
02878 //dvector value(const param_init_vector_vector& t);
02879 //dvector value(const param_init_bounded_vector_vector& t);
02880 
02881 dvector read_old_scale(int & old_nvar);
02882 
02883 int withinbound(int lb,int n,int ub);
02884 
02885 #if defined(_MSC_VER)
02886 #  if defined(min)
02887 #    undef min
02888 #  endif
02889 #  if defined(max)
02890 #    undef max
02891 #  endif
02892 #endif
02893 
02894 #include "param_init_bounded_number_matrix.h"
02895 
02896 extern int to_make_sure_admodel_cpp_gets_linked;
02897 #endif