ADMB Documentation  11.1.1903
 All Classes Files Functions Variables Typedefs Friends Defines
tpl2cpp_output.cpp
Go to the documentation of this file.
00001 // $Id: tpl2cpp_output.cpp 1737 2014-03-04 21:03:35Z johnoel $
00002 /*
00003  *
00004  * Author: Hans J. Skaug
00005  * Copyright (c) 2009-2012 ADMB foundation
00006  */
00007 
00029 model_data::model_data(int argc,char * argv[]) : ad_comm(argc,argv)
00030 {
00031   n.allocate("n");
00032   Y.allocate(1,10,1,10,"Y");
00033   y2 = 10.0;
00034 }
00035 
00039 void model_parameters::initializationfunction(void)
00040 {
00041   gamma.set_initial_value(1.0);
00042 }
00043 
00050 model_parameters::model_parameters(int sz,int argc,char * argv[]) :
00051  model_data(argc,argv) , function_minimizer(sz)
00052 {
00053   initializationfunction();
00054   alpha.allocate(1,3,1,"alpha");
00055   beta.allocate(1,3,-10000.0,10000.0,2,"beta");
00056   gamma.allocate(-6.0,6.0,"gamma");
00057   x1.allocate("x1");
00058   #ifndef NO_AD_INITIALIZE
00059   x1.initialize();
00060   #endif
00061   x2.allocate("x2");
00062   x3.allocate(1,4,"x3");
00063   l.allocate("l");
00064   prior_function_value.allocate("prior_function_value");
00065   likelihood_function_value.allocate("likelihood_function_value");
00066 }
00067 
00071 void model_parameters::preliminary_calculations(void)
00072 {
00073   admaster_slave_variable_interface(*this);
00074   Y = 10.0;
00075   penalty = 1.0;
00076 }
00077 
00081 void model_parameters::between_phases_calculations(void)
00082 {
00083   switch (current_phase())
00084   {
00085     case 1:
00086       penalty = 0.001;
00087     break;
00088     case 2:
00089       penalty = 0.001;
00090     break;
00091   }
00092 }
00093 
00099 void model_parameters::userfunction(void)
00100 {
00101   l =0.0;
00102   my_function();
00103   l = -norm2(beta);
00104 }
00105 
00110 void model_parameters::my_function(void)
00111 {
00112   x1 = x1 + 1.0;
00113 }
00114 
00119 void model_parameters::set_runtime(void)
00120 {
00121   dvector temp("{.1, .1, .001}");
00122   convergence_criteria.allocate(temp.indexmin(),temp.indexmax());
00123   convergence_criteria=temp;
00124   dvector temp1("{20, 20, 1000}");
00125   maximum_function_evaluations.allocate(temp1.indexmin(),temp1.indexmax());
00126   maximum_function_evaluations=temp1;
00127 }
00128 
00133 void model_parameters::final_calcs()
00134 {
00135 }
00136 
00141 void model_parameters::report()
00142 {
00143  adstring ad_tmp=initial_params::get_reportfile_name();
00144   ofstream report((char*)(adprogram_name + ad_tmp));
00145   if (!report)
00146   {
00147     cerr << "error trying to open report file"  << adprogram_name << ".rep";
00148     return;
00149   }
00150 }
00151 
00152 
00153   long int arrmblsize=0;
00154 
00172 int main(int argc,char * argv[])
00173 {
00174   ad_set_new_handler();
00175   ad_exit=&ad_boundf;
00176   arrmblsize = 4000000L;
00177 
00178   gradient_structure::set_NO_DERIVATIVES();
00179   gradient_structure::set_YES_SAVE_VARIABLES_VALUES();
00180   if (!arrmblsize) arrmblsize=15000000;
00181 
00182   // Step i) above
00183   model_parameters mp(arrmblsize,argc,argv);
00184   mp.iprint=10;
00185 
00186   // Step ii) above
00187   mp.preliminary_calculations();
00188 
00189   // Step iii) above. Note that "mp" by inheritance
00190   // is also of class function_minimizer
00191   mp.computations(argc,argv);
00192 
00193   return 0;
00194 }
00195 
00206 extern "C"  {
00207   void ad_boundf(int i)
00208   {
00209     /* so we can stop here */
00210     exit(i);
00211   }
00212 }