ADMB Documentation  11.1.2533
 All Classes Files Functions Variables Typedefs Friends Defines
df1b2fun.h
Go to the documentation of this file.
00001 /*
00002  * $Id: df1b2fun.h 2423 2014-09-29 19:35:53Z 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  */
00046 #if !defined(__DF1B2FUN__)
00047 #  define __DF1B2FUN__
00048 
00049 #if defined(__GNUC__) && (__GNUC__ < 3)
00050   #pragma interface
00051 #endif
00052 
00053 #include <adpool.h>
00054 #ifndef FVAR_HPP
00055 #  include <fvar.hpp>
00056 #endif
00057 #include <sys/stat.h>
00058 #if !defined(_MSC_VER)
00059   #include <stddef.h>
00060   #include <fcntl.h>
00061 #endif
00062 
00063 #define USE_BARD_PEN
00064 
00065 void ncount_checker(int ncount,int ncount_check);
00066 
00067 class named_dvar_matrix;
00068 
00069 int withinbound(int lb,int n,int ub);
00070 
00071 class do_naught_kludge;
00072 class newadkludge;
00073 
00074 
00079 class twointsandptr
00080 {
00081 public:
00082   short int ncopies;
00083   short int nvar;
00084 #if defined (INCLUDE_BLOCKSIZE)
00085   int blocksize;
00086 #endif
00087   adpool * ptr;
00088 };
00089 
00090 
00091 #if defined(__DERCHECK__)
00092 
00096 class dercheck_info
00097 {
00098   int ind_index;
00099 public:
00100   virtual void get_ind_index(void)
00101   {
00102     cerr << "cannot use this type here" << endl; ad_exit(1);
00103   }
00104 
00105   int node_number;
00106   int counter;
00107   int pass_number;
00108   int vartype;
00109   int dotflag;
00110   double der_value;
00111   double f1;
00112   double f2;
00113   double f3;
00114   double fd;
00115   double delta;
00116   dercheck_info(int _node_number,double _delta,int _index);
00117   void set_delta(double d){delta=d;}
00118   void set_node_number(int n){node_number=n;}
00119   void set_pass_number(int n){pass_number=n;}
00120   void set_index(int n){index=n;}
00121   void set_dotflag(int n){dotflag=n;}
00122   void set_vartype(int n){vartype=n;}
00123   void set_counter(int n){counter=n;}
00124   void set_f1(double d){f1=d;}
00125   void set_f2(double d){f2=d;}
00126   void set_f3(double d){f3=d;}
00127   void set_fd(void){fd=(f2-f3)/(2.0*delta);}
00128 };
00129 extern dercheck_info * derchecker;
00130 #endif
00131 
00132 typedef void * &  vreference;
00133 
00134 /*
00135 #if !defined(_MSC_VER)
00136 inline void increment_pointer(vreference p,int n)
00137 {
00138   char * cs =(char*)(p);
00139   cs+=n;
00140 }
00141 #endif
00142 */
00143 
00144 #include <df32fun.h>
00145 extern int global_nvar;
00146 class df1b2_gradlist;
00147 extern df1b2_gradlist* f1b2gradlist;
00148 extern df1b2_gradlist* localf1b2gradlist;
00149 extern df1b2_gradlist* globalf1b2gradlist;
00150 extern df1b2_gradlist** f1b2gradlist_stack;
00151 extern int max_num_init_df1b2variable;
00152 
00153 void df1b2_gradcalc1(void);
00154 
00155 extern char AD_allocation_error_message[];
00156 
00157 #if defined(__BORLANDC__)
00158 int adptr_diff(void * x, void * y) { return int(x)-int(y); }
00159 #else
00160 int adptr_diff(void* x, void* y);
00161 #endif
00162 
00163 void read_pass1_1(void);
00164 void read_pass1_2(void);
00165 
00166 #undef AD_ALLOCATE
00167 #define AD_ALLOCATE(ptr,type,n,classname) \
00168   if ( (ptr = new type[n])==NULL) \
00169   { \
00170     cerr << AD_allocation_error_message << "classname" << endl; \
00171     ad_exit(1); \
00172   }
00173 
00174 
00175 #undef ADUNCONST
00176 #define ADUNCONST(type,obj) type & obj = (type&) _##obj;
00177 
00182 struct df1b2_header
00183 {
00184   //double* ptr;
00185   double* u;
00186   double* u_dot;
00187   double* u_bar;
00188   double* u_dot_bar;
00189   double* u_tilde;
00190   double* u_dot_tilde;
00191   double* u_bar_tilde;
00192   double* u_dot_bar_tilde;
00193   int indindex;
00194 
00195   //double * get_ptr(void){return ptr;}
00196 
00197   double* get_u(void) const {return (double*)u;}
00198   double* get_u_dot(void) const {return (double*)u_dot;}
00199   double* get_u_bar(void) const {return (double*)u_bar;}
00200   double* get_u_dot_bar(void) const {return (double*)u_dot_bar;}
00201   double* get_u_tilde(void) const {return (double*)u_tilde;}
00202   double* get_u_dot_tilde(void) const {return (double*)u_dot_tilde;}
00203   double* get_u_bar_tilde(void) const {return (double*)u_bar_tilde;}
00204   double* get_u_dot_bar_tilde(void) const {return (double*)u_dot_bar_tilde;}
00205 };
00206   class adkludge1;
00207 
00208   class df1b2vector;
00209 
00214   class predf1b2vector
00215   {
00216     df1b2vector * p;
00217     int lb;
00218     int ub;
00219     inline predf1b2vector(df1b2vector * _p,int _lb,int _ub)
00220       {p=_p;lb=_lb,ub=_ub;}
00221     friend class df1b2vector;
00222   };
00223 
00224   class df3_one_variable;
00225   class df3_two_variable;
00226   class df3_three_variable;
00227   class random_effects_bounded_vector_info;
00228 
00233   class df1b2variable : public df1b2_header
00234   {
00235   public:
00236     double* ptr;
00237     int get_local_nvar(void) const {return int(((twointsandptr*)ptr)->nvar);}
00238     int allocated(void){return ptr!=0;}
00239     int unallocated(void){return ptr==0;}
00240     static adpool* pool;
00241     static int current_allocation_index;
00242     static int adpool_use_index[];
00243     static int pool_allocation_number[];
00244     static int allocation_counter;
00245     static const int adpool_vectorsize;
00246     static int adpool_counter;
00247     static void increment_adpool_counter(void);
00248     static const int adpool_stack_size;
00249     static adpool* adpool_vector[];
00250     static adpool* adpool_stack[];
00251     static int adpool_nvar_stack[];
00252     static int adpool_stack_pointer;
00253     static void save_adpool_pointer(void);
00254     static void restore_adpool_pointer(void);
00255     static int nvar_vector[];
00256     static int passnumber;
00257     static int nvar;  // the number of independent variables
00258     static int minder;  // the number of independent variables
00259     static int maxder;  // the number of independent variables
00260     static int blocksize;
00261     static int noallocate;
00262 
00263     static int get_passnumber(void){return passnumber;}
00264     static void set_nvar(int n){nvar=n;}
00265     static int get_nvar(void){return nvar;}
00266     static void set_minder(int n){minder=n;}
00267     static void set_maxder(int n){maxder=n;}
00268     static void set_blocksize(void);
00269     static int get_blocksize(void);
00270     static int get_blocksize(int n);
00271     int & get_ind_index(void){ return indindex;}
00272     const int& get_ind_index(void) const { return indindex;}
00273     short int* ncopies;
00274     // for fixed size n whole thing is 6n+2
00275     void initialize(void);
00276     void initialize(int n);
00277 
00278     df1b2variable(const do_naught_kludge&){ ptr = 0; }
00279 
00280 #if defined(USE_DDOUBLE)
00281 #undef double
00282     df1b2variable(double d);
00283 #define double dd_real
00284 #endif
00285     df1b2variable(double d);
00286     df1b2variable(void);
00287     void allocate(void);
00288     void allocate(const char *);
00289 
00290     df1b2variable(adkludge1 * );
00291     df1b2variable(const random_effects_bounded_vector_info& rebv);
00292 
00293     df1b2variable(const newadkludge * );
00294 
00295     df1b2variable(const df1b2variable& v);
00296 
00297     df1b2variable& operator = (const df3_one_variable& v);
00298     df1b2variable& operator = (const df3_two_variable& v);
00299     df1b2variable& operator = (const df3_three_variable& v);
00300     df1b2variable& operator = (const df1b2variable& v);
00301     df1b2variable& operator += (const df1b2variable& v);
00302     df1b2variable& operator -= (const df1b2variable& v);
00303     df1b2variable& operator *= (const df1b2variable& v);
00304     df1b2variable& operator /= (const df1b2variable& v);
00305 
00306     void operator = (double x);
00307 
00308     virtual ~df1b2variable();
00309     void deallocate(void);
00310   };
00311 
00312 void print_dot_derivatives(df1b2_header * px,const char * s);
00313 void print_derivatives(const adstring&, double f, double df,
00314   double d2f,double d3f,int bflag=0);
00315 void print_derivatives(const adstring&, double f, double df1,
00316   double df2,double df11,double df12, double df22,
00317   double df111, double df112, double df122, double df222,int bflag=0);
00318 
00319 void print_derivatives(df1b2_header * px,const char * s,
00320   int bflag=0);
00321 
00326   class init_df1b2variable : public df1b2variable
00327   {
00328   public:
00329     int ind_index;
00330     int get_index(void){return ind_index;}
00331     static int num_variables;
00332     static init_df1b2variable ** list;
00333     init_df1b2variable(double v=0.0);
00334     void operator = (double x);
00335     void set_u_dot(void);
00336   };
00337 
00342   class init_df1b2vector
00343   {
00344     int index_min;
00345     int index_max;
00346     int * ncopies;
00347     init_df1b2variable * trueptr;
00348     init_df1b2variable * ptr;
00349   public:
00350     void deallocate(void);
00351     void reallocate(void);
00352     void allocate(int lib,int ub);
00353     void allocate(void);
00354     init_df1b2vector(int lib,int ub);
00355     init_df1b2vector(void);
00356     init_df1b2vector(const init_df1b2vector& v);
00357     int indexmin(void) const {return index_min;}
00358     int indexmax(void) const {return index_max;}
00359 
00360 #if defined(OPT_LIB)
00361     init_df1b2variable& operator () (int i) { return ptr[i];}
00362     init_df1b2variable& operator [] (int i) { return ptr[i];}
00363 #else
00364     init_df1b2variable& operator () (int i);
00365     init_df1b2variable& operator [] (int i);
00366 #endif
00367     void set_value(const dvector&);
00368     ~init_df1b2vector();
00369   };
00370 
00376 class df1b2function1
00377 {
00378 public:
00379   double (*f)(double);
00380   double (*df)(double);
00381   double (*d2f)(double);
00382   double (*d3f)(double);
00383   adstring funname;
00384 
00385   df1b2function1(double (*_f)(double),double (*_df)(double),
00386       double (*d2f)(double),double (*_d3f)(double),
00387       const adstring& s="unnamed");
00388 
00389   df1b2variable operator () (const df1b2variable& x);
00390   //df1b2variable& operator () (const df1b2variable& z,const df1b2variable& x);
00391   df1b2variable& operator () (const df1b2variable& z,const df1b2variable& x,
00392     int s); // s is a switch for picking special function for simple
00393                // operations like +=
00394 };
00395 
00400   class df1b2function2
00401   {
00402   public:
00403     double (*f)(double,double);
00404     double (*df1)(double,double);
00405     double (*df2)(double,double);
00406     double (*d2f11)(double,double);
00407     double (*d2f12)(double,double);
00408     double (*d2f22)(double,double);
00409     double (*d3f111)(double,double);
00410     double (*d3f112)(double,double);
00411     double (*d3f122)(double,double);
00412     double (*d3f222)(double,double);
00413     adstring funname;
00414 
00415     df1b2function2
00416     (
00417       double (*_f)(double,double),
00418       double (*_df1)(double,double),double (*_df2)(double,double),
00419       double (*d2f11)(double,double),
00420       double (*d2f12)(double,double),
00421       double (*d2f22)(double,double),
00422       double (*_d3f111)(double,double),
00423       double (*_d3f112)(double,double),
00424       double (*_d3f122)(double,double),
00425       double (*_d3f222)(double,double),
00426       const adstring & funame="unnamed"
00427     );
00428 
00429     df1b2variable operator () (const df1b2variable& x,const df1b2variable& y);
00430   };
00431 
00436   class mydf1b2function2
00437   {
00438   public:
00439     double (*f)(double,double);
00440     double (*df1)(double,double);
00441     double (*df2)(double,double);
00442     double (*d2f11)(double,double);
00443     double (*d2f12)(double,double);
00444     double (*d2f22)(double,double);
00445     double (*d3f111)(double,double);
00446     double (*d3f112)(double,double);
00447     double (*d3f122)(double,double);
00448     double (*d3f222)(double,double);
00449 
00450     mydf1b2function2
00451     (
00452       double (*_f)(double,double),
00453       double (*_df1)(double,double),double (*_df2)(double,double),
00454       double (*d2f11)(double,double),
00455       double (*d2f12)(double,double),
00456       double (*d2f22)(double,double),
00457       double (*_d3f111)(double,double),
00458       double (*_d3f112)(double,double),
00459       double (*_d3f122)(double,double),
00460       double (*_d3f222)(double,double)
00461     );
00462 
00463     df1b2variable operator () (const df1b2variable& x,const df1b2variable& y);
00464   };
00465 
00470 class smartlist
00471 {
00472 public:
00473   char* buffer;
00474   char* buffend;
00475   char* bptr;
00476   char* sbptr;
00477   unsigned int bufsize;
00478   adstring filename;
00479   int fp;
00480   void saveposition(void){sbptr=bptr;}
00481   void reset(void){bptr=buffer;}
00482   void restoreposition(void){bptr=sbptr;}
00483   void restoreposition(int offset){bptr=sbptr+offset;}
00484   smartlist(unsigned int bufsize,const adstring& filename);
00485   double report_usage(void)
00486   {
00487     return double(size_t(bptr)-size_t(buffer))
00488            / double(size_t(buffend)-size_t(buffer));
00489   }
00490 };
00491 
00496   class test_smartlist
00497   {
00498   public:
00499     int direction;
00500     int written_flag;
00501     int noreadflag;
00502     void save_end(void);
00503     void restore_end(void);
00504     int eof_flag;
00505     int end_saved;
00506     double * doubleptr;
00507     char * true_buffer;
00508     char * true_buffend;
00509     char * recend;
00510     char * buffer;
00511     char * buffend;
00512     char * bptr;
00513     char * sbptr;
00514     unsigned int bufsize;
00515     adstring filename;
00516     int fp;
00517     void saveposition(void){sbptr=bptr;}
00518     void set_recend(){bptr=recend+1;} // one passed the end so that when
00519                                       // you back up n bytes it points to the
00520                                       // beginning of an n byte record
00521     void reset(void);
00522     int eof(void){ return eof_flag;}
00523     int get_noreadflag(void){ return noreadflag; }
00524     void set_noreadflag(int n){ noreadflag=n; }
00525     void restoreposition(void){bptr=sbptr;}
00526     void restoreposition(int offset){bptr=sbptr+offset;}
00527     test_smartlist(unsigned int bufsize,const adstring& filename);
00528     void allocate(unsigned int bufsize,const adstring& filename);
00529     test_smartlist(void);
00530     ~test_smartlist();
00531     void read_buffer(void);
00532     void set_forward(void){direction=0;}
00533     void set_backword(void){direction=-1;}
00534     void set_reverse(void){direction=-1;}
00535     void rewind(void);
00536     void initialize(void);
00537     void operator -= (int);
00538     void operator += (int);
00539     double report_usage(void)
00540     {
00541       return double(size_t(bptr)-size_t(buffer))
00542              / double(size_t(buffend)-size_t(buffer));
00543     }
00544     void write(void * p,int n);
00545     void write(int n);
00546     void write_buffer(void);
00547     void check_buffer_size(int);
00548     void add_buffer_fringe(int n){buffend-=n;}
00549     int written(void){return written_flag;}
00550   };
00551 
00552   typedef void (*ADrfptr)(void);
00553 
00558   class fixed_list_entry
00559   {
00560   public:
00561     int numbytes;
00562     ADrfptr pf;
00563   };
00564 
00569   class fixed_smartlist
00570   {
00571   public:
00572     ~fixed_smartlist();
00573     void operator ++ (void);
00574     void operator -- (void);
00575     int nentries;
00576     int direction;
00577     off_t endof_file_ptr;
00578     int written_flag;
00579     int noreadflag;
00580     void save_end(void);
00581     void restore_end(void);
00582     int eof_flag;
00583     int end_saved;
00584     double * doubleptr;
00585     fixed_list_entry * true_buffer;
00586     fixed_list_entry * true_buffend;
00587     fixed_list_entry * recend;
00588     fixed_list_entry * buffer;
00589     fixed_list_entry * buffend;
00590     fixed_list_entry * bptr;
00591     fixed_list_entry * sbptr;
00592     unsigned int bufsize;
00593     adstring filename;
00594     int fp;
00595     void saveposition(void){sbptr=bptr;}
00596     void set_recend(){bptr=recend+1;} // one passed the end so that when
00597                                       // you back up n bytes it points to the
00598                                       // beginning of an n byte record
00599     void reset(void);
00600     int eof(void){ return eof_flag;}
00601     void read_file(void);
00602     int get_noreadflag(void){ return noreadflag; }
00603     void set_noreadflag(int n){ noreadflag=n; }
00604     void restoreposition(void){bptr=sbptr;}
00605     void restoreposition(int offset){bptr=sbptr+offset;}
00606     fixed_smartlist(unsigned int bufsize,const adstring& filename);
00607     void allocate(unsigned int bufsize,const adstring& filename);
00608     fixed_smartlist(void);
00609     void read_buffer(void);
00610     void set_forward(void){direction=0;}
00611     void set_backword(void){direction=-1;}
00612     void set_reverse(void){direction=-1;}
00613     void rewind(void);
00614     void initialize(void);
00615     void operator -= (int);
00616     void operator += (int);
00617     double report_usage(void)
00618     {
00619       return double(size_t(bptr)-size_t(buffer))
00620              / double(size_t(buffend)-size_t(buffer));
00621     }
00622     void write(void * p,int n);
00623     void write(int n);
00624     void write_buffer(void);
00625     void write_buffer_one_less(void);
00626     void check_buffer_size(int);
00627     void add_buffer_fringe(int n){buffend-=n;}
00628     int written(void){return written_flag;}
00629   };
00630 
00635   class fixed_smartlist2
00636   {
00637   public:
00638     ~fixed_smartlist2();
00639     void operator ++ (void);
00640     void operator -- (void);
00641     int nentries;
00642     int direction;
00643     off_t endof_file_ptr;
00644     int written_flag;
00645     int noreadflag;
00646     void save_end(void);
00647     void restore_end(void);
00648     int eof_flag;
00649     int end_saved;
00650     double * doubleptr;
00651     int * true_buffer;
00652     int * true_buffend;
00653     int * recend;
00654     int * buffer;
00655     int * buffend;
00656     int * bptr;
00657     int * sbptr;
00658     unsigned int bufsize;
00659     adstring filename;
00660     int fp;
00661     void saveposition(void){sbptr=bptr;}
00662     void set_recend(){bptr=recend+1;} // one passed the end so that when
00663                                       // you back up n bytes it points to the
00664                                       // beginning of an n byte record
00665     void reset(void){bptr=buffer;}
00666     int eof(void){ return eof_flag; /*eof_flag=0;*/}
00667 
00668     void read_file(void);
00669     int get_noreadflag(void){ return noreadflag; }
00670     void set_noreadflag(int n){ noreadflag=n; }
00671     void restoreposition(void){bptr=sbptr;}
00672     void restoreposition(int offset){bptr=sbptr+offset;}
00673     fixed_smartlist2(unsigned int bufsize,const adstring& filename);
00674     void allocate(unsigned int bufsize,const adstring& filename);
00675     fixed_smartlist2(void);
00676     void read_buffer(void);
00677     void set_forward(void){direction=0;}
00678     void set_backword(void){direction=-1;}
00679     void set_reverse(void){direction=-1;}
00680     void rewind(void);
00681     void initialize(void);
00682     void operator -= (int);
00683     void operator += (int);
00684     double report_usage(void)
00685     {
00686       return double(size_t(bptr)-size_t(buffer)) /
00687              double(size_t(buffend)-size_t(buffer));
00688     }
00689     void write(void * p,int n);
00690     void write(int n);
00691     void write_buffer(void);
00692     void write_buffer_one_less(void);
00693     void check_buffer_size(int);
00694     void add_buffer_fringe(int n){buffend-=n;}
00695     int written(void){return written_flag;}
00696   };
00697 
00698 
00699   void write(const test_smartlist &,void *,int nsize);
00700   void read(const test_smartlist &,void *,int nsize);
00701   void memcpy(const test_smartlist &, void*, const size_t nsize);
00702   void memcpy(void*, const test_smartlist&, const size_t nsize);
00703 
00704   class df1b2function2c;
00705 
00710   class df1b2_gradlist
00711   {
00712   public:
00713 #if defined(CHECK_COUNT)
00714     static int ncount_check;
00715     static set_ncount_check(int n){ncount_check=n;}
00716 #endif
00717     int ncount;
00718     test_smartlist list;
00719     fixed_smartlist nlist;
00720     test_smartlist list2;
00721     fixed_smartlist2 nlist2;
00722     test_smartlist list3;
00723     fixed_smartlist2 nlist3;
00724     static int no_derivatives;
00725     static void set_no_derivatives(void) {no_derivatives=1;}
00726     static void set_yes_derivatives(void) {no_derivatives=0;}
00727     df1b2_gradlist(unsigned int bufsize,unsigned int nbufsize,
00728      unsigned int bufsize1, unsigned int nbufsize1,
00729      unsigned int bufsize2, unsigned int nbufsize2,const adstring& filename);
00730     int mywrite_pass1(const df1b2variable * px, const df1b2variable * py,
00731       df1b2variable * pz, mydf1b2function2 * pf);
00732     int write_pass1_sum(double x, const df1b2variable * py,
00733       df1b2variable * pz);
00734     int write_pass1_sum(const df1b2variable * px, const df1b2variable * py,
00735       df1b2variable * pz);
00736     int write_pass1_prod(double x, const df1b2variable * py,
00737       df1b2variable * pz);
00738     int write_pass1_prod(const df1b2variable * px, double py,
00739       df1b2variable * pz);
00740     int write_pass1x(const df1b2variable * _px, df1b2variable * pz,
00741       df1b2function1 * pf);
00742 
00743     int write_pass1_prod(const df1b2vector * px, const df1b2vector * py,
00744       df1b2variable * pz);
00745 
00746     int write_pass1_prod(const df1b2variable * px, const df1b2variable * py,
00747       df1b2variable * pz);
00748     int write_pass1_minuscv(const df1b2variable * py,df1b2variable * pz);
00749     int write_pass1_minusvc(const df1b2variable * py,df1b2variable * pz);
00750     int write_pass1_minus(const df1b2variable * px, const df1b2variable * py,
00751       df1b2variable * pz);
00752     int write_pass1c(const df1b2variable * px, double y, df1b2variable * pz,
00753       df1b2function2c * pf);
00754     int write_pass1c(double x,const df1b2variable * py, df1b2variable * pz,
00755       df1b2function2c * pf);
00756     int write_pass1(const df1b2variable * px, const df1b2variable * py,
00757       df1b2variable * pz, df1b2function2 * pf);
00758     int write_pass1_pluseq(const df1b2variable * px,df1b2variable * pz);
00759     int write_pass1_minuseq(const df1b2variable * px,df1b2variable * pz);
00760     int write_pass1_initialize(df1b2variable * pz);
00761     int write_pass1_eq(const df1b2variable * px,df1b2variable * pz);
00762     int write_pass1(const df1b2variable * px,
00763       df1b2variable * pz, df1b2function1 * pf);
00764     int write_pass1(const df1b2variable * px,
00765       df1b2variable * pz, double df, double d2f, double d3f );
00766 
00767     int write_pass1(const df1b2variable * _px,
00768       const df1b2variable * _py,df1b2variable * pz,double df_x,
00769       double df_y,
00770       double df_xx,
00771       double df_xy,
00772       double df_yy,
00773       double df_xxx,
00774       double df_xxy,
00775       double df_xyy,
00776       double df_yyy);
00777 
00778  int write_pass1(const df1b2variable * _px,
00779    const df1b2variable * _py,const df1b2variable * pw,
00780    const df1b2variable * pz,
00781    double df_x, double df_y, double df_z,
00782    double df_xx, double df_xy,double df_xz,double df_yy,
00783    double df_yz,double df_zz,
00784    double df_xxx,
00785    double df_xxy,
00786    double df_xxz,
00787    double df_xyy,
00788    double df_xyz,
00789    double df_xzz,
00790    double df_yyy,
00791    double df_yyz,
00792    double df_yzz,
00793    double df_zzz);
00794 
00795 
00796 
00797     int write_save_pass2_tilde_values(const df1b2variable * px);
00798     void reset(void);
00799   };
00800 
00805 class ad_dstar
00806 {
00807 public:
00808   static int n;
00809   static void allocate(int _n);
00810   double * p;
00811   ad_dstar(void);
00812   ~ad_dstar(void);
00813   operator double* (){return p;}
00814 };
00815 
00816 typedef void (**ADprfptr)(void);
00817 typedef void (*ADrfptr)(void);
00818 
00819 void set_dependent_variable(const df1b2variable& _x);
00820 
00821 dmatrix get_hessian(const init_df1b2vector& x);
00822 //df1b2variable user_function(const init_df1b2vector& x);
00823 
00824 dmatrix check_second_derivatives(const init_df1b2vector& x);
00825 d3_array check_third_derivatives(const init_df1b2vector& x);
00826 
00827 // ************************************************************
00828 // ************************************************************
00829 
00830 df1b2variable mfexp(const df1b2variable& x);
00831 df1b2variable mfexp(const df1b2variable& x,double b);
00832 
00833 // ************************************************************
00834 // ************************************************************
00835 
00836 df1b2variable fabs(const df1b2variable& x);
00837 df1b2variable max(const df1b2vector& t1);
00838 df1b2variable sfabs(const df1b2variable& x);
00839 df1b2variable pow(const df1b2variable& x,const df1b2variable& y);
00840 df1b2variable pow(const df1b2variable& x,double y);
00841 df1b2variable mypow(const df1b2variable& x,double y);
00842 df1b2variable pow(double x,const df1b2variable& y);
00843 df1b2variable sin(const df1b2variable& x);
00844 df1b2variable atan(const df1b2variable& x);
00845 df1b2variable tan(const df1b2variable& x);
00846 df1b2variable inv(const df1b2variable& x);
00847 df1b2variable sqrt(const df1b2variable& x);
00848 df1b2variable cos(const df1b2variable& x);
00849 df1b2variable exp(const df1b2variable& x);
00850 df1b2variable log(const df1b2variable& x);
00851 df1b2variable square(const df1b2variable& x);
00852 df1b2variable cube(const df1b2variable& x);
00853 df1b2variable fourth(const df1b2variable& x);
00854 df1b2variable operator * (const df1b2variable& x,double y);
00855 df1b2variable operator * (const df1b2variable& x,const df1b2variable& y);
00856 df1b2variable operator * (double x,const df1b2variable& y);
00857 df1b2variable mult_add(const df1b2variable& x,const df1b2variable& y);
00858 df1b2variable operator + (const df1b2variable& x,const df1b2variable& y);
00859 df1b2variable div(const df1b2variable& x,const df1b2variable& y);
00860 df1b2variable operator + (double x,const df1b2variable& y);
00861 df1b2variable operator + (const df1b2variable& x,double y);
00862 
00867 inline df1b2variable operator + (const df1b2variable& x,double y)
00868 {
00869   return y+x;
00870 }
00871 
00872 df1b2variable operator - (const df1b2variable& x,const df1b2variable& y);
00873 df1b2variable operator - (double x,const df1b2variable& y);
00874 df1b2variable operator / (const df1b2variable& x,const df1b2variable& y);
00875 df1b2variable operator / (const df1b2variable& x,double y);
00876 df1b2variable operator - (const df1b2variable& x,double y);
00877 df1b2variable operator / (double x,const df1b2variable& y);
00878 
00879 df1b2variable lgamma2(const df1b2variable& _x);//new log gamma using forward AD
00880 df1b2variable gammln(const df1b2variable& _xx);
00881 df1b2vector gammln(const df1b2vector&  _xx);
00882 df1b2variable log_comb(const df1b2variable& n, double k);
00883 df1b2variable log_comb(const df1b2variable& n, const df1b2variable& k);
00884 df1b2variable log_comb(double n, const df1b2variable& k);
00885 df1b2variable factln(const df1b2variable& n);
00886 
00887 // vector and matrix stuff
00888 
00893 class df1b2vector_header
00894 {
00895 protected:
00896   int offset;
00897   int index_min;
00898   int index_max;
00899 };
00900 
00901 class df3_one_vector;
00902 class funnel_init_df1b2vector;
00903 class df3_two_vector;
00904 
00905  // class predf1b2vector
00906  // {
00907  //   df1b2vector * p;
00908  //   int lb;
00909  //   int ub;
00910  //inline predf1b2vector(df1b2vector * _p,int _lb,int _ub) {p=_p;lb=_lb,ub=_ub;}
00911  //   friend class df1b2vector;
00912  // };
00913 
00918 class df1b2vector : public df1b2vector_header
00919 {
00920   df1b2variable * v;
00921   vector_shapex * shape;
00922 public:
00923   inline df1b2vector& operator -- (void)
00924   {
00925     index_min--;index_max--;v++; return *this;
00926   }
00927   inline df1b2vector& operator ++ (void)
00928   {
00929     index_min++;index_max++;v--; return *this;
00930   }
00931   virtual int pointersize(void) const { return sizeof(df1b2variable); }
00932   inline df1b2variable * getv(void) {return v;}
00933   int allocated(void){return v!=0;}
00934   int indexmin(void)const {return index_min;}
00935   int indexmax(void)const {return index_max;}
00936   int size(){return index_max-index_min+1;}
00937   df1b2vector(int lb,int ub);
00938   df1b2vector(const dvector& v);
00939   ~df1b2vector();
00940   df1b2vector(const df1b2vector&);
00941   void copy(const df1b2vector&);
00942   df1b2vector(void);
00943   void allocate(int lb,int ub,const char *);
00944   void allocate(int lb,int ub);
00945   void allocate(const ad_integer&,const ad_integer& ub);
00946   void noallocate(int lib,int ub);
00947   df1b2vector& shift(int);
00948   void allocate(void);
00949   void initialize(void);
00950   void deallocate(void);
00951   int get_offset(void){return offset;}
00952   df1b2vector& operator = (const df3_one_vector&);
00953   df1b2vector& operator = (const df1b2vector&);
00954   df1b2vector& operator = (const dvector&);
00955   df1b2vector& operator = (double);
00956   df1b2vector& operator = (const df1b2variable&);
00957   df1b2vector& operator = (const df3_two_vector& M);
00958 #  if defined(OPT_LIB)
00959   df1b2variable& operator () (int i) const
00960   {
00961    return *((df1b2variable*)((char*)(v)+i*pointersize()));
00962   }
00963   df1b2variable& operator [] (int i) const
00964   {
00965    return *((df1b2variable*)((char*)(v)+i*pointersize()));
00966   }
00967  //  df1b2vector operator () (int i,int j)
00968  //  {
00969  //    return predf1b2vector(this,i,j);
00970  //  }
00971  // df1b2vector(const predf1b2vector&);
00972 #  else
00973   //df1b2vector operator () (int i,int j);
00974   //df1b2variable& operator () const (int i);
00975   df1b2variable& operator () (int i) const;
00976   df1b2variable& operator [] (int i) const;
00977 #  endif
00978   df1b2vector operator() (const ivector & iv);
00979   df1b2vector& operator += (const df1b2vector& x);
00980   df1b2vector& operator += (const dvector& x);
00981   df1b2vector& operator += (double x);
00982   df1b2vector& operator -= (const df1b2vector& x);
00983   df1b2vector& operator -= (const dvector& x);
00984   df1b2vector& operator /= (const df1b2vector& x);
00985   df1b2vector& operator *= (const df1b2vector& x);
00986   df1b2vector& operator *= (const df1b2variable& x);
00987   df1b2vector& operator -= (const df1b2variable& x);
00988   df1b2vector& operator += (const df1b2variable& x);
00989   df1b2vector& operator /= (const df1b2variable& x);
00990   df1b2vector(const predf1b2vector&);
00991   inline df1b2vector operator () (int lb,int ub)
00992   {
00993     return predf1b2vector(this,lb,ub);
00994   }
00995   friend class random_effects_bounded_vector_info;
00996   friend class df1b2variable;
00997   friend class xf_df1b2vector;
00998   //df1b2vector(const funnel_init_df1b2vector& _s);
00999 };
01000 class df3_one_matrix;
01001 class df3_two_matrix;
01002 
01007 class df1b2matrix
01008 {
01009   int index_min;
01010   int index_max;
01011   df1b2vector * v;
01012   mat_shapex * shape;
01013 public:
01014   int allocated(void){return v!=0;}
01015   void initialize(void);
01016   ~df1b2matrix();
01017   void colfill(const int j, const df1b2vector& v);
01018   int rowmin(void) const {return index_min;}
01019   int indexmin(void) const {return index_min;}
01020   int indexmax(void) const {return index_max;}
01021   int rowmax(void) const {return index_max;}
01022   int size(void) const {return index_max-index_min+1;}
01023   df1b2matrix(int nrl,int nrh,int ncl,int nch);
01024   df1b2matrix(int nrl,int nrh);
01025   df1b2matrix(const df1b2matrix&);
01026   df1b2matrix(int nrl,int nrh,const index_type& ncl,
01027     const index_type& nch);
01028   df1b2matrix& operator =(const df3_one_matrix&);
01029 
01030   df1b2matrix& operator =(const df1b2matrix&);
01031   df1b2matrix& operator =(const dmatrix&);
01032   df1b2matrix& operator =(const df1b2variable&);
01033   df1b2matrix& operator =(double);
01034   df1b2matrix& operator = (const df3_two_matrix& M);
01035   df1b2matrix(void);
01036   df1b2matrix& operator +=(const df1b2matrix& M);
01037   df1b2matrix& operator -=(const df1b2matrix& M);
01038   void allocate(int nrl,int nrh,int ncl,int nch);
01039   void allocate(int nrl,int nrh);
01040   void allocate(int nrl,int nrh,int ncl,int nch,const char *);
01041   void allocate(int nrl,int nrh,const index_type& ncl,
01042     const index_type& nch);
01043   void allocate(int nrl,int nrh,const index_type& ncl,
01044     const index_type& nch,const char *);
01045   void allocate(void);
01046   void deallocate(void);
01047 #if defined(OPT_LIB)
01048   df1b2variable& operator () (int i,int j) const
01049     { return (df1b2variable&)(v[i][j]);}
01050   df1b2vector& operator [] (int i) const {return (df1b2vector&)(v[i]);}
01051   df1b2vector& operator () (int i) const {return (df1b2vector&)(v[i]);}
01052 #else
01053   df1b2variable& operator () (int i,int j) const;
01054   df1b2vector& operator [] (int i) const;
01055   df1b2vector& operator () (int i) const;
01056 #endif
01057   int colmin(void) const {return (*(df1b2matrix*)(this))(index_min).indexmin();}
01058   int colmax(void) const {return (*(df1b2matrix*)(this))(index_min).indexmax();}
01059   int colsize(void)const {return colmax()-colmin()+1;}
01060   df1b2matrix& operator *= (const df1b2variable& x);
01061   df1b2matrix& operator /= (const df1b2variable& x);
01062   df1b2matrix& operator *= (double x);
01063   df1b2matrix& operator /= (double x);
01064 };
01065 
01070 class df1b23array
01071 {
01072   int index_min;
01073   int index_max;
01074   df1b2matrix * v;
01075   vector_shapex * shape;
01076 public:
01077   int allocated(void){return v!=0;}
01078   void initialize(void);
01079   ~df1b23array();
01080   int indexmin(void){return index_min;}
01081   int indexmax(void){return index_max;}
01082   int size(void){return index_max-index_min+1;}
01083   df1b23array(int nrl,int nrh,int ncl,int nch,int,int);
01084   df1b23array(int nrl,int nrh);
01085   df1b23array(int nrl,int nrh,int,int);
01086   df1b23array(const df1b23array&);
01087   //df1b23array& operator =(const df3_one_matrix&);
01088 
01089   df1b23array& operator =(const df1b23array&);
01090   df1b23array& operator =(const df1b2variable&);
01091   df1b23array& operator =(double);
01092   df1b23array(void);
01093   df1b23array& operator +=(const df1b23array& M);
01094   df1b23array& operator -=(const df1b23array& M);
01095   void allocate(int nrl,int nrh,int ncl,int nch,int,int);
01096   void allocate(int nrl,int nrh,int,int);
01097   void allocate(int nrl,int nrh);
01098   void allocate(int nrl,int nrh,int ncl,int nch,int,int,const char *);
01099 
01100   void allocate(int nrl,int nrh,
01101     const index_type& ncl, const index_type& nch);
01102 
01103 
01104   void allocate(int nrl,int nrh,
01105     const index_type& ncl, const index_type& nch,
01106     const index_type& nxl, const index_type& nxh);
01107 
01108   void allocate(int nrl,int nrh,
01109     const index_type& ncl,const index_type& nch,
01110     const index_type& nxl,const index_type& nxh,
01111     const char *);
01112   void allocate(void);
01113   void deallocate(void);
01114 #  if defined(OPT_LIB)
01115   df1b2variable& operator () (int i,int j,int k){return v[i](j,k);}
01116   df1b2vector& operator () (int i,int j){return v[i][j];}
01117   df1b2matrix& operator () (int i){return v[i];}
01118   df1b2matrix& operator [] (int i){return v[i];}
01119 #else
01120   df1b2variable& operator () (int i,int j,int k);
01121   df1b2vector& operator () (int i,int j);
01122   df1b2matrix& operator () (int i);
01123   df1b2matrix& operator [] (int i);
01124 #endif
01125 };
01126 
01127 
01128 // **************************************
01129 // **************************************
01130 df1b2vector fabs(const df1b2vector& t1);
01131 df1b2vector mfexp(const df1b2vector& x);
01132 df1b2vector exp(const df1b2vector& x);
01133 df1b2vector sqrt(const df1b2vector& x);
01134 df1b2vector sin(const df1b2vector& x);
01135 df1b2vector tan(const df1b2vector& x);
01136 df1b2vector cos(const df1b2vector& x);
01137 df1b2vector log(const df1b2vector& x);
01138 
01139 df1b2matrix mfexp(const df1b2matrix& M);
01140 df1b2matrix log(const df1b2matrix& M);
01141 df1b2matrix trans(const df1b2matrix& M);
01142 df1b2matrix choleski_decomp(const df1b2matrix& M);
01143 df1b2matrix choleski_decomp_extra(const df1b2matrix& M);
01144 df1b2matrix exp(const df1b2matrix& M);
01145 df1b2vector column(const df1b2matrix&,int i);
01146 df1b2vector colsum(const df1b2matrix&);
01147 df1b2vector rowsum(const df1b2matrix&);
01148 
01149 df1b2vector operator * (double,const df1b2vector& y);
01150 df1b2vector operator * (const df1b2vector& y,const double);
01151 df1b2variable operator * (const df1b2vector& y,const dvector&);
01152 df1b2variable operator * (const dvector&,const df1b2vector& y);
01153 df1b2vector operator * (const df1b2vector& y,const df1b2variable&);
01154 df1b2vector operator * (const df1b2variable&,const df1b2vector& y);
01155 
01156 df1b2matrix outer_prod(const df1b2vector& x,const df1b2vector& y);
01157 df1b2matrix operator + (const df1b2matrix& M,const df1b2variable& x);
01158 
01159 df1b2matrix operator + (const df1b2matrix& M,const df1b2matrix& N);
01160 df1b2matrix operator + (const df1b2matrix& M,const dmatrix& N);
01161 
01162 df1b2matrix operator * (const df1b2matrix& M,const df1b2variable& x);
01163 df1b2matrix operator * (const dmatrix& M,const df1b2variable& x);
01164 df1b2vector operator * (const dmatrix& M,const df1b2vector& x);
01165 df1b2matrix operator * (const df1b2variable& x,const dmatrix& M);
01166 
01167 df1b2matrix operator * (const df1b2matrix& M,const df1b2matrix& x);
01168 df1b2matrix operator * (const dmatrix& M,const df1b2matrix& x);
01169 df1b2matrix operator + (const dmatrix& M,const df1b2matrix& x);
01170 df1b2matrix operator + (const df1b2variable&, const df1b2matrix& M);
01171 df1b2vector operator + (const df1b2variable&, const dvector& M);
01172 df1b2matrix operator * (const df1b2variable&, const df1b2matrix& M);
01173 df1b2matrix operator + (const df1b2matrix& M,const double x);
01174 df1b2matrix operator * (const df1b2matrix& M,const double x);
01175 
01176 df1b2matrix operator - (const df1b2matrix& M,const dmatrix& x);
01177 df1b2matrix operator - (const df1b2matrix& M,const double x);
01178 df1b2matrix operator - (const df1b2matrix& M,const df1b2variable& x);
01179 df1b2matrix operator - (const df1b2matrix& M,const df1b2matrix& x);
01180 df1b2matrix operator - (const dmatrix& M,const df1b2matrix& x);
01181 df1b2matrix operator - (const df1b2variable&, const df1b2matrix& M);
01182 df1b2matrix operator - (const double, const df1b2matrix& M);
01183 
01184 df1b2matrix operator + (const df1b2variable&, const df1b2matrix& M);
01185 
01186 df1b2matrix operator + (const double, const df1b2matrix& M);
01187 df1b2matrix operator * (const double, const df1b2matrix& M);
01188 df1b2matrix elem_prod(const df1b2matrix& x,const df1b2matrix& y);
01189 df1b2matrix elem_prod(const dmatrix& x,const df1b2matrix& y);
01190 df1b2matrix elem_prod(const df1b2matrix& x,const dmatrix& y);
01191 df1b2matrix elem_div(const df1b2matrix& x,const df1b2matrix& y);
01192 df1b2matrix elem_div(const dmatrix& x,const df1b2matrix& y);
01193 df1b2matrix elem_div(const df1b2matrix& x,const dmatrix& y);
01194 
01195 df1b2vector elem_prod(const df1b2vector& x,const df1b2vector& y);
01196 df1b2vector elem_prod(const df1b2vector& x,const dvector& y);
01197 df1b2vector elem_prod(const dvector& x,const df1b2vector& y);
01198 df1b2vector elem_div(const df1b2vector& x,const df1b2vector& y);
01199 df1b2vector elem_div(const dvector& x,const df1b2vector& y);
01200 df1b2vector elem_div(const df1b2vector& x,const dvector& y);
01201 
01202 df1b2vector operator + (const df1b2variable& x,const df1b2vector& y);
01203 df1b2vector operator + (double x,const df1b2vector& y);
01204 df1b2vector operator + (const df1b2vector& x,const df1b2vector& y);
01205 df1b2vector operator + (const df1b2vector& x,const df1b2variable& y);
01206 df1b2vector operator + (const dvector& x,const df1b2vector& y);
01207 df1b2vector operator + (const df1b2vector& y,const dvector& x);
01208 
01209 df1b2vector operator - (const df1b2vector& x,const df1b2vector& y);
01210 df1b2vector operator - (const dvector& x,const df1b2vector& y);
01211 df1b2vector operator - (const df1b2variable& x,const df1b2vector& y);
01212 df1b2vector operator - (const df1b2vector& x,const df1b2vector& y);
01213 df1b2vector operator - (const df1b2variable& x,const df1b2vector& y);
01214 df1b2vector operator - (const df1b2variable& x,const dvector& y);
01215 df1b2vector operator - (const df1b2vector& x,const df1b2variable& y);
01216 df1b2vector operator - (const df1b2vector& x,const dvector& y);
01217 
01218 df1b2vector operator * (const df1b2variable& y,const dvector&);
01219 
01220 df1b2vector operator * (const df1b2vector& x,const df1b2variable& y);
01221 df1b2vector operator * (const df1b2vector& x,double y);
01222 
01223 df1b2vector operator / (const df1b2variable& y,const df1b2vector& x);
01224 df1b2vector operator / (const double& y,const df1b2vector& x);
01225 
01226 df1b2vector operator / (const df1b2vector& x,const df1b2variable& y);
01227 df1b2vector operator / (const df1b2vector& x,double y);
01228 df1b2vector pow(const df1b2vector& x,double y);
01229 df1b2vector pow(const df1b2vector& v,const df1b2variable & x);
01230 df1b2vector pow(const df1b2vector& v,const df1b2vector & x);
01231 df1b2vector pow(const df1b2variable& v,const df1b2vector & x);
01232 df1b2vector pow(df1b2vector const& _x,dvector const& v);
01233 df1b2vector pow(double v,const df1b2vector & x);
01234 df1b2vector pow(const dvector& x,  const df1b2vector& a);
01235 df1b2vector pow(const dvector& x,  const df1b2variable& a);
01236 
01237 df1b2vector operator / (const dvector& x,const df1b2variable& y);
01238 df1b2vector operator + (const dvector& x,const df1b2variable& y);
01239 df1b2vector operator - (const dvector& x,const df1b2variable& y);
01240 df1b2vector operator * (const dvector& x,const df1b2variable& y);
01241 // **************************************
01242 // **************************************
01243 df1b2variable sum(const df1b2vector& x);
01244 df1b2variable mean(const df1b2vector& x);
01245 df1b2variable norm2(const df1b2vector& x);
01246 df1b2variable sumsq(const df1b2vector& x);
01247 df1b2variable norm(const df1b2vector& x);
01248 
01249 df1b2variable norm2(const df1b2matrix& x);
01250 df1b2variable sumsq(const df1b2matrix& x);
01251 df1b2variable norm(const df1b2matrix& x);
01252 df1b2variable mean(const df1b2matrix& x);
01253 df1b2variable sum(const df1b2matrix& x);
01254 df1b2matrix square(const df1b2matrix& x);
01255 df1b2vector square(const df1b2vector& x);
01256 df1b2vector cube(const df1b2vector& x);
01257 df1b2vector solve(const df1b2matrix& x,const dvector&);
01258 df1b2vector solve(const df1b2matrix& x,const df1b2vector&);
01259 
01260 int size_count(const df1b2matrix& x);
01261 int size_count(const df1b2vector& x);
01262 
01263 df1b2vector first_difference(const df1b2vector& x);
01264 
01265 df1b2vector operator * (const dvector& ,const df1b2matrix& );
01266 df1b2vector operator * (const df1b2vector& ,const df1b2matrix& );
01267 df1b2vector operator * (const df1b2vector& ,const dmatrix& );
01268 df1b2variable operator * (const df1b2vector& x,const df1b2vector& y);
01269 df1b2vector operator * (const df1b2matrix& M,const df1b2vector& x);
01270 df1b2vector operator * (const df1b2matrix& M,const dvector& x);
01271 void check_shape(const df1b2vector & x,const df1b2vector & y,const char * s);
01272 void check_shape(const df1b2vector & x,const dvector & y,const char * s);
01273 void check_shape(const dvector & x,const df1b2vector & y,const char * s);
01274 void check_shape(const df1b2vector & x,const df1b2matrix & y,const char * s);
01275 
01276 void checkidentiferstring(const char * ids,test_smartlist& list);
01277 
01278 double& value(const df1b2variable& _x);
01279 dvector value(const df1b2vector& _x);
01280 dmatrix value(const df1b2matrix& _x);
01281 
01286 class initial_df1b2params
01287 {
01288 public:
01289   static int stddev_scale(const dvector& d,const dvector& x);
01290   static int current_phase;
01291   static int separable_flag;
01292   static int separable_calculation_type;
01293   static int have_bounded_random_effects;
01294   int phase_start;
01295   int phase_save;
01296   int ind_index;
01297   double scalefactor;
01298 
01299   static void save_varsptr(void);
01300   static double cobjfun;
01301   static void restore_varsptr(void);
01302   static imatrix * pointer_table;
01303   static initial_df1b2params **  varsptr;  // this should be a resizeable
01304   static initial_df1b2params **  varsptr_sav;  // this should be a resizeable
01305   static int num_initial_df1b2params;         // array
01306   static int num_initial_df1b2params_sav;         // array
01307   virtual void set_value(const dvector&,const int& ii)=0;
01308   virtual void set_index(int aflag,const int& ii)=0;
01309   static int set_index(void);
01310   virtual void set_value(const init_df1b2vector&,const int& ii,
01311     const df1b2variable&)=0;
01312   static void reset(const init_df1b2vector&,const df1b2variable&);
01313   static void reset_all(const dvector&);
01314   static void reset(const df1b2vector&,const df1b2variable&);
01315   virtual void add_to_list(void);
01316   initial_df1b2params(void);
01317   void set_phase_start(int n){phase_start=n; phase_save=n;}
01318   virtual void sd_scale(const dvector& d,const dvector& x,const int& ii)=0;
01319   double get_scalefactor();
01320   void set_scalefactor(const double);
01321 };
01322 
01323 typedef initial_df1b2params * P_INITIAL_DF1B2PARAMS;
01324 
01329 class do_naught_kludge
01330 {
01331 };
01332 
01337 class df1b2_init_vector : public df1b2vector, public initial_df1b2params
01338 {
01339 public:
01340   virtual ~df1b2_init_vector() {;}
01341 
01342   virtual void sd_scale(const dvector& d,const dvector& x,const int& ii);
01343   void set_phase_start(int n){phase_start=n; phase_save=n;}
01344   virtual void set_value(const dvector& x,const int& _ii);
01345   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01346     const df1b2variable& pen);
01347   void allocate(int min, int max,int phase_start, const adstring& s="unnamed");
01348   void allocate(int min, int max,const adstring& s="unnamed");
01349   virtual void set_index(int aflag,const int& ii);
01350 };
01351 
01356 class df1b2_init_matrix : public df1b2matrix, public initial_df1b2params
01357 {
01358 public:
01359   virtual void sd_scale(const dvector& d,const dvector& x,const int& ii);
01360 
01361   inline void allocate(int rmin,int rmax,const index_type& cmin,
01362     const index_type& cmax,int ps,const char * s)
01363   {
01364     set_phase_start(ps);
01365     df1b2matrix::allocate(rmin,rmax,cmin,cmax,s);
01366   }
01367 
01368   inline void allocate(int rmin,int rmax,const index_type& cmin,
01369     const index_type& cmax,const char * s)
01370   {
01371     df1b2matrix::allocate(rmin,rmax,cmin,cmax,s);
01372   }
01373 
01374   inline void allocate(int rmin,int rmax,int cmin,int cmax)
01375   {
01376     df1b2matrix::allocate(rmin,rmax,cmin,cmax);
01377   }
01378   inline void allocate(int rmin,int rmax,int cmin,int cmax,int ps,
01379     const char * s)
01380   {
01381     set_phase_start(ps);
01382     df1b2matrix::allocate(rmin,rmax,cmin,cmax,s);
01383   }
01384   inline void allocate(int rmin,int rmax,int cmin,int cmax,const char * s)
01385   {
01386     df1b2matrix::allocate(rmin,rmax,cmin,cmax,s);
01387   }
01388   inline void allocate(int rmin, int rmax, int cmin, int cmax, double, double,
01389     const char* s)
01390   {
01391     df1b2matrix::allocate(rmin,rmax,cmin,cmax,s);
01392   }
01393   void set_phase_start(int n){phase_start=n; phase_save=n;}
01394   virtual void set_value(const dvector& x,const int& _ii);
01395   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01396     const df1b2variable& pen);
01397   virtual void set_index(int aflag,const int& ii);
01398 };
01399 
01400 
01405 class df1b2_init_number : public df1b2variable, public initial_df1b2params
01406 {
01407   static do_naught_kludge do_naught_kludge_a;
01408 public:
01409   virtual void sd_scale(const dvector& d,const dvector& x,const int& ii);
01410   virtual int & get_ind_index(void) { return ind_index; }
01411   void set_phase_start(int n){phase_start=n; phase_save=n;}
01412   virtual void set_value(const dvector& x,const int& _ii);
01413   virtual void set_value(const init_df1b2vector&,const int& ii,
01414     const df1b2variable&);
01415   virtual void set_index(int aflag,const int& ii);
01416 
01417   void allocate(const adstring&);
01418   void allocate(int,const adstring&);
01419   df1b2_init_number();
01420   void operator = (const df1b2variable& _x);
01421 };
01422 
01427 class df1b2_init_number_vector
01428 {
01429   df1b2_init_number * v;
01430   int index_min;
01431   int index_max;
01432   double_index_type * it;
01433 public:
01434   df1b2_init_number_vector();
01435 
01436 #if defined(OPT_LIB)
01437    df1b2_init_number& operator [] (int i) { return v[i];}
01438    df1b2_init_number& operator () (int i) { return v[i];}
01439 #else
01440    df1b2_init_number& operator [] (int i);
01441    df1b2_init_number& operator () (int i);
01442 #endif
01443   void allocate(int min1,int max1,const index_type& phase_start,
01444     const char * s);
01445 
01446   void allocate(int min1,int max1,const char * s);
01447 
01448   int allocated(void) { return (v!=NULL); }
01449   int indexmin(void) {return (index_min);}
01450   int indexmax(void) {return (index_max);}
01451   ~df1b2_init_number_vector();
01452   void deallocate(void);
01453 };
01454 
01455 class df1b2_init_bounded_number;
01456 
01461 class df1b2_init_bounded_number :public df1b2_init_number
01462 {
01463   double minb;
01464   double maxb;
01465 public:
01466   void allocate(double _minb,double _maxb,int _phase_start,
01467     const char * s="UNNAMED");
01468   virtual void sd_scale(const dvector& d,const dvector& x,const int& ii);
01469 
01470   void allocate(double _minb,double _maxb,const char * s="UNNAMED");
01471   //void allocate(const ad_double& _minb,const ad_double& _maxb,
01472    // const char * s="UNNAMED");
01473 
01474   virtual void set_value(const dvector& x,const int& _ii);
01475   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01476     const df1b2variable& pen);
01477 };
01478 
01483 class df1b2_init_bounded_number_vector
01484 {
01485   df1b2_init_bounded_number * v;
01486   int index_min;
01487   int index_max;
01488   double_index_type * it;
01489 public:
01490   //virtual void sd_scale(const dvector& d,const dvector& x,const int& ii);
01491   df1b2_init_bounded_number_vector();
01492 
01493 #if defined(OPT_LIB)
01494    df1b2_init_bounded_number& operator [] (int i) { return v[i];}
01495    df1b2_init_bounded_number& operator () (int i) { return v[i];}
01496 #else
01497    df1b2_init_bounded_number& operator [] (int i);
01498    df1b2_init_bounded_number& operator () (int i);
01499 #endif
01500   void allocate(int min1,int max1, const double_index_type& bmin,
01501    const double_index_type& bmax, const char * s);
01502 
01503   void allocate(int min1,int max1, const double_index_type& bmin,
01504    const double_index_type& bmax, const index_type& phase_start,
01505     const char * s);
01506 
01507 
01508   int allocated(void) { return (v!=NULL); }
01509   int indexmin(void) {return (index_min);}
01510   int indexmax(void) {return (index_max);}
01511   ~df1b2_init_bounded_number_vector();
01512   void deallocate(void);
01513 };
01514 
01519 class df1b2_init_bounded_vector : public df1b2_init_vector
01520 {
01521 protected:
01522   double minb;
01523   double maxb;
01524 public:
01525   virtual void sd_scale(const dvector& d,const dvector& x,const int& ii);
01526   void allocate(int,int,double,double,int,const char *);
01527   void allocate(int,int,double,double,const char *);
01528   void allocate(int,int,double,double);
01529   //void allocate(int,int);
01530   virtual void set_value(const dvector& x,const int& _ii);
01531   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01532     const df1b2variable& pen);
01533   inline double getminb(void){return minb;}
01534   inline double getmaxb(void){return maxb;}
01535 };
01536 
01537 class re_df1b2_init_bounded_vector;
01538 
01543 class random_effects_bounded_vector_info
01544 {
01545   re_df1b2_init_bounded_vector * pv;
01546   int i;
01547 public:
01548   random_effects_bounded_vector_info
01549     ( re_df1b2_init_bounded_vector * _pv,int _i) : pv(_pv), i(_i) {}
01550   friend class funnel_init_df1b2variable;
01551   friend class df1b2variable;
01552   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01553     const df1b2variable& pen);
01554 };
01555 
01560 class re_df1b2_init_bounded_vector : public df1b2_init_bounded_vector
01561 {
01562 public:
01563   random_effects_bounded_vector_info operator () (int i)
01564   {
01565     return random_effects_bounded_vector_info(this,i);
01566   }
01567   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01568     const df1b2variable& pen);
01569   virtual void set_value(const dvector& x,const int& _ii);
01570   re_df1b2_init_bounded_vector(void);
01571 };
01572 
01577 class df1b2_init_bounded_matrix : public df1b2_init_matrix
01578 {
01579 protected:
01580   double minb;
01581   double maxb;
01582 public:
01583   virtual void sd_scale(const dvector& d,const dvector& x,const int& ii);
01584   void allocate(int,int,int,int,double,double,int,const char *);
01585   void allocate(int,int,const index_type& ,const index_type& ,double,double,int,
01586     const char *);
01587   void allocate(int,int,int,int,double,double,const char *);
01588   void allocate(int,int,const index_type& ,const index_type& ,double,double,
01589     const char *);
01590   void allocate(int,int,int,int,double,double);
01591   //void allocate(int,int);
01592   virtual void set_value(const dvector& x,const int& _ii);
01593   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01594     const df1b2variable& pen);
01595 };
01596 
01601 class df1b2_init_bounded_dev_vector : public df1b2_init_bounded_vector
01602 {
01603 public:
01604   virtual void set_value(const dvector& x,const int& _ii);
01605   virtual void set_value(const init_df1b2vector& x,const int& _ii,
01606     const df1b2variable& pen);
01607 };
01608 
01609 void set_value(const df1b2variable& u,const init_df1b2vector& x,const int& _ii,
01610   double fmin,double fmax,const df1b2variable& fpen);
01611 
01612 void set_value(const df1b2variable& u,const init_df1b2vector& x,const int& _ii,
01613   double fmin,double fmax,const df1b2variable& fpen,double s);
01614 
01615 df1b2variable boundp(const df1b2variable& x, double fmin, double fmax);
01616 df1b2variable boundp(const df1b2variable& x, double fmin, double fmax,
01617   const df1b2variable& _fpen);
01618 df1b2variable boundp(const df1b2variable& x, double fmin, double fmax,
01619   const df1b2variable& _fpen,double s);
01620 
01621   ostream& operator << (const ostream& _os, const df1b2variable& _x);
01622   ostream& operator << (const ostream& _os, const df1b2vector& _x);
01623   ostream& operator << (const ostream& _os, const df1b2matrix& _x);
01624 
01625   class re_objective_function_value : public df1b2variable
01626   {
01627   public:
01628     static re_objective_function_value * pobjfun;
01629     static double fun_without_pen;
01630     re_objective_function_value(void);
01631     ~re_objective_function_value();
01632     re_objective_function_value& operator = (const df1b2variable& v);
01633     re_objective_function_value& operator = (double v);
01634     void allocate(void);
01635     void allocate(const char *);
01636   };
01637 
01638 df1b2variable posfun(const df1b2variable&x,const double eps);
01639 df1b2variable posfun2(const df1b2variable&x,const double eps,
01640   const df1b2variable& _pen);
01641 df1b2variable posfun(const df1b2variable&x,const double eps,
01642   const df1b2variable& _pen);
01643 
01648 inline df1b2variable operator - (const df1b2variable& x)
01649 {
01650   return -double(1.0)*x;
01651 }
01652 
01657 inline df1b2vector operator - (const df1b2vector& x)
01658 {
01659   return -double(1.0)*x;
01660 }
01661 
01662 df1b2variable gamma_density(const df1b2variable& _x,double r, double mu);
01663 df1b2variable gamma_density(const df1b2variable& _x,const df1b2variable& _r,
01664   const  df1b2variable& _mu);
01665 
01666 df1b2variable log_gamma_density(const df1b2variable& _x,double r, double mu);
01667 df1b2variable log_gamma_density(const df1b2variable& _x,const df1b2variable& _r,
01668   const  df1b2variable& _mu);
01669 
01670 
01671 df1b2variable log_negbinomial_density(double x,const df1b2variable& mu,
01672   const df1b2variable& tau);
01673 
01674 df1b2variable log_density_poisson(double x,const df1b2variable& mu);
01675 
01676 ostream& operator << (const ostream& ostr,const df1b2variable& z);
01677 ostream& operator << (const ostream& ostr,const df1b2vector& z);
01678 ostream& operator << (const ostream& ostr,const df1b2matrix& z);
01679 ostream& operator << (const ostream& ostr,const df1b2_init_number_vector& z);
01680 ostream& operator << (const ostream& ostr,const init_df1b2vector& z);
01681 ostream& operator << (const ostream& ostr,
01682   const df1b2_init_bounded_number_vector& z);
01683 
01684 class adkludge1;
01685 
01686 
01691   class df1b2_header_ptr_vector
01692   {
01693     int index_min;
01694     int index_max;
01695     df1b2_header ** v;
01696   public:
01697     df1b2_header_ptr_vector(int mmin,int mmax);
01698     ~df1b2_header_ptr_vector();
01699     inline df1b2_header * & operator () (int i) { return *(v+i); }
01700     inline df1b2_header * & operator [] (int i) { return *(v+i); }
01701     int indexmin(void) {return index_min;}
01702     int indexmax(void) {return index_max;}
01703   };
01704 
01709   class double_ptr_vector
01710   {
01711     int index_min;
01712     int index_max;
01713     double ** v;
01714   public:
01715     double_ptr_vector(int mmin,int mmax);
01716     ~double_ptr_vector();
01717     inline double * & operator () (int i) { return *(v+i); }
01718     inline double * & operator [] (int i) { return *(v+i); }
01719     int indexmin(void) {return index_min;}
01720     int indexmax(void) {return index_max;}
01721   };
01722 
01723 int active(const df1b2_init_vector& x);
01724 int active(const df1b2_init_number& x);
01725 int active(const df1b2_init_matrix& x);
01726 //int active(const df1b2_init_bounded_vector& x);
01727 
01728 //int active (const df1b2_init_vector &);
01729 //int active(const initial_df1b2params& x);
01730 //int active(const df1b2vector& x);
01731 //int active(const df1b2matrix& x);
01732 
01733 double evaluate_function_quiet(const dvector& x,function_minimizer * pfmin);
01734 double evaluate_function(const dvector& x,function_minimizer * pfmin);
01735 double evaluate_function(double& fval,const dvector& x,
01736   function_minimizer * pfmin);
01737 double evaluate_function(double& fval,const dvector& x,const dvector&,
01738   function_minimizer * pfmin);
01739 
01740 
01741 double evaluate_function_no_derivatives(const dvector& x,
01742   function_minimizer * pfmin);
01743 
01744 #include <df1b2fnl.h>
01745 
01746 int allocated(const df1b2_init_vector&);
01747 int allocated(const df1b2vector&);
01748 int allocated(const df1b2_init_matrix&);
01749 #include <df3fun.h>
01750 
01751 /*
01752 df1b2variable betai(const df1b2variable & _a, const df1b2variable & _b,
01753          const df1b2variable & _x);
01754 df1b2variable betai(const df1b2variable & _a, const df1b2variable & _b,
01755          double _x);
01756 */
01757 
01758 df1b2variable betai(const df1b2variable& a, const df1b2variable& b,
01759   double x, int maxit=100);
01760 
01761 double do_gauss_hermite_block_diagonal(const dvector& x,
01762   const dvector& u0,const dmatrix& Hess,const dvector& _xadjoint,
01763   const dvector& _uadjoint,const dmatrix& _Hessadjoint,
01764   function_minimizer * pmin);
01765 
01766 double do_gauss_hermite_block_diagonal_multi(const dvector& x,
01767   const dvector& u0,const dmatrix& Hess,const dvector& _xadjoint,
01768   const dvector& _uadjoint,const dmatrix& _Hessadjoint,
01769   function_minimizer * pmin);
01770 
01771 double calculate_importance_sample_block_diagonal(const dvector& x,
01772   const dvector& u0,const dmatrix& Hess,const dvector& _xadjoint,
01773   const dvector& _uadjoint,const dmatrix& _Hessadjoint,
01774   function_minimizer * pmin);
01775 
01776 double calculate_importance_sample_block_diagonal_option2(const dvector& x,
01777   const dvector& u0,const dmatrix& Hess,const dvector& _xadjoint,
01778   const dvector& _uadjoint,const dmatrix& _Hessadjoint,
01779   function_minimizer * pmin);
01780 
01781 double calculate_importance_sample_block_diagonal_option_antithetical
01782   (const dvector& x,const dvector& u0,const dmatrix& Hess,
01783   const dvector& _xadjoint,const dvector& _uadjoint,
01784   const dmatrix& _Hessadjoint,function_minimizer * pmin);
01785 
01786 double calculate_importance_sample_block_diagonal_funnel(const dvector& x,
01787   const dvector& u0,const dmatrix& Hess,const dvector& _xadjoint,
01788   const dvector& _uadjoint,const dmatrix& _Hessadjoint,
01789   function_minimizer * pmin);
01790 
01791 double calculate_importance_sample(const dvector& x,const dvector& u0,
01792   const dmatrix& Hess,const dvector& _xadjoint,const dvector& _uadjoint,
01793   const dmatrix& _Hessadjoint,function_minimizer * pmin);
01794 
01795 double calculate_importance_sample_shess(const dvector& x,const dvector& u0,
01796   const dmatrix& Hess,const dvector& _xadjoint,const dvector& _uadjoint,
01797   const dmatrix& _Hessadjoint,function_minimizer * pmin);
01798 double calculate_importance_sample(const dvector& x,const dvector& u0,
01799   const banded_symmetric_dmatrix& bHess,const dvector& _xadjoint,
01800   const dvector& _uadjoint,
01801   const banded_symmetric_dmatrix& _bHessadjoint,function_minimizer * pmin);
01802 
01803 dvector evaluate_function_with_quadprior(const dvector& x,int usize,
01804   function_minimizer * pfmin);
01805 
01810 class style_flag_class
01811 {
01812 public:
01813   int old_style_flag;
01814   virtual void set_old_style_flag(void)=0;
01815   //style_flag_class(void) {set_old_style_flag();}
01816 };
01817 
01822 class quadratic_prior : public style_flag_class
01823 {
01824   dmatrix * pMinv;
01825   dvar_matrix * dfpMinv;
01826   dvar_vector * pu;
01827   int xmyindex;
01828 public:
01829   static int qflag;
01830   static quadratic_prior * ptr[]; // this should be a resizeable array
01831   static void get_M_calculations(void);
01832   static void cleanup_pMinv();
01833   static void cleanup_dfpMinv();
01834   static int num_quadratic_prior;
01835   static const int max_num_quadratic_prior;
01836   void add_to_list(void);
01837 public:
01838   static int in_qp_calculations;
01839   int get_offset(int xs);
01840   int get_myindex(void) { return xmyindex;}
01841   static quadratic_prior * get_ptr(int i){ return ptr[i];}
01842   void operator = (const dvar_matrix &);
01843   void operator = (const dmatrix &);
01844   static int get_in_qp_calculations() { return in_qp_calculations; }
01845   static int get_num_quadratic_prior(void) { return num_quadratic_prior;}
01846   static dvariable get_quadratic_priors(void);
01847   dvariable get_function(void);
01848   quadratic_prior(void);
01849   ~quadratic_prior(void);
01850   void allocate(const dvar_vector & _u,const char * s);
01851   void allocate(const dvar_vector & _u);
01852   void allocate(const dvar_matrix & _M, const dvar_vector & _u,const char * s);
01853   void allocate(const dvar_matrix & _M, const dvar_vector & _u);
01854   //dmatrix get_cHessian(void);
01855   void get_cHessian(dmatrix,int);
01856   void get_cHessian(dvar_matrix,int);
01857   void get_cHessian_from_vHessian(dmatrix ,int);
01858   void get_vHessian(dvar_matrix ,int);
01859   void get_cgradient(dvector,int);
01860   dvar_matrix get_Hessian(void);
01861   dvar_vector get_gradient(void);
01862   static dvar_vector get_gradient_contribution(void);
01863   static dvar_matrix get_Hessian_contribution(void);
01864   static void get_cgradient_contribution(dvector,int);
01865   static void get_cHessian_contribution(dmatrix,int);
01866   static void get_vHessian_contribution(dvar_matrix  ,int );
01867   static void get_cHessian_contribution_from_vHessian(dmatrix,int);
01868   friend class df1b2quadratic_prior;
01869   virtual void get_cM(void)=0;
01870 };
01871 
01876 class df1b2quadratic_prior : public style_flag_class
01877 {
01878   ivector * index;
01879   df1b2matrix * M;
01880   dmatrix * CM;
01881 public:
01882   dmatrix * Lxu;
01883   df1b2_init_vector * pu;
01884   int xmyindex;
01885   static df1b2quadratic_prior * ptr[]; // this should be a resizeable array
01886   static int num_quadratic_prior;
01887   static const int max_num_quadratic_prior;
01888   void add_to_list(void);
01889 public:
01890   static df1b2quadratic_prior * get_ptr(int i){ return ptr[i];}
01891   int num_active_parameters;
01892   int get_num_active_parameters(void) { return num_active_parameters; }
01893   int get_myindex(void) { return xmyindex;}
01894   void operator = (const df1b2matrix &);
01895   void operator = (const dmatrix &);
01896   static int get_num_quadratic_prior(void) { return num_quadratic_prior;}
01897   static dvariable get_quadratic_priors(void);
01898   df1b2variable get_function(void);
01899   df1b2quadratic_prior(void);
01900   ~df1b2quadratic_prior(void);
01901   void allocate(const df1b2_init_vector & _u,const char * s);
01902   void allocate(const df1b2_init_vector & _u);
01903   void allocate(const df1b2matrix & _M, const df1b2_init_vector & _u,
01904     const char * s);
01905   void allocate(const df1b2matrix & _M, const df1b2_init_vector & _u);
01906   void allocate(const dvar_matrix & _M, const dvar_vector & _u,const char * s);
01907   void allocate(const dvar_matrix & _M, const dvar_vector & _u);
01908   dmatrix get_cHessian(void);
01909   dvector get_cgradient(void);
01910   dvar_matrix get_Hessian(void);
01911   dvar_vector get_gradient(void);
01912   static dvar_vector get_gradient_contribution(void);
01913   static dvar_matrix get_Hessian_contribution(void);
01914   static dvector get_cgradient_contribution(void);
01915   static dmatrix get_cHessian_contribution(void);
01916   static void get_Lxu_contribution(dmatrix&);
01917   virtual void get_Lxu(dmatrix&)=0;
01918   friend class quadratic_prior;
01919   friend class df1b2_parameters;
01920 };
01921 
01926 class normal_quadratic_prior : public quadratic_prior
01927 {
01928   virtual void set_old_style_flag(void);
01929 public:
01930   normal_quadratic_prior(void);
01931   void operator = (const dvar_matrix & M);
01932 };
01933 
01938 class normal_df1b2quadratic_prior : public df1b2quadratic_prior
01939 {
01940   virtual void set_old_style_flag(void);
01941 public:
01942   void operator = (const df1b2matrix & M);
01943   normal_df1b2quadratic_prior(void);
01944 };
01945 
01950 class quadratic_re_penalty : public quadratic_prior
01951 {
01952   virtual void set_old_style_flag(void);
01953 public:
01954   quadratic_re_penalty(void);
01955   void operator = (const dvar_matrix & M);
01956   void operator = (const dmatrix & M);
01957 };
01958 
01963 class df1b2quadratic_re_penalty : public df1b2quadratic_prior
01964 {
01965   virtual void set_old_style_flag(void);
01966 public:
01967   void operator = (const df1b2matrix & M);
01968   void operator = (const dmatrix & M);
01969   df1b2quadratic_re_penalty(void);
01970 };
01971 
01972 dvar_vector solve(const named_dvar_matrix &,const random_effects_vector&);
01973 
01978 class constant_quadratic_re_penalty : public quadratic_prior
01979 {
01980   virtual void set_old_style_flag(void);
01981 public:
01982   constant_quadratic_re_penalty(void);
01983   void operator = (const dmatrix & M);
01984 };
01985 
01990 class constant_df1b2quadratic_re_penalty : public df1b2quadratic_prior
01991 {
01992   virtual void set_old_style_flag(void);
01993 public:
01994   void operator = (const dmatrix & M);
01995   constant_df1b2quadratic_re_penalty(void);
01996 };
01997 
01998 df1b2vector solve(df1b2matrix& M,df1b2vector& v,const df1b2variable& ln_det);
01999 
02000 df1b2vector solve(df1b2matrix& M,df1b2vector& v,const df1b2variable& ln_det,
02001   const int& sgn);
02002 df1b2vector lower_triangular_solve(const df1b2matrix& m,const df1b2vector& v);
02003 df1b2vector lower_triangular_solve_trans(const df1b2matrix& m,
02004   const df1b2vector& v);
02005 
02006 //df1b2variable ln_det(df1b2matrix& M);
02007 // line above replaced with line below based on issue #37
02008 df1b2variable ln_det(const df1b2matrix & m1);
02009 
02010 df1b2variable ln_det(df1b2matrix& M,int & sgn);
02011 
02012 //df1b2vector solve(df1b2matrix& M,df1b2vector& v);
02013 
02014 df1b2matrix expm(const df1b2matrix & A);
02015 df1b2matrix solve(const df1b2matrix& aa,const df1b2matrix& tz,
02016   df1b2variable ln_unsigned_det,df1b2variable& sign);
02017 df1b2matrix solve(const df1b2matrix& aa,const df1b2matrix& tz);
02018 df1b2vector solve(const df1b2matrix& aa,const df1b2vector& z,
02019   const df1b2variable& ld, df1b2variable& sign);
02020 
02021 void check_pool_depths();
02022 
02023 df1b2variable lower_triangular_ln_det(const df1b2matrix& m);
02024 df1b2variable lower_triangular_ln_det(const df1b2matrix& m,int& sgn);
02025 df1b2variable bounder(const df1b2variable&  x,double min,double max,
02026   double scale);
02027 
02028 df1b2variable inv_cumd_beta_stable(const df1b2variable& a,
02029   const df1b2variable& b,const df1b2variable& x,double eps=1.e-7);
02030 
02031 df1b2variable bounded_cumd_norm(const df1b2variable& _x,double beta);
02032 df1b2variable cumd_norm(const df1b2variable& _x);
02033 df1b2variable inv_cumd_exponential(const df1b2variable& y);
02034 df1b2variable cumd_exponential(const df1b2variable& x);
02035 extern int make_sure_df1b2fun_gets_linked;
02036 
02037 df1b2variable inv_cumd_normal_mixture(const df1b2variable& _x,double _a);
02038 df1b2variable inv_cumd_normal_logistic_mixture(const df1b2variable& _x,
02039   double _a);
02040 
02041 df1b2variable beta_deviate(const df1b2variable& _x,const df1b2variable& _a,
02042   const df1b2variable& _b,double eps=1.e-7);
02043 df1b2variable robust_normal_logistic_mixture_deviate(const df1b2variable& x,
02044   double spread=3.0);
02045 df1b2variable robust_normal_mixture_deviate(const df1b2variable& x,
02046   double spread=3.0);
02047 
02048 df1b2variable gamma_deviate(const df1b2variable& _x,const df1b2variable& _a);
02049 df1b2variable inv_cumd_gamma(const df1b2variable& _y,const df1b2variable& _a);
02050 double inv_cumd_gamma(double y,double _a);
02051 
02052 df1b2variable inv_cumd_cauchy(const df1b2variable& n);
02053 df1b2variable inv_cumd_t(const df1b2variable& n,const df1b2variable&  u,
02054   double eps=1.e-7);
02055 
02060   class df1b2function_tweaker
02061   {
02062     double mult;
02063     double eps;
02064     dvector coffs;
02065   public:
02066     df1b2function_tweaker(double eps,double mult);
02067     df1b2variable operator () (const df1b2variable&);
02068   };
02069 
02070 df1b2vector posfun(const df1b2vector& x,double eps,
02071   const df1b2variable& _pen);
02072 
02073 df1b2variable norm_to_gamma(const df1b2variable & v,const df1b2variable& alpha,
02074   double bound=0.999999);
02075 
02076 void print_is_diagnostics(laplace_approximation_calculator *lapprox);
02077 
02078   ofstream &  operator << (const ofstream& _s,const nested_calls_shape& m);
02079 
02080   df1b2variable log_der_logistic(double a,double b,const df1b2variable& x);
02081   df1b2variable logistic(double a,double b,const df1b2variable& x);
02082   df1b2variable dflogistic(double a,double b,const df1b2variable& x);
02083 
02084   df1b2variable dfposfun(const df1b2variable& x,const double eps);
02085   void ADMB_getcallindex(const df1b2variable& x);
02086   void ADMB_getcallindex(const df1b2vector& x);
02087   void ADMB_getcallindex(const df1b2matrix& x);
02088 
02089 df1b2variable asin(const df1b2variable& xx);
02090 #endif //!defined(__DF1B2FUN__)