ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
admodel.h
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * 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   class laplace_approximation_calculator;
00058   void cleanup_laplace_stuff(laplace_approximation_calculator *);
00059 
00060 #include <fvar.hpp>
00061 
00062 //#include <d4arr.hpp>
00063 #include <cifstrem.h>
00064 
00065 #include <adstring.hpp>
00066 class init_xml_doc;
00067 
00068 //#define _ADSTD_ std::
00069 #define param_matrix named_dvar_matrix
00070 #define param_vector named_dvar_vector
00071 #define param_number named_dvariable
00072 #define param_3array named_dvar3_array
00073 #define param_4array named_dvar4_array
00074 #define param_5array named_dvar5_array
00075 #define param_6array named_dvar6_array
00076 #define param_7array named_dvar7_array
00077 
00078 #define SPparam_matrix SPnamed_dvar_matrix
00079 #define SPparam_vector SPnamed_dvar_vector
00080 #define SPparam_number SPnamed_dvariable
00081 #define SPparam_3array SPnamed_dvar3_array
00082 #define SPparam_4array SPnamed_dvar4_array
00083   double mfexp(const double);
00084   dvariable mfexp(const prevariable& v1);
00085   dvar_vector mfexp(const dvar_vector&);
00086   dvector mfexp(const dvector&);
00087 
00088   class param_init_bounded_number_vector;
00089   class model_parameters;
00090   extern int AD_gaussflag;
00091 
00092   extern function_minimizer * pfm;
00093   extern int traceflag;
00094   extern int ADqd_flag;
00095 /*
00096  void set_value_inv(const dvariable& x, const dvector& v, const int& ii);
00097  void set_value_inv(const dvar_matrix& x, const dvector& v, const int& ii);
00098  void set_value_inv(const dvar_vector&, const dvector&, const int &ii);
00099  void set_value_inv(const dvariable& u, const dvector& x, const int& ii,
00100    const double fmin, const double fmax);
00101  void set_value_inv(const dvar_matrix& u, const dvector& x, const int& ii,
00102   const double fmin,const double fmax);
00103  void set_value_inv(const dvar3_array& u, const dvector& x, const int& ii,
00104   const double fmin,const double fmax);
00105  void set_value_inv(const dvar3_array& u, const dvector& x, const int& ii);
00106 */
00107 
00108   void copy_value_to_vector(const prevariable& x, const dvector& v,
00109     const int& ii);
00110   void copy_value_to_vector(const dvar_vector& x, const dvector& v,
00111     const int& ii);
00112   void copy_value_to_vector(const dvar_matrix& x, const dvector& v,
00113     const int& ii);
00114   void copy_value_to_vector(const dvar3_array& x, const dvector& v,
00115     const int& ii);
00116 
00117   void restore_value_from_vector(const prevariable& x, const dvector& v,
00118     const int& ii);
00119   void restore_value_from_vector(const dvar_vector& x, const dvector& v,
00120     const int& ii);
00121   void restore_value_from_vector(const dvar_matrix& x, const dvector& v,
00122     const int& ii);
00123   void restore_value_from_vector(dvar3_array& x, const dvector& v,
00124     const int& ii);
00125 
00130 class AD_matherror
00131 {
00132 public:
00133 #if defined (_BORLANDC_)
00134   exception * err;
00135   AD_matherror(exception * _err) : err(_err) {;}
00136 #endif
00137 #if defined (_MSC_VER)
00138   _exception * err;
00139   AD_matherror(_exception * _err) : err(_err) {;}
00140 #endif
00141 };
00142 
00143 class model_data;
00144 
00149 class label_class
00150 {
00151   const char * name;
00152   friend ostream& operator<<(const ostream& s, const label_class& lc);
00153   friend class model_name_tag;
00154 public:
00155   const char * mychar(void) { return name;}
00156   label_class(const char * s){name=s;}
00157 };
00158 
00163 class model_name_tag
00164 {
00165 protected:
00166   adstring name;
00167   //friend ostream& operator<<(const ostream& os, const model_name_tag& mnt);
00168 public:
00169   model_name_tag(void){;}
00170   void allocate(const char * s);
00171   label_class label(void){return (char*)(name);}
00172   const char * get_name(void) { return name;}
00173 };
00174 
00179 class named_dvar_vector : public dvar_vector, public model_name_tag
00180 {
00181 protected:
00182   named_dvar_vector(void) : dvar_vector(), model_name_tag() {;}
00183   named_dvar_vector& operator=(const dvar_vector& m);
00184   named_dvar_vector& operator=(const dvector& m);
00185   named_dvar_vector& operator=(const double m);
00186   named_dvar_vector& operator=(const prevariable& m);
00187   friend class model_parameters;
00188   void allocate(int mmin,int mmax,const char * s);
00189   void allocate(const char * s);
00190 };
00191 
00196 class equality_constraint_vector : public named_dvar_vector
00197 {
00198 protected:
00199   equality_constraint_vector(void);
00200   equality_constraint_vector& operator=(const dvar_vector& m);
00201   equality_constraint_vector& operator=(const dvector& m);
00202   equality_constraint_vector& operator=(const double m);
00203   equality_constraint_vector& operator=(const prevariable& m);
00204   friend class model_parameters;
00205   void allocate(int mmin,int mmax,const char * s);
00206 };
00207 
00212 class inequality_constraint_vector : public named_dvar_vector
00213 {
00214 protected:
00215   inequality_constraint_vector(void);
00216   inequality_constraint_vector& operator=(const dvar_vector& m);
00217   inequality_constraint_vector& operator=(const dvector& m);
00218   inequality_constraint_vector& operator=(const double m);
00219   inequality_constraint_vector& operator=(const prevariable& m);
00220   friend class model_parameters;
00221   void allocate(int mmin,int mmax,const char * s);
00222 };
00223 
00228 class dll_param_vector : public named_dvar_vector
00229 {
00230   double * pd;
00231 public:
00232   ~dll_param_vector();
00233   void allocate(double *_pd,int mmin,int mmax,const char * s);
00234   dll_param_vector& operator=(const dvar_vector& m);
00235   dll_param_vector& operator=(const dvector& m);
00236   dll_param_vector& operator=(const double m);
00237   dll_param_vector& operator=(const prevariable& m);
00238 };
00239 
00244 class named_dvariable : public dvariable, public model_name_tag
00245 {
00246   //named_dvariable& operator=(const dvariable& m);
00247 protected:
00248   named_dvariable(void) : dvariable(), model_name_tag() {;}
00249   void allocate(const char * s);
00250   named_dvariable& operator=(const prevariable& m);
00251   named_dvariable& operator=(const double m);
00252   friend class model_parameters;
00253 };
00254 
00259 class dll_param_number : public named_dvariable
00260 {
00261   double * pd;
00262 protected:
00263   //named_dvariable(void) : dvariable(), model_name_tag() {;}
00264   void allocate(double *_d,const char * s);
00265   dll_param_number& operator=(const prevariable& m);
00266   dll_param_number& operator=(const double m);
00267   virtual ~dll_param_number();
00268   friend class model_parameters;
00269 };
00270 
00275 class named_dvar_matrix : public dvar_matrix, public model_name_tag
00276 {
00277 protected:
00278   named_dvar_matrix(void) : dvar_matrix(), model_name_tag() {;}
00279   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00280   void allocate(int rmin,int rmax,const char * s);
00281   void allocate(const char * s);
00282   //void allocate(int rmin,int rmax,int,const ivector&, const char * s);
00283   void allocate(
00284     int rmin, int rmax,
00285     const index_type& cmin, const index_type& cmax,
00286     const char* s);
00287 public:
00288   named_dvar_matrix& operator=(const double m);
00289   named_dvar_matrix& operator=(const dmatrix& m);
00290   named_dvar_matrix& operator=(const dvar_matrix& m);
00291   named_dvar_matrix& operator=(const dvariable& m);
00292 
00293   friend class model_parameters;
00294 };
00295 
00300 class dll_param_matrix : public named_dvar_matrix
00301 {
00302   double * pd;
00303 public:
00304   //named_dvar_matrix(void) : dvar_matrix(), model_name_tag() {;}
00305   void allocate(double * ,int rmin,int rmax,int cmin,int cmax,const char * s);
00306   void allocate(double * ,int rmin,int rmax,const index_type&
00307      ,const index_type& ,const char * s);
00308   dll_param_matrix& operator=(const dvariable& m);
00309   dll_param_matrix & operator = (const double m);
00310   dll_param_matrix& operator=(const dmatrix& m);
00311   dll_param_matrix& operator=(const dvar_matrix& m);
00312   virtual ~dll_param_matrix();
00313 };
00314 
00319 class named_dvar3_array : public dvar3_array, public model_name_tag
00320 {
00321 protected:
00322   named_dvar3_array(void) : dvar3_array(), model_name_tag() {;}
00323  void allocate(const ad_integer& sl,const ad_integer& sh,
00324   const index_type& nrl,const index_type& nrh,const index_type& ncl,
00325     const index_type& nch,const char * s="UNNAMED");
00326   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00327     const char * s="UNNAMED");
00328 
00329   void allocate(int hsl,int hsu,int rmin,int rmax,const char * s="UNNAMED");
00330   void allocate(int hsl,int hsu,const index_type& rmin,const index_type& rmax,
00331     const char * s="UNNAMED");
00332   void allocate(int hsl,int hsu,const char * s="UNNAMED");
00333   void allocate(const char * s="UNNAMED");
00334 
00335 
00336   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00337                 int cmin, int cmax, const char *s = "UNNAMED");
00338   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00339     int cmin,int cmax,const char * s="UNNAMED");
00340   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00341     int cmin,int cmax,const char * s="UNNAMED");
00342   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00343     int cmax,const char * s="UNNAMED");
00344   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00345                 const ivector& cmax, const char *s = "UNNAMED");
00346   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00347                 const ivector& cmax, const char *s = "UNNAMED");
00348   named_dvar3_array& operator=(const dvar3_array& m);
00349   named_dvar3_array& operator=(const d3_array& m);
00350   friend class model_parameters;
00351 };
00352 
00357 class named_dvar4_array : public dvar4_array, public model_name_tag
00358 {
00359 protected:
00360   named_dvar4_array(void) : dvar4_array(), model_name_tag() {;}
00361   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00362   int cmin,int cmax,const char * s);
00363   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00364     const index_type&,const index_type&,const index_type&,const index_type&,
00365     const char *s);
00366 
00367   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00368     const index_type&,const index_type&,const char *s);
00369 
00370   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00371     const char *s);
00372   void allocate(ad_integer,ad_integer,const char *s);
00373   void allocate(const char *s);
00374 
00375   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00376     const char * s);
00377   void allocate(int hhsl,int hhsu,int hsl,int hsu,const char * s);
00378   void allocate(int hhsl,int hhsu,const char * s);
00379 
00380   named_dvar4_array& operator=(const dvar4_array& m);
00381   named_dvar4_array& operator=(const d4_array& m);
00382   friend class model_parameters;
00383 };
00384 
00389 class named_dvar5_array : public dvar5_array, public model_name_tag
00390 {
00391 protected:
00392   named_dvar5_array(void) : dvar5_array(), model_name_tag() {;}
00393   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00394   int cmin,int cmax,
00395   int l5,int u5,
00396   const char * s);
00397 
00398   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00399     const index_type& hsl,const index_type& hsu,
00400     const index_type& sl,const index_type& sh,
00401     const index_type& nrl,const index_type& nrh,
00402     const index_type& ncl,const index_type& nch,
00403     const char * s);
00404 
00405   named_dvar5_array& operator=(const dvar5_array& m);
00406   named_dvar5_array& operator=(const d5_array& m);
00407   friend class model_parameters;
00408 };
00409 
00414 class named_dvar6_array : public dvar6_array, public model_name_tag
00415 {
00416 protected:
00417   named_dvar6_array(void) : dvar6_array(), model_name_tag() {;}
00418   void allocate(int hhsl,int hhsu,
00419     int hsl,int hsu,
00420     int rmin,int rmax,
00421     int cmin,int cmax,
00422     int l5,int u5,
00423     int l6,int u6,
00424     const char * s);
00425 
00426   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00427     const index_type& hsl,const index_type& hsu,
00428     const index_type& sl,const index_type& sh,
00429     const index_type& nrl,const index_type& nrh,
00430     const index_type& ncl,const index_type& nch,
00431     const index_type& l5,const index_type& u5,
00432     const char * s);
00433 
00434   named_dvar6_array& operator=(const dvar6_array& m);
00435   named_dvar6_array& operator=(const d6_array& m);
00436   friend class model_parameters;
00437 };
00438 
00443 class named_dvar7_array : public dvar7_array, public model_name_tag
00444 {
00445 protected:
00446   named_dvar7_array(void) : dvar7_array(), model_name_tag() {;}
00447   void allocate(
00448     int hhsl,int hhsu,
00449     int hsl,int hsu,
00450     int rmin,int rmax,
00451     int cmin,int cmax,
00452     int l5,int u5,
00453     int l6,int u6,
00454     int l7,int u7,
00455     const char * s);
00456 
00457   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00458     const index_type& hsl,const index_type& hsu,
00459     const index_type& sl,const index_type& sh,
00460     const index_type& nrl,const index_type& nrh,
00461     const index_type& ncl,const index_type& nch,
00462     const index_type& l5,const index_type& u5,
00463     const index_type& l6,const index_type& u6,
00464     const char * s);
00465 
00466   named_dvar7_array& operator=(const dvar7_array& m);
00467   named_dvar7_array& operator=(const d7_array& m);
00468   friend class model_parameters;
00469 };
00470 
00475 class named_dvector : public dvector, public model_name_tag
00476 {
00477 protected:
00478   named_dvector(void) : dvector(), model_name_tag() {;}
00479   void allocate(int mmin,int mmax,const char * s);
00480   void allocate(const char * s);
00481   void allocate(int mmin, const ivector& mmax, const char *s);
00482   named_dvector& operator=(const dvector& m);
00483   named_dvector& operator=(const double m);
00484   friend class model_data;
00485 };
00486 
00491 class named_ivector : public ivector, public model_name_tag
00492 {
00493 protected:
00494   named_ivector(void) : ivector(), model_name_tag() {;}
00495   void allocate(int mmin,int mmax,const char * s);
00496 };
00497 
00502 class named_dmatrix : public dmatrix, public model_name_tag
00503 {
00504 protected:
00505   named_dmatrix(void) : dmatrix(), model_name_tag() {;}
00506   void allocate(int rmin,int rmax,const char * s);
00507   void allocate(const char * s);
00508   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00509   void allocate(int rmin,int rmax,const ivector& cmin,int cmax,const char * s);
00510   void allocate(int rmin,int rmax,const ivector& cmin,const ivector& cmax,
00511     const char * s);
00512   void allocate(int rmin,int rmax,int cmin,const ivector& cmax,const char * s);
00513   named_dmatrix& operator=(const dmatrix& m);
00514   named_dmatrix& operator=(const double m);
00515 };
00516 
00521 class named_imatrix : public imatrix, public model_name_tag
00522 {
00523 protected:
00524   named_imatrix(void) : imatrix(), model_name_tag() {;}
00525   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00526   void allocate(int rmin, int rmax, const index_type& cmin,
00527                 const index_type& cmax, const char *s);
00528   named_imatrix& operator=(const imatrix& m);
00529   named_imatrix& operator=(const int& m);
00530 };
00531 
00536 class named_d3_array : public d3_array, public model_name_tag
00537 {
00538 protected:
00539   named_d3_array(void) : d3_array(), model_name_tag() {;}
00540   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00541     const char * s);
00542   void allocate(int hsl, int hsu, const index_type& rmin,
00543                 const index_type& rmax, const index_type& cmin,
00544                 const index_type& cmax, const char *s);
00545   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00546     int cmin,int cmax,const char * s);
00547   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00548     int cmin,int cmax,const char * s);
00549   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00550     int cmin,int cmax,const char * s);
00551   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00552     int cmax, const char * s);
00553   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00554                 const ivector& cmax, const char *s);
00555   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00556                 const ivector& cmax, const char *s);
00557   named_d3_array& operator=(const d3_array& m);
00558 
00559   void allocate(int hsl,int hsu,const index_type& rmin,const index_type& rmax,
00560     const char * s);
00561   void allocate(int hsl,int hsu,int rmin,int rmax,const char * s);
00562   void allocate(int hsl,int hsu,const char * s);
00563   void allocate(const char * s);
00564 };
00565 
00570 class named_i3_array : public i3_array, public model_name_tag
00571 {
00572 protected:
00573   named_i3_array(void) : i3_array(), model_name_tag() {;}
00574   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00575     const char * s);
00576   void allocate(int hsl, int hsu, const index_type& rmin,
00577                 const index_type& rmax, const index_type& cmin,
00578                 const index_type& cmax, const char *s);
00579   named_i3_array& operator=(const i3_array& m);
00580 };
00581 
00586 class named_d4_array : public d4_array, public model_name_tag
00587 {
00588 protected:
00589   named_d4_array(void) : d4_array(), model_name_tag() {;}
00590   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00591     const index_type&,const index_type&,const index_type&,const index_type&,
00592     const char * s);
00593   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00594     int rmax,int cmin,int cmax,const char * s);
00595 
00596   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00597     int rmax,const char * s);
00598   void allocate(int hhsl,int hhsu,int hsl,int hsu,const char * s);
00599   void allocate(int hhsl,int hhsu,const char * s);
00600   void allocate(const char * s);
00601 
00602   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00603     const index_type&,const index_type&,const char * s);
00604   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00605     const char * s);
00606   void allocate(ad_integer,ad_integer,const char * s);
00607 
00608 
00609   named_d4_array& operator=(const d4_array& m);
00610 };
00611 class named_i4_array : public i4_array, public model_name_tag
00612 {
00613 protected:
00614   named_i4_array(void) : i4_array(), model_name_tag() {;}
00615   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00616     const index_type&,const index_type&,const index_type&,const index_type&,
00617     const char * s);
00618   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00619     int rmax,int cmin,int cmax,const char * s);
00620 
00621   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00622     int rmax,const char * s);
00623   void allocate(int hhsl,int hhsu,int hsl,int hsu,const char * s);
00624   void allocate(int hhsl,int hhsu,const char * s);
00625   void allocate(const char * s);
00626 
00627   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00628     const index_type&,const index_type&,const char * s);
00629   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00630     const char * s);
00631   void allocate(ad_integer,ad_integer,const char * s);
00632 
00633 
00634   named_i4_array& operator=(const i4_array& m);
00635 };
00636 
00641 class named_d5_array : public d5_array, public model_name_tag
00642 {
00643 protected:
00644   named_d5_array(void) : d5_array(), model_name_tag() {;}
00645   void allocate(int l5,int u5,int hhsl,int hhsu,int hsl,int hsu,int rmin,
00646     int rmax,int cmin,int cmax,const char * s);
00647   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00648     const index_type& hsl,const index_type& hsu, const index_type& sl,
00649     const index_type& sh,const index_type& nrl,const index_type& nrh,
00650     const index_type& ncl,const index_type& nch,const char * s);
00651 
00652   named_d5_array& operator=(const d5_array& m);
00653 };
00654 
00659 class named_d6_array : public d6_array, public model_name_tag
00660 {
00661 protected:
00662   named_d6_array(void) : d6_array(), model_name_tag() {;}
00663   void allocate(int l6,int u6,int l5,int u5,int hhsl,int hhsu,int hsl,
00664     int hsu,int rmin,int rmax,int cmin,int cmax,const char * s);
00665   void allocate(const ad_integer& l6,const ad_integer& u6,
00666     const index_type& l5,const index_type& u5,
00667     const index_type& hhsl,const index_type& hhsu,
00668     const index_type& hsl,const index_type& hsu,
00669     const index_type& sl,const index_type& sh,
00670     const index_type& nrl,const index_type& nrh,
00671     const char * s);
00672 
00673   named_d6_array& operator=(const d6_array& m);
00674 };
00675 
00680 class named_d7_array : public d7_array, public model_name_tag
00681 {
00682 protected:
00683   named_d7_array(void) : d7_array(), model_name_tag() {;}
00684   void allocate(int l7,int u7,int l6,int u6,int l5,int u5,int hhsl,
00685     int hhsu,int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00686     const char * s);
00687   void allocate(const ad_integer& l7,const ad_integer& u7,
00688     const index_type& l6,const index_type& u6,
00689     const index_type& l5,const index_type& u5,
00690     const index_type& hhsl,const index_type& hhsu,
00691     const index_type& hsl,const index_type& hsu,
00692     const index_type& sl,const index_type& sh,
00693     const index_type& nrl,const index_type& nrh,
00694     const char * s);
00695 
00696   named_d7_array& operator=(const d7_array& m);
00697 };
00698 
00699 
00700 class function_minimizer;
00701 
00702 #if defined(USE_ADPVM)
00703 
00707 class pvm_params
00708 {
00709   static pvm_params * varsptr[]; // this should be a resizeable array
00710   static int num_pvm_params;
00711   static const int maxnum_pvm_params;
00712   void add_to_list(void);
00713   virtual void send_to_slaves(void)=0;
00714   virtual void get_from_master(void)=0;
00715 public:
00716   static void pvm_params::send_all_to_slaves(void);
00717   static void pvm_params::get_all_from_master(void);
00718   void allocate(const char *);
00719   void allocate(void);
00720 };
00721 
00726 class pvm_number : public pvm_params
00727 {
00728 public:
00729   virtual void send_to_slaves(void);
00730   virtual void get_from_master(void);
00731   dvector v;
00732   double d;
00733   operator double();
00734   void assign(const dvector&);
00735   void assign(double);
00736 };
00737 
00742 class pvm_int : public pvm_params
00743 {
00744 public:
00745   virtual void send_to_slaves(void);
00746   virtual void get_from_master(void);
00747   ivector v;
00748   int d;
00749   operator int();
00750   void assign(const ivector&);
00751   void assign(int);
00752 };
00753 #endif // #if defined(USE_ADPVM)
00754 
00755 class initial_params;
00756 typedef initial_params* pinitial_params;
00757 typedef void* ptovoid;
00761 class adlist_ptr
00762 {
00763   ptovoid * ptr;
00764   int current_size;
00765   int current;
00766   void resize(void);
00767   void add_to_list(void* p);
00768 public:
00769   adlist_ptr(int init_size);
00770   ~adlist_ptr();
00771 
00772   void initialize();
00773 
00774   pinitial_params& operator[](int i);
00775 
00776   friend class initial_params;
00777 };
00778 
00779 #if defined(USE_SHARE_FLAGS)
00780 
00785   class shareinfo
00786   {
00787     index_type * sflags;
00788     index_type * original_sflags;
00789     index_type * aflags;
00790     index_type * invflags;
00791     i3_array * bmap;
00792     int dimension;
00793     int maxshare;
00794     int current_phase;
00795   public:
00796     void get_inv_matrix_shared( int _cf);
00797     void get_inv_vector_shared( int _cf);
00798     int & get_maxshare(void) { return maxshare; }
00799     i3_array & get_bmap(void);
00800     int & get_dimension(void){ return dimension;}
00801     index_type * get_original_shareflags(void);
00802     index_type * get_shareflags(void);
00803     int& get_current_phase(void);
00804     index_type * get_activeflags(void);
00805     index_type * get_invflags(void);
00806     void set_shareflags(const index_type& sf);
00807     void set_original_shareflags(const index_type& sf);
00808     void reset_shareflags(const index_type& sf);
00809     void set_activeflags(const index_type& af);
00810     void set_bmap(const i3_array& af);
00811     void reset_bmap(const i3_array& af);
00812     void set_invflags(const index_type& af);
00813     shareinfo(const index_type& sf,const index_type& af);
00814     ~shareinfo();
00815   };
00816 #endif
00817 
00822 class initial_params
00823 {
00824 protected:
00825 #if defined(USE_SHARE_FLAGS)
00826   shareinfo * share_flags;
00827 #endif
00828   virtual ~initial_params();
00829   int active_flag;
00830   int initial_value_flag;
00831   double initial_value;
00832   double scalefactor;
00833 public:
00834 #if defined(USE_SHARE_FLAGS)
00835   virtual void setshare(const index_type& sf,const index_type& af);
00836   virtual void shared_set_value_inv(const dvector&,const int&);
00837   virtual void shared_set_value(const dvar_vector&,const int&,
00838     const dvariable& pen);
00839   virtual int shared_size_count(void); // get the number of active parameters
00840 #endif
00841   double get_scalefactor();
00842   void set_scalefactor(const double);
00843 #if !defined(BIG_INIT_PARAMS)
00844   static initial_params  varsptr[]; // this should be a resizeable array
00845 #else
00846   static adlist_ptr varsptr; // this should be a resizeable array
00847 #endif
00848   static int num_initial_params;
00849   static const int max_num_initial_params;
00850   static int straight_through_flag;
00851   static int num_active_initial_params;
00852   static int max_number_phases;
00853   static int current_phase;
00854   static int restart_phase;
00855   static int sd_phase;
00856   static int mc_phase;
00857   static int mceval_phase;
00858   int phase_start;
00859   int phase_save;
00860   int phase_stop;
00861   virtual void set_random_effects_active();
00862   void restore_phase_start(void);
00863   virtual void set_random_effects_inactive();
00864   virtual void set_only_random_effects_active();
00865   virtual void set_only_random_effects_inactive();
00866   virtual void set_value(const dvar_vector&, const int&,
00867     const dvariable& pen) = 0;
00868   virtual void dev_correction(const dmatrix&, const int&) = 0;
00869   void set_initial_value(double x);
00870   double get_initial_value(void);
00871   void set_phase_start(int x);
00872   int get_phase_start(void);
00873   static void set_all_simulation_bounds(const dmatrix& symbds);
00874   static void set_all_simulation_bounds(const dmatrix& symbds, const dvector&);
00875   static void get_jacobian_value(const dvector& y, const dvector& jac);
00876   static int correct_for_dev_objects(const dmatrix &H);
00877   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii) = 0;
00878   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
00879   //  const int& ii) = 0;
00880   virtual void set_value_inv(const dvector&, const int&) = 0;
00881   virtual void add_value(const dvector&, const int&) = 0;
00882   virtual void add_value(const dvector&, const dvector&, const int&,
00883     const double&, const dvector&) = 0;
00884   virtual void get_jacobian(const dvector&, const dvector&, const int&) = 0;
00885   //virtual void check_tightness(const dvector&, const int&) = 0;
00886   virtual void copy_value_to_vector(const dvector&, const int&) = 0;
00887   virtual void restore_value_from_vector(const dvector&, const int&) = 0;
00888   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00889   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
00890     const int& ii)=0;
00891   virtual void mc_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00892   virtual void curv_scale(const dvector& d, const dvector& x,
00893     const int& ii) = 0;
00894   virtual void hess_scale(const dvector& d, const dvector& x,
00895     const int& ii) = 0;
00896   virtual int size_count(void)=0; // get the number of active parameters
00897 
00898   // save the objects value in to a text file
00899   virtual void save_value(ofstream& ofs) = 0;
00900 
00901   // save the objects value in a binary file
00902   virtual void bsave_value(uostream& uos) = 0;
00903 
00904   virtual void save_value(const ofstream& ofs, int prec) = 0;
00905   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
00906     int& offset)=0;
00907   virtual const char* label() = 0;
00908   void allocate(int _phase_start);
00909   void set_active_flag(void);
00910   void set_inactive_flag(void);
00911   friend int active(const initial_params& ip);
00912   static adstring get_reportfile_name(void);
00913   initial_params(void);
00914   static void xinit(const dvector& x); // get the number of active parameters
00915   // get the number of active parameters
00916   static void xinit_all(const dvector& x);
00917   static void save_all(const ofstream& _ofs,int prec,const dvector&g);
00918   // get the number of active parameters
00919   static void set_active_random_effects(void);
00920   // get the number of active parameters
00921   static void set_active_only_random_effects(void);
00922   // get the number of active parameters
00923   static void set_inactive_only_random_effects(void);
00924   // get the number of active parameters
00925   static void set_inactive_random_effects(void);
00926   // get the number of active parameters
00927   static void restore_start_phase(void);
00928   static void xinit1(const dvector& x, const dvector& g);
00929   //save all initial parameter values in a vector
00930   static void copy_all_values(const dvector& x, const int& ii);
00931   //get ivalues for all active parameters from a vector
00932   static void restore_all_values(const dvector& x, const int& ii);
00933   // get the number of active parameters
00934   static dvariable reset(const dvar_vector& x);
00935   // get the number of active parameters
00936   static dvariable reset(const dvector& x);
00937   static dvariable reset1(const dvar_vector& x, const dvector& g);
00938   // get the number of active parameters
00939   static dvariable reset(const dvar_vector& x, const dvector& pen);
00940   // get the number of active parameters
00941   static dvariable reset_all(const dvar_vector& x,const dvector& pen);
00942   static int nvarcalc();
00943   static int nvarcalc_all(void);
00944   static int num_active_calc(void);
00945   static int stddev_scale(const dvector& d, const dvector& x);
00946   static int stddev_vscale(const dvar_vector& d,const dvar_vector& x);
00947   static int montecarlo_scale(const dvector& d, const dvector& x);
00948   static int stddev_curvscale(const dvector& d, const dvector& x);
00949   static void read(void);
00950   static void save(void);
00951   static void save(const ofstream& ofs, int prec);
00952   static void restore(const ifstream& ifs);
00953   static void add_random_vector(const dvector& x);
00954   static void add_random_vector(const dvector& y, const dvector& x,
00955     const double& ll, const dvector& diag);
00956   virtual void restore_value(const ifstream& ifs) = 0;
00957   virtual void add_to_list(void);
00958 #if defined(USE_ADPVM)
00959   virtual void pvm_pack(void)=0;
00960   virtual void pvm_unpack(void)=0;
00961 #endif
00962 
00963   friend class function_minimizer;
00964 };
00965 
00966 void pvm_pack(const dvar_vector&);
00967 void pvm_unpack(const dvar_vector&);
00968 void pvm_pack(const prevariable&);
00969 void pvm_unpack(const prevariable&);
00970 void pvm_pack(const dvar_matrix&);
00971 void pvm_unpack(const dvar_matrix&);
00972 
00977 class param_init_vector: public named_dvar_vector, public initial_params
00978 {
00979 public:
00980 #if defined(USE_SHARE_FLAGS)
00981   virtual void setshare(const index_type& sf,const index_type& af);
00982   virtual void shared_set_value_inv(const dvector&,const int&);
00983   virtual void shared_set_value(const dvar_vector&,const int&,
00984     const dvariable& pen);
00985   virtual int shared_size_count(void); // get the number of active parameters
00986 #endif
00987   virtual void dev_correction(const dmatrix& H, const int& ii);
00988   virtual const char * label(void);
00989   param_init_vector();
00990 #if defined(USE_ADPVM)
00991   void pvm_pack(void){::pvm_pack(*this);}
00992   void pvm_unpack(void){::pvm_unpack(*this);}
00993 #endif
00994 private:
00995   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
00996   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
00997   //  const int& ii);
00998   virtual void add_value(const dvector&, const dvector&, const int&,
00999     const double&, const dvector&);
01000   virtual void add_value(const dvector&, const int&);
01001   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01002   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01003     const int& ii);
01004 
01005   virtual void set_value(const dvar_vector& x, const int& ii,
01006     const dvariable& pen);
01007   virtual void set_value_inv(const dvector& x, const int& ii);
01008   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01009   virtual void restore_value_from_vector(const dvector&, const int&);
01010   virtual int size_count(void);
01011   virtual void sd_scale(const dvector& d, const dvector& x, const int&);
01012   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01013   virtual void curv_scale(const dvector& d, const dvector& x,const int&);
01014   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01015   virtual void save_value(ofstream& ofs);
01016   virtual void bsave_value(uostream& uos);
01017   virtual void save_value(const ofstream& ofs, int prec);
01018   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
01019     int& offset);
01020   virtual void restore_value(const ifstream& ifs);
01021   void report_value(void);
01022   //virtual void read_value(void);
01023   void allocate(int imin,int imax,int phasestart=1,const char * s="UNNAMED");
01024   void allocate(const ad_integer& imin,const ad_integer& imax,
01025     const ad_integer& phasestart=1,const char * s="UNNAMED");
01026   void allocate(int imin,int imax,const char * s="UNNAMED");
01027 #if defined(USE_SHARE_FLAGS)
01028   void allocate(int imin,int imax,const ivector& ishare,
01029     const char * s="UNNAMED");
01030 #endif
01031   friend class model_parameters;
01032   friend class param_init_vector_vector;
01033 public:
01034   param_init_vector& operator = (const dvector&);
01035   param_init_vector& operator = (const dvar_vector&);
01036   param_init_vector& operator = (const prevariable&);
01037   param_init_vector& operator = (const double&);
01038 };
01039 
01044 class dll_param_init_vector: public param_init_vector
01045 {
01046   double * pd;
01047 public:
01048   dll_param_init_vector& operator = (const dvector&);
01049   dll_param_init_vector& operator = (const dvar_vector&);
01050   dll_param_init_vector& operator = (const prevariable&);
01051   dll_param_init_vector& operator = (const double&);
01052   void allocate(double * _pd,int imin,int imax,
01053     int phasestart=1,const char * s="UNNAMED");
01054   void allocate(double * _pd,int imin,int imax,
01055     const char * s="UNNAMED");
01056 
01057   virtual ~dll_param_init_vector();
01058   friend class model_parameters;
01059 };
01060 
01065 class param_init_bounded_vector: public named_dvar_vector, public initial_params
01066 {
01067   virtual void* parent_this(void){return this;}
01068 public:
01069   double get_minb(void);
01070   void set_minb(double b);
01071   double get_maxb(void);
01072   void set_maxb(double b);
01073 protected:
01074   double minb;
01075   double maxb;
01076   param_init_bounded_vector();
01077 private:
01078   virtual void dev_correction(const dmatrix&, const int&);
01079   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01080   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01081     const int& ii);
01082   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01083   //  const int& ii);
01084   virtual void add_value(const dvector&, const dvector&, const int&,
01085     const double&, const dvector&);
01086   virtual void add_value(const dvector&, const int&);
01087   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01088   virtual void set_value(const dvar_vector& x, const int& ii,
01089     const dvariable& pen);
01090   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01091   virtual void restore_value_from_vector(const dvector&, const int&);
01092   virtual void set_value_inv(const dvector& x, const int& ii);
01093   virtual int size_count(void);
01094   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01095   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01096   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01097   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01098   void allocate(int imin,int imax,double _minb,double _maxb,
01099     int phasestart=1, const char * name="UNNAMED");
01100   void allocate(int imin,int imax,double _minb,double _maxb,
01101     const char * name="UNNAMED");
01102  //void param_init_bounded_vector::allocate(const ad_integer& imin,
01103    //const ad_integer& imax,const ad_double& _minb,const ad_double& _maxb,
01104    //const ad_integer& phase_start,const char * s);
01105   friend class model_parameters;
01106   friend class param_init_bounded_vector_vector;
01107   virtual const char * label(void);
01108   virtual void save_value(const ofstream& ofs, int prec);
01109   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
01110     int& offset);
01111   virtual void restore_value(const ifstream& ifs);
01112   virtual void save_value(ofstream& ofs);
01113   virtual void bsave_value(uostream& uos);
01114   void report_value(void);
01115   //virtual void read_value(void);
01116 public:
01117   param_init_bounded_vector& operator = (const dvector&);
01118   param_init_bounded_vector& operator = (const dvar_vector&);
01119   param_init_bounded_vector& operator = (const prevariable&);
01120   param_init_bounded_vector& operator = (const double&);
01121 #if defined(USE_ADPVM)
01122   void pvm_pack(void){::pvm_pack(*this);}
01123   void pvm_unpack(void){::pvm_unpack(*this);}
01124 #endif
01125 };
01126 
01131 class dll_param_init_bounded_vector: public param_init_bounded_vector
01132 {
01133   double * pd;
01134 public:
01135   void allocate(double * _pd,int imin,int imax,double _minb,double _maxb,
01136     int phasestart=1, const char * name="UNNAMED");
01137   void allocate(double * _pd,int imin,int imax,double _minb,double _maxb,
01138     const char * name="UNNAMED");
01139   ~dll_param_init_bounded_vector();
01140 };
01141 
01146 class param_init_bounded_dev_vector: public param_init_bounded_vector
01147 {
01148   virtual void set_value(const dvar_vector& x, const int& ii,
01149     const dvariable& pen);
01150   virtual void dev_correction(const dmatrix& H, const int& ii);
01151 public:
01152   param_init_bounded_dev_vector& operator = (const dvar_vector& m);
01153   param_init_bounded_dev_vector& operator = (const dvector& m);
01154   param_init_bounded_dev_vector& operator = (const prevariable& m);
01155   param_init_bounded_dev_vector& operator = (const double& m);
01156 };
01157 
01162 class param_init_number: public named_dvariable, public initial_params
01163 {
01164   virtual void dev_correction(const dmatrix&, const int&);
01165   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01166 
01167 #if defined(USE_ADPVM)
01168   void pvm_pack(void){::pvm_pack(*this);}
01169   void pvm_unpack(void){::pvm_unpack(*this);}
01170 #endif
01171 
01172 //  virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01173 //    const int& ii);
01174   virtual void add_value(const dvector&, const dvector&, const int&,
01175     const double&, const dvector&);
01176   virtual void add_value(const dvector&, const int&);
01177   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01178   virtual void set_value(const dvar_vector& x, const int& ii,
01179     const dvariable& pen);
01180   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01181   virtual void restore_value_from_vector(const dvector&, const int&);
01182   virtual void set_value_inv(const dvector& x, const int& ii);
01183   virtual int size_count(void);
01184   virtual void save_value(const ofstream& ofs, int prec);
01185   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
01186     int& offset);
01187   virtual void restore_value(const ifstream& ifs);
01188   virtual void save_value(ofstream& ofs);
01189   virtual void bsave_value(uostream& uos);
01190   void report_value(void);
01191   virtual const char * label(void);
01192   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01193   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01194   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01195   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01196   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01197     const int& ii);
01198   //virtual void read_value(void);
01199 protected:
01200   void allocate(int phase_start=1,const char *s="UNNAMED");
01201   void allocate(const char *s="UNNAMED");
01202   void allocate(init_xml_doc&, const char *s="UNNAMED");
01203   friend class model_parameters;
01204   friend class param_init_number_vector;
01205   param_init_number();
01206   param_init_number& operator=(const double m);
01207   param_init_number& operator=(const prevariable& m);
01208 };
01209 
01214 class dll_param_init_number: public param_init_number
01215 {
01216   double * pd;
01217 public:
01218   void allocate(double * pd,int phase_start=1,const char *s="UNNAMED");
01219   void allocate(double *pd,const char *s="UNNAMED");
01220   virtual ~dll_param_init_number();
01221   dll_param_init_number& operator=(const double m);
01222   dll_param_init_number& operator=(const prevariable& m);
01223 };
01224 
01225 //forward declaration
01226 class data_vector;
01233 class param_init_bounded_number: public param_init_number
01234 {
01235 public:
01236   double get_minb(void);
01237   void set_minb(double b);
01238   double get_maxb(void);
01239   void set_maxb(double b);
01240 protected:
01241   double minb;
01242   double maxb;
01243   void allocate(double _minb,double _maxb,int phase_start=1,
01244     const char * s="UNNAMED");
01245   void allocate(double _minb,double _maxb,const char * s="UNNAMED");
01246   // Added by Steve Martell for using input data for allocation.
01247   void allocate(const data_vector& v,const char * s="UNNAMED");
01248   void allocate(init_xml_doc&, const char * s="UNNAMED");
01249 
01250 public:
01251 #if defined(USE_ADPVM)
01252   void pvm_pack(void){::pvm_pack(*this);}
01253   void pvm_unpack(void){::pvm_unpack(*this);}
01254 #endif
01255   param_init_bounded_number();
01256 private:
01257   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01258 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01259 //  const int& ii);
01260   virtual void add_value(const dvector&, const dvector&, const int&,
01261     const double&, const dvector&);
01262   virtual void add_value(const dvector&, const int&);
01263   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01264   virtual void set_value(const dvar_vector& x, const int& ii,
01265     const dvariable& pen);
01266   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01267   virtual void restore_value_from_vector(const dvector&, const int&);
01268   virtual void set_value_inv(const dvector& x, const int& ii);
01269   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01270   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01271   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01272   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01273   virtual const char * label(void);
01274   void report_value(void);
01275   param_init_bounded_number& operator=(const double m);
01276   param_init_bounded_number& operator=(const prevariable& m);
01277   friend class model_parameters;
01278   friend class param_init_bounded_number_vector;
01279   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01280     const int& ii);
01281 };
01282 
01287 class dll_param_init_bounded_number: public param_init_bounded_number
01288 {
01289   double * pd;
01290 public:
01291   void allocate(double * _pd,double _minb,double _maxb,int phase_start=1,
01292     const char * s="UNNAMED");
01293   void allocate(double* _pd,double _minb, double _maxb,const char* s="UNNAMED");
01294 public:
01295   virtual ~dll_param_init_bounded_number();
01296   void report_value(void);
01297 };
01298 
01303 class param_init_matrix: public named_dvar_matrix,public initial_params
01304 {
01305 #if defined(USE_SHARE_FLAGS)
01306   virtual void shared_set_value_inv(const dvector& x,const int& ii);
01307   virtual int shared_size_count(void); // get the number of active parameters
01308   virtual void shared_set_value(const dvar_vector&,const int&,
01309     const dvariable& pen);
01310 #endif
01311   virtual void dev_correction(const dmatrix&, const int&);
01312   virtual void set_simulation_bounds(const dmatrix& symbds,const int& ii);
01313 #if defined(USE_ADPVM)
01314   void pvm_pack(void){::pvm_pack(*this);}
01315   void pvm_unpack(void){::pvm_unpack(*this);}
01316 #endif
01317 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01318 //  const int& ii);
01319   virtual void add_value(const dvector&, const dvector&, const int&,
01320     const double&, const dvector&);
01321   virtual void add_value(const dvector&, const int&);
01322   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01323 public:
01324   virtual void set_value(const dvar_vector& x, const int& ii,
01325     const dvariable& pen);
01326   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01327   virtual void restore_value_from_vector(const dvector&, const int&);
01328   virtual void set_value_inv(const dvector& x, const int& ii);
01329   virtual int size_count(void);
01330   virtual void save_value(ofstream& ofs);
01331   virtual void bsave_value(uostream& uos);
01332   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
01333     int& offset);
01334   virtual void save_value(const ofstream& ofs, int prec);
01335   virtual void restore_value(const ifstream& ifs);
01336   void report_value(void);
01337   //virtual void read_value(void);
01338   virtual const char * label(void);
01339   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01340   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01341   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01342   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01343   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01344     const int& ii);
01345 
01346 public:
01347   void allocate(int rmin,int rmax,int cmin,int cmax,
01348     int phase_start=1,const char * = "UNNAMED");
01349 #if defined(USE_SHARE_FLAGS)
01350   //void allocate(int rmin,int rmax,int cmin,int cmax, const imatrix& jshare,
01351   // const char * = "UNNAMED");
01352   virtual void setshare(const index_type& sf,const index_type& af);
01353 #endif
01354   void allocate(int rmin,int rmax,int cmin,int cmax,
01355     const char * = "UNNAMED");
01356  void allocate(const ad_integer& imin,const ad_integer&imax,
01357    const index_type& imin2,const index_type& imax2,
01358    const ad_integer& phase_start, const char * s);
01359   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01360                 const index_type& cmin, const index_type& cmax,
01361                 const char * = "UNNAMED");
01362   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01363                 const index_type& cmin, const index_type& cmax,
01364                 int phase_start = 1, const char * = "UNNAMED");
01365   param_init_matrix(void);
01366   param_init_matrix& operator = (const dmatrix& m);
01367   param_init_matrix& operator = (const dvar_matrix& m);
01368   param_init_matrix& operator = (const dvariable& m);
01369   param_init_matrix& operator = (const double& m);
01370 };
01371 
01376 class dll_param_init_matrix: public param_init_matrix
01377 {
01378   double * d;
01379 public:
01380   void allocate(double* _d,int rmin,int rmax,int cmin,int cmax,
01381     int phase_start=1,const char * = "UNNAMED");
01382   void allocate(double * _d,int rmin,int rmax,int cmin,int cmax,
01383     const char * = "UNNAMED");
01384   virtual ~dll_param_init_matrix();
01385   dll_param_init_matrix(){d=NULL;}
01386   dll_param_init_matrix& operator = (const dmatrix& m);
01387   dll_param_init_matrix& operator = (const dvar_matrix& m);
01388   dll_param_init_matrix& operator = (const dvariable& m);
01389   dll_param_init_matrix& operator = (const double& m);
01390 };
01391 
01396 class param_init_bounded_matrix: public param_init_matrix
01397 {
01398 public:
01399   double get_minb(void);
01400   void set_minb(double b);
01401   double get_maxb(void);
01402   void set_maxb(double b);
01403 protected:
01404   double minb;
01405   double maxb;
01406   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01407 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
01408 //  const int& ii);
01409   virtual void add_value(const dvector&, const dvector&, const int&,
01410     const double&, const dvector&);
01411   virtual void add_value(const dvector&, const int&);
01412   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01413 public:
01414 #if defined(USE_ADPVM)
01415   void pvm_pack(void){::pvm_pack(*this);}
01416   void pvm_unpack(void){::pvm_unpack(*this);}
01417 #endif
01418   virtual void set_value(const dvar_vector& x, const int& ii,
01419     const dvariable& pen);
01420 #if defined(USE_SHARE_FLAGS)
01421   virtual void shared_set_value_inv(const dvector&,const int&);
01422   virtual void shared_set_value(const dvar_vector&,const int&,
01423     const dvariable& pen);
01424 #endif
01425   virtual void set_value_inv(const dvector& x, const int& ii);
01426   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01427   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01428   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01429   virtual void hess_scale(const dvector&, const dvector&, const int&){}
01430   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
01431     const int& ii);
01432 
01433 public:
01434  void allocate(const ad_integer& imin,
01435    const ad_integer& imax, const ad_integer& imin2,
01436    const ad_integer& imax2, const ad_double& _bmin,
01437    const ad_double& _bmax, const ad_integer& phase_start,
01438    const char * s);
01439 
01440   param_init_bounded_matrix(void);
01441   void allocate(int rmin,int rmax,int cmin,int cmax,
01442     double _minb,double _maxb,
01443     int phase_start=1,const char * = "UNNAMED");
01444   void allocate(int rmin,int rmax,int cmin,int cmax,
01445     double _minb,double _maxb,const char * = "UNNAMED");
01446 
01447   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01448     const index_type& cmin,
01449                 const index_type& cmax, double _minb, double _maxb,
01450                 const char * = "UNNAMED");
01451   void allocate(const ad_integer& rmin, const ad_integer& rmax,
01452     const index_type& cmin,
01453                 const index_type& cmax, double _minb, double _maxb,
01454                 int phase_start = 1, const char * = "UNNAMED");
01455 };
01456 
01461 class data_int: public model_name_tag
01462 {
01463 protected:
01464   int val;
01465 
01466   data_int& operator=(const int);
01467 
01468   void allocate(int n,const char * s="UNNAMED");
01469   void allocate(const char * s="UNNAMED");
01470   void allocate(init_xml_doc&, const char * s="UNNAMED");
01471 
01472 public:
01473   ~data_int() { }
01474   operator int() const { return val; }
01475 
01476   friend class model_data;
01477   friend class model_parameters;
01478   friend int operator + (int n,data_int v);
01479   friend int operator + (data_int v,int n);
01480   friend int operator + (data_int v,data_int n);
01481 };
01482 
01487 class named_adstring : public adstring, public model_name_tag
01488 {
01489 protected:
01490   void allocate(const char * s1,const char * s="UNNAMED");
01491   void operator = (const adstring&);
01492   void operator = (const char *);
01493 };
01494 
01499 class named_line_adstring : public line_adstring, public model_name_tag
01500 {
01501 protected:
01502   void allocate(const char * s1,const char * s="UNNAMED");
01503   void operator = (const adstring&);
01504   void operator = (const char *);
01505 };
01506 
01511 class init_adstring: public named_adstring
01512 {
01513 public:
01514   void allocate(const char * s="UNNAMED");
01515 };
01516 
01521 class init_line_adstring: public named_line_adstring
01522 {
01523 public:
01524   void allocate(const char * s="UNNAMED");
01525 };
01526 
01531 class dll_named_adstring : public named_adstring
01532 {
01533   char ** d;
01534 public:
01535   void allocate(char ** ps1,const char * s="UNNAMED");
01536   void operator = (const adstring&);
01537   void operator = (const char *);
01538   ~dll_named_adstring();
01539   dll_named_adstring(void){d=NULL;}
01540 };
01541 
01546 class dll_data_int : public data_int
01547 {
01548 public:
01549   int *pi;
01550   void allocate(int *_pi,const char * s);
01551   virtual ~dll_data_int();
01552 };
01553 
01558 class data_matrix : public named_dmatrix
01559 {
01560 public:
01561   data_matrix(void) : named_dmatrix() {;}
01562   data_matrix& operator=(const dmatrix& m);
01563   data_matrix& operator=(const double& m);
01564 private:
01565   void allocate(int rmin,int rmax,int cmin,int cmax,
01566     const char * = "UNNAMED");
01567   void allocate(int rmin, int rmax, const ivector& cmin, const ivector& cmax,
01568     const char * = "UNNAMED");
01569   void allocate(int rmin, int rmax, const ivector& cmin, int cmax,
01570     const char * = "UNNAMED");
01571   void allocate(int rmin, int rmax, int cmin, const ivector& cmax,
01572     const char * = "UNNAMED");
01573   void allocate(init_xml_doc&, const char * = "UNNAMED");
01574   friend class model_data;
01575 };
01576 
01581 class dll_data_matrix : public data_matrix
01582 {
01583   double * d;
01584 public:
01585   void allocate(double * _d,int rmin,int rmax,int cmin,int cmax,
01586     const char * _s = "UNNAMED");
01587   virtual ~dll_data_matrix();
01588   dll_data_matrix& operator=(const dmatrix &m);
01589   dll_data_matrix& operator=(const double &m);
01590 };
01591 
01596 class data_3array : public named_d3_array
01597 {
01598 public:
01599   data_3array(void) : named_d3_array() {;}
01600 private:
01601   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
01602     const char * ="UNNAMED");
01603   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
01604     int cmin,int cmax,const char * ="UNNAMED");
01605   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
01606     int cmin,int cmax,const char * ="UNNAMED");
01607   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
01608     int cmin,int cmax,const char * ="UNNAMED");
01609   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
01610     int cmax, const char * ="UNNAMED");
01611   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
01612                 const ivector& cmax, const char * ="UNNAMED");
01613   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
01614                 const ivector& cmax, const char * ="UNNAMED");
01615   void allocate(int hsl,int hsu, const index_type& rmin, const index_type& rmax,
01616     const index_type& cmin, const index_type& cmax, const char * ="UNNAMED");
01617   friend class model_data;
01618 };
01619 
01620 class data_3iarray : public named_i3_array
01621 {
01622   data_3iarray(void) : named_i3_array() {;}
01623   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
01624     const char * ="UNNAMED");
01625   void allocate(int hsl, int hsu,const index_type& rmin, const index_type& rmax,
01626     const index_type& cmin, const index_type& cmax, const char * ="UNNAMED");
01627   friend class model_data;
01628 };
01629 
01634 class dll_data_3array : public data_3array
01635 {
01636   double * d;
01637 public:
01638   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
01639     int cmin,int cmax,const char * _s = "UNNAMED");
01640   dll_data_3array& operator=(const d3_array &);
01641   virtual ~dll_data_3array();
01642   friend class model_data;
01643 };
01644 
01645 
01650 class data_5array : public named_d5_array
01651 {
01652   data_5array(void) : named_d5_array() {;}
01653   void allocate(int hhsl,int hhsu,
01654     int hhhsl,int hhhsu,
01655     int hsl,int hsu,int rmin,int rmax,
01656     int cmin,int cmax,const char * ="UNNAMED");
01657   void allocate(ad_integer hhhsl, ad_integer hhhsu, const index_type& hhsl,
01658     const index_type& hhsu, const index_type& hsl, const index_type& hsu,
01659     const index_type& rmin, const index_type& rmax, const index_type& cmin,
01660     const index_type& cmax, const char * ="UNNAMED");
01661   friend class model_data;
01662 };
01663 
01668 class data_4array : public named_d4_array
01669 {
01670   data_4array(void) : named_d4_array() {;}
01671   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
01672     int cmin,int cmax,const char * ="UNNAMED");
01673   void allocate(ad_integer hhsl, ad_integer hhsu, const index_type& hsl,
01674     const index_type& hsu, const index_type& rmin, const index_type& rmax,
01675     const index_type& cmin, const index_type& cmax, const char * ="UNNAMED");
01676   friend class model_data;
01677 };
01678 
01679 class data_4iarray : public named_i4_array
01680 {
01681   data_4iarray(void) : named_i4_array() {;}
01682   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
01683     int cmin,int cmax,const char * ="UNNAMED");
01684   void allocate(ad_integer hhsl, ad_integer hhsu, const index_type& hsl,
01685     const index_type& hsu, const index_type& rmin, const index_type& rmax,
01686     const index_type& cmin, const index_type& cmax, const char * ="UNNAMED");
01687   friend class model_data;
01688 };
01689 
01694 class data_imatrix : public named_imatrix
01695 {
01696   data_imatrix(void) : named_imatrix() {;}
01697   void allocate(int rmin,int rmax,int cmin,int cmax,const char * ="UNNAMED");
01698   void allocate(int rmin, int rmax, const index_type&, const index_type& cmax,
01699     const char * ="UNNAMED");
01700   friend class model_data;
01701 };
01702 
01707 class data_vector : public named_dvector
01708 {
01709 public:
01710   data_vector& operator=(const dvector& m);
01711   data_vector& operator=(const double m);
01712   data_vector(void) : named_dvector() {;}
01713 private:
01714   void allocate(int imin,int imax,const char * ="UNNAMED");
01715   void allocate(int imin, const ivector& imax, const char * ="UNNAMED");
01716   void allocate(init_xml_doc&, const char * ="UNNAMED");
01717   friend class model_data;
01718 };
01719 
01724 class dll_data_vector : public data_vector
01725 {
01726 public:
01727   double * pd;
01728   void allocate(double * pd,int imin,int imax,const char * ="UNNAMED");
01729   void allocate(double *pd, int imin, const ivector& imax,
01730     const char * ="UNNAMED");
01731   virtual ~dll_data_vector();
01732   dll_data_vector& operator = (const dvector& x);
01733   dll_data_vector& operator = (const double& x);
01734 };
01735 
01740 class data_ivector : public named_ivector
01741 {
01742 public:
01743   data_ivector(void) : named_ivector() {;}
01744 private:
01745   void allocate(int imin,int imax,const char * ="UNNAMED");
01746   friend class model_data;
01747 };
01748 
01753 class data_number : public model_name_tag
01754 {
01755 protected:
01756   double val;
01757   void allocate(const char * ="UNNAMED");
01758 public:
01759   void report_value(void);
01760   operator double() {return val;}
01761   double& value(void) {return val;}
01762   void initialize(void) {val=0.0;}
01763   friend class model_data;
01764   data_number & operator=(const double& m);
01765 };
01766 
01771 class dll_data_number : public data_number
01772 {
01773 public:
01774   double * pd;
01775   void allocate(double *_pd,const char * s);
01776   virtual ~dll_data_number();
01777   dll_data_number & operator=(const double& m);
01778 };
01779 
01780 typedef dvariable (model_parameters::*PMF) (const dvariable&);
01781 typedef dvariable (model_parameters::*PMFI) (const dvariable&,int n);
01782 typedef dvariable (model_parameters::*PMFVI) (const dvar_vector&,int n);
01783 typedef void (model_parameters::*PMFVIV4) (const dvar_vector&,int n,
01784   dvariable& f1, const dvariable& f2, const dvariable& f3, const dvariable& f4);
01785 
01786   class init_df1b2vector;
01787   class df1b2vector;
01788   class df1b2variable;
01789 
01794 class function_minimizer
01795 {
01796 public:
01797   static int bad_step_flag;
01798   static int likeprof_flag;
01799   static int first_hessian_flag;
01800   static int test_trust_flag;
01801   static int random_effects_flag;
01802   dmatrix * negdirections;
01803   static int negative_eigenvalue_flag;
01804   static int inner_opt_flag;
01805   static int inner_opt(void);
01806   laplace_approximation_calculator * lapprox;
01807   dvector * multinomial_weights;
01808   void set_multinomial_weights(dvector&d);
01809   //init_df1b2vector* py;
01810   virtual void AD_uf_inner();
01811   virtual void AD_uf_outer();
01812   virtual void user_function();
01813   void pre_user_function(void);
01814   //void df1b2_pre_user_function(void);
01815   //virtual void user_function(const init_df1b2vector& x,df1b2variable& f);
01816   //static int hesstype;
01817   //int set_hessian_type(int);
01818   void hess_routine_noparallel_randomeffects(void);
01819   void other_separable_stuff_begin(void);
01820   void other_separable_stuff_end(void);
01821   void begin_df1b2_funnel(void){;}
01822   void setup_quadprior_calcs(void){;}
01823   void end_df1b2_funnel(void){;}
01824   void get_function_difference(void);
01825   void start_get_importance_sampling_comnponent(void);
01826   void end_get_importance_sampling_comnponent(void);
01827   int spminflag;
01828   int repeatminflag;
01829   int mcmc2_flag;
01830   int robust_hybrid_flag;
01831   long ifn;
01832   int maxfn;
01833   int iprint;
01834   double crit;
01835   int imax;
01836   double dfn;
01837   long iexit;
01838   long ihflag;
01839   long ihang;
01840   int scroll_flag;
01841   int maxfn_flag;
01842   int quit_flag;
01843   double min_improve;
01844   void pre_userfunction(void);
01845   virtual void userfunction(void)=0;
01846   virtual void allocate() {}
01847   virtual void deallocate() {}
01848   static named_dvar_vector * ph;
01849   static named_dvar_vector * pg;
01850 protected:
01851   double ffbest;
01852 private:
01853   gradient_structure * pgs;
01854   adstring_array param_labels;
01855   ivector param_size;
01856 protected:
01857   void report_function_minimizer_stats(void){;}
01858   virtual void report(const dvector& gradients){;};
01859   static dvector convergence_criteria;
01860   static dvector maximum_function_evaluations;
01861   static int sd_flag;
01862   static adstring user_data_file;
01863   static adstring user_par_file;
01864   static int have_constraints;
01865 public:
01866   virtual dvariable user_randeff(const dvar_vector& x);
01867   virtual dvar_vector user_dfrandeff(const dvar_vector& x);
01868   virtual dvar_matrix user_d2frandeff(const dvar_vector& x);
01869   void limited_memory_quasi_newton(const independent_variables&,int);
01870   void limited_memory_quasi_newton(const independent_variables&,int,int);
01871   void limited_memory_quasi_newton(double& f, const independent_variables&,
01872     int, int, int,double);
01873   function_minimizer(long int sz=0L);
01874   void likeprof_routine(double global_min);
01875   virtual ~function_minimizer();
01876   virtual void other_calculations(void){;}
01877   virtual void final_calcs(void){;}
01878   virtual void minimize(void);
01879   virtual void constraints_minimize(void);
01880   virtual void between_phases_calculations(void){;}
01881   void computations(int argc,char * argv[]);
01882   void computations1(int argc,char * argv[]);
01883   void computations_np(int argc,char * argv[]);
01884   void computations(void);
01885   void hess_routine(void);
01886   void hess_routine_noparallel(void);
01887   void hess_routine_master(void);
01888   void hess_routine_slave(void);
01889   void constraint_report(void);
01890   void pvm_slave_likeprof_routine(void);
01891   void pvm_master_function_evaluation_profile(double& f,
01892     independent_variables& x,const dvector & g,int nvar,int iprof,double weight,
01893     double new_value);
01894   void pvm_slave_prof_minimize(int underflow_flag);
01895   void pvm_master_prof_minimize(int iprof, double sigma,
01896     double new_value, const double& _fprof, const int underflow_flag,
01897     double global_min, const double& _penalties,
01898     const double& _final_weight);
01899   //void pvm_master_function_evaluation_profile(double& f,
01900    // independent_variables& x,dvector & g,int nvar,int iprof);
01901   void pvm_slave_function_evaluation(void);
01902   void pvm_slave_function_evaluation_no_derivatives(void);
01903   void pvm_slave_function_evaluation_noder(void);
01904   void pvm_master_function_evaluation_no_derivatives(double& f,
01905     independent_variables& x,int nvar);
01906   void pvm_master_function_evaluation(double& f,
01907     independent_variables& x,const dvector & g,int nvar);
01908   dmatrix dep_hess_routine(const dvariable& dep);
01909   void top_mcmc_routine(int,int,double,int);
01910   void mcmc_routine(int,int,double,int);
01911   void sgibbs_mcmc_routine(int,int,double,int);
01912   void hybrid_mcmc_routine(int,int,double,int);
01913   double pvm_master_get_monte_carlo_value(int nvar,
01914     const dvector& x);
01915   void pvm_slave_get_monte_carlo_value(int nvar);
01916   void mcmc_eval(void);
01917   //void hess_routine_and_constraint(int);
01918   void hess_routine_and_constraint(int iprof, const dvector& g,
01919     dvector& fg);
01920   dmatrix diag_hess_routine(void);
01921   void hess_inv(void);
01922   void depvars_routine(void);
01923   void sd_routine(void);
01924   int ef_(double * f, double * x);
01925   int constrained_minimization2(int _n,int _nh, int _ng,dvector& __x);
01926   static int constraint_exit_number;
01927   void get_bigS(int ndvar,int nvar1,int nvar,
01928     dmatrix& S,dmatrix& BS,dvector& scale);
01929 
01930 #ifdef CURVE_CORRECT
01931   void constraint_hess_routine(int ip);
01932   void get_curvature_correction_factors(int ip,
01933     dvector& g, const int underflow_flag, const dvector& eigenvals,
01934     dvector& curvcor);
01935 #endif
01936   double projected_jacobian(const dvector& g, const dvector& xscale);
01937 
01938   dvariable random_effects_maximization(const dvar_vector& v);
01939   void prof_minimize_re(int iprof, double sigma,
01940     double new_value, const double& fprof, const int underflow_flag,
01941     double global_min, const double& penalties, const double& final_weight);
01942   void prof_minimize(int iprof, double sigma,
01943     double new_value, const double& fprof, const int underflow_flag,
01944     double global_min, const double& penalties, const double& final_weight);
01945   void begin_gauss_hermite_stuff(void);
01946   void begin_funnel_stuff(void);
01947   void end_gauss_hermite_stuff(void);
01948 
01949   void prof_hess_routine(int ip,double new_value,double final_weight);
01950 
01951   void quasi_newton_minimizer1(int nvar,double _crit,
01952     double& f, const independent_variables& x,const dvector& g);
01953 
01954   double hess_determinant(int underflow_flag);
01955 
01956 #ifndef CURVE_CORRECT
01957   void normalize_posterior_distribution(double udet,
01958     const dvector& siglevel, const ofstream& ofs2, int num_pp,
01959     const dvector& all_values, const dmatrix& actual_value, double global_min,
01960     int offset, const dmatrix& lprof, const dmatrix& ldet, const dmatrix& xdist,
01961     const dmatrix& penalties);
01962   //  dmatrix& penalties, const hdmatrix& lg_jacob);
01963 #else
01964   void normalize_posterior_distribution(double udet,
01965     const dvector& siglevel, const ofstream& ofs2, int num_pp,
01966     const dvector& all_values, const dmatrix& actual_value,
01967     double global_min,
01968     int offset, const dmatrix& lprof, const dmatrix& ldet,
01969     const dmatrix& xdist,
01970     const d3_array& eigenvals,d3_array& curvcor);
01971 #endif
01972   void get_particular_grad(int iprof, int nvar, const dvector& fg,
01973     const dvector& g);
01974   double projected_hess_determinant(const dvector& g, const int underflow_flag,
01975     const dvector& xscale, const double& ln_det_proj_jac);
01976 //  double projected_hess_determinant(const dvector& fg, const dvector& g,
01977   //const int underflow_flag, const dvector& xscale,
01978   // const double& ln_det_proj_jac);
01979   double projected_hess_determinant(const dvector& g,const int underflow_flag);
01980   double projected_hess_determinant(const dmatrix& hh, const dvector& g,
01981     const int underflow_flag);
01982  //double projected_hess_determinant(const dvector& g, const int underflow_flag,
01983     //dvector& xscale, const double& ln_det_proj_jac);
01984 
01985   double projected_hess_determinant(const dvector& fg, const dvector& g,
01986     const int underflow_flag, const dvector& curvscale, const dvector& xscale,
01987     double& ln_det_proj_jac, const double& tmp, const dmatrix& hesses);
01988   double diag_projected_hess_determinant(const dvector& g,
01989     const int underflow_flag, dmatrix& dh);
01990     double unrestricted_hess_determinant(void);
01991   void monte_carlo_routine(void);
01992   double get_monte_carlo_value(int nvar, const independent_variables& x);
01993   double get_monte_carlo_value(int nvar, const independent_variables& x,
01994     dvector& g);
01995   double get_hybrid_monte_carlo_value(int nvar,const independent_variables& x,
01996     dvector& g);
01997   void mcmc_computations(void);
01998 #if defined(USE_ADPVM)
01999   void pvm_slave_mcmc_computations(void);
02000   void pvm_master_mcmc_computations(void);
02001 #endif
02002   double get_monte_carlo_value(int nvar, const dvector& x);
02003   void sob_routine(int nmcmc,double dscale,int restart_flag);
02004   void sobol_importance_routine(int nmcmc,int iseed0,double dscale,
02005   int restart_flag);
02006   void pvm_master_mcmc_routine(int nmcmc,int iseed0,double dscale,
02007     int restart_flag);
02008 #if defined(USE_ADPVM)
02009   void pvm_slave_mcmc_routine(void);
02010 #else
02011   void pvm_slave_mcmc_routine(void) {}
02012 #endif
02013   void trust_region_update(int nvar,int _crit,
02014     independent_variables& x,const dvector& _g,const double& _f);
02015 
02016   void multint4(int n, const dvar_vector& a, const dvar_vector& b,
02017     const dvar_vector& h, double al, int m, const dvariable& e,
02018     const dvariable& aint1, const dvariable& aint2, dvariable& aint3,
02019     const dvariable& aint4, const int& key, PMFVIV4 f);
02020 
02021   void multint(int n, const dvar_vector& a, const dvar_vector& b,
02022     const dvar_vector& h, double al, int m, const dvariable& e,
02023     const dvariable& aint, const int& key, PMFVI f);
02024 
02025   virtual void set_runtime(void);
02026   virtual void set_runtime_maxfn(const char *);
02027   virtual void set_runtime_crit(const char *);
02028   dvariable adromb(PMF,double a,double b,int ns=9);
02029   dvariable adromb(PMF, const dvariable& a, double b, int ns = 9);
02030   dvariable adromb(PMF, const dvariable& a, const dvariable& b, int ns = 9);
02031   dvariable adromb(PMF, double a, const dvariable& b, int ns = 9);
02032 
02033   dvariable adrombo(PMF,double a,double b,int ns=9);
02034   dvariable adrombo(PMF, const dvariable& a, double b, int ns = 9);
02035   dvariable adrombo(PMF, const dvariable& a, const dvariable& b, int ns = 9);
02036   dvariable adrombo(PMF, double a, const dvariable& b,int ns = 9);
02037 
02038   dvariable trapzd(void*,double a,double b,int n);
02039   dvariable trapzd(PMF,double a,double b,int n);
02040   dvariable trapzd(PMF, double a, const dvariable& b, int n);
02041   dvariable trapzd(PMF, const dvariable& a, double b, int n);
02042   dvariable trapzd(PMF, const dvariable& a, const dvariable& b, int n);
02043 
02044   dvariable midpnt(PMF,double a,double b,int n);
02045   dvariable midpnt(PMF, double a, const dvariable& b, int n);
02046   dvariable midpnt(PMF, const dvariable& a, double b, int n);
02047   dvariable midpnt(PMF, const dvariable& a, const dvariable& b, int n);
02048 
02049   virtual void * mycast() { return (void*)this;}
02050 
02051   void neldmead(int n, dvector& _start, dvector& _xmin, double *ynewlo,
02052     double reqmin, double delta,int *icount, int *numres, int *ifault);
02053   void adamoeba(const dmatrix& p, const dvector& y, int ndim, double ftol,
02054      int maxfn);
02055   void set_initial_simplex(const dmatrix& p, const dvector& y, int nvar,
02056     const dvector& x, double delta);
02057   double amxxx(const dmatrix& p, const dvector& y, const dvector& psum,
02058     int ndim, int ihi, double fac);
02059   friend class equality_constraint_vector;
02060   friend class inequality_constraint_vector;
02061   void quasi_newton_block(int nvar,int crit,independent_variables& x,
02062     const dvector& g,const double& f);
02063   void limited_memory_quasi_newton_block(int nvar,int _crit,
02064     independent_variables& x,const dvector& _g,const double& _f,
02065     int nsteps);
02066 
02067   void function_evaluation_block_pvm_slave_random_effects(int nvar,int _crit,
02068     independent_variables& x,const dvector& g,const double& f);
02069   void quasi_newton_block_pvm_master_random_effects(int nvar,int _crit,
02070     independent_variables& x,const dvector& g,const double& f);
02071   void function_evaluation_block_pvm_slave_random_effects(void);
02072   void hess_routine_random_effects(void);
02073   void quasi_newton_block_pvm_master(int nvar,int _crit,
02074     independent_variables& x,const dvector& g,const double& f);
02075   void hess_routine_noparallel_random_effects(void);
02076 #if defined(USE_ADPVM)
02077   void function_evaluation_block_pvm_slave(void);
02078   void hess_routine_slave_random_effects(void);
02079 #endif
02080   dvariable do_gauss_hermite_integration(void);
02081   void end_df1b2_funnel_stuff(void);
02082 
02083 private:
02084   dvariable do_gauss_hermite_integration_multi(void);
02085 };
02086 
02087 cifstream& operator>>(const cifstream& s, const param_init_number& x);
02088 cifstream& operator>>(const cifstream& s, const param_init_vector& v);
02089 cifstream& operator>>(const cifstream& s, const param_init_matrix& m);
02090 ostream& operator<<(const ostream& s, const label_class& lc);
02091 
02096 class stddev_params
02097 {
02098 public:
02099   // this should be a resizeable array
02100   static stddev_params * stddevptr[150];
02101   // this should be a resizeable array
02102   static stddev_params * stddev_number_ptr[150];
02103   static void get_all_sd_values(const dvector& x, const int& ii);
02104   static int num_stddev_params;
02105   static int num_stddev_number_params;
02106   static ivector copy_all_number_offsets(void);
02107   void allocate(void){;};
02108   static int num_stddev_calc(void);
02109   static int num_stddev_number_calc(void);
02110   static void get_stddev_number_offset(void);
02111 public:
02112   stddev_params(void){;}
02113   virtual void setindex(int);
02114   virtual int getindex(void);
02115   virtual int size_count(void)=0; // get the number of active parameters
02116   virtual void set_dependent_variables(void)=0;
02117   virtual void copy_value_to_vector(const dvector&,const int&) = 0;
02118   virtual void get_sd_values(const dvector& x, const int& ii) = 0;
02119   //get the number of active parameters
02120   static void copy_all_values(const dvector& x, const int& ii);
02121   //get the number of active parameters
02122   static void copy_all_number_values(const dvector& x, const int& ii);
02123   virtual void add_to_list(void);
02124   virtual void add_to_gui_list(void);
02125   virtual const char * label()=0;
02126   friend class function_minimizer;
02127 };
02128 
02133 class likeprof_params
02134 {
02135   double stepsize;
02136   int    stepnumber;
02137 protected:
02138 public:
02139   static likeprof_params * likeprofptr[500]; // this should be a
02140                                                // resizeable array
02141   static int num_likeprof_params;
02142   void allocate(void){;};
02143   static int num_stddev_calc(void);
02144 public:
02145   likeprof_params(void);
02146   virtual void add_to_list(void);
02147   virtual const char * label()=0;
02148   virtual dvariable variable(void)=0;
02149   virtual double& get_sigma(void)=0;
02150   virtual double get_value(void)=0;
02151   double get_stepsize(void);
02152   int get_stepnumber(void);
02153   void set_stepsize(double);
02154   void set_stepnumber(int);
02155   friend class function_minimizer;
02156 };
02157 
02162 class param_stddev_vector: public named_dvar_vector , stddev_params
02163 {
02164   dvector sd;
02165     virtual int size_count(void); // get the number of active parameters
02166     virtual const char * label(void);
02167     param_stddev_vector();
02168     void allocate(int imin,int imax,const char * s="UNNAMED");
02169     virtual void set_dependent_variables(void);
02170     friend class model_parameters;
02171     virtual void copy_value_to_vector(const dvector& x, const int& ii);
02172     virtual void get_sd_values(const dvector& x, const int& ii);
02173   param_stddev_vector& operator=(const dvar_vector& m);
02174   param_stddev_vector& operator=(const dvector& m);
02175   param_stddev_vector& operator=(const double m);
02176 };
02177 
02182 class param_stddev_number: public named_dvariable , public stddev_params
02183 {
02184   double sd;
02185   int index;
02186   void allocate(const char *s="UNNAMED");
02187   virtual void setindex(int);
02188   virtual int getindex(void);
02189   virtual int size_count(void); // get the number of active parameters
02190   virtual const char * label(void);
02191   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02192   virtual void get_sd_values(const dvector& x, const int& ii);
02193 protected:
02194   param_stddev_number();
02195   friend class model_parameters;
02196   virtual void set_dependent_variables(void);
02197   param_stddev_number& operator=(const prevariable&);
02198   param_stddev_number& operator=(const double);
02199 };
02200 
02205 class param_likeprof_number: public param_stddev_number ,
02206     public likeprof_params
02207 {
02208     double sigma;
02209     void allocate(const char *s="UNNAMED");
02210     virtual int size_count(void); // get the number of active parameters
02211     virtual const char * label(void);
02212     virtual double& get_sigma(void){return sigma;}
02213     virtual double get_value(void){return value(*this);}
02214     //void copy_value_to_vector(const dvector& x, const int& ii);
02215     virtual dvariable variable(void){ return dvariable(*this);}
02216     param_likeprof_number();
02217     friend class model_parameters;
02218 public:
02219     param_likeprof_number& operator=(const prevariable&);
02220     param_likeprof_number& operator=(const double);
02221 };
02222 
02227 class param_stddev_matrix: public named_dvar_matrix , stddev_params
02228 {
02229   dmatrix sd;
02230     virtual int size_count(void);
02231     //virtual void read_value(void);
02232     virtual const char * label(void);
02233     void allocate(int rmin,int rmax,int cmin,int cmax,
02234     const char * s="UNNAMED");
02235   param_stddev_matrix(void);
02236   friend class model_parameters;
02237   virtual void set_dependent_variables(void);
02238   virtual void get_sd_values(const dvector& x, const int& ii);
02239   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02240   param_stddev_matrix& operator=(const double m);
02241   param_stddev_matrix& operator=(const dmatrix& m);
02242   param_stddev_matrix& operator=(const dvar_matrix& m);
02243 };
02244 
02249   class objective_function_value : public named_dvariable
02250   {
02251   public:
02252     static objective_function_value * pobjfun;
02253     static double fun_without_pen;
02254     static double gmax;
02255     objective_function_value();
02256     objective_function_value& operator=(const prevariable& v);
02257     objective_function_value& operator=(const double v);
02258   };
02259 
02260   int withinbound(int lb,int n,int ub);
02261 
02262 double cumd_cauchy(const double& x);
02263 double density_cauchy(const double& x);
02264 double log_density_cauchy(const double& x);
02265 double inv_cumd_cauchy(const double& x);
02266 
02267 double cumd_mixture(const double& x);
02268 double inv_cumd_mixture(const double& y);
02269 double cumd_mixture_02(const double& x);
02270 double inv_cumd_mixture_02(const double& y);
02271 
02272 #if defined _ADM_HIGHER_ARRAYS__
02273 
02278 class param_init_matrix: public named_dvar_matrix, public initial_params
02279 {
02280   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
02281 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
02282 //  const int& ii);
02283   virtual void add_value(const dvector&, const dvector&, const int&,
02284     const double&, const dvector&);
02285   virtual void add_value(const dvector&, const int&);
02286   virtual void get_jacobian(const dvector&, const dvector&, const int&);
02287 public:
02288   virtual void set_value(const dvar_vector& x, const int& ii,
02289     const dvariable& pen);
02290   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02291   virtual void restore_value_from_vector(const dvector&, const int&);
02292   virtual void set_value_inv(const dvector& x, const int& ii);
02293   virtual int size_count(void);
02294   virtual void save_value(ofstream& ofs);
02295   virtual void bsave_value(uostream& uos);
02296   virtual void save_value(const ofstream& ofs, int prec);
02297   virtual void restore_value(const ifstream& ifs);
02298   void report_value(void);
02299   //virtual void read_value(void);
02300   virtual const char * label(void);
02301   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
02302   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
02303   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
02304   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){;};
02305 
02306 public:
02307   void allocate(int rmin,int rmax,int cmin,int cmax,
02308     int phase_start=1,const char * = "UNNAMED");
02309   void allocate(int rmin,int rmax,int cmin,int cmax,
02310     const char * = "UNNAMED");
02311   param_init_matrix(void);
02312   param_init_matrix& operator = (const dmatrix& m);
02313   param_init_matrix& operator = (const dvar_matrix& m);
02314   param_init_matrix& operator = (const dvariable& m);
02315   param_init_matrix& operator = (const double& m);
02316 };
02317 #endif // #if defined _ADM_HIGER_ARRAYS__
02318 
02323 class param_init_d3array: public named_dvar3_array, public initial_params
02324 {
02325 public:
02326 #if defined(USE_SHARE_FLAGS)
02327   virtual void setshare(const index_type& sf,const index_type& af);
02328   virtual void shared_set_value_inv(const dvector&,const int&);
02329   virtual void shared_set_value(const dvar_vector&,const int&,
02330     const dvariable& pen);
02331   virtual int shared_size_count(void); // get the number of active parameters
02332 #endif
02333 
02334   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,
02335     const int& ii);
02336   virtual void dev_correction(const dmatrix&, const int&);
02337   virtual void curv_scale(const dvector& d, const dvector& x, const int& ii);
02338   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
02339 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds,
02340 //  const int& ii);
02341   virtual void add_value(const dvector&, const dvector&, const int&,
02342     const double&, const dvector&);
02343   virtual void add_value(const dvector&, const int&);
02344   virtual void get_jacobian(const dvector&, const dvector&, const int&);
02345   virtual void set_value(const dvar_vector& x, const int& ii,
02346     const dvariable& pen);
02347   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02348   virtual void restore_value_from_vector(const dvector&,const int&);
02349   virtual void set_value_inv(const dvector& x, const int& ii);
02350   virtual int size_count(void);
02351   virtual void save_value(ofstream& ofs);
02352   virtual void bsave_value(uostream& uos);
02353   virtual void save_value(const ofstream& ofs, int prec);
02354   virtual void save_value(const ofstream& ofs, int prec,const dvector&,
02355     int& offset){}
02356   virtual void restore_value(const ifstream& ifs);
02357   void report_value(void);
02358   //virtual void read_value(void);
02359   virtual const char * label(void);
02360   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
02361   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
02362   virtual void hess_scale(const dvector& d, const dvector& x, const  int& ii);
02363 
02364 public:
02365 #if defined(USE_ADPVM)
02366   virtual void pvm_pack(void) { cerr << "Error" << endl; ad_exit(1);}
02367   virtual void pvm_unpack(void) { cerr << "Error" << endl; ad_exit(1);}
02368 #endif
02369 
02370   void allocate(const ad_integer& sl,const ad_integer& sh,
02371     const index_type& nrl,const index_type& nrh,
02372     const index_type& ncl,const index_type& nch,const char * s="UNNAMED");
02373 
02374   void allocate(const ad_integer& sl,const ad_integer& sh,
02375     const index_type& nrl,const index_type& nrh,
02376     const index_type& ncl,const index_type& nch,int phase_start=1,
02377     const char * s="UNNAMED");
02378 
02379   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
02380     int phase_start=1,const char * = "UNNAMED");
02381   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
02382     const char * = "UNNAMED");
02383   param_init_d3array(void);
02384 };
02385 
02390 class dll_param_init_d3array: public param_init_d3array
02391 {
02392   double * d;
02393 public:
02394   void allocate(double* _d,int hmin,int hmax,
02395     int rmin,int rmax,int cmin,int cmax,
02396     int phase_start=1,const char * = "UNNAMED");
02397   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
02398     int cmin,int cmax,const char * = "UNNAMED");
02399   virtual ~dll_param_init_d3array();
02400   dll_param_init_d3array(){d=NULL;}
02401   dll_param_init_d3array& operator=(const d3_array&);
02402   dll_param_init_d3array& operator=(const dvar3_array&);
02403 };
02404 
02409 class dll_param_d3array: public named_dvar3_array
02410 {
02411   double * d;
02412 public:
02413   void allocate(double* _d,int hmin,int hmax,
02414     int rmin,int rmax,int cmin,int cmax,
02415     int phase_start=1,const char * = "UNNAMED");
02416   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
02417     int cmin,int cmax,const char * = "UNNAMED");
02418   virtual ~dll_param_d3array();
02419   dll_param_d3array(){d=NULL;}
02420   dll_param_d3array& operator=(const d3_array&);
02421   dll_param_d3array& operator=(const dvar3_array&);
02422 };
02423 
02424 
02425 //double set_value_mc(const double& x, const double fmin, const double fmax);
02426 
02427 void set_value_mc(const dvar_vector& x, const dvar_vector& v, const int& ii,
02428   const double fmin, const double fmax);
02429 
02430 double set_value_inv_mc(double v,double fmin,double fmax);
02431 
02432 double set_value_inv_mc(const prevariable& v, double fmin, double fmax);
02433 
02434 void set_value_inv_mc(const dvar_vector& x, const dvector& v, const int& ii,
02435   const double fmin, const double fmax);
02436 
02437 //double set_value_inv_mc(const dvector&, const dvector& x, int ii, double minb,
02438 //  double maxb);
02439 
02440 double set_value_mc(double z,double min,double max);
02441 double ndfboundp( double x, double fmin, double fmax,const double& fpen);
02442 double ndfboundp_mc( double x, double fmin, double fmax,const double& fpen);
02443 
02444 void copy_value_from_vector(const double& _sd,const dvector& x,const int & _ii);
02445 void copy_value_from_vector(const dvector& _sd,const dvector& x,
02446   const int & _ii);
02447 void copy_value_from_vector(const dmatrix& _sd,const dvector& x,
02448   const int & _ii);
02449 
02450 dvector bounded_multivariate_normal(int nvar, const dvector& a1,
02451   const dvector& b1, dmatrix& ch, const double& _wght,
02452   const random_number_generator & rng);
02453 
02454 void bounded_multivariate_normal_mcmc(int nvar, const dvector& a1,
02455   const dvector& b1, dmatrix& ch, const double& wght, const dvector& y,
02456   const random_number_generator & rng);
02457 
02458 void bounded_multivariate_uniform_mcmc(int nvar, const dvector& a1,
02459   const dvector& b1, dmatrix& ch, const double& wght, const dvector& y,
02460   const random_number_generator & rng);
02461 
02462 dvector bounded_multivariate_normal(int nvar, const dvector& a1,
02463   const dvector& b1, dmatrix& ch, const double& lprob,
02464   random_number_generator &rng);
02465 
02466 dvector bounded_multivariate_normal_sobol(int nvar, const dvector& a1,
02467   const dvector& b1, dmatrix& ch, const double& lprob,
02468   const random_number_generator &rng);
02469 
02470 dvector probing_bounded_multivariate_normal(int nvar, const dvector& a1,
02471   const dvector& b1, dmatrix& ch, const double& lprob, double pprobe,
02472   const random_number_generator &rng);
02473 
02474 dvector bounded_multivariate_uniform(int nvar, const dvector& a1,
02475   const dvector& b1, dmatrix& ch, const double& lprob,
02476   random_number_generator &rng);
02477 
02478 dvector bounded_robust_multivariate_normal(int nvar, const dvector& a1,
02479   const dvector& b1, dmatrix& ch, const dmatrix& ch3, double contaminant,
02480   const double& _wght, random_number_generator &rng);
02481 
02482 void probing_bounded_multivariate_normal_mcmc(int nvar, const dvector& a1,
02483   const dvector& b1, dmatrix& ch, const double& wght, const dvector& v,
02484   double pprobe, const random_number_generator &rng);
02485 
02486 /*
02487 int option_match(int argc,char * argv[], const char * string);
02488 int option_match(int argc,char * argv[], const char * string, const int& nopt);
02489 int option_match(char * s, const char * string, const int& _nopt);
02490 int option_match(char * s, const char * string);
02491 */
02492 
02493 double inv_cumd_exp(double x);
02494 double cumd_exp(double x);
02495 
02496 double ffmax(double a,double b);
02497 double ffmin(double a,double b);
02498 
02499 void check_datafile_pointer(void * p);
02500 
02501 adstring get_reportfile_name(void);
02502 
02503 void ad_make_code_reentrant(void);
02504 
02505 char** parse_dll_options(char *pname, const int& argc,
02506   char * dll_options);
02507 
02508 void parse_dll_options(char *pname, const int& argc, char *dll_options,
02509   char *** pargv);
02510 
02511 char** no_dll_options(char *pname, const int& argc);
02512 
02513 void cleanup_argv(int nopt,char *** pa);
02514 
02515 void get_sp_printf(void);
02516 
02517 void do_dll_housekeeping(int argc,char ** argv);
02518 
02519 void adwait(double);
02520 
02521 int ad_get_commandline_option(const char *option_label, const int &option_value,
02522   const char * error_message);
02523 
02528 class param_init_vector_vector
02529 {
02530   param_init_vector * v;
02531   int index_min;
02532   int index_max;
02533   double_index_type * it;
02534 
02535 public:
02536   param_init_vector_vector();
02537   ~param_init_vector_vector();
02538 
02539   void set_scalefactor(double s);
02540   void set_scalefactor(const dvector& s);
02541   dvector get_scalefactor(void);
02542 
02543 #if defined(OPT_LIB)
02544   param_init_vector& operator [] (int i) { return v[i];}
02545   param_init_vector& operator () (int i) { return v[i];}
02546   prevariable operator () (int i,int j) { return v[i][j];}
02547 #else
02548   param_init_vector& operator [] (int i);
02549   param_init_vector& operator () (int i);
02550   prevariable operator () (int i,int j);
02551 #endif
02552 
02553   void allocate(int min1,int max1,const index_type& min,
02554      const index_type& max,const index_type& phase_start,
02555      const char * s);
02556 
02557   void allocate(int min1,int max1,const index_type& min,
02558      const index_type& max,const char * s);
02559 
02560   bool allocated() const { return v != NULL; }
02561   int indexmin(void) {return (index_min);}
02562   int indexmax(void) {return (index_max);}
02563   void set_initial_value(const double_index_type& it);
02564   void deallocate(void);
02565 };
02566 
02571 class param_init_bounded_vector_vector
02572 {
02573   param_init_bounded_vector* v;
02574   int index_min;
02575   int index_max;
02576   double_index_type* it;
02577 public:
02578   param_init_bounded_vector_vector();
02579   ~param_init_bounded_vector_vector();
02580 
02581   void set_scalefactor(double s);
02582   void set_scalefactor(const dvector& s);
02583   dvector get_scalefactor(void);
02584 #if defined(OPT_LIB)
02585   param_init_bounded_vector& operator [] (int i) { return v[i];}
02586   param_init_bounded_vector& operator () (int i) { return v[i];}
02587   prevariable operator () (int i,int j) { return v[i][j];}
02588 #else
02589   param_init_bounded_vector& operator [] (int i);
02590   param_init_bounded_vector& operator () (int i);
02591   prevariable operator () (int i,int j);
02592 #endif
02593 
02594   void allocate(int min1,int max1,
02595     const index_type& min,
02596     const index_type& max,
02597     const double_index_type& dmin,
02598     const double_index_type& dmax,
02599     const index_type& phase_start,
02600     const char* s);
02601 
02602   void allocate(int min1,int max1,
02603     const index_type& min,
02604     const index_type& max,
02605     const double_index_type& dmin,
02606     const double_index_type& dmax,
02607     const char* s);
02608 
02609   bool allocated() const { return v != NULL; }
02610   int indexmin() const {return index_min;}
02611   int indexmax() const {return index_max;}
02612   void deallocate(void);
02613   void set_initial_value(const double_index_type& it);
02614 };
02615 
02620 class param_init_matrix_vector
02621 {
02622   param_init_matrix* v;
02623   int index_min;
02624   int index_max;
02625   double_index_type* it;
02626 
02627 public:
02628   param_init_matrix_vector();
02629    ~param_init_matrix_vector();
02630 
02631   void set_scalefactor(double s);
02632   void set_scalefactor(const dvector& s);
02633   dvector get_scalefactor(void);
02634 
02635 #if defined(OPT_LIB)
02636   param_init_matrix& operator [] (int i) { return v[i];}
02637   param_init_matrix& operator () (int i) { return v[i];}
02638   dvar_vector& operator () (int i,int j) { return v[i][j];}
02639   prevariable operator () (int i,int j,int k) { return v[i](j,k);}
02640 #else
02641   param_init_matrix& operator [] (int i);
02642   param_init_matrix& operator () (int i);
02643   dvar_vector& operator () (int i,int j);
02644   prevariable operator () (int i,int j,int k);
02645 #endif
02646   void allocate(int min0,int max0,const index_type& min,
02647      const index_type& max,const index_type& min1,
02648      const index_type& max1,const index_type& phase_start,
02649      const char * s);
02650 
02651   void allocate(int min0,int max0,const index_type& min,
02652      const index_type& max,const index_type& min1,
02653      const index_type& max1,const char * s);
02654 
02655   bool allocated() const { return v != NULL; }
02656   int indexmin() const { return index_min;}
02657   int indexmax() const { return index_max;}
02658   void set_initial_value(const double_index_type& it);
02659   void deallocate(void);
02660 };
02661 
02666 class param_init_bounded_matrix_vector
02667 {
02668   param_init_bounded_matrix * v;
02669   int index_min;
02670   int index_max;
02671   double_index_type * it;
02672 public:
02673   param_init_bounded_matrix_vector();
02674   ~param_init_bounded_matrix_vector();
02675 
02676   void set_scalefactor(double s);
02677   void set_scalefactor(const dvector& s);
02678   dvector get_scalefactor(void);
02679 
02680   void allocate(int min1,int max1,
02681     const index_type& min, const index_type& max, const index_type& min2,
02682     const index_type& max2, const double_index_type& dmin2,
02683     const double_index_type& dmax2, const index_type& phase_start,
02684     const char * s);
02685 
02686   void allocate(int min1,int max1,
02687     const index_type& min, const index_type& max, const index_type& min2,
02688     const index_type& max2, const double_index_type& dmin2,
02689     const double_index_type& dmax2,const char * s);
02690 
02691 #if defined(OPT_LIB)
02692   param_init_bounded_matrix& operator [] (int i) { return v[i];}
02693   param_init_bounded_matrix& operator () (int i) { return v[i];}
02694   dvar_vector& operator () (int i,int j) { return v[i][j];}
02695   prevariable operator () (int i,int j,int k) { return v[i](j,k);}
02696 #else
02697   param_init_bounded_matrix& operator [] (int i);
02698   param_init_bounded_matrix& operator () (int i);
02699   dvar_vector& operator () (int i,int j);
02700   prevariable operator () (int i,int j,int k);
02701 #endif
02702 
02703   bool allocated() const { return v != NULL; }
02704   int indexmin() const { return index_min; }
02705   int indexmax() const { return index_max; }
02706   void set_initial_value(const double_index_type& it);
02707   void deallocate(void);
02708 };
02709 
02714 class param_init_number_vector
02715 {
02716   param_init_number* v;
02717   int index_min;
02718   int index_max;
02719   double_index_type* it;
02720 public:
02721   param_init_number_vector();
02722   ~param_init_number_vector();
02723 
02724   void set_scalefactor(double s);
02725   void set_scalefactor(const dvector& s);
02726   dvector get_scalefactor(void);
02727 
02728 #if defined(OPT_LIB)
02729   param_init_number& operator[](int i) { return v[i];}
02730   param_init_number& operator()(int i) { return v[i];}
02731 #else
02732   param_init_number& operator[](int i);
02733   param_init_number& operator()(int i);
02734 #endif
02735 
02736   void allocate(int min1,int max1,const index_type& phase_start,
02737      const char * s);
02738 
02739   void allocate(int min1,int max1,const char * s);
02740 
02741   bool allocated() const { return v != NULL; }
02742   int indexmin() const { return index_min; }
02743   int indexmax() const { return index_max; }
02744   void set_initial_value(const double_index_type& it);
02745   void deallocate(void);
02746 };
02747 
02755  class data_matrix;
02756 class param_init_bounded_number_vector
02757 {
02758   param_init_bounded_number* v;
02759   int index_min;
02760   int index_max;
02761   double_index_type* it;
02762 public:
02763   param_init_bounded_number_vector();
02764   ~param_init_bounded_number_vector();
02765 
02766   void set_scalefactor(double s);
02767   void set_scalefactor(const dvector& s);
02768   dvector get_scalefactor(void);
02769 
02770 #if defined(OPT_LIB)
02771   param_init_bounded_number& operator [] (int i) { return v[i];}
02772   param_init_bounded_number& operator () (int i) { return v[i];}
02773 #else
02774   param_init_bounded_number& operator [] (int i);
02775   param_init_bounded_number& operator () (int i);
02776 #endif
02777 
02778   void allocate(int min1,int max1,const double_index_type & bmin,
02779     const double_index_type & bmax,const index_type& phase_start,
02780     const char * s);
02781 
02782   void allocate(int min1,int max1,const double_index_type & bmin,
02783      const double_index_type & bmax,const char * s);
02784 
02785   // Added by Steve Martell, Jan 18, 2014.
02786   void allocate(const data_matrix &m, const char *s);
02787 
02788   bool allocated() const { return v != NULL; }
02789   int indexmin() const { return (index_min); }
02790   int indexmax() const { return (index_max); }
02791   void set_initial_value(const double_index_type& it);
02792   void deallocate(void);
02793 };
02794   extern int traceflag;
02795   void tracing_message(int traceflag,const char *s,int *pn);
02796   void tracing_message(int traceflag,const char *s,double *pn);
02797   void set_gauss_covariance_matrix(const dll_data_matrix& m);
02798   void set_gauss_covariance_matrix(const dmatrix& m);
02799   void set_covariance_matrix(const dll_data_matrix& m);
02800   void set_covariance_matrix(const dmatrix& m);
02801 
02802   //ostream& operator<<(const ostream&, const param_init_number_vector);
02803   //ostream& operator<<(const ostream&, const param_init_bounded_number_vector);
02804   //ostream& operator<<(const ostream&, const param_init_vector_vector);
02805   //ostream& operator<<(const ostream&, const param_init_bounded_vector_vector);
02806   //ostream& operator<<(const ostream&, const param_init_matrix_vector);
02807   //ostream& operator<<(const ostream&, const param_init_bounded_matrix_vector);
02808 
02813   class vector_kludge : public dvar_vector
02814   {
02815     public:
02816      vector_kludge(const param_init_number_vector &);
02817      vector_kludge(const param_init_bounded_number_vector &);
02818   };
02823   class matrix_kludge : public dvar_matrix
02824   {
02825     public:
02826      matrix_kludge(const param_init_vector_vector &);
02827      matrix_kludge(const param_init_bounded_vector_vector &);
02828   };
02829 
02830 void read_covariance_matrix(const dmatrix& S, int nvar, int& hbf,
02831   dvector& sscale);
02832 
02833 dvector value(const param_init_number_vector& t);
02834 dvector value(const param_init_bounded_number_vector& t);
02835 //dvector value(const param_init_bounded_number_matrix& t);
02836 //dvector value(const param_init_vector_vector& t);
02837 //dvector value(const param_init_bounded_vector_vector& t);
02838 
02839 dvector read_old_scale(int & old_nvar);
02840 
02841 int withinbound(int lb,int n,int ub);
02842 
02843 #if defined(_MSC_VER)
02844 #  if defined(min)
02845 #    undef min
02846 #  endif
02847 #  if defined(max)
02848 #    undef max
02849 #  endif
02850 #endif
02851 
02852 #include "param_init_bounded_number_matrix.h"
02853 
02854 #endif