ADMB Documentation  11.1.1540
 All Classes Files Functions Variables Typedefs Friends Defines
admod2.h
Go to the documentation of this file.
00001 /*
00002  * $Id: admod2.h 1112 2013-07-12 21:41:41Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 #if defined(__GNUC__)
00046   #if (__GNUC__ < 3)
00047     #pragma interface
00048   #endif
00049 #else
00050   #pragma interface
00051 #endif
00052 
00053 #ifndef _ADMODEL_H_
00054   #define  _ADMODEL_H_
00055 #ifdef __GNUDOS__
00056   #define CGNU_DOUBLE double
00057 #else
00058   #define CGNU_DOUBLE const double&
00059 #endif
00060 #include <fvar.hpp>
00061 #include <d4arr.hpp>
00062 #include <cifstrem.h>
00063 #include <iomanip.h>
00064 #include <adstring.hpp>
00065 #define param_matrix named_dvar_matrix
00066 #define param_vector named_dvar_vector
00067 #define param_number named_dvariable
00068 #define param_3array named_dvar3_array
00069 #define param_4array named_dvar4_array
00070 #define MAX_NUM_DATA_FILES 10
00071 #define MAX_NUM_PAR_FILES 10
00072 
00073   double mfexp(CGNU_DOUBLE );
00074   dvariable mfexp(const prevariable& v1);
00075   dvar_vector mfexp(const dvar_vector& );
00076   dvector mfexp(const dvector& );
00077 
00078 
00079  void set_value_inv(const dvariable& x, const dvector& v, const int& ii);
00080  void set_value_inv(const dvar_matrix& x, const dvector& v, const int& ii);
00081  void set_value_inv(const dvar_vector&, const dvector&, const int &ii);
00082  void set_value_inv(const dvariable& u, const dvector& x, const int& ii,CGNU_DOUBLE fmin,
00083   CGNU_DOUBLE fmax);
00084  void set_value_inv(const  dvar_matrix& u, const dvector& x, const int& ii,
00085   CGNU_DOUBLE fmin,CGNU_DOUBLE fmax);
00086 
00087   void copy_value_to_vector(const prevariable& x,const dvector& v,const int& ii);
00088   void copy_value_to_vector(const dvar_vector& x,const dvector& v,const int& ii);
00089   void copy_value_to_vector(const dvar_matrix& x,const dvector& v,const int& ii);
00090   void copy_value_to_vector(const dvar3_array& x,const dvector& v,const int& ii);
00091 
00092   void restore_value_from_vector(const prevariable& x, const dvector& v, const int& ii);
00093   void restore_value_from_vector(const dvar_vector& x, const dvector& v, const int& ii);
00094   void restore_value_from_vector(const dvar_matrix& x, const dvector& v, const int& ii);
00095   void restore_value_from_vector(dvar3_array& x, const dvector& v, const int& ii);
00096 
00097 
00098 class model_data;
00099 
00104 class label_class
00105 {
00106   const char * name;
00107   friend ostream& operator<<(const ostream& s, const label_class& lc);
00108   friend class model_name_tag;
00109 public:
00110   operator const char * () { return name;}
00111   label_class(const char * s){name=s;}
00112 };
00113 
00118 class model_name_tag
00119 {
00120   const char * name;
00121   //friend ostream& operator<<(const ostream& os, const model_name_tag& mnt);
00122 public:
00123   model_name_tag(void){}
00124   void allocate(const char * s);
00125   label_class label(void){return name;}
00126 };
00127 
00132 class named_dvar_vector : public dvar_vector, public model_name_tag
00133 {
00134 protected:
00135   named_dvar_vector(void) : dvar_vector(), model_name_tag() {}
00136   named_dvar_vector& operator=(const dvar_vector& m);
00137   named_dvar_vector& operator=(const dvector& m);
00138   named_dvar_vector& operator = (CGNU_DOUBLE m);
00139   named_dvar_vector& operator=(const prevariable& m);
00140   friend class model_parameters;
00141   void allocate(int mmin,int mmax,const char * s);
00142 };
00143 
00148 class named_dvariable : public dvariable, public model_name_tag
00149 {
00150   //named_dvariable& operator=(const dvariable& m);
00151 protected:
00152   named_dvariable(void) : dvariable(), model_name_tag() {}
00153   void allocate(const char * s);
00154   named_dvariable& operator=(const prevariable& m);
00155   named_dvariable& operator = (CGNU_DOUBLE m);
00156   friend class model_parameters;
00157 };
00158 
00163 class named_dvar_matrix : public dvar_matrix, public model_name_tag
00164 {
00165 protected:
00166   named_dvar_matrix(void) : dvar_matrix(), model_name_tag() {}
00167   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00168 public:
00169   named_dvar_matrix& operator = (CGNU_DOUBLE m);
00170   named_dvar_matrix& operator=(const dmatrix& m);
00171   named_dvar_matrix& operator=(const dvar_matrix& m);
00172   friend class model_parameters;
00173 };
00174 
00179 class named_dvar3_array : public dvar3_array, public model_name_tag
00180 {
00181 protected:
00182   named_dvar3_array(void) : dvar3_array(), model_name_tag() {}
00183   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00184     const char * s);
00185   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00186     int cmin,int cmax,const char * s);
00187   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00188     int cmin, int cmax, const char * s);
00189   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00190     int cmin,int cmax,const char * s);
00191   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00192     int cmax,const char * s);
00193   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00194                 const ivector& cmax, const char *s);
00195   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00196                 const ivector& cmax, const char *s);
00197   named_dvar3_array& operator=(const dvar3_array& m);
00198   named_dvar3_array& operator=(const d3_array& m);
00199   friend class model_parameters;
00200 };
00201 
00206 class named_dvar4_array : public dvar4_array, public model_name_tag
00207 {
00208 protected:
00209   named_dvar4_array(void) : dvar4_array(), model_name_tag() {}
00210   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00211   int cmin,int cmax,const char * s);
00212   named_dvar4_array& operator=(const dvar4_array& m);
00213   named_dvar4_array& operator=(const d4_array& m);
00214   friend class model_parameters;
00215 };
00216 
00221 class named_dvector : public dvector, public model_name_tag
00222 {
00223 protected:
00224   named_dvector(void) : dvector(), model_name_tag() {}
00225   void allocate(int mmin,int mmax,const char * s);
00226   named_dvector& operator=(const dvector& m);
00227   named_dvector& operator = (CGNU_DOUBLE m);
00228 };
00229 
00234 class named_ivector : public ivector, public model_name_tag
00235 {
00236 protected:
00237   named_ivector(void) : ivector(), model_name_tag() {}
00238   void allocate(int mmin,int mmax,const char * s);
00239 };
00240 
00245 class named_dmatrix : public dmatrix, public model_name_tag
00246 {
00247 protected:
00248   named_dmatrix(void) : dmatrix(), model_name_tag() {}
00249   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00250   named_dmatrix& operator=(const dmatrix& m);
00251   named_dmatrix& operator = (CGNU_DOUBLE m);
00252 };
00253 
00258 class named_imatrix : public imatrix, public model_name_tag
00259 {
00260 protected:
00261   named_imatrix(void) : imatrix(), model_name_tag() {}
00262   void allocate(int rmin,int rmax,int cmin,int cmax,const char * s);
00263   named_imatrix& operator=(const imatrix& m);
00264   named_imatrix& operator=(const int& m);
00265 };
00266 
00271 class named_d3_array : public d3_array, public model_name_tag
00272 {
00273 protected:
00274   named_d3_array(void) : d3_array(), model_name_tag() {}
00275   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00276     const char * s);
00277   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00278     int cmin,int cmax,const char * s);
00279   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00280     int cmin,int cmax,const char * s);
00281   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00282     int cmin,int cmax,const char * s);
00283   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00284     int cmax, const char * s);
00285   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00286                 const ivector& cmax, const char *s);
00287   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00288                 const ivector& cmax, const char *s);
00289   named_d3_array& operator=(const d3_array& m);
00290 };
00291 
00296 class named_d4_array : public d4_array, public model_name_tag
00297 {
00298 protected:
00299   named_d4_array(void) : d4_array(), model_name_tag() {}
00300   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,
00301     int rmax,int cmin,int cmax,const char * s);
00302   named_d4_array& operator=(const d4_array& m);
00303 };
00304 
00305 class function_minimizer;
00306 
00311 class initial_params
00312 {
00313 protected:
00314   int active_flag;
00315   int initial_value_flag;
00316   double initial_value;
00317 public:
00318   static initial_params * varsptr[120]; // this should be a resizeable array
00319   static num_initial_params;
00320   static num_active_initial_params;
00321   static int max_number_phases;
00322   static int current_phase;
00323   static int sd_phase;
00324   int phase_start;
00325   int phase_stop;
00326   virtual void set_value(const dvar_vector&, const int&, const dvariable& pen) = 0;
00327   void set_initial_value(double x);
00328   virtual void set_value_inv(const dvector&, const int&) = 0;
00329   virtual void copy_value_to_vector(const dvector&, const int&) = 0;
00330   virtual void restore_value_from_vector(const dvector&, const int&) = 0;
00331   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii) = 0;
00332   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii)=0;
00333   virtual int size_count(void)=0; // get the number of active parameters
00334   virtual void save_value(void)=0; // save the objects value in a file
00335   virtual void save_value(const ofstream& ofs, int prec)=0;
00336   virtual const char * label()=0;
00337   void allocate(int _phase_start);
00338   void set_active_flag(void);
00339   void set_inactive_flag(void);
00340   friend int active(const initial_params& ip);
00341 public:
00342   initial_params(void);
00343   static void xinit(const dvector& x); // get the number of active parameters
00344   static void copy_all_values(const dvector& x, const int& ii); //save all initial parameter
00345                                                    // values in a vector
00346   static void restore_all_values(const dvector& x, const int& ii); //get ivalues for all
00347                                     // active parameters from a vector
00348   static dvariable reset(const dvar_vector& x); // get the number of active parameters
00349   static int nvarcalc(void);
00350   static int num_active_calc(void);
00351   static int stddev_scale(const dvector& d,const dvector& x);
00352   static void read(void);
00353   static void save(void);
00354   static void save(const ofstream& ofs, int prec);
00355   static void restore(const ifstream& ifs);
00356   virtual void restore_value(const ifstream& ifs) = 0;
00357   virtual void add_to_list(void);
00358   friend class function_minimizer;
00359 };
00360 
00365 class param_init_vector: public named_dvar_vector , public initial_params
00366 {
00367 public:
00368   virtual const char * label(void);
00369 protected:
00370   param_init_vector();
00371 private:
00372   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00373   virtual void set_value_inv(const dvector& x, const int& ii);
00374   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00375   virtual void restore_value_from_vector(const dvector&, const int&);
00376   virtual int size_count(void);
00377   virtual void sd_scale(const dvector& d, const dvector& x, const int&);
00378   virtual void hess_scale(const dvector& d, const dvector& x, const int&){};
00379   param_init_vector();
00380   virtual void save_value(void);
00381   virtual void save_value(const ofstream& ofs, int prec);
00382   virtual void restore_value(const ifstream& ifs);
00383   void report_value(void);
00384   //virtual void read_value(void);
00385   void allocate(int imin,int imax,int phasestart=1,const char * s="UNNAMED");
00386   void allocate(int imin,int imax,const char * s="UNNAMED");
00387   friend class model_parameters;
00388 };
00389 
00394 class param_init_bounded_vector: public named_dvar_vector,public initial_params
00395 {
00396   virtual void* parent_this(void){return this;}
00397 public:
00398   double minb;
00399   double maxb;
00400   param_init_bounded_vector();
00401 private:
00402   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00403   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00404   virtual void restore_value_from_vector(const dvector&, const int&);
00405   virtual void set_value_inv(const dvector& x, const int& ii);
00406   virtual int size_count(void);
00407   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00408   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){};
00409   void allocate(int imin,int imax,double _minb,double _maxb,
00410     int phasestart=1, const char * name="UNNAMED");
00411   void allocate(int imin,int imax,double _minb,double _maxb,
00412     const char * name="UNNAMED");
00413   friend class model_parameters;
00414   virtual const char * label(void);
00415   virtual void save_value(const ofstream& ofs,int prec);
00416   virtual void restore_value(const ifstream& ifs);
00417   virtual void save_value(void);
00418   void report_value(void);
00419   //virtual void read_value(void);
00420 };
00421 
00426 class param_init_bounded_dev_vector: public param_init_bounded_vector
00427 {
00428   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00429 };
00430 
00435 class param_init_number: public named_dvariable , public initial_params
00436 {
00437   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00438   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00439   virtual void restore_value_from_vector(const dvector&, const int&);
00440   virtual void set_value_inv(const dvector& x, const int& ii);
00441   virtual int size_count(void);
00442   virtual void save_value(const ofstream& ofs, int prec);
00443   virtual void restore_value(const ifstream& ifs);
00444   virtual void save_value(void);
00445   void report_value(void);
00446   virtual const char * label(void);
00447   param_init_number& operator = (CGNU_DOUBLE m);
00448   param_init_number& operator = (const prevariable& m);
00449   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00450   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){};
00451   //virtual void read_value(void);
00452 protected:
00453   void allocate(int phase_start=1,const char *s="UNNAMED");
00454   void allocate(const char *s="UNNAMED");
00455   friend class model_parameters;
00456   param_init_number();
00457 };
00458 
00463 class param_init_bounded_number: public param_init_number
00464 {
00465   double minb;
00466   double maxb;
00467 protected:
00468   param_init_bounded_number();
00469   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00470   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00471   virtual void restore_value_from_vector(const dvector&, const int&);
00472   virtual void set_value_inv(const dvector& x, const int& ii);
00473   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00474   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){};
00475   virtual const char * label(void);
00476   void report_value(void);
00477   void allocate(double _minb,double _maxb,int phase_start=1,
00478     const char * s="UNNAMED");
00479   param_init_bounded_number& operator = (CGNU_DOUBLE m);
00480   param_init_bounded_number& operator=(const prevariable& m);
00481   void allocate(double _minb,double _maxb,const char * s="UNNAMED");
00482   friend class model_parameters;
00483   param_init_bounded_number();
00484 };
00485 
00490 class param_init_matrix: public named_dvar_matrix,public initial_params
00491 {
00492 public:
00493 
00494   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00495   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00496   virtual void restore_value_from_vector(const dvector&, const int&);
00497   virtual void set_value_inv(const dvector& x, const int& ii);
00498   virtual int size_count(void);
00499   virtual void save_value(void);
00500   virtual void save_value(const ofstream& ofs, int prec);
00501   virtual void restore_value(const ifstream& ifs);
00502   void report_value(void);
00503   //virtual void read_value(void);
00504   virtual const char * label(void);
00505   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00506   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){};
00507 
00508 public:
00509 
00510   void allocate(int rmin,int rmax,int cmin,int cmax,
00511     int phase_start=1,const char * = "UNNAMED");
00512   void allocate(int rmin,int rmax,int cmin,int cmax,
00513     const char * = "UNNAMED");
00514   param_init_matrix(void);
00515 };
00516 
00521 class param_init_bounded_matrix: public param_init_matrix
00522 {
00523   double minb;
00524   double maxb;
00525 public:
00526 
00527   virtual void set_value(const dvar_vector& x, const int& ii, const dvariable& pen);
00528   virtual void set_value_inv(const dvector& x, const int& ii);
00529   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00530   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){};
00531 
00532 public:
00533 
00534   void allocate(int rmin,int rmax,int cmin,int cmax,
00535     double _minb,double _maxb,
00536     int phase_start=1,const char * = "UNNAMED");
00537   void allocate(int rmin,int rmax,int cmin,int cmax,
00538     double _minb,double _maxb,const char * = "UNNAMED");
00539   param_init_bounded_matrix(void);
00540 };
00541 
00546 class data_int : public model_name_tag
00547 {
00548   int val;
00549   void allocate(int n,const char * s="UNNAMED");
00550   void allocate(const char * s="UNNAMED");
00551   operator int() {return val;}
00552   friend class model_data;
00553   friend class model_parameters;
00554   friend int operator + (int n,data_int v);
00555   friend int operator + (data_int v,int n);
00556   friend int operator + (data_int v,data_int n);
00557 };
00558 
00563 class data_matrix : public named_dmatrix
00564 {
00565   data_matrix(void) : named_dmatrix() {}
00566   void allocate(int rmin,int rmax,int cmin,int cmax,
00567     const char * = "UNNAMED");
00568   friend class model_data;
00569 };
00570 
00575 class data_3array : public named_d3_array
00576 {
00577   data_3array(void) : named_d3_array() {}
00578   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,int cmax,
00579     const char * ="UNNAMED");
00580   void allocate(int hsl, int hsu, const ivector& rmin, int rmax,
00581     int cmin,int cmax,const char * ="UNNAMED");
00582   void allocate(int hsl, int hsu, int rmin, const ivector& rmax,
00583     int cmin,int cmax,const char * ="UNNAMED");
00584   void allocate(int hsl, int hsu, const ivector& rmin, const ivector& rmax,
00585     int cmin,int cmax,const char * ="UNNAMED");
00586   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin, int cmax,
00587     const char * ="UNNAMED");
00588   void allocate(int hsl, int hsu, int rmin, int rmax, const ivector& cmin,
00589                 const ivector& cmax, const char * = "UNNAMED");
00590   void allocate(int hsl,int hsu,int rmin,int rmax,int cmin,
00591                 const ivector& cmax ,const char * = "UNNAMED");
00592   friend class model_data;
00593 };
00594 
00599 class data_4array : public named_d4_array
00600 {
00601   data_4array(void) : named_d4_array() {}
00602   void allocate(int hhsl,int hhsu,int hsl,int hsu,int rmin,int rmax,
00603     int cmin,int cmax,const char * ="UNNAMED");
00604   friend class model_data;
00605 };
00606 
00611 class data_imatrix : public named_imatrix
00612 {
00613   data_imatrix(void) : named_imatrix() {}
00614   void allocate(int rmin,int rmax,int cmin,int cmax,const char * ="UNNAMED");
00615   friend class model_data;
00616 };
00617 
00622 class data_vector : public named_dvector
00623 {
00624 public:
00625   data_vector& operator=(const dvector& m);
00626   data_vector& operator = (CGNU_DOUBLE m);
00627 private:
00628   data_vector(void) : named_dvector() {}
00629   void allocate(int imin,int imax,const char * ="UNNAMED");
00630   friend class model_data;
00631 };
00632 
00637 class data_ivector : public named_ivector
00638 {
00639   data_ivector(void) : named_ivector() {}
00640   void allocate(int imin,int imax,const char * ="UNNAMED");
00641   friend class model_data;
00642 };
00643 
00648 class data_number : public model_name_tag
00649 {
00650   double val;
00651   void allocate(const char * ="UNNAMED");
00652 public:
00653   void report_value(void);
00654   operator double() {return val;}
00655   friend class model_data;
00656 };
00657 
00662 class function_minimizer
00663 {
00664 public:
00665   int maxfn;
00666   int iprint;
00667   double crit;
00668   int imax;
00669   double dfn;
00670   int iexit;
00671   int ihflag;
00672   int ihang;
00673   int scroll_flag;
00674   int maxfn_flag;
00675   int quit_flag;
00676   double min_improve;
00677 protected:
00678   double ffbest;
00679 private:
00680   gradient_structure * pgs;
00681   adstring_array param_labels;
00682   ivector param_size;
00683 protected:
00684   void report_function_minimizer_stats(void){}
00685   virtual void userfunction(void)=0;
00686   virtual void report(void){};
00687   static dvector convergence_criteria;
00688   static dvector maximum_function_evaluations;
00689   static int sd_flag;
00690   static adstring user_data_file;
00691   static adstring user_pin_file;
00692 public:
00693   function_minimizer(long int sz=0L);
00694   void likeprof_routine(double global_min);
00695   virtual ~function_minimizer();
00696   virtual void minimize(void);
00697   void computations(int argc,char * argv[]);
00698   void computations_np(int argc,char * argv[]);
00699   void computations(void);
00700   void hess_routine(void);
00701   void hess_inv(void);
00702   void depvars_routine(void);
00703   void sd_routine(void);
00704 
00705 #ifdef CURVE_CORRECT
00706   void constraint_hess_routine(int ip);
00707   void get_curvature_correction_factors(int ip,
00708     dvector& g, const int underflow_flag, const dvector& eigenvals,
00709     dvector& curvcor);
00710 #endif
00711 
00712   void prof_minimize(int iprof, double sigma,
00713     double new_value, const double& fprof, const int underflow_flag,
00714     double global_min, const double& penalties, const double& final_weight);
00715 #ifndef CURVE_CORRECT
00716   void normalize_posterior_distribution(double udet,
00717     dvector& siglevel, const ofstream& ofs2,int num_pp,
00718     dvector& all_values, const dmatrix& actual_value, double global_min,
00719     int offset, const dmatrix& lprof, const dmatrix& ldet, const dmatrix& xdist,
00720     dmatrix& penalties, const dmatrix& lg_jacob, const dmatrix& pdet,
00721     dmatrix& lg_prjacob);
00722 #else
00723   void normalize_posterior_distribution(double udet,
00724     dvector& siglevel, const ofstream& ofs2, int num_pp,
00725     dvector& all_values, const dmatrix& actual_value, double global_min,
00726     int offset, const dmatrix& lprof, const dmatrix& ldet, const dmatrix& xdist,
00727     d3_array& eigenvals,d3_array& curvcor);
00728 #endif
00729   void get_particular_grad(int iprof,int nvar, const dvector& g);
00730 double projected_hess_determinant(const dvector& fg, const dvector& g,
00731   const int underflow_flag, const dvector& xscale, const double& ln_det_proj_jac)
00732   double projected_hess_determinant(const dmatrix& hh, const dvector& g,
00733     const int underflow_flag);
00734   double projected_hess_determinant(const dvector& g,
00735     const int underflow_flag, const dvector& xscale, const double& ln_det_proj_jac,
00736     double& ln_det_proj);
00737 
00738   double diag_projected_hess_determinant(const dvector& g, const int underflow_flagi,
00739     dmatrix&);
00740   double unrestricted_hess_determinant(void);
00741 
00742   static void set_runtime(void);
00743 };
00744 
00745 cifstream& operator>>(const cifstream& s, const param_init_number& x);
00746 cifstream& operator>>(const cifstream& s, const param_init_vector& v);
00747 cifstream& operator>>(const cifstream& s, const param_init_matrix& m);
00748 ostream& operator<<(const ostream& s, const label_class& lc);
00749 
00754 class stddev_params
00755 {
00756 protected:
00757 public:
00758   static stddev_params * stddevptr[100]; // this should be a resizeable array
00759   static num_stddev_params;
00760   void allocate(void){};
00761   static int num_stddev_calc(void);
00762 public:
00763   stddev_params(void){}
00764   virtual int size_count(void)=0; // get the number of active parameters
00765   virtual void set_dependent_variables(void)=0;
00766   virtual void copy_value_to_vector(const dvector&, const int&) = 0;
00767   static void copy_all_values(const dvector& x, const int& ii); //get the number of active parameters
00768   virtual void add_to_list(void);
00769   virtual const char * label()=0;
00770   friend class function_minimizer;
00771 };
00772 
00777 class likeprof_params
00778 {
00779   double stepsize;
00780   int    stepnumber;
00781 protected:
00782 public:
00783   static likeprof_params * likeprofptr[50]; // this should be a
00784                                                // resizeable array
00785   static num_likeprof_params;
00786   void allocate(void){};
00787   static int num_stddev_calc(void);
00788 public:
00789   likeprof_params(void);
00790   virtual void add_to_list(void);
00791   virtual const char * label()=0;
00792   virtual dvariable variable(void)=0;
00793   virtual double& get_sigma(void)=0;
00794   virtual double get_value(void)=0;
00795   double get_stepsize(void);
00796   int get_stepnumber(void);
00797   void set_stepsize(double);
00798   void set_stepnumber(int);
00799   friend class function_minimizer;
00800 };
00801 
00806 class param_stddev_vector: public named_dvar_vector , stddev_params
00807 {
00808   virtual int size_count(void); // get the number of active parameters
00809   virtual const char * label(void);
00810   param_stddev_vector();
00811   void allocate(int imin,int imax,const char * s="UNNAMED");
00812   virtual void set_dependent_variables(void);
00813   friend class model_parameters;
00814   void copy_value_to_vector(const dvector& x, const int& ii);
00815   param_stddev_vector& operator=(const dvar_vector& m);
00816   param_stddev_vector& operator=(const dvector& m);
00817   param_stddev_vector& operator = (CGNU_DOUBLE m);
00818 };
00819 
00824 class param_stddev_number: public named_dvariable , public stddev_params
00825 {
00826   void allocate(const char *s="UNNAMED");
00827   virtual int size_count(void); // get the number of active parameters
00828   virtual const char * label(void);
00829   void copy_value_to_vector(const dvector& x, const int& ii);
00830 protected:
00831   param_stddev_number();
00832   friend class model_parameters;
00833   virtual void set_dependent_variables(void);
00834   param_stddev_number& operator=(const prevariable&);
00835   param_stddev_number& operator = (CGNU_DOUBLE);
00836 };
00837 
00842 class param_likeprof_number: public param_stddev_number ,
00843   public likeprof_params
00844 {
00845   double sigma;
00846   void allocate(const char *s="UNNAMED");
00847   virtual int size_count(void); // get the number of active parameters
00848   virtual const char * label(void);
00849   virtual double& get_sigma(void){return sigma;}
00850   virtual double get_value(void){return value(*this);}
00851   //void copy_value_to_vector(const dvector& x, const int& ii);
00852   virtual dvariable variable(void){ return dvariable(*this);}
00853   param_likeprof_number();
00854   friend class model_parameters;
00855 public:
00856   param_likeprof_number& operator=(const prevariable&);
00857   param_likeprof_number& operator = (CGNU_DOUBLE);
00858 };
00859 
00864 class param_stddev_matrix: public named_dvar_matrix , stddev_params
00865 {
00866   virtual int size_count(void);
00867   //virtual void read_value(void);
00868   virtual const char * label(void);
00869   void allocate(int rmin,int rmax,int cmin,int cmax,
00870     const char * s="UNNAMED");
00871   param_stddev_matrix(void);
00872   friend class model_parameters;
00873   virtual void set_dependent_variables(void);
00874   void copy_value_to_vector(const dvector& x, const int& ii);
00875   param_stddev_matrix& operator = (CGNU_DOUBLE m);
00876   param_stddev_matrix& operator=(const dmatrix& m);
00877   param_stddev_matrix& operator=(const dvar_matrix& m);
00878 };
00879 
00884 class ad_comm
00885 {
00886 protected:
00887   ad_comm(char * argv[]);
00888   ad_comm(const char * root);
00889   void allocate(const char * root);
00890   ~ad_comm();
00891 public:
00892   static cifstream * global_datafile[MAX_NUM_DATA_FILES];
00893   static cifstream * global_parfile[MAX_NUM_PARS_FILES];
00894   static ofstream *  global_savefile;
00895   static adstring adprogram_name;
00896   static change_datafile_name;
00897   static change_parfile_name;
00898 };
00899 
00904   class objective_function_value : public named_dvariable
00905   {
00906   public:
00907     static objective_function_value * pobjfun;
00908     objective_function_value();
00909     objective_function_value& operator=(const prevariable& v);
00910     objective_function_value& operator = (CGNU_DOUBLE v);
00911   };
00912 
00917 class param_init_d3array: public named_dvar3_array,public initial_params
00918 {
00919 public:
00920 
00921   virtual void set_value(const dvar_vector& x,const int& ii, const dvariable& pen);
00922   virtual void copy_value_to_vector(const dvector& x, const int& ii);
00923   virtual void restore_value_from_vector(const dvector&, const int&);
00924   virtual void set_value_inv(const dvector& x, const int& ii);
00925   virtual int size_count(void);
00926   virtual void save_value(void);
00927   virtual void save_value(const ofstream& ofs, int prec);
00928   virtual void restore_value(const ifstream& ifs);
00929   void report_value(void);
00930   //virtual void read_value(void);
00931   virtual const char * label(void);
00932   virtual void sd_scale(const dvector& d, const dvector& x, const int& ii);
00933   virtual void hess_scale(const dvector& d, const dvector& x, const int& ii){};
00934 
00935 public:
00936 
00937   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
00938     int phase_start=1,const char * = "UNNAMED");
00939   void allocate(int smin,int smax,int rmin,int rmax,int cmin,int cmax,
00940     const char * = "UNNAMED");
00941   param_init_d3array(void);
00942 };
00943 
00944 #endif