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