ADMB Documentation  11.1.1517
 All Classes Files Functions Variables Typedefs Friends Defines
mcmcvar.h
Go to the documentation of this file.
00001 /*
00002  * $Id: mcmcvar.h 1112 2013-07-12 21:41:41Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 //#define DO_PROFILE
00046 #if !defined(__MSVC32__)
00047   #if defined(__GNUC__)
00048     #if (__GNUC__ < 3)
00049       #pragma interface
00050     #endif
00051   #else
00052     #pragma interface
00053   #endif
00054 #endif
00055 #ifndef _ADMODEL_H_
00056   #define  _ADMODEL_H_
00057 
00058 #if !defined(linux)
00059 #  define BORCAST (prevariable&)
00060 #else
00061 #  define BORCAST
00062 #endif
00063 #if defined(USE_LAPLACE)
00064   class laplace_approximation_calculator;
00065   void cleanup_laplace_stuff(laplace_approximation_calculator *);
00066 #endif
00067 
00068 #include <fvar.hpp>
00069 #if defined(USE_ADPVM)
00070 #  include <adpvm2.h>
00071 #endif
00072 
00073 //#include <d4arr.hpp>
00074 #include <cifstrem.h>
00075 
00076 #include <adstring.hpp>
00077 
00078 #if defined(UNIXKLUDGE)
00079 #include <unistd.h>
00080 #endif
00081 
00082 //#define _ADSTD_ std::
00083 #define param_matrix named_dvar_matrix
00084 #define param_vector named_dvar_vector
00085 #define param_number named_dvariable
00086 #define param_3array named_dvar3_array
00087 #define param_4array named_dvar4_array
00088 #define param_5array named_dvar5_array
00089 #define param_6array named_dvar6_array
00090 #define param_7array named_dvar7_array
00091 
00092 #define SPparam_matrix SPnamed_dvar_matrix
00093 #define SPparam_vector SPnamed_dvar_vector
00094 #define SPparam_number SPnamed_dvariable
00095 #define SPparam_3array SPnamed_dvar3_array
00096 #define SPparam_4array SPnamed_dvar4_array
00097   double mfexp(CGNU_DOUBLE );
00098   dvariable mfexp(const prevariable& v1);
00099   dvar_vector mfexp(const dvar_vector& );
00100   dvector mfexp(const dvector& );
00101 
00102   class param_init_bounded_number_vector;
00103   class model_parameters;
00104   extern int AD_gaussflag;
00105 
00106   extern function_minimizer * pfm;
00107   extern int traceflag;
00108   extern int ADqd_flag;
00109 /*
00110  void set_value_inv(const dvariable& x, const dvector& v, const int& ii);
00111  void set_value_inv(const dvar_matrix& x, const dvector& v, const int& ii);
00112  void set_value_inv(const dvar_vector&, const dvector&, const int &ii);
00113  void set_value_inv(const dvariable& u, const dvector& x, const int& ii,CGNU_DOUBLE fmin,
00114   CGNU_DOUBLE fmax);
00115  void set_value_inv(const dvar_matrix& u, const dvector& x, const int& ii,
00116   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
00117  void set_value_inv(const dvar3_array& u, const dvector& x, const int& ii,
00118   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
00119  void set_value_inv(const dvar3_array& u, const dvector& x, const int& ii);
00120 */
00121 
00122   void copy_value_to_vector(const prevariable& x, const dvector& v, const int& ii);
00123   void copy_value_to_vector(const dvar_vector& x, const dvector& v, const int& ii);
00124   void copy_value_to_vector(const dvar_matrix& x, const dvector& v, const int& ii);
00125   void copy_value_to_vector(const dvar3_array& x, const dvector& v, const int& ii);
00126 
00127   void restore_value_from_vector(const prevariable& x, const dvector& v,const int& ii);
00128   void restore_value_from_vector(const dvar_vector& x, const dvector& v, const int& ii);
00129   void restore_value_from_vector(const dvar_matrix& x, const dvector& v, const int& ii);
00130   void restore_value_from_vector(dvar3_array& x, const dvector& v, const int& ii);
00131 
00136 class AD_matherror
00137 {
00138 public:
00139 #if defined (_BORLANDC_)
00140   exception * err;
00141   AD_matherror(exception * _err) : err(_err) {;}
00142 #endif
00143 #if defined (__MSVC32__)
00144   _exception * err;
00145   AD_matherror(_exception * _err) : err(_err) {;}
00146 #endif
00147 
00148 };
00149 
00150 
00151 class model_data;
00152 
00157 class label_class
00158 {
00159   const char * name;
00160   friend ostream& operator<<(const ostream& s, const label_class& lc);
00161   friend class model_name_tag;
00162 public:
00163   const char * mychar(void) { return name;}
00164   label_class(const char * s){name=s;}
00165 };
00166 
00171 class model_name_tag
00172 {
00173 protected:
00174   adstring name;
00175   //friend ostream& operator<<(const ostream& os, const model_name_tag& mnt);
00176 public:
00177   model_name_tag(void){;}
00178   void allocate(const char * s);
00179   label_class label(void){return (char*)(name);}
00180 };
00181 
00186 class named_dvar_vector : public dvar_vector, public model_name_tag
00187 {
00188 protected:
00189   named_dvar_vector(void) : dvar_vector(), model_name_tag() {;}
00190   named_dvar_vector& operator=(const dvar_vector& m);
00191   named_dvar_vector& operator=(const dvector& m);
00192   named_dvar_vector& operator = (CGNU_DOUBLE m);
00193   named_dvar_vector& operator=(const prevariable& m);
00194   friend class model_parameters;
00195   void allocate(int mmin,int mmax,const char * s);
00196   void allocate(const char * s);
00197 };
00198 
00203 class equality_constraint_vector : public named_dvar_vector
00204 {
00205 protected:
00206   equality_constraint_vector(void);
00207   equality_constraint_vector& operator=(const dvar_vector& m);
00208   equality_constraint_vector& operator=(const dvector& m);
00209   equality_constraint_vector& operator = (CGNU_DOUBLE m);
00210   equality_constraint_vector& operator=(const prevariable& m);
00211   friend class model_parameters;
00212   void allocate(int mmin,int mmax,const char * s);
00213 };
00214 
00219 class inequality_constraint_vector : public named_dvar_vector
00220 {
00221 protected:
00222   inequality_constraint_vector(void);
00223   inequality_constraint_vector& operator=(const dvar_vector& m);
00224   inequality_constraint_vector& operator=(const dvector& m);
00225   inequality_constraint_vector& operator = (CGNU_DOUBLE m);
00226   inequality_constraint_vector& operator=(const prevariable& m);
00227   friend class model_parameters;
00228   void allocate(int mmin,int mmax,const char * s);
00229 };
00230 
00235 class dll_param_vector : public named_dvar_vector
00236 {
00237   double * pd;
00238 public:
00239   ~dll_param_vector();
00240   void allocate(double *_pd,int mmin,int mmax,const char * s);
00241   dll_param_vector& operator=(const dvar_vector& m);
00242   dll_param_vector& operator=(const dvector& m);
00243   dll_param_vector& operator = (CGNU_DOUBLE m);
00244   dll_param_vector& operator=(const prevariable& m);
00245 };
00246 
00251 class named_dvariable : public dvariable, public model_name_tag
00252 {
00253   //named_dvariable& operator=(const dvariable& m);
00254 protected:
00255   named_dvariable(void) : dvariable(), model_name_tag() {;}
00256   void allocate(const char * s);
00257   named_dvariable& operator=(const prevariable& m);
00258   named_dvariable& operator = (CGNU_DOUBLE m);
00259   friend class model_parameters;
00260 };
00261 
00266 class dll_param_number : public named_dvariable
00267 {
00268   double * pd;
00269 protected:
00270   //named_dvariable(void) : dvariable(), model_name_tag() {;}
00271   void allocate(double *_d,const char * s);
00272   dll_param_number& operator=(const prevariable& m);
00273   dll_param_number& operator = (CGNU_DOUBLE m);
00274   virtual ~dll_param_number();
00275   friend class model_parameters;
00276 };
00277 
00282 class named_dvar_matrix : public dvar_matrix, public model_name_tag
00283 {
00284 protected:
00285   named_dvar_matrix(void) : dvar_matrix(), model_name_tag() {;}
00286   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00287   void allocate(int rmin,int rmax,const char * s);
00288   void allocate(const char * s);
00289   //void allocate(int rmin,int rmax,int,const ivector&,
00290     //const char * s);
00291   void allocate(int rmin,int rmax,const index_type&,const index_type&,
00292     const char * s);
00293 public:
00294   named_dvar_matrix& operator = (CGNU_DOUBLE m);
00295   named_dvar_matrix& operator=(const dmatrix& m);
00296   named_dvar_matrix& operator=(const dvar_matrix& m);
00297   named_dvar_matrix& operator=(const dvariable& m);
00298   friend class model_parameters;
00299 };
00300 
00305 class dll_param_matrix : public named_dvar_matrix
00306 {
00307   double * pd;
00308 public:
00309   //named_dvar_matrix(void) : dvar_matrix(), model_name_tag() {;}
00310   void allocate(double * ,int rmin,int rmax,int cmin,int cmax,const char * s);
00311   void allocate(double * ,int rmin,int rmax,const index_type&
00312      ,const index_type& ,const char * s);
00313   dll_param_matrix & operator=(const dvariable& m);
00314   dll_param_matrix & operator = (const double m);
00315   dll_param_matrix& operator=(const dmatrix& m);
00316   dll_param_matrix& operator=(const dvar_matrix& m);
00317   virtual ~dll_param_matrix();
00318 };
00319 
00324 class named_dvar3_array : public dvar3_array, public model_name_tag
00325 {
00326 protected:
00327   named_dvar3_array(void) : dvar3_array(), model_name_tag() {;}
00328  void allocate(const ad_integer& sl,const ad_integer& sh,
00329   const index_type& nrl,const index_type& nrh,const index_type& ncl,
00330     const index_type& nch,const char * s="UNNAMED");
00331   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00332     const char * s="UNNAMED");
00333 
00334   void allocate(int hsl,int hsu,int rmin,int rmax,const char * s="UNNAMED");
00335   void allocate(int hsl,int hsu,const index_type& rmin,const index_type& rmax,
00336     const char * s="UNNAMED");
00337   void allocate(int hsl,int hsu,const char * s="UNNAMED");
00338   void allocate(const char * s="UNNAMED");
00339 
00340 
00341   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00342                 int cmin, int cmax, const char * s="UNNAMED");
00343   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00344                 int cmin, int cmax, const char *s = "UNNAMED");
00345   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00346                 int cmin, int cmax, const char *s = "UNNAMED");
00347   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00348                 int cmax, const char *s = "UNNAMED");
00349   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00350                 const ivector& cmax, const char *s = "UNNAMED");
00351   void allocate(int hsl, int hsu, int rmin, int rmax, int cmin,
00352                 const ivector& cmax, const char *s = "UNNAMED");
00353   named_dvar3_array& operator=(const dvar3_array& m);
00354   named_dvar3_array& operator=(const d3_array& m);
00355   friend class model_parameters;
00356 };
00357 
00362 class named_dvar4_array : public dvar4_array, public model_name_tag
00363 {
00364 protected:
00365   named_dvar4_array(void) : dvar4_array(), model_name_tag() {;}
00366   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00367   int cmin,int cmax,const char * s);
00368   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00369     const index_type&,const index_type&,const index_type&,const index_type&,
00370     const char *s);
00371 
00372   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00373     const index_type&,const index_type&,const char *s);
00374 
00375   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00376     const char *s);
00377   void allocate(ad_integer,ad_integer,const char *s);
00378   void allocate(const char *s);
00379 
00380   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00381     const char * s);
00382   void allocate(int hhsl,int hhsu,int hsl,int hsu,const char * s);
00383   void allocate(int hhsl,int hhsu,const char * s);
00384 
00385   named_dvar4_array& operator=(const dvar4_array& m);
00386   named_dvar4_array& operator=(const d4_array& m);
00387   friend class model_parameters;
00388 };
00389 
00394 class named_dvar5_array : public dvar5_array, public model_name_tag
00395 {
00396 protected:
00397   named_dvar5_array(void) : dvar5_array(), model_name_tag() {;}
00398   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00399   int cmin,int cmax,
00400   int l5,int u5,
00401   const char * s);
00402 
00403   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00404     const index_type& hsl,const index_type& hsu,
00405     const index_type& sl,const index_type& sh,
00406     const index_type& nrl,const index_type& nrh,
00407     const index_type& ncl,const index_type& nch,
00408     const char * s);
00409 
00410   named_dvar5_array& operator=(const dvar5_array& m);
00411   named_dvar5_array& operator=(const d5_array& m);
00412   friend class model_parameters;
00413 };
00414 
00419 class named_dvar6_array : public dvar6_array, public model_name_tag
00420 {
00421 protected:
00422   named_dvar6_array(void) : dvar6_array(), model_name_tag() {;}
00423   void allocate(int hhsl,int hhsu,
00424     int hsl,int hsu,
00425     int rmin,int rmax,
00426     int cmin,int cmax,
00427     int l5,int u5,
00428     int l6,int u6,
00429     const char * s);
00430 
00431   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00432     const index_type& hsl,const index_type& hsu,
00433     const index_type& sl,const index_type& sh,
00434     const index_type& nrl,const index_type& nrh,
00435     const index_type& ncl,const index_type& nch,
00436     const index_type& l5,const index_type& u5,
00437     const char * s);
00438 
00439   named_dvar6_array& operator=(const dvar6_array& m);
00440   named_dvar6_array& operator=(const d6_array& m);
00441   friend class model_parameters;
00442 };
00443 
00448 class named_dvar7_array : public dvar7_array, public model_name_tag
00449 {
00450 protected:
00451   named_dvar7_array(void) : dvar7_array(), model_name_tag() {;}
00452   void allocate(
00453     int hhsl,int hhsu,
00454     int hsl,int hsu,
00455     int rmin,int rmax,
00456     int cmin,int cmax,
00457     int l5,int u5,
00458     int l6,int u6,
00459     int l7,int u7,
00460     const char * s);
00461 
00462   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00463     const index_type& hsl,const index_type& hsu,
00464     const index_type& sl,const index_type& sh,
00465     const index_type& nrl,const index_type& nrh,
00466     const index_type& ncl,const index_type& nch,
00467     const index_type& l5,const index_type& u5,
00468     const index_type& l6,const index_type& u6,
00469     const char * s);
00470 
00471   named_dvar7_array& operator=(const dvar7_array& m);
00472   named_dvar7_array& operator=(const d7_array& m);
00473   friend class model_parameters;
00474 };
00475 
00480 class named_dvector : public dvector, public model_name_tag
00481 {
00482 protected:
00483   named_dvector(void) : dvector(), model_name_tag() {;}
00484   void allocate(int mmin,int mmax,const char * s);
00485   void allocate(const char * s);
00486   void allocate(int mmin, const ivector& mmax, const char *s);
00487   named_dvector& operator=(const dvector& m);
00488   named_dvector& operator = (CGNU_DOUBLE m);
00489   friend class model_data;
00490 };
00491 
00496 class named_ivector : public ivector, public model_name_tag
00497 {
00498 protected:
00499   named_ivector(void) : ivector(), model_name_tag() {;}
00500   void allocate(int mmin,int mmax,const char * s);
00501 };
00502 
00507 class named_dmatrix : public dmatrix, public model_name_tag
00508 {
00509 protected:
00510   named_dmatrix(void) : dmatrix(), model_name_tag() {;}
00511   void allocate(int rmin,int rmax,const char * s);
00512   void allocate(const char * s);
00513   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00514   void allocate(int rmin,int rmax,const ivector& cmin,int cmax,const char * s);
00515   void allocate(int rmin,int rmax,const ivector& cmin,const ivector& cmax,const char * s);
00516   void allocate(int rmin,int rmax,int cmin,const ivector& cmax,const char * s);
00517   named_dmatrix& operator=(const dmatrix& m);
00518   named_dmatrix& operator = (CGNU_DOUBLE m);
00519 };
00520 
00525 class named_imatrix : public imatrix, public model_name_tag
00526 {
00527 protected:
00528   named_imatrix(void) : imatrix(), model_name_tag() {;}
00529   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00530   void allocate(int rmin, int rmax, const index_type& cmin,
00531                 const index_type& cmax, const char *s);
00532   named_imatrix& operator=(const imatrix& m);
00533   named_imatrix& operator=(const int& m);
00534 };
00535 
00540 class named_d3_array : public d3_array, public model_name_tag
00541 {
00542 protected:
00543   named_d3_array(void) : d3_array(), model_name_tag() {;}
00544   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00545     const char * s);
00546   void allocate(int hsl, int hsu, const index_type& rmin,
00547                 const index_type& rmax, const index_type& cmin,
00548                 const index_type& cmax, const char *s);
00549   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00550                 int cmin, int cmax, const char *s);
00551   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00552                 int cmin, int cmax, const char *s);
00553   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00554     int cmin,int cmax,const char * s);
00555   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00556     int cmax, const char * s);
00557   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00558                 const ivector& cmax, const char *s);
00559   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00560                 const ivector& cmax, const char *s);
00561   named_d3_array& operator=(const d3_array& m);
00562 
00563   void allocate(int hsl,int hsu,const index_type& rmin,const index_type& rmax,
00564     const char * s);
00565   void allocate(int hsl,int hsu,int rmin,int rmax,const char * s);
00566   void allocate(int hsl,int hsu,const char * s);
00567   void allocate(const char * s);
00568 };
00569 
00574 class named_i3_array : public i3_array, public model_name_tag
00575 {
00576 protected:
00577   named_i3_array(void) : i3_array(), model_name_tag() {;}
00578   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00579     const char * s);
00580   void allocate(int hsl, int hsu, const index_type& rmin,
00581                 const index_type& rmax, const index_type& cmin,
00582                 const index_type& cmax, const char *s);
00583   named_i3_array& operator=(const i3_array& m);
00584 };
00585 
00590 class named_d4_array : public d4_array, public model_name_tag
00591 {
00592 protected:
00593   named_d4_array(void) : d4_array(), model_name_tag() {;}
00594   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00595     const index_type&,const index_type&,const index_type&,const index_type&,
00596     const char * s);
00597   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00598     int rmax,int cmin,int cmax,const char * s);
00599 
00600   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00601     int rmax,const char * s);
00602   void allocate(int hhsl,int hhsu,int hsl,int hsu,const char * s);
00603   void allocate(int hhsl,int hhsu,const char * s);
00604   void allocate(const char * s);
00605 
00606   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00607     const index_type&,const index_type&,const char * s);
00608   void allocate(ad_integer,ad_integer,const index_type&,const index_type&,
00609     const char * s);
00610   void allocate(ad_integer,ad_integer,const char * s);
00611 
00612 
00613   named_d4_array& operator=(const d4_array& m);
00614 };
00615 
00620 class named_d5_array : public d5_array, public model_name_tag
00621 {
00622 protected:
00623   named_d5_array(void) : d5_array(), model_name_tag() {;}
00624   void allocate(int l5,int u5,int hhsl,int hhsu,int hsl,int hsu,int rmin,
00625     int rmax,int cmin,int cmax,const char * s);
00626   void allocate(const ad_integer& hhsl,const ad_integer& hhsu,
00627     const index_type& hsl,const index_type& hsu, const index_type& sl,
00628     const index_type& sh,const index_type& nrl,const index_type& nrh,
00629     const index_type& ncl,const index_type& nch,const char * s);
00630 
00631   named_d5_array& operator=(const d5_array& m);
00632 };
00633 
00638 class named_d6_array : public d6_array, public model_name_tag
00639 {
00640 protected:
00641   named_d6_array(void) : d6_array(), model_name_tag() {;}
00642   void allocate(int l6,int u6,int l5,int u5,int hhsl,int hhsu,int hsl,
00643     int hsu,int rmin,int rmax,int cmin,int cmax,const char * s);
00644   void allocate(const ad_integer& l6,const ad_integer& u6,
00645     const index_type& l5,const index_type& u5,
00646     const index_type& hhsl,const index_type& hhsu,
00647     const index_type& hsl,const index_type& hsu,
00648     const index_type& sl,const index_type& sh,
00649     const index_type& nrl,const index_type& nrh,
00650     const char * s);
00651 
00652   named_d6_array& operator=(const d6_array& m);
00653 };
00654 
00659 class named_d7_array : public d7_array, public model_name_tag
00660 {
00661 protected:
00662   named_d7_array(void) : d7_array(), model_name_tag() {;}
00663   void allocate(int l7,int u7,int l6,int u6,int l5,int u5,int hhsl,
00664     int hhsu,int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00665     const char * s);
00666   void allocate(const ad_integer& l7,const ad_integer& u7,
00667     const index_type& l6,const index_type& u6,
00668     const index_type& l5,const index_type& u5,
00669     const index_type& hhsl,const index_type& hhsu,
00670     const index_type& hsl,const index_type& hsu,
00671     const index_type& sl,const index_type& sh,
00672     const index_type& nrl,const index_type& nrh,
00673     const char * s);
00674 
00675   named_d7_array& operator=(const d7_array& m);
00676 };
00677 
00678 
00679 class function_minimizer;
00680 
00681 #if defined(USE_ADPVM)
00682 
00687 class pvm_params
00688 {
00689   static pvm_params * varsptr[]; // this should be a resizeable array
00690   static num_pvm_params;
00691   static const int maxnum_pvm_params;
00692   void add_to_list(void);
00693   virtual void send_to_slaves(void)=0;
00694   virtual void get_from_master(void)=0;
00695 public:
00696   static void pvm_params::send_all_to_slaves(void);
00697   static void pvm_params::get_all_from_master(void);
00698   void allocate(const char *);
00699   void allocate(void);
00700 };
00701 
00706 class pvm_number : public pvm_params
00707 {
00708 public:
00709   virtual void send_to_slaves(void);
00710   virtual void get_from_master(void);
00711   dvector v;
00712   double d;
00713   operator double();
00714   void assign(const dvector&);
00715   void assign(double);
00716 };
00717 
00722 class pvm_int : public pvm_params
00723 {
00724 public:
00725   virtual void send_to_slaves(void);
00726   virtual void get_from_master(void);
00727   ivector v;
00728   int d;
00729   operator int();
00730   void assign(const ivector&);
00731   void assign(int);
00732 };
00733 #endif // #if defined(USE_ADPVM)
00734 
00739 class initial_params
00740 {
00741 protected:
00742   int active_flag;
00743   int initial_value_flag;
00744   double initial_value;
00745   double scalefactor;
00746 public:
00747   double get_scalefactor();
00748   void set_scalefactor(const double);
00749   static initial_params * varsptr[]; // this should be a resizeable array
00750   static int num_initial_params;
00751   static const int max_num_initial_params;
00752   static int straight_through_flag;
00753   static int num_active_initial_params;
00754   static int max_number_phases;
00755   static int current_phase;
00756   static int restart_phase;
00757   static int sd_phase;
00758   static int mc_phase;
00759   static int mceval_phase;
00760   int phase_start;
00761   int phase_save;
00762   int phase_stop;
00763   virtual void set_random_effects_active();
00764   void restore_phase_start(void);
00765   virtual void set_random_effects_inactive();
00766   virtual void set_only_random_effects_active();
00767   virtual void set_only_random_effects_inactive();
00768   virtual void set_value(const dvar_vector&, const int&, const dvariable& pen) = 0;
00769   virtual void dev_correction(const dmatrix&, const int&) = 0;
00770   void set_initial_value(double x);
00771   double get_initial_value(void);
00772   void set_phase_start(int x);
00773   int get_phase_start(void);
00774   static void set_all_simulation_bounds(const dmatrix& symbds);
00775   static void set_all_simulation_bounds(const dmatrix& symbds, const dvector&);
00776   static void get_jacobian_value(const dvector& y, const dvector& jac);
00777   static int correct_for_dev_objects(const dmatrix &H);
00778   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii) = 0;
00779   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii) = 0;
00780   virtual void set_value_inv(const dvector&, const int&) = 0;
00781   virtual void add_value(const dvector&, const int&) = 0;
00782   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&) = 0;
00783   virtual void get_jacobian(const dvector&, const dvector&, const int&) = 0;
00784   //virtual void check_tightness(const dvector&, const int&) = 0;
00785   virtual void copy_value_to_vector(const dvector&, const int&) = 0;
00786   virtual void restore_value_from_vector(const dvector&, const int&) = 0;
00787   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00788   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,const int& ii)=0;
00789   virtual void mc_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00790   virtual void curv_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00791   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00792   virtual int size_count(void)=0; // get the number of active parameters
00793   virtual void save_value(void)=0; // save the objects value in a ascii file
00794   virtual void bsave_value(void)=0; // save the objects value in a binary file
00795   virtual void save_value(const ofstream& ofs, int prec) = 0;
00796   //virtual void bsave_value(const uostream& ofs) = 0;
00797     virtual const char * label()=0;
00798   void allocate(int _phase_start);
00799   void set_active_flag(void);
00800   void set_inactive_flag(void);
00801   friend int active(const initial_params& ip);
00802   static adstring get_reportfile_name(void);
00803   initial_params(void);
00804   static void xinit(const dvector& x); // get the number of active parameters
00805   static void xinit_all(const dvector& x); // get the number of active parameters
00806   static void set_active_random_effects(void); // get the number of active parameters
00807   static void set_active_only_random_effects(void); // get the number of active parameters
00808   static void set_inactive_only_random_effects(void); // get the number of active parameters
00809   static void set_inactive_random_effects(void); // get the number of active parameters
00810   static void restore_start_phase(void); // get the number of active parameters
00811   static void xinit1(const dvector& x, const dvector& g);
00812   static void copy_all_values(const dvector& x, const int& ii);//save all initial parameter
00813                                                    // values in a vector
00814   static void restore_all_values(const dvector& x,const int& ii); //get ivalues for all
00815                                     // active parameters from a vector
00816   static dvariable reset(const dvar_vector& x); // get the number of active parameters
00817   static dvariable reset(const dvector& x); // get the number of active parameters
00818   static dvariable reset1(const dvar_vector& x, const dvector& g);
00819   static dvariable reset(const dvar_vector& x, const dvector& pen); // get the number of active parameters
00820   static dvariable reset_all(const dvar_vector& x,const dvector& pen); // get the number of active parameters
00821   static int nvarcalc(void);
00822   static int nvarcalc_all(void);
00823   static int num_active_calc(void);
00824   static int stddev_scale(const dvector& d, const dvector& x);
00825   static int stddev_vscale(const dvar_vector& d,const dvar_vector& x);
00826   static int montecarlo_scale(const dvector& d, const dvector& x);
00827   static int stddev_curvscale(const dvector& d, const dvector& x);
00828   static void read(void);
00829   static void save(void);
00830   static void save(const ofstream& ofs, int prec);
00831   static void restore(const ifstream& ifs);
00832   static void add_random_vector(const dvector& x);
00833   static void add_random_vector(const dvector& y, const dvector& x, const double& ll, const dvector& diag);
00834   virtual void restore_value(const ifstream& ifs) = 0;
00835   virtual void add_to_list(void);
00836 #if defined(USE_ADPVM)
00837   virtual void pvm_pack(void)=0;
00838   virtual void pvm_unpack(void)=0;
00839 #endif
00840 
00841   friend class function_minimizer;
00842 };
00843 
00844 void pvm_pack(const dvar_vector&);
00845 void pvm_unpack(const dvar_vector&);
00846 void pvm_pack(const prevariable&);
00847 void pvm_unpack(const prevariable&);
00848 void pvm_pack(const dvar_matrix&);
00849 void pvm_unpack(const dvar_matrix&);
00850 
00855 class param_init_vector: public named_dvar_vector , public initial_params
00856 {
00857 public:
00858   virtual void dev_correction(const dmatrix& H, const int& ii);
00859   virtual const char * label(void);
00860   param_init_vector();
00861 #if defined(USE_ADPVM)
00862   void pvm_pack(void){::pvm_pack(*this);}
00863   void pvm_unpack(void){::pvm_unpack(*this);}
00864 #endif
00865 private:
00866   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
00867 //  virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
00868   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&);
00869   virtual void add_value(const dvector&, const int&);
00870   virtual void get_jacobian(const dvector&, const dvector&, const int&);
00871   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,const int& ii);
00872 
00873   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00874   virtual void set_value_inv(const dvector& x, const int& ii);
00875   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00876   virtual void restore_value_from_vector(const dvector&, const int&);
00877   virtual int size_count(void);
00878   virtual void sd_scale(const dvector& d, const dvector& x, const int&);
00879   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
00880   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
00881   virtual void hess_scale(const dvector& d, const dvector& x, const int&){;};
00882   virtual void save_value(void);
00883   virtual void bsave_value(void);
00884   virtual void save_value(const ofstream& ofs, int prec);
00885   virtual void restore_value(const ifstream& ifs);
00886   void report_value(void);
00887   //virtual void read_value(void);
00888   void allocate(int imin,int imax,int phasestart=1,const char * s="UNNAMED");
00889   void allocate(const ad_integer& imin,const ad_integer& imax,
00890     const ad_integer& phasestart=1,const char * s="UNNAMED");
00891   void allocate(int imin,int imax,const char * s="UNNAMED");
00892   friend class model_parameters;
00893   friend class param_init_vector_vector;
00894 public:
00895   param_init_vector& operator = (const dvector&);
00896   param_init_vector& operator = (const dvar_vector&);
00897   param_init_vector& operator = (const prevariable&);
00898   param_init_vector& operator = (const double&);
00899 };
00900 
00905 class dll_param_init_vector: public param_init_vector
00906 {
00907   double * pd;
00908 public:
00909   dll_param_init_vector& operator = (const dvector&);
00910   dll_param_init_vector& operator = (const dvar_vector&);
00911   dll_param_init_vector& operator = (const prevariable&);
00912   dll_param_init_vector& operator = (const double&);
00913   void allocate(double * _pd,int imin,int imax,
00914     int phasestart=1,const char * s="UNNAMED");
00915   void allocate(double * _pd,int imin,int imax,
00916     const char * s="UNNAMED");
00917 
00918   virtual ~dll_param_init_vector();
00919   friend class model_parameters;
00920 };
00921 
00926 class param_init_bounded_vector: public named_dvar_vector,public initial_params
00927 {
00928   virtual void* parent_this(void){return this;}
00929 public:
00930   double get_minb(void);
00931   void set_minb(double b);
00932   double get_maxb(void);
00933   void set_maxb(double b);
00934 protected:
00935   double minb;
00936   double maxb;
00937   param_init_bounded_vector();
00938 private:
00939   virtual void dev_correction(const dmatrix&, const int&);
00940   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
00941   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,const int& ii);
00942 //  virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
00943   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&);
00944   virtual void add_value(const dvector&, const int&);
00945   virtual void get_jacobian(const dvector&, const dvector&, const int&);
00946   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00947   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00948   virtual void restore_value_from_vector(const dvector&, const int&);
00949   virtual void set_value_inv(const dvector& x, const int& ii);
00950   virtual int size_count(void);
00951   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00952   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
00953   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
00954   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){;};
00955   void allocate(int imin,int imax,double _minb,double _maxb,
00956     int phasestart=1, const char * name="UNNAMED");
00957   void allocate(int imin,int imax,double _minb,double _maxb,
00958     const char * name="UNNAMED");
00959  //void param_init_bounded_vector::allocate(const ad_integer& imin,
00960    //const ad_integer& imax,const ad_double& _minb,const ad_double& _maxb,
00961    //const ad_integer& phase_start,const char * s);
00962   friend class model_parameters;
00963   friend class param_init_bounded_vector_vector;
00964   virtual const char * label(void);
00965   virtual void save_value(const ofstream& ofs, int prec);
00966   virtual void restore_value(const ifstream& ifs);
00967   virtual void save_value(void);
00968   virtual void bsave_value(void);
00969   void report_value(void);
00970   //virtual void read_value(void);
00971 public:
00972   param_init_bounded_vector& operator = (const dvector&);
00973   param_init_bounded_vector& operator = (const dvar_vector&);
00974   param_init_bounded_vector& operator = (const prevariable&);
00975   param_init_bounded_vector& operator = (const double&);
00976 #if defined(USE_ADPVM)
00977   void pvm_pack(void){::pvm_pack(*this);}
00978   void pvm_unpack(void){::pvm_unpack(*this);}
00979 #endif
00980 };
00981 
00986 class dll_param_init_bounded_vector: public param_init_bounded_vector
00987 {
00988   double * pd;
00989 public:
00990   void allocate(double * _pd,int imin,int imax,double _minb,double _maxb,
00991     int phasestart=1, const char * name="UNNAMED");
00992   void allocate(double * _pd,int imin,int imax,double _minb,double _maxb,
00993     const char * name="UNNAMED");
00994   ~dll_param_init_bounded_vector();
00995 };
00996 
01001 class param_init_bounded_dev_vector: public param_init_bounded_vector
01002 {
01003   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
01004   virtual void dev_correction(const dmatrix& H, const int& ii);
01005 public:
01006   param_init_bounded_dev_vector& operator = (const dvar_vector& m);
01007   param_init_bounded_dev_vector& operator = (const dvector& m);
01008   param_init_bounded_dev_vector& operator = (const prevariable& m);
01009   param_init_bounded_dev_vector& operator = (const double& m);
01010 };
01011 
01016 class param_init_number: public named_dvariable , public initial_params
01017 {
01018   virtual void dev_correction(const dmatrix&, const int&);
01019   virtual void set_simulation_bounds(const dmatrix& symbds,const int& ii);
01020 
01021 #if defined(USE_ADPVM)
01022   void pvm_pack(void){::pvm_pack(*this);}
01023   void pvm_unpack(void){::pvm_unpack(*this);}
01024 #endif
01025 
01026 //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
01027   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&);
01028   virtual void add_value(const dvector&,const int&);
01029   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01030   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
01031   virtual void copy_value_to_vector(const dvector& x, const nint& ii);
01032   virtual void restore_value_from_vector(const dvector&, const int&);
01033   virtual void set_value_inv(const dvector& x, const int& ii);
01034   virtual int size_count(void);
01035   virtual void save_value(const ofstream& ofs, int prec);
01036   virtual void restore_value(const ifstream& ifs);
01037   virtual void save_value(void);
01038   virtual void bsave_value(void);
01039   void report_value(void);
01040   virtual const char * label(void);
01041   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01042   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01043   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01044   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii) {;};
01045   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,const int& ii);
01046   //virtual void read_value(void);
01047 protected:
01048   void allocate(int phase_start=1,const char *s="UNNAMED");
01049   void allocate(const char *s="UNNAMED");
01050   friend class model_parameters;
01051   friend class param_init_number_vector;
01052   param_init_number();
01053   param_init_number& operator = (CGNU_DOUBLE m);
01054   param_init_number& operator=(const prevariable& m);
01055 };
01056 
01061 class dll_param_init_number: public param_init_number
01062 {
01063   double * pd;
01064 public:
01065   void allocate(double * pd,int phase_start=1,const char *s="UNNAMED");
01066   void allocate(double *pd,const char *s="UNNAMED");
01067   virtual ~dll_param_init_number();
01068   dll_param_init_number& operator = (CGNU_DOUBLE m);
01069   dll_param_init_number& operator=(const prevariable& m);
01070 };
01071 
01076 class param_init_bounded_number: public param_init_number
01077 {
01078 public:
01079   double get_minb(void);
01080   void set_minb(double b);
01081   double get_maxb(void);
01082   void set_maxb(double b);
01083 protected:
01084   double minb;
01085   double maxb;
01086   void allocate(double _minb,double _maxb,int phase_start=1,
01087     const char * s="UNNAMED");
01088   void allocate(double _minb,double _maxb,const char * s="UNNAMED");
01089 public:
01090 #if defined(USE_ADPVM)
01091   void pvm_pack(void){::pvm_pack(*this);}
01092   void pvm_unpack(void){::pvm_unpack(*this);}
01093 #endif
01094   param_init_bounded_number();
01095 private:
01096   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01097   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
01098   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&);
01099   virtual void add_value(const dvector&, const int&);
01100   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01101   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
01102   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01103   virtual void restore_value_from_vector(const dvector&, const int&);
01104   virtual void set_value_inv(const dvector& x, const int& ii);
01105   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01106   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01107   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01108   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){;};
01109   virtual const char * label(void);
01110   void report_value(void);
01111   param_init_bounded_number& operator = (CGNU_DOUBLE m);
01112   param_init_bounded_number& operator=(const prevariable& m);
01113   friend class model_parameters;
01114   friend class param_init_bounded_number_vector;
01115   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,const int& ii);
01116 };
01117 
01122 class dll_param_init_bounded_number: public param_init_bounded_number
01123 {
01124   double * pd;
01125 public:
01126   void allocate(double * _pd,double _minb,double _maxb,int phase_start=1,
01127     const char * s="UNNAMED");
01128   void allocate(double * _pd,double _minb,double _maxb,const char * s="UNNAMED");
01129 public:
01130   virtual ~dll_param_init_bounded_number();
01131   void report_value(void);
01132 };
01133 
01138 class param_init_matrix: public named_dvar_matrix,public initial_params
01139 {
01140   virtual void dev_correction(const dmatrix&, const int&);
01141   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01142 #if defined(USE_ADPVM)
01143   void pvm_pack(void){::pvm_pack(*this);}
01144   void pvm_unpack(void){::pvm_unpack(*this);}
01145 #endif
01146 //  virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
01147   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&);
01148   virtual void add_value(const dvector&, const int&);
01149   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01150 public:
01151 
01152   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
01153   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01154   virtual void restore_value_from_vector(const dvector&, const int&);
01155   virtual void set_value_inv(const dvector& x, const int& ii);
01156   virtual int size_count(void);
01157   virtual void save_value(void);
01158   virtual void bsave_value(void);
01159   virtual void save_value(const ofstream& ofs, int prec);
01160   virtual void restore_value(const ifstream& ifs);
01161   void report_value(void);
01162   //virtual void read_value(void);
01163   virtual const char * label(void);
01164   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01165   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01166   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01167   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){;};
01168   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,const int& ii);
01169 
01170 public:
01171 
01172   void allocate(int rmin,int rmax,int cmin,int cmax,
01173     int phase_start=1,const char * = "UNNAMED");
01174   void allocate(int rmin,int rmax,int cmin,int cmax,
01175     const char * = "UNNAMED");
01176  void allocate(const ad_integer& imin,const ad_integer&imax,
01177    const index_type& imin2,const index_type& imax2,
01178    const ad_integer& phase_start, const char * s);
01179   void allocate(const ad_integer& rmin,const ad_integer& rmax, const index_type& cmin, const index_type& cmax, const char * = "UNNAMED");
01180   void allocate(const ad_integer& rmin,const ad_integer& rmax, const index_type& cmin, const index_type& cmax, int phase_start=1,const char * = "UNNAMED");
01181   param_init_matrix(void);
01182   param_init_matrix& operator = (const dmatrix& m);
01183   param_init_matrix& operator = (const dvar_matrix& m);
01184   param_init_matrix& operator = (const dvariable& m);
01185   param_init_matrix& operator = (const double& m);
01186 };
01187 
01192 class dll_param_init_matrix: public param_init_matrix
01193 {
01194   double * d;
01195 public:
01196   void allocate(double* _d,int rmin,int rmax,int cmin,int cmax,
01197     int phase_start=1,const char * = "UNNAMED");
01198   void allocate(double * _d,int rmin,int rmax,int cmin,int cmax,
01199     const char * = "UNNAMED");
01200   virtual ~dll_param_init_matrix();
01201   dll_param_init_matrix(){d=NULL;}
01202   dll_param_init_matrix& operator = (const dmatrix& m);
01203   dll_param_init_matrix& operator = (const dvar_matrix& m);
01204   dll_param_init_matrix& operator = (const dvariable& m);
01205   dll_param_init_matrix& operator = (const double& m);
01206 };
01207 
01212 class param_init_bounded_matrix: public param_init_matrix
01213 {
01214 public:
01215   double get_minb(void);
01216   void set_minb(double b);
01217   double get_maxb(void);
01218   void set_maxb(double b);
01219 protected:
01220   double minb;
01221   double maxb;
01222   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
01223   //virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
01224   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&);
01225   virtual void add_value(const dvector&, const int&);
01226   virtual void get_jacobian(const dvector&, const dvector&, const int&);
01227 public:
01228 
01229 #if defined(USE_ADPVM)
01230   void pvm_pack(void){::pvm_pack(*this);}
01231   void pvm_unpack(void){::pvm_unpack(*this);}
01232 #endif
01233   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
01234   virtual void set_value_inv(const dvector& x, const int& ii);
01235   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
01236   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
01237   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
01238   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){;};
01239   virtual void sd_vscale(const dvar_vector& d,const dvar_vector& x,const int& ii);
01240 
01241 public:
01242 
01243  void allocate(const ad_integer& imin,
01244    const ad_integer& imax, const ad_integer& imin2,
01245    const ad_integer& imax2, const ad_double& _bmin,
01246    const ad_double& _bmax, const ad_integer& phase_start,
01247    const char * s);
01248 
01249   param_init_bounded_matrix(void);
01250   void allocate(int rmin,int rmax,int cmin,int cmax,
01251     double _minb,double _maxb,
01252     int phase_start=1,const char * = "UNNAMED");
01253   void allocate(int rmin,int rmax,int cmin,int cmax,
01254     double _minb,double _maxb,const char * = "UNNAMED");
01255 
01256   void allocate(const ad_integer& rmin, const ad_integer& rmax, const index_type& cmin,
01257                 const index_type& cmax, double _minb, double _maxb,
01258                 const char * = "UNNAMED");
01259   void allocate(const ad_integer& rmin, const ad_integer& rmax, const index_type& cmin,
01260                 const index_type& cmax, double _minb, double _maxb,
01261                 int phase_start = 1, const char * = "UNNAMED");
01262 };
01263 
01268 class data_int : public model_name_tag
01269 {
01270 protected:
01271   int val;
01272   data_int& operator=(const int);
01273   void allocate(int n,const char * s="UNNAMED");
01274   void allocate(const char * s="UNNAMED");
01275   friend class model_data;
01276   friend class model_parameters;
01277   friend int operator + (int n,data_int v);
01278   friend int operator + (data_int v,int n);
01279   friend int operator + (data_int v,data_int n);
01280 public:
01281   operator int() {return val;}
01282 #if !defined (__BORLANDC__)
01283   //operator const int() const {return val;}
01284 #endif
01285   virtual ~data_int(){;}
01286 };
01287 
01292 class named_adstring : public adstring, public model_name_tag
01293 {
01294 protected:
01295   void allocate(const char * s1,const char * s="UNNAMED");
01296   void operator = (const adstring&);
01297   void operator = (const char *);
01298 public:
01299 };
01300 
01305 class named_line_adstring : public line_adstring, public model_name_tag
01306 {
01307 protected:
01308   void allocate(const char * s1,const char * s="UNNAMED");
01309   void operator = (const adstring&);
01310   void operator = (const char *);
01311 public:
01312 };
01313 
01318 class init_adstring: public named_adstring
01319 {
01320 public:
01321   void allocate(const char * s="UNNAMED");
01322 };
01323 
01328 class init_line_adstring: public named_line_adstring
01329 {
01330 public:
01331   void allocate(const char * s="UNNAMED");
01332 };
01333 
01338 class dll_named_adstring : public named_adstring
01339 {
01340   char ** d;
01341 public:
01342   void allocate(char ** ps1,const char * s="UNNAMED");
01343   void operator = (const adstring&);
01344   void operator = (const char *);
01345   ~dll_named_adstring();
01346   dll_named_adstring(void){d=NULL;}
01347 };
01348 
01353 class dll_data_int : public data_int
01354 {
01355 public:
01356   int *pi;
01357   void allocate(int *_pi,const char * s);
01358   virtual ~dll_data_int();
01359 };
01360 
01365 class data_matrix : public named_dmatrix
01366 {
01367 public:
01368   data_matrix(void) : named_dmatrix() {;}
01369   data_matrix& operator=(const dmatrix& m);
01370   data_matrix& operator=(const double& m);
01371 private:
01372   void allocate(int rmin, int rmax, int cmin, int cmax,
01373     const char * = "UNNAMED");
01374   void allocate(int rmin, int rmax, const ivector& cmin, const ivector& cmax,
01375     const char * = "UNNAMED");
01376   void allocate(int rmin, int rmax, const ivector& cmin, int cmax,
01377     const char * = "UNNAMED");
01378   void allocate(int rmin, int rmax, int cmin, const ivector& cmax,
01379     const char * = "UNNAMED");
01380   friend class model_data;
01381 };
01382 
01387 class dll_data_matrix : public data_matrix
01388 {
01389   double * d;
01390 public:
01391   void allocate(double * _d,int rmin,int rmax,int cmin,int cmax,
01392     const char * _s = "UNNAMED");
01393   virtual ~dll_data_matrix();
01394   dll_data_matrix& operator=(const dmatrix & m);
01395   dll_data_matrix& operator=(const double & m);
01396 };
01397 
01402 class data_3array : public named_d3_array
01403 {
01404 public:
01405   data_3array(void) : named_d3_array() {;}
01406 private:
01407   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
01408     const char * ="UNNAMED");
01409   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
01410     int cmin,int cmax,const char * ="UNNAMED");
01411   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
01412     int cmin,int cmax,const char * ="UNNAMED");
01413   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
01414     int cmin,int cmax,const char * ="UNNAMED");
01415   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin, int cmax,
01416     const char * ="UNNAMED");
01417   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
01418                 const ivector& cmax, const char * = "UNNAMED");
01419   void allocate(int hsl, int hsu, int rmin, int rmax, int cmin,
01420                 const ivector& cmax, const char * = "UNNAMED");
01421   void allocate(int hsl, int hsu, const index_type& rmin, const index_type& rmax, const index_type& cmin,
01422                 const index_type& cmax, const char * = "UNNAMED");
01423   friend class model_data;
01424 };
01425 
01430 class dll_data_3array : public data_3array
01431 {
01432   double * d;
01433 public:
01434   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
01435     int cmin,int cmax,const char * _s = "UNNAMED");
01436   dll_data_3array& operator=(const d3_array &);
01437   virtual ~dll_data_3array();
01438   friend class model_data;
01439 };
01440 
01445 class data_3iarray : public named_i3_array
01446 {
01447   data_3iarray(void) : named_i3_array() {;}
01448   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
01449     const char * ="UNNAMED");
01450   void allocate(int hsl, int hsu, const index_type& rmin, const index_type& rmax, const index_type& cmin,
01451                 const index_type& cmax, const char * = "UNNAMED");
01452   friend class model_data;
01453 };
01454 
01459 class data_5array : public named_d5_array
01460 {
01461   data_5array(void) : named_d5_array() {;}
01462   void allocate(int hhsl,int hhsu,
01463     int hhhsl,int hhhsu,
01464     int hsl,int hsu,int rmin,int rmax,
01465     int cmin,int cmax,const char * ="UNNAMED");
01466   void allocate(ad_integer hhhsl, ad_integer hhhsu,
01467                 const index_type& hhsl, const index_type& hhsu,
01468     const index_type& hsl, const index_type& hsu, const index_type& rmin, const index_type& rmax,
01469     const index_type& cmin, const index_type& cmax, const char * = "UNNAMED");
01470   friend class model_data;
01471 };
01472 
01477 class data_4array : public named_d4_array
01478 {
01479   data_4array(void) : named_d4_array() {;}
01480   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
01481     int cmin,int cmax,const char * ="UNNAMED");
01482   void allocate(ad_integer hhsl, ad_integer hhsu, const index_type& hsl, const index_type& hsu, const index_type& rmin, const index_type& rmax,
01483      const index_type& cmin, const index_type& cmax, const char * = "UNNAMED");
01484   friend class model_data;
01485 };
01486 
01491 class data_imatrix : public named_imatrix
01492 {
01493   data_imatrix(void) : named_imatrix() {;}
01494   void allocate(int rmin,int rmax,int cmin,int cmax,const char * ="UNNAMED");
01495   void allocate(int rmin,int rmax, const index_type&, const index_type& cmax,
01496     const char * ="UNNAMED");
01497   friend class model_data;
01498 };
01499 
01504 class data_vector : public named_dvector
01505 {
01506 public:
01507   data_vector& operator=(const dvector& m);
01508   data_vector& operator = (CGNU_DOUBLE m);
01509   data_vector(void) : named_dvector() {;}
01510 private:
01511   void allocate(int imin,int imax,const char * ="UNNAMED");
01512   void allocate(int imin, const ivector& imax, const char * = "UNNAMED");
01513   friend class model_data;
01514 };
01515 
01520 class dll_data_vector : public data_vector
01521 {
01522 public:
01523   double * pd;
01524   void allocate(double * pd,int imin,int imax,const char * ="UNNAMED");
01525   void allocate(double *pd, int imin, const ivector& imax, const char * = "UNNAMED");
01526   virtual ~dll_data_vector();
01527   dll_data_vector& operator = (const dvector& x);
01528   dll_data_vector& operator = (const double& x);
01529 };
01530 
01535 class data_ivector : public named_ivector
01536 {
01537 public:
01538   data_ivector(void) : named_ivector() {;}
01539 private:
01540   void allocate(int imin,int imax,const char * ="UNNAMED");
01541   friend class model_data;
01542 };
01543 
01548 class data_number : public model_name_tag
01549 {
01550 protected:
01551   double val;
01552   void allocate(const char * ="UNNAMED");
01553 public:
01554   void report_value(void);
01555   operator double() {return val;}
01556   double& value(void) {return val;}
01557   void initialize(void) {val=0.0;}
01558   friend class model_data;
01559   data_number& operator=(const double& m);
01560 };
01561 
01566 class dll_data_number : public data_number
01567 {
01568 public:
01569   double * pd;
01570   void allocate(double *_pd,const char * s);
01571   virtual ~dll_data_number();
01572   dll_data_number& operator=(const double& m);
01573 };
01574 
01575 typedef dvariable (model_parameters::*PMF) (const dvariable&);
01576 typedef dvariable (model_parameters::*PMFI) (const dvariable&,int n);
01577 typedef dvariable (model_parameters::*PMFVI) (const dvar_vector&,int n);
01578 typedef void (model_parameters::*PMFVIV4) (const dvar_vector&, int n,
01579   dvariable& f1, const dvariable& f2, const dvariable& f3, const dvariable& f4);
01580 
01581 #if defined(USE_LAPLACE)
01582   class init_df1b2vector;
01583   class df1b2vector;
01584   class df1b2variable;
01585 #endif
01586 
01591 class function_minimizer
01592 {
01593 public:
01594   static int first_hessian_flag;
01595   static int test_trust_flag;
01596   static int random_effects_flag;
01597 #if defined(USE_LAPLACE)
01598   laplace_approximation_calculator * lapprox;
01599   //init_df1b2vector* py;
01600   virtual void AD_uf_inner(void);
01601   virtual void AD_uf_outer(void);
01602   virtual void user_function(void);
01603   //virtual void user_function(const init_df1b2vector& x,df1b2variable& f);
01604   //static int hesstype;
01605   //int set_hessian_type(int);
01606   static int negative_eigenvalue_flag;
01607   void hess_routine_noparallel_randomeffects(void);
01608   void begin_df1b2_funnel(void){;}
01609   void setup_quadprior_calcs(void){;}
01610   void end_df1b2_funnel(void){;}
01611 #endif
01612   int ifn;
01613   int maxfn;
01614   int iprint;
01615   double crit;
01616   int imax;
01617   double dfn;
01618   int iexit;
01619   int ihflag;
01620   int ihang;
01621   int scroll_flag;
01622   int maxfn_flag;
01623   int quit_flag;
01624   double min_improve;
01625   virtual void userfunction(void)=0;
01626   virtual void allocate(void){;}
01627   static named_dvar_vector * ph;
01628   static named_dvar_vector * pg;
01629 protected:
01630   double ffbest;
01631 private:
01632   gradient_structure * pgs;
01633   adstring_array param_labels;
01634   ivector param_size;
01635 protected:
01636   void report_function_minimizer_stats(void){;}
01637   virtual void report(void){;};
01638   static dvector convergence_criteria;
01639   static dvector maximum_function_evaluations;
01640   static int sd_flag;
01641   static adstring user_data_file;
01642   static adstring user_par_file;
01643   static int have_constraints;
01644 public:
01645   virtual dvariable user_randeff(const dvar_vector& x);
01646   virtual dvar_vector user_dfrandeff(const dvar_vector& x);
01647   virtual dvar_matrix user_d2frandeff(const dvar_vector& x);
01648   void limited_memory_quasi_newton(const independent_variables&, int);
01649   void limited_memory_quasi_newton(const independent_variables&, int, int);
01650   void limited_memory_quasi_newton(double& f, const independent_variables&,int,int,
01651     int,double);
01652   function_minimizer(long int sz=0L);
01653   void likeprof_routine(double global_min);
01654   virtual ~function_minimizer();
01655   virtual void other_calculations(void){;}
01656   virtual void final_calcs(void){;}
01657   virtual void minimize(void);
01658   virtual void constraints_minimize(void);
01659   virtual void between_phases_calculations(void){;}
01660   void computations(int argc,char * argv[]);
01661   void computationsx(int argc,char * argv[]);
01662   void computations1(int argc,char * argv[]);
01663   void computations_np(int argc,char * argv[]);
01664   void computations(void);
01665   void hess_routine(void);
01666   void hess_routine_noparallel(void);
01667   void hess_routine_master(void);
01668   void hess_routine_slave(void);
01669   void constraint_report(void);
01670   void pvm_slave_likeprof_routine(void);
01671   void pvm_master_function_evaluation_profile(double& f,
01672     independent_variables& x,const dvector & g,int nvar,int iprof,double weight,
01673     double new_value);
01674   void pvm_slave_prof_minimize(int underflow_flag);
01675   void pvm_master_prof_minimize(int iprof, double sigma,
01676     double new_value, const double& _fprof, const int underflow_flag,
01677     double global_min, const double& _penalties,
01678     const double& _final_weight);
01679   //void pvm_master_function_evaluation_profile(double& f,
01680    // independent_variables& x,dvector & g,int nvar,int iprof);
01681   void pvm_slave_function_evaluation(void);
01682   void pvm_slave_function_evaluation_no_derivatives(void);
01683   void pvm_slave_function_evaluation_noder(void);
01684   void pvm_master_function_evaluation_no_derivatives(double& f,
01685     independent_variables& x,int nvar);
01686   void pvm_master_function_evaluation(double& f,
01687     independent_variables& x,const dvector & g,int nvar);
01688   dmatrix dep_hess_routine(const dvariable& dep);
01689   void mcmc_routine(int,int,double,int);
01690   double pvm_master_get_monte_carlo_value(int nvar,
01691     const dvector& x);
01692   void pvm_slave_get_monte_carlo_value(int nvar);
01693   void mcmc_eval(void);
01694   //void hess_routine_and_constraint(int);
01695   void hess_routine_and_constraint(int iprof,const dvector& g,
01696     dvector& fg);
01697   dmatrix diag_hess_routine(void);
01698   void hess_inv(void);
01699   void depvars_routine(void);
01700   void sd_routine(void);
01701   int ef_(double * f, double * x);
01702   int constrained_minimization2(int _n,int _nh, int _ng,dvector& __x);
01703   static int constraint_exit_number;
01704 
01705 #ifdef CURVE_CORRECT
01706   void constraint_hess_routine(int ip);
01707   void get_curvature_correction_factors(int ip,
01708     dvector& g, const int underflow_flag, const dvector& eigenvals,
01709     dvector& curvcor);
01710 #endif
01711   double projected_jacobian(const dvector& g, const dvector& xscale);
01712 
01713   dvariable random_effects_maximization(const dvar_vector& v);
01714   void prof_minimize(int iprof, double sigma,
01715     double new_value, const double& fprof,const int underflow_flag,
01716     double global_min, const double& penalties, const double& final_weight);
01717 
01718   void prof_hess_routine(int ip,double new_value,double final_weight);
01719 
01720   void quasi_newton_minimizer1(int nvar,double _crit,
01721     double& f, const independent_variables& x, const dvector& g);
01722 
01723   double hess_determinant(int underflow_flag);
01724 
01725 #ifndef CURVE_CORRECT
01726   void normalize_posterior_distribution(double udet,
01727     const dvector& siglevel, const ofstream& ofs2, int num_pp,
01728     const dvector& all_values, const dmatrix& actual_value, double global_min,
01729     int offset, const dmatrix& lprof, const dmatrix& ldet, const dmatrix& xdist,
01730     const dmatrix& penalties);
01731   //  dmatrix& penalties, const dmatrix& lg_jacob);
01732 #else
01733   void normalize_posterior_distribution(double udet,
01734     const dvector& siglevel, const ofstream& ofs2, int num_pp,
01735     const dvector& all_values, const dmatrix& actual_value,
01736     double global_min,
01737     int offset, const dmatrix& lprof, const dmatrix& ldet,
01738     const dmatrix& xdist,
01739     const d3_array& eigenvals, d3_array& curvcor);
01740 #endif
01741   void get_particular_grad(int iprof, int nvar, const dvector& fg, const dvector& g);
01742   double projected_hess_determinant(const dvector& g, const int underflow_flag,
01743     const dvector& xscale, const double& ln_det_proj_jac);
01744 //  double projected_hess_determinant(const dvector& fg, const dvector& g,
01745   //const int underflow_flag, const dvector& xscale, const double& ln_det_proj_jac);
01746   double projected_hess_determinant(const dvector& g, const int underflow_flag);
01747   double projected_hess_determinant(const dmatrix& hh, const dvector& g,
01748     const int underflow_flag);
01749   //double projected_hess_determinant(const dvector& g,const int underflow_flag,
01750     //dvector& xscale, const double& ln_det_proj_jac);
01751 
01752   double projected_hess_determinant(const dvector& fg, const dvector& g,
01753     const int underflow_flag, const dvector& curvscale, const dvector& xscale,
01754     double& ln_det_proj_jac, const double& tmp, const dmatrix& hesses);
01755   double diag_projected_hess_determinant(const dvector& g, const int underflow_flag,
01756     dmatrix& dh);
01757     double unrestricted_hess_determinant(void);
01758   void monte_carlo_routine(void);
01759   double get_monte_carlo_value(int nvar, const independent_variables& x);
01760   void mcmc_computations(void);
01761   void pvm_slave_mcmc_computations(void);
01762   void pvm_master_mcmc_computations(void);
01763   double get_monte_carlo_value(int nvar, const dvector& x);
01764   void sob_routine(int nmcmc,double dscale,int restart_flag);
01765   void sobol_importance_routine(int nmcmc,int iseed0,double dscale,
01766   int restart_flag);
01767   void pvm_master_mcmc_routine(int nmcmc,int iseed0,double dscale,
01768     int restart_flag);
01769   void pvm_slave_mcmc_routine(void);
01770   void function_minimizer::trust_region_update(int nvar,int _crit,
01771     independent_variables& x,const dvector& _g,const double& _f);
01772 
01773   void multint4(int n, const dvar_vector& a, const dvar_vector& b, const dvar_vector& h,
01774     double al, int m, const dvariable& e, const dvariable& aint1, const dvariable& aint2,
01775     dvariable& aint3, const dvariable& aint4, const int& key, PMFVIV4 f);
01776 
01777   void multint(int n, const dvar_vector& a, const dvar_vector& b, const dvar_vector& h,
01778     double al, int m, const dvariable& e, const dvariable& aint, const int& key, PMFVI f);
01779 
01780   virtual void set_runtime(void);
01781   virtual void set_runtime_maxfn(const char *);
01782   virtual void set_runtime_crit(const char *);
01783   dvariable adromb(PMF,double a,double b,int ns=9);
01784   dvariable adromb(PMF, const dvariable& a, double b, int ns = 9);
01785   dvariable adromb(PMF, const dvariable& a, const dvariable& b, int ns = 9);
01786   dvariable adromb(PMF, double a, const dvariable& b, int ns = 9);
01787 
01788   dvariable adrombo(PMF,double a,double b,int ns=9);
01789   dvariable adrombo(PMF, const dvariable& a, double b, int ns = 9);
01790   dvariable adrombo(PMF, const dvariable& a, const dvariable& b,int ns = 9);
01791   dvariable adrombo(PMF, double a, const dvariable& b,int ns = 9);
01792 
01793   dvariable trapzd(void*,double a,double b,int n);
01794   dvariable trapzd(PMF,double a,double b,int n);
01795   dvariable trapzd(PMF, double a, const dvariable& b, int n);
01796   dvariable trapzd(PMF, const dvariable& a, double b, int n);
01797   dvariable trapzd(PMF, const dvariable& a, const dvariable& b, int n);
01798 
01799   dvariable midpnt(PMF,double a,double b,int n);
01800   dvariable midpnt(PMF, double a, const dvariable& b, int n);
01801   dvariable midpnt(PMF, const dvariable& a, double b, int n);
01802   dvariable midpnt(PMF, const dvariable& a, const dvariable& b,int n);
01803 
01804   virtual void * mycast() { return (void*)this;}
01805 
01806   void adamoeba(const dmatrix& p, const dvector& y, int ndim, double ftol,int maxfn);
01807   void set_initial_simplex(const dmatrix& p, const dvector& y, int nvar, const dvector& x,
01808     double delta);
01809   double amxxx(const dmatrix& p, const dvector& y, const dvector& psum, int ndim,
01810     int ihi, double fac);
01811   friend class equality_constraint_vector;
01812   friend class inequality_constraint_vector;
01813   void quasi_newton_block(int nvar,int crit,independent_variables& x,
01814     const dvector& g,const double& f);
01815 #if defined(USE_LAPLACE)
01816   void function_evaluation_block_pvm_slave_random_effects(int nvar,int _crit,
01817     independent_variables& x,const dvector& g,const double& f);
01818   void quasi_newton_block_pvm_master_random_effects(int nvar,int _crit,
01819     independent_variables& x,const dvector& g,const double& f);
01820   void function_evaluation_block_pvm_slave_random_effects(void);
01821   void function_minimizer::hess_routine_random_effects(void);
01822 #endif
01823   void quasi_newton_block_pvm_master(int nvar,int _crit,
01824     independent_variables& x,const dvector& g,const double& f);
01825   void function_minimizer::hess_routine_noparallel_random_effects(void);
01826 #if defined(USE_ADPVM)
01827   void function_evaluation_block_pvm_slave(void);
01828   void function_minimizer::hess_routine_slave_random_effects(void);
01829 #endif
01830 };
01831 
01832 cifstream& operator>>(const cifstream& s, const param_init_number& x);
01833 cifstream& operator>>(const cifstream& s, const param_init_vector& v);
01834 cifstream& operator>>(const cifstream& s, const param_init_matrix& m);
01835 ostream& operator<<(const ostream& s, const label_class& lc);
01836 
01841 class stddev_params
01842 {
01843 protected:
01844 public:
01845   static stddev_params * stddevptr[150]; // this should be a resizeable array
01846   static stddev_params * stddev_number_ptr[150]; // this should be a resizeable array
01847   static void get_all_sd_values(const dvector& x, const int& ii);
01848   static int num_stddev_params;
01849   static int num_stddev_number_params;
01850   static ivector copy_all_number_offsets(void);
01851   void allocate(void){;};
01852   static int num_stddev_calc(void);
01853   static int num_stddev_number_calc(void);
01854   static void get_stddev_number_offset(void);
01855 public:
01856   stddev_params(void){;}
01857   virtual void setindex(int);
01858   virtual int getindex(void);
01859   virtual int size_count(void)=0; // get the number of active parameters
01860   virtual void set_dependent_variables(void)=0;
01861   virtual void copy_value_to_vector(const dvector&, const int&) = 0;
01862   virtual void get_sd_values(const dvector& x, const int& ii) = 0;
01863   static void copy_all_values(const dvector& x, const int& ii); //get the number of active parameters
01864   static void copy_all_number_values(const dvector& x, const int& ii); //get the number of active parameters
01865   virtual void add_to_list(void);
01866   virtual void add_to_gui_list(void);
01867   virtual const char * label()=0;
01868   friend class function_minimizer;
01869 };
01870 
01875 class likeprof_params
01876 {
01877   double stepsize;
01878   int    stepnumber;
01879 protected:
01880 public:
01881   static likeprof_params * likeprofptr[50]; // this should be a
01882                                                // resizeable array
01883   static int num_likeprof_params;
01884   void allocate(void){;};
01885   static int num_stddev_calc(void);
01886 public:
01887   likeprof_params(void);
01888   virtual void add_to_list(void);
01889   virtual const char * label()=0;
01890   virtual dvariable variable(void)=0;
01891   virtual double& get_sigma(void)=0;
01892   virtual double get_value(void)=0;
01893   double get_stepsize(void);
01894   int get_stepnumber(void);
01895   void set_stepsize(double);
01896   void set_stepnumber(int);
01897   friend class function_minimizer;
01898 };
01899 
01904 class param_stddev_vector: public named_dvar_vector , stddev_params
01905 {
01906   dvector sd;
01907     virtual int size_count(void); // get the number of active parameters
01908     virtual const char * label(void);
01909     param_stddev_vector();
01910     void allocate(int imin,int imax,const char * s="UNNAMED");
01911     virtual void set_dependent_variables(void);
01912     friend class model_parameters;
01913     virtual void copy_value_to_vector(const dvector& x, const int& ii);
01914     virtual void get_sd_values(const dvector& x, const int& ii);
01915   param_stddev_vector& operator=(const dvar_vector& m);
01916   param_stddev_vector& operator=(const dvector& m);
01917   param_stddev_vector& operator = (CGNU_DOUBLE m);
01918 };
01919 
01924 class param_stddev_number: public named_dvariable , public stddev_params
01925 {
01926   double sd;
01927   int index;
01928   void allocate(const char *s="UNNAMED");
01929   virtual void setindex(int);
01930   virtual int getindex(void);
01931   virtual int size_count(void); // get the number of active parameters
01932   virtual const char * label(void);
01933   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01934   virtual void get_sd_values(const dvector& x, const int& ii);
01935 protected:
01936   param_stddev_number();
01937   friend class model_parameters;
01938   virtual void set_dependent_variables(void);
01939   param_stddev_number& operator=(const prevariable&);
01940   param_stddev_number& operator = (CGNU_DOUBLE);
01941 };
01942 
01947 class param_likeprof_number: public param_stddev_number ,
01948     public likeprof_params
01949 {
01950     double sigma;
01951     void allocate(const char *s="UNNAMED");
01952     virtual int size_count(void); // get the number of active parameters
01953     virtual const char * label(void);
01954     virtual double& get_sigma(void){return sigma;}
01955     virtual double get_value(void){return value(*this);}
01956     //void copy_value_to_vector(const dvector& x, const int& ii);
01957     virtual dvariable variable(void){ return dvariable(*this);}
01958     param_likeprof_number();
01959     friend class model_parameters;
01960 public:
01961     param_likeprof_number& operator=(const prevariable&);
01962     param_likeprof_number& operator = (CGNU_DOUBLE);
01963 };
01964 
01969 class param_stddev_matrix: public named_dvar_matrix , stddev_params
01970 {
01971   dmatrix sd;
01972     virtual int size_count(void);
01973     //virtual void read_value(void);
01974     virtual const char * label(void);
01975     void allocate(int rmin,int rmax,int cmin,int cmax,
01976     const char * s="UNNAMED");
01977   param_stddev_matrix(void);
01978   friend class model_parameters;
01979   virtual void set_dependent_variables(void);
01980   virtual void get_sd_values(const dvector& x, const int& ii);
01981   virtual void copy_value_to_vector(const dvector& x, const int& ii);
01982   param_stddev_matrix& operator = (CGNU_DOUBLE m);
01983   param_stddev_matrix& operator=(const dmatrix& m);
01984   param_stddev_matrix& operator=(const dvar_matrix& m);
01985 };
01986 
01991 class adpvm_slave_args
01992 {
01993   char ** argv;
01994   int num_args;
01995   ivector length_args;
01996 public:
01997   int counter;
01998   char * operator () (int);
01999   operator char ** ();
02000   void operator -- (void);
02001   adpvm_slave_args(int num_args,int len_args);
02002   adpvm_slave_args(int num_args,const ivector& len_args);
02003   ~adpvm_slave_args();
02004   int get_num_args(void);
02005 };
02006 
02007 void strcpy(const adpvm_slave_args& a,const char * s);
02008 class adpvm_manager;
02009 
02014   class objective_function_value : public named_dvariable
02015   {
02016   public:
02017     static objective_function_value * pobjfun;
02018     static double fun_without_pen;
02019     static double gmax;
02020     objective_function_value();
02021     objective_function_value& operator=(const prevariable& v);
02022     objective_function_value& operator = (CGNU_DOUBLE v);
02023   };
02024 
02025   int withinbound(int lb,int n,int ub);
02026 
02027 double cumd_cauchy(const double& x);
02028 double density_cauchy(const double& x);
02029 double log_density_cauchy(const double& x);
02030 double inv_cumd_cauchy(const double& x);
02031 
02032 double cumd_mixture(const double& x);
02033 double inv_cumd_mixture(const double& y);
02034 double cumd_mixture_02(const double& x);
02035 double inv_cumd_mixture_02(const double& y);
02036 
02037 #if defined _ADM_HIGHER_ARRAYS__
02038 
02043 class param_init_matrix: public named_dvar_matrix,public initial_params
02044 {
02045   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
02046 //  virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
02047   virtual void add_value(const dvector&, const dvector&, const int&, cons tdouble&, const dvector&);
02048   virtual void add_value(const dvector&, const int&);
02049   virtual void get_jacobian(const dvector&, const dvector&,const int&);
02050 public:
02051 
02052   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
02053   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02054   virtual void restore_value_from_vector(const dvector&, const int&);
02055   virtual void set_value_inv(const dvector& x, const int& ii);
02056   virtual int size_count(void);
02057   virtual void save_value(void);
02058   virtual void bsave_value(void);
02059   virtual void save_value(const ofstream& ofs, int prec);
02060   virtual void restore_value(const ifstream& ifs);
02061   void report_value(void);
02062   //virtual void read_value(void);
02063   virtual const char * label(void);
02064   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
02065   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
02066   virtual void curv_scale(const dvector& d, const dvector& x, const int&);
02067   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){;};
02068 
02069 public:
02070 
02071   void allocate(int rmin,int rmax,int cmin,int cmax,
02072     int phase_start=1,const char * = "UNNAMED");
02073   void allocate(int rmin,int rmax,int cmin,int cmax,
02074     const char * = "UNNAMED");
02075   param_init_matrix(void);
02076   param_init_matrix& operator = (const dmatrix& m);
02077   param_init_matrix& operator = (const dvar_matrix& m);
02078   param_init_matrix& operator = (const dvariable& m);
02079   param_init_matrix& operator = (const double& m);
02080 };
02081 #endif // #if defined _ADM_HIGER_ARRAYS__
02082 
02087 class param_init_d3array: public named_dvar3_array,public initial_params
02088 {
02089 public:
02090 
02091   virtual void dev_correction(const dmatrix&, const int&);
02092   virtual void curv_scale(const dvector& d, const dvector& x, const int& ii);
02093   virtual void set_simulation_bounds(const dmatrix& symbds, const int& ii);
02094 //  virtual void set_simulation_bounds(const dmatrix&, const dvector& symbds, const int& ii);
02095   virtual void add_value(const dvector&, const dvector&, const int&, const double&, const dvector&);
02096   virtual void add_value(const dvector&, const int&);
02097   virtual void get_jacobian(const dvector&, const dvector&, const int&);
02098   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
02099   virtual void copy_value_to_vector(const dvector& x, const int& ii);
02100   virtual void restore_value_from_vector(const dvector&, const int&);
02101   virtual void set_value_inv(const dvector& x, const int& ii);
02102   virtual int size_count(void);
02103   virtual void save_value(void);
02104   virtual void bsave_value(void);
02105   virtual void save_value(const ofstream& ofs, int prec);
02106   virtual void restore_value(const ifstream& ifs);
02107   void report_value(void);
02108   //virtual void read_value(void);
02109   virtual const char * label(void);
02110   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
02111   virtual void mc_scale(const dvector& d, const dvector& x, const int&);
02112   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii);
02113 
02114 public:
02115 
02116   void allocate(const ad_integer& sl,const ad_integer& sh,
02117     const index_type& nrl,const index_type& nrh,
02118     const index_type& ncl,const index_type& nch,const char * s="UNNAMED");
02119 
02120   void allocate(const ad_integer& sl,const ad_integer& sh,
02121     const index_type& nrl,const index_type& nrh,
02122     const index_type& ncl,const index_type& nch,int phase_start=1,
02123     const char * s="UNNAMED");
02124 
02125   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
02126     int phase_start=1,const char * = "UNNAMED");
02127   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
02128     const char * = "UNNAMED");
02129   param_init_d3array(void);
02130 };
02131 
02136 class dll_param_init_d3array: public param_init_d3array
02137 {
02138   double * d;
02139 public:
02140   void allocate(double* _d,int hmin,int hmax,
02141     int rmin,int rmax,int cmin,int cmax,
02142     int phase_start=1,const char * = "UNNAMED");
02143   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
02144     int cmin,int cmax,const char * = "UNNAMED");
02145   virtual ~dll_param_init_d3array();
02146   dll_param_init_d3array(){d=NULL;}
02147   dll_param_init_d3array& operator=(const d3_array&);
02148   dll_param_init_d3array& operator=(const dvar3_array&);
02149 };
02150 
02155 class dll_param_d3array: public named_dvar3_array
02156 {
02157   double * d;
02158 public:
02159   void allocate(double* _d,int hmin,int hmax,
02160     int rmin,int rmax,int cmin,int cmax,
02161     int phase_start=1,const char * = "UNNAMED");
02162   void allocate(double * _d,int hmin,int hmax,int rmin,int rmax,
02163     int cmin,int cmax,const char * = "UNNAMED");
02164   virtual ~dll_param_d3array();
02165   dll_param_d3array(){d=NULL;}
02166   dll_param_d3array& operator=(const d3_array&);
02167   dll_param_d3array& operator=(const dvar3_array&);
02168 };
02169 
02170 
02171 //double set_value_mc(const double& x,CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
02172 
02173 void set_value_mc(const dvar_vector& x, cons tdvar_vector& v, const int& ii,
02174   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
02175 
02176 double set_value_inv_mc(double v,double fmin,double fmax);
02177 
02178 double set_value_inv_mc(const prevariable& v, double fmin, double fmax);
02179 
02180 void set_value_inv_mc(const dvar_vector& x, const dvector& v, const int& ii,
02181   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
02182 
02183 //double set_value_inv_mc(const dvector&, const dvector& x,int ii,double minb,double maxb);
02184 
02185 double set_value_mc(double z,double min,double max);
02186 double ndfboundp( double x, double fmin, double fmax,const double& fpen);
02187 double ndfboundp_mc( double x, double fmin, double fmax,const double& fpen);
02188 
02189 void copy_value_from_vector(const double& _sd,const dvector& x,const int & _ii);
02190 void copy_value_from_vector(const dvector& _sd,const dvector& x,const int & _ii);
02191 void copy_value_from_vector(const dmatrix& _sd,const dvector& x,const int & _ii);
02192 
02193 void bounded_multivariate_normal_mcmc(int nvar, const dvector& a1, const dvector& b1,
02194   dmatrix& ch, const double& wght, const dvector& y, const random_number_generator& rng);
02195 
02196 void bounded_multivariate_uniform_mcmc(int nvar, const dvector& a1, const dvector& b1,
02197   dmatrix& ch, const double& wght, const dvector& y, const random_number_generator& rng);
02198 
02199 dvector bounded_multivariate_normal(int nvar, const dvector& a1, const dvector& b1,
02200   dmatrix& ch, const double& lprob, const random_number_generator& rng);
02201 
02202 dvector bounded_multivariate_normal_sobol(int nvar, const dvector& a1, const dvector& b1,
02203   dmatrix& ch, const double& lprob, const random_number_generator& rng);
02204 
02205 dvector probing_bounded_multivariate_normal(int nvar, const dvector& a1, const dvector& b1,
02206   dmatrix& ch, const double& lprob,double pprobe, const random_number_generator& rng);
02207 
02208 dvector bounded_multivariate_uniform(int nvar, const dvector& a1, const dvector& b1,
02209   dmatrix& ch, const double& lprob, random_number_generator& rng);
02210 
02211 void probing_bounded_multivariate_normal_mcmc(int nvar, const dvector& a1, const dvector& b1,
02212   dmatrix& ch, const double& wght, const dvector& v,double pprobe, const random_number_generator& rng);
02213 
02214 /*
02215 int option_match(int argc,char * argv[], const char * string);
02216 int option_match(int argc,char * argv[], const char * string, const int& nopt);
02217 int option_match(char * s, const char * string, const int& _nopt);
02218 int option_match(char * s, const char * string);
02219 */
02220 
02221 double inv_cumd_exp(double x);
02222 double cumd_exp(double x);
02223 
02224 double ffmax(double a,double b);
02225 double ffmin(double a,double b);
02226 
02227 void check_datafile_pointer(void * p);
02228 
02229 #if (defined(__GNUDOS__))
02230 #  if (defined(linux)) || (defined(__ADSGI__))
02231 #    define IOS_BINARY 0
02232 #  else
02233 #    define IOS_BINARY ios::bin
02234 #  endif
02235 #endif
02236 
02237 #if (defined(__BORLANDC__))
02238 #  define IOS_BINARY ios::binary
02239 #endif
02240 
02241 adstring get_reportfile_name(void);
02242 
02243 void ad_make_code_reentrant(void);
02244 
02245 char ** parse_dll_options(char *pname, const int& argc, char *dll_options);
02246 
02247 char ** no_dll_options(char *pname, const int& argc);
02248 
02249 void cleanup_argv(int nopt,char *** pa);
02250 
02251 void get_sp_printf(void);
02252 
02253 void do_dll_housekeeping(int argc,char ** argv);
02254 
02255 void adwait(double);
02256 
02257 int ad_get_commandline_option(const char *option_label, const int & option_value,
02258   const char * error_message);
02259 
02264  class param_init_vector_vector
02265  {
02266    param_init_vector * v;
02267    int index_min;
02268    int index_max;
02269    double_index_type * it;
02270 
02271  public:
02272   void set_scalefactor(double s);
02273   void set_scalefactor(const dvector& s);
02274   dvector get_scalefactor(void);
02275 
02276 #if defined(OPT_LIB)
02277    param_init_vector& operator [] (int i) { return v[i];}
02278    param_init_vector& operator () (int i) { return v[i];}
02279    prevariable operator () (int i,int j) { return BORCAST(v[i][j]);}
02280 #else
02281    param_init_vector& operator [] (int i);
02282    param_init_vector& operator () (int i);
02283    prevariable operator () (int i,int j);
02284 #endif
02285 
02286    void allocate(int min1,int max1,const index_type& min,
02287      const index_type& max,const index_type& phase_start,
02288      const char * s);
02289 
02290    void allocate(int min1,int max1,const index_type& min,
02291      const index_type& max,const char * s);
02292 
02293    param_init_vector_vector();
02294    int allocated(void) { return (v!=NULL); }
02295    int indexmin(void) {return (index_min);}
02296    int indexmax(void) {return (index_max);}
02297    ~param_init_vector_vector();
02298    void set_initial_value(const double_index_type& it);
02299    void deallocate(void);
02300  };
02301 
02306  class param_init_bounded_vector_vector
02307  {
02308    param_init_bounded_vector * v;
02309    int index_min;
02310    int index_max;
02311    double_index_type * it;
02312 
02313  public:
02314 
02315   void set_scalefactor(double s);
02316   void set_scalefactor(const dvector& s);
02317   dvector get_scalefactor(void);
02318   param_init_bounded_vector_vector();
02319 #if defined(OPT_LIB)
02320    param_init_bounded_vector& operator [] (int i) { return v[i];}
02321    param_init_bounded_vector& operator () (int i) { return v[i];}
02322    prevariable operator () (int i,int j) { return BORCAST (v[i][j]);}
02323 #else
02324    param_init_bounded_vector& operator [] (int i);
02325    param_init_bounded_vector& operator () (int i);
02326    prevariable operator () (int i,int j);
02327 #endif
02328 
02329    void allocate(int min1,int max1,
02330      const index_type& min,
02331      const index_type& max,
02332      const double_index_type& dmin,
02333      const double_index_type& dmax,
02334      const index_type& phase_start,
02335      const char * s);
02336 
02337    void allocate(int min1,int max1,
02338      const index_type& min,
02339      const index_type& max,
02340      const double_index_type& dmin,
02341      const double_index_type& dmax,
02342      const char * s);
02343 
02344    int allocated(void) { return (v!=NULL); }
02345    int indexmin(void) {return (index_min);}
02346    int indexmax(void) {return (index_max);}
02347    ~param_init_bounded_vector_vector();
02348    void deallocate(void);
02349    void set_initial_value(const double_index_type& it);
02350  };
02351 
02356  class param_init_matrix_vector
02357  {
02358    param_init_matrix * v;
02359    int index_min;
02360    int index_max;
02361    double_index_type * it;
02362 
02363  public:
02364   param_init_matrix_vector();
02365   void set_scalefactor(double s);
02366   void set_scalefactor(const dvector& s);
02367   dvector get_scalefactor(void);
02368 
02369 #if defined(OPT_LIB)
02370    param_init_matrix& operator [] (int i) { return v[i];}
02371    param_init_matrix& operator () (int i) { return v[i];}
02372    dvar_vector& operator () (int i,int j) { return v[i][j];}
02373    prevariable operator () (int i,int j,int k) { return BORCAST (v[i](j,k));}
02374 #else
02375    param_init_matrix& operator [] (int i);
02376    param_init_matrix& operator () (int i);
02377    dvar_vector& operator () (int i,int j);
02378    prevariable operator () (int i,int j,int k);
02379 #endif
02380 
02381    void allocate(int min0,int max0,const index_type& min,
02382      const index_type& max,const index_type& min1,
02383      const index_type& max1,const index_type& phase_start,
02384      const char * s);
02385 
02386    void allocate(int min0,int max0,const index_type& min,
02387      const index_type& max,const index_type& min1,
02388      const index_type& max1,const char * s);
02389 
02390    int allocated(void) { return (v!=NULL); }
02391    int indexmin(void) {return (index_min);}
02392    int indexmax(void) {return (index_max);}
02393    ~param_init_matrix_vector();
02394    void set_initial_value(const double_index_type& it);
02395    void deallocate(void);
02396  };
02397 
02402  class param_init_bounded_matrix_vector
02403  {
02404    param_init_bounded_matrix * v;
02405    int index_min;
02406    int index_max;
02407    double_index_type * it;
02408 
02409  public:
02410   void set_scalefactor(double s);
02411   void set_scalefactor(const dvector& s);
02412   dvector get_scalefactor(void);
02413   param_init_bounded_matrix_vector();
02414 
02415    void param_init_bounded_matrix_vector::allocate(int min1,int max1,
02416      const index_type& min, const index_type& max, const index_type& min2,
02417      const index_type& max2, const double_index_type& dmin2,
02418      const double_index_type& dmax2, const index_type& phase_start,
02419      const char * s);
02420 
02421    void param_init_bounded_matrix_vector::allocate(int min1,int max1,
02422      const index_type& min, const index_type& max, const index_type& min2,
02423      const index_type& max2, const double_index_type& dmin2,
02424      const double_index_type& dmax2,const char * s);
02425 
02426 #if defined(OPT_LIB)
02427    param_init_bounded_matrix& operator [] (int i) { return v[i];}
02428    param_init_bounded_matrix& operator () (int i) { return v[i];}
02429    dvar_vector& operator () (int i,int j) { return v[i][j];}
02430    prevariable operator () (int i,int j,int k) { return BORCAST (v[i](j,k));}
02431 #else
02432    param_init_bounded_matrix& operator [] (int i);
02433    param_init_bounded_matrix& operator () (int i);
02434    dvar_vector& operator () (int i,int j);
02435    prevariable operator () (int i,int j,int k);
02436 #endif
02437 
02438    int allocated(void) { return (v!=NULL); }
02439    int indexmin(void) {return (index_min);}
02440    int indexmax(void) {return (index_max);}
02441    ~param_init_bounded_matrix_vector();
02442    void set_initial_value(const double_index_type& it);
02443    void deallocate(void);
02444  };
02445 
02450  class param_init_number_vector
02451  {
02452    param_init_number * v;
02453    int index_min;
02454    int index_max;
02455    double_index_type * it;
02456 
02457  public:
02458 
02459   void set_scalefactor(double s);
02460   void set_scalefactor(const dvector& s);
02461   dvector get_scalefactor(void);
02462   param_init_number_vector();
02463 
02464 #if defined(OPT_LIB)
02465    param_init_number& operator [] (int i) { return v[i];}
02466    param_init_number& operator () (int i) { return v[i];}
02467 #else
02468    param_init_number& operator [] (int i);
02469    param_init_number& operator () (int i);
02470 #endif
02471 
02472    void allocate(int min1,int max1,const index_type& phase_start,
02473      const char * s);
02474 
02475    void allocate(int min1,int max1,const char * s);
02476 
02477    int allocated(void) { return (v!=NULL); }
02478    int indexmin(void) {return (index_min);}
02479    int indexmax(void) {return (index_max);}
02480    ~param_init_number_vector();
02481    void set_initial_value(const double_index_type& it);
02482    void deallocate(void);
02483  };
02484 
02489  class param_init_bounded_number_vector
02490  {
02491    param_init_bounded_number * v;
02492    int index_min;
02493    int index_max;
02494    double_index_type * it;
02495 
02496  public:
02497 
02498   void set_scalefactor(double s);
02499   void set_scalefactor(const dvector& s);
02500   dvector get_scalefactor(void);
02501   param_init_bounded_number_vector();
02502 
02503 #if defined(OPT_LIB)
02504    param_init_bounded_number& operator [] (int i) { return v[i];}
02505    param_init_bounded_number& operator () (int i) { return v[i];}
02506 #else
02507    param_init_bounded_number& operator [] (int i);
02508    param_init_bounded_number& operator () (int i);
02509 #endif
02510 
02511    void allocate(int min1,int max1,const double_index_type & bmin,
02512      const double_index_type & bmax,const index_type& phase_start,
02513      const char * s);
02514 
02515    void allocate(int min1,int max1,const double_index_type & bmin,
02516      const double_index_type & bmax,const char * s);
02517 
02518    int allocated(void) { return (v!=NULL); }
02519    int indexmin(void) {return (index_min);}
02520    int indexmax(void) {return (index_max);}
02521    ~param_init_bounded_number_vector();
02522    void set_initial_value(const double_index_type& it);
02523    void deallocate(void);
02524  };
02525   extern int traceflag;
02526   void tracing_message(int traceflag,const char *s,int *pn);
02527   void tracing_message(int traceflag,const char *s,double *pn);
02528   void set_gauss_covariance_matrix(const dll_data_matrix& m);
02529   void set_gauss_covariance_matrix(const dmatrix& m);
02530   void set_covariance_matrix(const dll_data_matrix& m);
02531   void set_covariance_matrix(const dmatrix& m);
02532 
02533   //ostream& operator <<  (const ostream&, const param_init_number_vector);
02534   //ostream& operator <<  (const ostream&, const param_init_bounded_number_vector);
02535   //ostream& operator <<  (const ostream&, const param_init_vector_vector);
02536   //ostream& operator <<  (const ostream&, const param_init_bounded_vector_vector);
02537   //ostream& operator <<  (const ostream&, const param_init_matrix_vector);
02538   //ostream& operator <<  (const ostream&, const param_init_bounded_matrix_vector);
02539 
02544   class vector_kludge : public dvar_vector
02545   {
02546     public:
02547      vector_kludge(const param_init_number_vector &);
02548      vector_kludge(const param_init_bounded_number_vector &);
02549   };
02550 
02555   class matrix_kludge : public dvar_matrix
02556   {
02557     public:
02558      matrix_kludge(const param_init_vector_vector &);
02559      matrix_kludge(const param_init_bounded_vector_vector &);
02560   };
02561 
02562 class ad_comm;
02563 
02568 class adpvm_manager
02569 {
02570   adstring_array slave_names;
02571   adpvm_slave_args * slave_argv;
02572 public:
02573   struct pvmhostinfo *hostp;
02574   int nhost;
02575   int mode;  // 1 = master 2 = slave
02576   int copy;
02577   int slave_number;
02578   int narch;
02579   imatrix id;
02580   int num_slave_processes;
02581   ivector num_per_host;
02582   int start_slave_processes(const ad_comm& mp);
02583   imatrix slave_assignments;
02584   adtimer tm;
02585   int timing_flag;
02586   void master_slave_variable_interface(const ad_comm& mp);
02587   void master_slave_variable_interface(void);
02588   void get_variable_values_from_master(void);
02589   void send_variable_values_to_slaves(void);
02590   adpvm_manager(int);
02591   ~adpvm_manager();
02592 #  if defined(USE_LAPLACE)
02593       int start_slave_processes_for_random_effects(const ad_comm& mp);
02594 #  endif
02595 };
02596 
02597 void send_dmatrix_to_slaves(const dmatrix&  x,ivector& jmin,ivector& jmax);
02598 dvariable receive_f_from_slaves(void);
02599 void send_x_to_slaves(const dvar_vector& x);
02600 void send_dvector_to_slaves(const dvector& x);
02601 void send_dvector_to_master(const dvector& x);
02602 void send_dmatrix_to_master(const dmatrix& x);
02603 dvar_vector get_x_from_master(void);
02604 dvector get_dvector_from_master(void);
02605 dmatrix get_dmatrix_from_master(void);
02606 void send_f_to_master(const dvariable& x);
02607 void send_int_to_master(int i);
02608 dvar_matrix get_f_from_slaves();
02609 d3_array get_dmatrix_from_slaves();
02610 d3_array get_dmatrix_from_slaves(const imatrix& flags);
02611 dmatrix get_dvector_from_slaves();
02612 void admaster_slave_variable_interface(const ad_comm& mp);
02613 void admaster_slave_variable_interface(void);
02614 int get_int_from_master(void);
02615 imatrix get_int_from_slaves(void);
02616 void send_int_to_slaves(int  x);
02617 void send_int_to_slaves(const ivector& x);
02618 int check_pvm_message(int i,int j);
02619 
02620 int withinbound(int lb,int n,int ub);
02621 
02622 #if defined(__MSVC32__)
02623 #  if defined(min)
02624 #    undef min
02625 #  endif
02626 #  if defined(max)
02627 #    undef max
02628 #  endif
02629 #endif
02630 
02631 #endif