ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
model.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
7 #include <admodel.h>
8 #ifdef DEBUG
9  #include <cassert>
10 #endif
11 
12 #ifdef ISZERO
13  #undef ISZERO
14 #endif
15 #define ISZERO(d) ((d)==0.0)
16 
18 
20 
27  int AD_gaussflag=0;
28  int ADqd_flag=0;
29 
31  {
32  return scalefactor;
33  }
34  void initial_params::set_scalefactor(const double sf)
35  {
36  scalefactor=sf;
37  }
38 
44 
45  int withinbound(int lb,int n,int ub)
46  {
47  if (lb<=n && n<=ub)
48  return 1;
49  else
50  return 0;
51  }
52 
57 {
58  if (num_initial_params > 0)
59  {
61  }
62 #if defined(USE_SHARE_FLAGS)
63  if (share_flags)
64  {
65  delete share_flags;
66  share_flags = 0;
67  }
68 #endif
69 }
70 
71 extern int* pointer_to_phase;
72 
77 {
78 #if defined(USE_SHARE_FLAGS)
79  share_flags = 0;
80 #endif
81  phase_start = 0;
82  phase_save = -9999;
83  initial_value = 0;
85  active_flag = 0;
86  scalefactor = 0;
88 }
89 
91  {
94  }
95 
97  {
98  return initial_value;
99  }
100 
102  {
103  phase_start=i;
104  phase_save=i;
105  }
106 
108  {
109  return phase_start;
110  }
111 
112  void model_name_tag::allocate(const char * s)
113  {
114  name=s;
115  }
116 
117 void initial_params::allocate(int _phase_start)
118 {
119  add_to_list();
120 
121  phase_start = _phase_start;
123  if (max_number_phases < _phase_start)
124  {
125  max_number_phases = _phase_start;
126  }
127 }
128 
130 {
131  // this is the list of fundamental objects
132  varsptr.add_to_list(this);
133 
135 }
136 
138  {
139  cout << H << endl << endl;
140  int ii=1;
141  for (int i=0;i<num_initial_params;i++)
142  {
144  {
145  (varsptr[i])->dev_correction(H,ii);
146  }
147  }
148  cout << H << endl << endl;
149  return ii-1;
150  }
151 
153 {
154  int nvar = 0;
155  for (int i = 0; i < num_initial_params; i++)
156  {
157  //if ((varsptr[i])->phase_start <= current_phase)
158 #if defined(USE_SHARE_FLAGS)
159  if (varsptr[i]->share_flags != 0)
160  {
161  nvar += (varsptr[i])->shared_size_count();
162  }
163  else
164  {
165 #endif
167  {
168  nvar += (varsptr[i])->size_count();
169  }
170 #if defined(USE_SHARE_FLAGS)
171  }
172 #endif
173  }
174  return nvar;
175 }
176 
178  {
179  int ntypes=0;
180  for (int i=0;i<num_initial_params;i++)
181  {
182  //if ((varsptr[i])->phase_start <= current_phase)
184  {
185  ntypes++;
186  }
187  }
188  return ntypes;
189  }
190 
192  {
193  int ii=1;
194  for (int i=0;i<num_initial_params;i++)
195  {
197  (varsptr[i])->sd_vscale(d,x,ii);
198  }
199  return ii-1;
200  }
201 
203  {
204  int ii=1;
205  for (int i=0;i<num_initial_params;i++)
206  {
207  //if ((varsptr[i])->phase_start <= current_phase)
209  (varsptr[i])->sd_scale(d,x,ii);
210  }
211  return ii-1;
212  }
213 
215  {
216  int ii=1;
217  for (int i=0;i<num_initial_params;i++)
218  {
219  //if ((varsptr[i])->phase_start <= current_phase)
221  (varsptr[i])->curv_scale(d,x,ii);
222  }
223  return ii-1;
224  }
225 
227  {
228  int ii=1;
229  for (int i=0;i<num_initial_params;i++)
230  {
231  //if ((varsptr[i])->phase_start <= current_phase)
232 # if defined(USE_SHARE_FLAGS)
233  if (varsptr[i]->share_flags !=0)
234  {
235  (varsptr[i])->shared_set_value_inv(x,ii);
236  }
237  else
238  {
239 # endif
241  {
242  (varsptr[i])->set_value_inv(x,ii);
243  (varsptr[i])->set_active_flag();
244  }
245 # if defined(USE_SHARE_FLAGS)
246  }
247 # endif
248  }
249  }
250 
252  {
253  for (int i=0;i<num_initial_params;i++)
254  {
256  }
257  }
258 
260  {
261  for (int i=0;i<num_initial_params;i++)
262  {
264  }
265  }
266 
268  {
269  for (int i=0;i<num_initial_params;i++)
270  {
272  }
273  }
274 
276  {
277  for (int i=0;i<num_initial_params;i++)
278  {
280  }
281  }
282 
284  {
286  }
287 
289  {
290  for (int i=0;i<num_initial_params;i++)
291  {
293  }
294  }
295 
296 void initial_params::xinit1(const dvector& _x, const dvector& g)
297  {
298  int ii=1;
299  dvector& x=(dvector&) _x;
300  for (int i=0;i<num_initial_params;i++)
301  {
302  //if ((varsptr[i])->phase_start <= current_phase)
304  {
305  (varsptr[i])->set_value_inv(x,ii);
306  (varsptr[i])->set_active_flag();
307  }
308  }
309  x=elem_prod(x,g);
310  }
311 
313  {
314  dvector& _pen = (dvector&)__pen;
315  int ii=1;
316  dvariable pen=0.0;
317  dvariable pen1;
318  for (int i=0;i<num_initial_params;i++)
319  {
321  {
322  (varsptr[i])->set_value(x,ii,pen1);
323  _pen(ii-1)=value(pen1);
324  pen+=pen1;
325  }
326  }
327  return pen;
328  }
329 
331  {
332  dvar_vector& x=(dvar_vector&) _x;
333  int ii=1;
334  dvariable pen=0.0;
335  x=elem_div(x,g);
336  for (int i=0;i<num_initial_params;i++)
337  {
338  //if ((varsptr[i])->phase_start <= current_phase)
340  (varsptr[i])->set_value(x,ii,pen);
341  }
342  return pen;
343  }
344 
346  {
347  int ii=1;
348  dvariable pen=0.0;
349  for (int i=0;i<num_initial_params;i++)
350  {
351 # if defined(USE_SHARE_FLAGS)
352  if (varsptr[i]->share_flags !=0)
353  {
354  (varsptr[i])->shared_set_value(x,ii,pen);
355  }
356  else
357  {
358 # endif
359  //if ((varsptr[i])->phase_start <= current_phase)
361  (varsptr[i])->set_value(x,ii,pen);
362 # if defined(USE_SHARE_FLAGS)
363  }
364 # endif
365  }
366  return pen;
367  }
368 
370  {
371  int ii=1;
372  dvariable pen=0.0;
373  for (int i=0;i<num_initial_params;i++)
374  {
375  //if ((varsptr[i])->phase_start <= current_phase)
377  (varsptr[i])->set_value(x,ii,pen);
378  }
379  return pen;
380  }
381 
383 {
384  adstring extension;
386  {
387  extension = "ar";
388  }
389  else if (current_phase >= 10)
390  {
391  extension = str(current_phase);
392  }
393  else
394  {
395  extension = "0" + str(current_phase);
396  }
397  {
398  adstring tadstring=ad_comm::adprogram_name + adstring(".p") + extension;
399  ofstream parfile((char*)tadstring);
400  if (parfile.good())
401  {
402  parfile << setshowpoint() << setprecision(15)
403  << "# Number of parameters = " << initial_params::nvarcalc()
404  << " Objective function value = " << *objective_function_value::pobjfun
405  << " Maximum gradient component = " << objective_function_value::gmax
406  << endl;
407 
408  for (int i = 0; i < num_initial_params; ++i)
409  {
410  varsptr[i]->save_value(parfile);
411  }
412  }
413  }
414  {
415  adstring tadstring = ad_comm::adprogram_name + adstring(".b") + extension;
416  uostream barfile((char*)tadstring);
417  if (barfile.good())
418  {
419  for (int i = 0; i < num_initial_params; ++i)
420  {
421  (varsptr[i])->bsave_value(barfile);
422  }
423  }
424  }
425 }
426 
428  {
429  active_flag=1;
430  }
431 
433  {
434  active_flag=0;
435  }
436 
437  int active(const initial_params& ip)
438  {
439  return ip.active_flag;
440  }
441 
442 void param_init_number::set_value(const dvar_vector& x, const int& ii,
443  const dvariable& pen)
444  {
445  if (ISZERO(scalefactor))
446  ::set_value(*this,x,ii);
447  else
448  ::set_value(*this,x,ii,scalefactor);
449  }
450 
451 void param_init_number::set_value_inv(const dvector& x, const int& ii)
452  {
453  if (ISZERO(scalefactor))
454  ::set_value_inv(*this,(const dvector&)(x),ii);
455  else
456  ::set_value_inv(*this,(const dvector&)(x),ii,scalefactor);
457  }
458 
461  {
462  //add_to_list();
463  }
464 
468 unsigned int param_init_number::size_count() const
469 {
470  return 1;
471 }
472 
480  const char* _s)
481 {
482  double lb = _v(1);
483  double ub = _v(2);
484  int phz = static_cast<int>(_v(3));
485 
486  allocate(lb, ub, phz, _s);
487 }
488 
490  double _maxb,int _phase_start,const char * _s)
491  {
492  minb=_minb;
493  maxb=_maxb;
494  if (minb>maxb)
495  {
496  cerr << "Error allocating init_bounded_number " << endl
497  << " minb = " << minb << " maxb = " << maxb << endl;
498  ad_exit(1);
499  }
501  initial_params::allocate(_phase_start);
503  {
504  *(ad_comm::global_bparfile) >> value(*this);
505  if (!(*(ad_comm::global_bparfile)))
506  {
507  cerr << "error reading parameters from binary file "
508  << endl;
509  ad_exit(1);
510  }
511  }
512  else if (ad_comm::global_parfile)
513  {
514  *(ad_comm::global_parfile) >> value(*this);
515  if (!(*(ad_comm::global_parfile)))
516  {
517  cerr << "error reading parameters from file "
519  ad_exit(1);
520  }
521  }
522  else
523  {
525  || initial_value >= maxb)
526  {
528  }
529  else
530  {
532  }
533  }
534  }
536  const int& ii, const dvariable& pen)
537  {
538  if (ISZERO(scalefactor))
539  ::set_value(*this,x,ii,minb,maxb,pen);
540  else
541  ::set_value(*this,x,ii,minb,maxb,pen,scalefactor);
542  }
543 
545  {
546  if (ISZERO(scalefactor))
547  ::set_value_inv(*this,x,ii,minb,maxb);
548  else
550  }
551  void param_init_bounded_number::allocate(double _minb,double _maxb,
552  const char * _s)
553  {
554  allocate(_minb,_maxb,1,_s);
555  }
556 
561 {
562  if (!p)
563  {
564  cerr << " Error trying to read in model data " << endl;
565  cerr << " This is usual caused by a missing DAT file " << endl;
566  ad_exit(1);
567  }
568 }
569 
571  {
572  val=v;
573  return *this;
574  }
575 
576  void data_number::allocate(const char * s)
577  {
581  }
582 
583  void named_dvariable::allocate(const char * s)
584  {
586  }
587 
588  void named_dvector::allocate(int mmin,int mmax,const char * s)
589  {
590  dvector::allocate(mmin,mmax);
592  }
593 
594  void named_dvector::allocate(const char * s)
595  {
598  }
599 
600 void named_adstring_array::allocate(int mmin, int mmax, const char* s)
601 {
602  adstring_array::allocate(mmin, mmax);
604 }
606 {
609 }
610 
611 
612  void named_ivector::allocate(int mmin,int mmax,const char * s)
613  {
614  ivector::allocate(mmin,mmax);
616  }
617 
618  void named_dvar_vector::allocate(int mmin,int mmax,const char * s)
619  {
620  dvar_vector::allocate(mmin,mmax);
622  }
623  void named_dvar_vector::allocate(const char * s)
624  {
627  }
628 
629  void param_init_number::allocate( int phasestart,const char * s)
630  {
632  initial_params::allocate(phasestart);
634  {
635  *(ad_comm::global_bparfile) >> value(*this);
636  if (!(*(ad_comm::global_bparfile)))
637  {
638  cerr << "error reading parameters from binary file "
639  << endl;
640  ad_exit(1);
641  }
642  }
643  else if (ad_comm::global_parfile)
644  {
645  *(ad_comm::global_parfile) >> value(*this);
646  if (!(*(ad_comm::global_parfile)))
647  {
648  cerr << "error reading parameters from file "
650  ad_exit(1);
651  }
652  }
653  else
654  {
656  }
657  }
658 
659  void param_init_number::allocate(const char * _s)
660  {
661  allocate(1,_s);
662  }
663 
669 void param_init_number::save_value(ofstream& ofs)
670 {
671 #ifdef __ZTC__
672  ofs << label_class(this->label()) << *this << endl;
673 #else
674  //std::streamsize save = ofs.precision();
675  ofs << label_class(this->label())
676  << setprecision(12) << dvariable(*this)
677  << endl;
678  //ofs.precision(save);
679 #endif
680 }
681 
683 {
684  dvariable tmp = *this;
685  uos << tmp;
686 }
687 
689  const int& ii, const dvariable& pen)
690  {
691  if (ISZERO(scalefactor))
692  ::set_value(*this,x,ii);
693  else
694  ::set_value(*this,x,ii,scalefactor);
695  }
696 
697  void param_init_vector::set_value_inv(const dvector& x, const int& ii)
698  {
699 # if defined(USE_SHARE_FLAGS)
700  if (share_flags)
701  {
702  int ndim=share_flags->get_shareflags()->dimension();
703  if (ndim!=1)
704  {
705  cerr << "grouping flags dimension error" << endl;
706  ad_exit(1);
707  }
708  }
709  else
710  {
711 # endif
712  if (ISZERO(scalefactor))
713  ::set_value_inv(*this,x,ii);
714  else
715  ::set_value_inv(*this,x,ii,scalefactor);
716 # if defined(USE_SHARE_FLAGS)
717  }
718 # endif
719  }
720 
724 unsigned int param_init_vector::size_count() const
725 {
726  return ::size_count(*this);
727 }
728 
732 {
733  //add_to_list();
734 }
735 
736 void param_init_vector::save_value(ofstream& ofs)
737 {
738  if (!(!(*this)))
739  ofs << label_class(this->label()) << dvar_vector(*this) << endl;
740 }
741 
743 {
744  if (!(!(*this)))
745  {
746  dvar_vector& tmp = *this;
747  uos << tmp;
748  }
749 }
750 
751  /*
752  void param_init_vector::allocate(int imin,int imax,
753  const ivector& ishare,const char * s)
754  {
755  share_flags=new index_type(ishare);
756  allocate(imin,imax,1,s);
757  }
758  */
767  int imin,
768  int imax,
769  int _phase_start,
770  const char* s)
771 {
772  named_dvar_vector::allocate(imin, imax, s);
773  if (!(!(*this)))
774  {
775  initial_params::allocate(_phase_start);
777  {
779  if (!(*(ad_comm::global_bparfile)))
780  {
781  cerr << "error reading parameters from binary file.\n";
782  ad_exit(1);
783  }
784  }
785  else if (ad_comm::global_parfile)
786  {
788  if (!(*(ad_comm::global_parfile)))
789  {
790  cerr << "error reading parameters from file "
792  ad_exit(1);
793  }
794  }
795  else
796  {
798  }
799  }
800  else
801  {
803  }
804 }
805 
806  void param_init_matrix::allocate(int rmin,int rmax,int cmin,int cmax,
807  const char * s)
808  {
809  allocate(rmin,rmax,cmin,cmax,1,s);
810  }
811 
812  /*
813  void param_init_matrix::allocate(int rmin,int rmax,int cmin,int cmax,
814  const imatrix& jshare,const char * s)
815  {
816  share_flags=new index_type(jshare);
817  allocate(rmin,rmax,cmin,cmax,1,s);
818  }
819  */
820 
821  void param_init_matrix::allocate(int rmin,int rmax,int cmin,int cmax,
822  int _phase_start, const char * s)
823  {
824  named_dvar_matrix::allocate(rmin,rmax,cmin,cmax,s);
825  if (!(!(*this)))
826  {
827  initial_params::allocate(_phase_start);
829  {
831  if (!(*(ad_comm::global_bparfile)))
832  {
833  cerr << "error reading parameters from binary file "
834  << endl;
835  ad_exit(1);
836  }
837  }
838  else if (ad_comm::global_parfile)
839  {
841  if (!(*(ad_comm::global_parfile)))
842  {
843  cerr << "error reading parameters from file "
845  ad_exit(1);
846  }
847  }
848  else
849  {
851  }
852  }
853  else
854  {
856  }
857  }
858 
859  void param_init_vector::allocate(int imin,int imax,const char * s)
860  {
861  allocate(imin,imax,1,s);
862  }
863 
865  const int& ii, const dvariable& pen)
866  {
867  if (!(!(*this)))
868  {
870  {
871  set_value_mc(*this,x,ii,minb,maxb);
872  }
873  else
874  {
875  if (ISZERO(scalefactor))
876  ::set_value(*this,x,ii,minb,maxb,pen);
877  else
878  ::set_value(*this,x,ii,minb,maxb,pen,scalefactor);
879  }
880  }
881  }
882 
884  {
885  if (!(!(*this)))
886  {
888  {
889  set_value_inv_mc(*this,x,ii,minb,maxb);
890  }
891  else
892  {
893  if (ISZERO(scalefactor))
894  ::set_value_inv(*this,x,ii,minb,maxb);
895  else
897  }
898  }
899  }
900 
905 {
906  return ::size_count(*this);
907 }
908 
914  initial_params(),
915  minb(0),
916  maxb(0)
917 
918 {
919  //add_to_list();
920 }
926  minb(0),
927  maxb(0)
928 {
929  //add_to_list();
930 }
931 
932  void param_init_bounded_vector::allocate(int imin,int imax,
933  double _minb,double _maxb,int _phase_start,const char * s)
934  {
935  minb=_minb;
936  maxb=_maxb;
937  named_dvar_vector::allocate(imin,imax,s);
938  initial_params::allocate(_phase_start);
939  if (!(!(*this)))
940  {
942  {
944  if (!(*(ad_comm::global_bparfile)))
945  {
946  cerr << "error reading parameters from binary file "
947  << endl;
948  ad_exit(1);
949  }
950  }
951  else if (ad_comm::global_parfile)
952  {
954  if (!(*(ad_comm::global_parfile)))
955  {
956  cerr << "error reading parameters from file "
958  ad_exit(1);
959  }
960  }
961  else
962  {
964  || initial_value >= maxb)
965  {
966  initial_value=(minb+maxb)/2.;
967  }
969  }
970  }
971  else
972  {
974  }
975  }
976 
977  void param_init_bounded_vector::allocate(int imin,int imax,
978  double _minb,double _maxb,const char * s)
979  {
980  allocate(imin,imax,_minb,_maxb,1,s);
981  }
982 
984 {
985  if (!(!(*this)))
986  ofs << label_class(this->label()) << dvar_vector(*this) << endl;
987 }
988 
990 {
991  if (!(!(*this)))
992  {
993  dvar_vector& tmp = *this;
994  uos << tmp;
995  }
996 }
997 
998 void param_init_matrix::set_value(const dvar_vector& x, const int& ii,
999  const dvariable& pen)
1000  {
1001  if (ISZERO(scalefactor))
1002  ::set_value(*this,x,ii);
1003  else
1004  ::set_value(*this,x,ii,scalefactor);
1005  }
1006 
1007 
1008 void param_init_matrix::set_value_inv(const dvector& x, const int& ii)
1009  {
1010  if (ISZERO(scalefactor))
1011  ::set_value_inv(*this,x,ii);
1012  else
1013  ::set_value_inv(*this,x,ii,scalefactor);
1014  }
1015 
1017  initial_params()
1018  {
1019  //add_to_list();
1020  }
1021 
1025 unsigned int param_init_matrix::size_count() const
1026 {
1027  return ::size_count(*this);
1028 }
1029 
1031 {
1032  if (!(!(*this)))
1033  ofs << label_class(this->label()) << dvar_matrix(*this) << endl;
1034 }
1035 
1037 {
1038  if (!(!(*this)))
1039  {
1040  dvar_matrix& tmp = *this;
1041  uos << tmp;
1042  }
1043 }
1044 
1045  void data_matrix::allocate(int rmin,int rmax,int cmin,int cmax,
1046  const char * s)
1047  {
1048  named_dmatrix::allocate(rmin,rmax,cmin,cmax,s);
1049  if (!(!(*this)))
1050  {
1052  *(ad_comm::global_datafile) >> *this;
1053  }
1054  }
1055 
1056 void data_matrix::allocate(int rmin,int rmax, const ivector& cmin,
1057  const ivector& cmax, const char * s)
1058  {
1059  named_dmatrix::allocate(rmin,rmax,cmin,cmax,s);
1060  if (!(!(*this)))
1061  {
1063  *(ad_comm::global_datafile) >> *this;
1064  }
1065  }
1066 
1067 void data_matrix::allocate(int rmin,int rmax,int cmin, const ivector& cmax,
1068  const char * s)
1069  {
1070  named_dmatrix::allocate(rmin,rmax,cmin,cmax,s);
1071  if (!(!(*this)))
1072  {
1074  *(ad_comm::global_datafile) >> *this;
1075  }
1076  }
1077 
1078 void data_matrix::allocate(int rmin,int rmax, const ivector& cmin,int cmax,
1079  const char * s)
1080  {
1081  named_dmatrix::allocate(rmin,rmax,cmin,cmax,s);
1082  if (!(!(*this)))
1083  {
1085  *(ad_comm::global_datafile) >> *this;
1086  }
1087  }
1088 
1089  void data_3array::allocate(int hsl,int hsu,int rmin,int rmax,
1090  int cmin,int cmax,const char * s)
1091  {
1092  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1093  if (!(!(*this)))
1094  {
1096  *(ad_comm::global_datafile) >> d3_array(*this);
1097  }
1098  }
1099 
1100 void data_3array::allocate(int hsl, int hsu, const index_type& rmin,
1101  const index_type& rmax, const index_type& cmin,
1102  const index_type& cmax, const char * s)
1103  {
1104  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1105  if (!(!(*this)))
1106  {
1108  *(ad_comm::global_datafile) >> d3_array(*this);
1109  }
1110  }
1111 
1112 void data_3array::allocate(int hsl, int hsu, const ivector& rmin,
1113  int rmax, int cmin, int cmax, const char * s)
1114  {
1115  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1116  if (!(!(*this)))
1117  {
1119  *(ad_comm::global_datafile) >> d3_array(*this);
1120  }
1121  }
1122 
1123  void data_3array::allocate(int hsl, int hsu, int rmin,
1124  const ivector& rmax, int cmin, int cmax, const char * s)
1125  {
1126  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1127  if (!(!(*this)))
1128  {
1130  *(ad_comm::global_datafile) >> d3_array(*this);
1131  }
1132  }
1133 
1134 void data_3array::allocate(int hsl,int hsu, const ivector& rmin,
1135  const ivector& rmax,int cmin,int cmax,const char * s)
1136  {
1137  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1138  if (!(!(*this)))
1139  {
1141  *(ad_comm::global_datafile) >> d3_array(*this);
1142  }
1143  }
1144 
1145 void data_3array::allocate(int hsl, int hsu, int rmin, int rmax,
1146  const ivector& cmin, int cmax, const char * s)
1147  {
1148  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1149  if (!(!(*this)))
1150  {
1152  *(ad_comm::global_datafile) >> d3_array(*this);
1153  }
1154  }
1155 
1156 void data_3array::allocate(int hsl, int hsu, int rmin, int rmax,
1157  int cmin, const ivector& cmax, const char * s)
1158  {
1159  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1160  if (!(!(*this)))
1161  {
1163  *(ad_comm::global_datafile) >> d3_array(*this);
1164  }
1165  }
1166 
1167  void data_3array::allocate(int hsl,int hsu,int rmin,int rmax,
1168  const ivector& cmin, const ivector& cmax,const char * s)
1169  {
1170  named_d3_array::allocate(hsl,hsu,rmin,rmax,cmin,cmax,s);
1171  if (!(!(*this)))
1172  {
1174  *(ad_comm::global_datafile) >> d3_array(*this);
1175  }
1176  }
1177 
1178  void data_imatrix::allocate(int rmin,int rmax,int cmin,int cmax,
1179  const char * s)
1180  {
1181  named_imatrix::allocate(rmin,rmax,cmin,cmax,s);
1182  if (!(!(*this)))
1183  {
1185  *(ad_comm::global_datafile) >> imatrix(*this);
1186  }
1187  }
1188 
1189 void data_imatrix::allocate(int rmin,int rmax, const index_type& cmin,
1190  const index_type& cmax, const char * s)
1191  {
1192  named_imatrix::allocate(rmin,rmax,cmin,cmax,s);
1193  if (!(!(*this)))
1194  {
1196  *(ad_comm::global_datafile) >> imatrix(*this);
1197  }
1198  }
1199 
1200  void data_int::allocate(int n,const char * s)
1201  {
1202  val=n;
1204  }
1205 
1206  void data_int::allocate(const char * s)
1207  {
1211  }
1212 
1213 void named_imatrix::allocate(int rmin,int rmax,int cmin,int cmax,
1214  const char * s)
1215 {
1216  imatrix::allocate(rmin,rmax,cmin,cmax);
1218 }
1219 
1220 void named_imatrix::allocate(int rmin,int rmax, const index_type& cmin,
1221  const index_type& cmax, const char * s)
1222 {
1223  imatrix::allocate(rmin,rmax,cmin,cmax);
1225 }
1226 
1227  void data_vector::allocate(int imin,int imax,const char * s)
1228  {
1229  named_dvector::allocate(imin,imax,s);
1230  if (!(!(*this)))
1231  {
1233  *(ad_comm::global_datafile) >> dvector(*this);
1234  }
1235  }
1236 
1237 
1239 {
1240  int imax = 1;
1241  *(ad_comm::global_datafile) >> imax;
1242  allocate(1, imax, s);
1243 }
1244 void data_adstring_array::allocate(int imin, int imax, const char* s)
1245 {
1246  named_adstring_array::allocate(imin, imax, s);
1247  if (size() > 0)
1248  {
1250  for (int i = indexmin(); i <= indexmax(); ++i)
1251  {
1252  *(ad_comm::global_datafile) >> operator[](i);
1253  }
1254  }
1255 }
1256  void data_ivector::allocate(int imin,int imax,const char * s)
1257  {
1258  named_ivector::allocate(imin,imax,s);
1259  if (!(!(*this)))
1260  {
1262  *(ad_comm::global_datafile) >> ivector(*this);
1263  }
1264  }
1265 
1266 
1268 {
1269  adstring tmp;
1271  tmp="rep";
1272  else if (current_phase>=10)
1273  tmp="r" + str(current_phase);
1274  else
1275  tmp="r0" + str(current_phase);
1276  tmp = "." + tmp;
1277  return tmp;
1278 }
1279 
1281 {
1282  //phase_save=phase_start;
1283  phase_start=-1;
1284 }
1285 
1287 {
1289 }
1291 
1293 
1295 {
1296 #ifdef DEBUG
1297  assert(static_cast<unsigned int>(i) < current);
1298 #endif
1299 
1300  unsigned int index = static_cast<unsigned int>(i);
1301  if (index < current_size)
1302  {
1303  return (pinitial_params&)ptr[index];
1304  }
1305  return (pinitial_params&)list[index - current_size];
1306 }
1310 {
1311  current = 0;
1312  current_size = 0;
1313  ptr = nullptr;
1314 }
1318 void adlist_ptr::allocate(unsigned int init_size)
1319 {
1320  current = 0;
1321  if (init_size > 0)
1322  {
1323  ptr = new ptovoid[init_size] { nullptr };
1324  if (ptr == 0)
1325  {
1326  cerr << "Error: allocating memory in adlist_ptr" << endl;
1327  ad_exit(1);
1328  }
1329  current_size = init_size;
1330  }
1331 }
1335 /*
1336 void adlist_ptr::resize(void)
1337 {
1338  current_size *= 2;
1339  ptovoid* tmp = new ptovoid[current_size];
1340  if (tmp == 0)
1341  {
1342  cerr << "Error: allocating memory in adlist_ptr" << endl;
1343  }
1344  for (unsigned int i = 0; i < current; ++i)
1345  {
1346  tmp[i] = ptr[i];
1347  }
1348  delete [] ptr;
1349  ptr = tmp;
1350  tmp = 0;
1351 }
1352 */
1354 {
1355  for (unsigned int i = 0; i < current_size; ++i)
1356  {
1357  ptr[i] = 0;
1358  }
1359  list.clear();
1360  //reset current index to beginning
1361  current = 0;
1362 }
1367 {
1368  if (current >= current_size)
1369  {
1370  list.push_back(p);
1371  ++current;
1372  }
1373  else
1374  {
1375  ptr[current++] = p;
1376  }
1377 }
1382 {
1383  if (ptr)
1384  {
1385  delete [] ptr;
1386  ptr = 0;
1387  }
1388  list.clear();
1389 }
double val
Definition: admodel.h:1806
virtual void set_value(const dvar_vector &x, const int &ii, const dvariable &pen)
Definition: model.cpp:442
virtual void set_value(const dvar_vector &x, const int &ii, const dvariable &pen)
Definition: model.cpp:864
void allocate(void)
Does NOT allocate, but initializes empty d3_array.
Definition: d3arr10.cpp:11
dvar_vector()
Default constructor.
Definition: fvar_arr.cpp:150
ptovoid * ptr
Definition: admodel.h:751
virtual void set_value(const dvar_vector &, const int &, const dvariable &pen)=0
d3_array elem_prod(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements product of a(i, j, k) * b(i, j, k).
Definition: d3arr2a.cpp:92
virtual unsigned int size_count() const
Returns the number of active parameters.
Definition: model.cpp:904
static adstring user_par_file
Definition: admodel.h:1920
index_type * get_shareflags(void)
Definition: shared.cpp:204
adstring name
Definition: admodel.h:167
Uses polymorphism to get index information from various data types to be used in constructing and all...
Definition: fvar.hpp:7731
virtual unsigned int size_count() const =0
double get_scalefactor()
Definition: model.cpp:30
ivector()
Default constructor.
Definition: ivector.cpp:37
virtual void shared_set_value_inv(const dvector &, const int &)
Definition: shared.cpp:31
void allocate(void)
Does not allocate, but initializes imatrix members.
Definition: imat.cpp:138
param_init_bounded_vector()
Default constructor.
Definition: model.cpp:912
int indexmin(void) const
Definition: string5.cpp:68
dvector()
Construct a dvector without allocating memory.
Definition: dvector.cpp:378
param_init_vector()
Default constructor.
Definition: model.cpp:730
virtual ~initial_params()
Destructor.
Definition: model.cpp:56
void allocate(const char *="UNNAMED")
Definition: model.cpp:576
static adstring user_data_file
Definition: admodel.h:1919
virtual void set_value_inv(const dvector &x, const int &ii)
Definition: model.cpp:544
static void set_active_random_effects(void)
Definition: model.cpp:267
static void xinit1(const dvector &x, const dvector &g)
Definition: model.cpp:296
static int stddev_curvscale(const dvector &d, const dvector &x)
Definition: model.cpp:214
int withinbound(int lb, int n, int ub)
Definition: model.cpp:45
void allocate(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat0.cpp:8
adlist_ptr()
Default constructor.
Definition: model.cpp:1309
static int sd_phase
Definition: admodel.h:844
void set_scalefactor(const double)
Definition: model.cpp:34
virtual void sd_vscale(const dvar_vector &d, const dvar_vector &x, const int &ii)=0
static int num_active_calc(void)
Definition: model.cpp:177
virtual void set_value(const dvar_vector &x, const int &ii, const dvariable &pen)
Definition: model.cpp:688
For storing void pointers in a array.
Definition: admodel.h:746
Description not yet available.
Definition: admodel.h:242
void allocate(double _minb, double _maxb, int phase_start=1, const char *s="UNNAMED")
Definition: model.cpp:489
#define x
#define ISZERO(d)
Definition: model.cpp:15
Vector of double precision numbers.
Definition: dvector.h:50
virtual void bsave_value(uostream &uos)
Definition: model.cpp:742
pinitial_params & operator[](int i)
Definition: model.cpp:1294
int ADqd_flag
Definition: model.cpp:28
std::vector< void * > list
Definition: admodel.h:753
Description not yet available.
Definition: admodel.h:1151
static int correct_for_dev_objects(const dmatrix &H)
Definition: model.cpp:137
static int max_num_initial_params
Definition: admodel.h:837
int AD_gaussflag
Definition: model.cpp:27
void allocate(void)
Does not allocate, but initializes dvar_vector to empty.
Definition: fvar_arr.cpp:216
static uistream * global_bparfile
Definition: fvar.hpp:8859
double get_initial_value(void)
Definition: model.cpp:96
virtual int shared_size_count(void)
Definition: shared.cpp:15
int phase_save
Definition: admodel.h:849
d3_array elem_div(const d3_array &a, const d3_array &b)
Returns d3_array results with computed elements division of a(i, j, k) / b(i, j, k).
Definition: d3arr2a.cpp:112
int dimension() const
Definition: fvar.hpp:7756
double scalefactor
Definition: admodel.h:824
virtual void save_value(ofstream &ofs)
Definition: model.cpp:736
exitptr ad_exit
Definition: gradstrc.cpp:53
virtual void set_value_inv(const dvector &x, const int &ii)
Definition: model.cpp:451
void set_initial_value(double x)
Definition: model.cpp:90
void allocate(void)
Allocate dvector without allocating memory.
Definition: dvector.cpp:495
static dvariable reset(const dvar_vector &x)
Definition: model.cpp:345
virtual unsigned int size_count() const
Returns the number of active parameters.
Definition: model.cpp:1025
virtual void set_value(const dvar_vector &x, const int &ii, const dvariable &pen)
Definition: model.cpp:535
virtual void save_value(const ofstream &ofs, int prec)
Write values of param_init_matrix into output stream _ofs.
Definition: model12.cpp:60
ADMB variable vector.
Definition: fvar.hpp:2172
Description not yet available.
Definition: admodel.h:814
static void restore_start_phase(void)
Definition: model.cpp:275
static adstring adprogram_name
Definition: fvar.hpp:8860
param_init_bounded_number()
Default constructor.
Definition: model.cpp:924
virtual unsigned int size_count() const
Returns number of active paramters.
Definition: model.cpp:468
static dvariable reset1(const dvar_vector &x, const dvector &g)
Definition: model.cpp:330
dvariable()
Default constructor.
Definition: fvar.hpp:1526
param_init_matrix(void)
Definition: model.cpp:1016
Description not yet available.
Definition: admodel.h:271
virtual void bsave_value(uostream &uos)
Definition: model.cpp:1036
static int nvarcalc()
Definition: model.cpp:152
virtual void add_to_list(void)
Definition: model.cpp:129
void restore_phase_start(void)
Definition: model.cpp:283
void allocate()
Definition: adstring.hpp:210
d3_array(void)
Default constructor.
Definition: d3arr10.cpp:20
virtual void set_only_random_effects_active()
Definition: model.cpp:1280
static int stddev_vscale(const dvar_vector &d, const dvar_vector &x)
Definition: model.cpp:191
Description not yet available.
Definition: admodel.h:1761
virtual const char * label(void)
Definition: model11.cpp:258
void allocate(const char *s)
Definition: model.cpp:112
shareinfo * share_flags
Definition: admodel.h:818
virtual void dev_correction(const dmatrix &, const int &)=0
static adstring get_reportfile_name(void)
Definition: model.cpp:1267
virtual void save_value(ofstream &ofs)
Definition: model.cpp:1030
prnstream & endl(prnstream &)
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
void check_datafile_pointer(void *p)
Exits if p is null.
Definition: model.cpp:560
static int current_phase
Definition: admodel.h:842
static void set_active_only_random_effects(void)
Definition: model.cpp:251
virtual void bsave_value(uostream &uos)
Definition: model.cpp:989
static dvector maximum_function_evaluations
Definition: admodel.h:1917
virtual void set_value_inv(const dvector &x, const int &ii)
Definition: model.cpp:697
static int max_number_phases
Definition: admodel.h:841
virtual unsigned int size_count() const
Returns the number of active parameters.
Definition: model.cpp:724
virtual void set_value_inv(const dvector &x, const int &ii)
Definition: model.cpp:883
Description not yet available.
Definition: fvar.hpp:3398
static double gmax
Definition: admodel.h:2396
int get_phase_start(void)
Definition: model.cpp:107
preshowpoint setshowpoint(void)
Description not yet available.
Definition: admanip.cpp:38
int val
Definition: admodel.h:1477
void allocate(void)
Does not allocate, but initializes members.
Definition: fvar_mat.cpp:479
virtual void set_random_effects_inactive()
Definition: model.cpp:1292
void add_to_list(void *)
Store pointer p to array.
Definition: model.cpp:1366
virtual void save_value(const ofstream &ofs, int prec)
Write values of param_init_number into output stream _ofs.
Definition: model12.cpp:30
static objective_function_value * pobjfun
Definition: admodel.h:2394
Description not yet available.
void allocate(const char *s)
Definition: model.cpp:583
static void xinit(const dvector &x)
Definition: model.cpp:226
virtual void curv_scale(const dvector &d, const dvector &x, const int &ii)=0
Description not yet available.
Definition: admodel.h:180
double set_value_inv_mc(double v, double fmin, double fmax)
Definition: mod_mc3.cpp:116
int * pointer_to_phase
Definition: newfmin.cpp:86
initial_params(void)
Default constructor.
Definition: model.cpp:76
void allocate(unsigned int init_size)
Construct array with init_size.
Definition: model.cpp:1318
static void set_inactive_random_effects(void)
Definition: model.cpp:288
Description not yet available.
Definition: fvar.hpp:2819
int active_flag
Definition: admodel.h:821
friend double & value(const prevariable &v1)
Definition: fvar.hpp:1495
void set_value(const dvar_matrix &x, const dvar_vector &v, const int &_ii, double s)
Description not yet available.
Definition: set.cpp:235
void * ptovoid
Definition: admodel.h:750
static int num_initial_params
Definition: admodel.h:836
void set_value_mc(const dvar_vector &x, const dvar_vector &v, const int &ii, const double fmin, const double fmax)
Definition: mod_mc3.cpp:152
void set_value_inv(const dvar_matrix &x, const dvector &v, const int &ii, double s)
Description not yet available.
Definition: setin.cpp:412
static cifstream * global_datafile
Definition: fvar.hpp:8856
virtual const char * label(void)
Definition: model11.cpp:252
void set_inactive_flag(void)
Definition: model.cpp:432
adstring str(double x, int minwidth=17, int decplaces=-1)
Convert x to adstring with minimum width and total number of decimal places.
Definition: str.cpp:25
virtual void set_random_effects_active()
Definition: model.cpp:1290
void allocate()
Does not allocate, but initializes class members.
Definition: ivector.cpp:316
virtual void set_only_random_effects_inactive()
Definition: model.cpp:1286
adstring get_file_name(void)
Definition: cifstrem.cpp:81
void allocate(int _phase_start)
Definition: model.cpp:117
prevariable & operator=(const prevariable &)
Assigns a value to a prevariable object.
Definition: fvar_o10.cpp:61
imatrix(void)
Default constructor.
Definition: imat.cpp:238
int size() const
Definition: string5.cpp:65
dvar_matrix()
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: fvar_mat.cpp:15
void set_active_flag(void)
Definition: model.cpp:427
void initialize()
Double array size if needed.
Definition: model.cpp:1353
dvar_matrix & operator=(const dvar_matrix &)
Assigns other values to dvar_matrix.
Definition: fvar_mat.cpp:515
void allocate(int phase_start=1, const char *s="UNNAMED")
Definition: model.cpp:629
double initial_value
Definition: admodel.h:823
int active(const initial_params &ip)
Definition: model.cpp:437
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
int phase_start
Definition: admodel.h:848
int indexmax(void) const
Definition: string5.cpp:71
unsigned int size_count(const dvector &x)
Returns total size of elements in vector x.
Definition: dsize.cpp:17
data_number & operator=(const double &m)
Definition: model.cpp:570
static int restart_phase
Definition: admodel.h:843
int initial_value_flag
Definition: admodel.h:822
static int sd_flag
Definition: admodel.h:1918
static int mceval_phase
Definition: admodel.h:847
virtual void set_value_inv(const dvector &, const int &)=0
virtual void bsave_value(uostream &uos)
Definition: model.cpp:682
virtual const char * label(void)
Definition: model11.cpp:234
~adlist_ptr()
Destructor.
Definition: model.cpp:1381
static void save(void)
Definition: model.cpp:382
dvar_vector & operator=(const dvar_vector &t)
Assign values from other t to dvar_vector.
Definition: fvar_a20.cpp:31
void set_phase_start(int x)
Definition: model.cpp:101
void allocate(int n, const char *s="UNNAMED")
Definition: model.cpp:1200
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
unsigned int current
Definition: admodel.h:748
static cifstream * global_parfile
Definition: fvar.hpp:8857
static int stddev_scale(const dvector &d, const dvector &x)
Definition: model.cpp:202
static int mc_phase
Definition: admodel.h:846
virtual const char * label(void)
Definition: model11.cpp:246
virtual void bsave_value(uostream &uos)=0
virtual void sd_scale(const dvector &d, const dvector &x, const int &ii)=0
static dvector convergence_criteria
Definition: admodel.h:1915
virtual void shared_set_value(const dvar_vector &, const int &, const dvariable &pen)
Definition: shared.cpp:23
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
Description not yet available.
Definition: admodel.h:150
virtual void set_value(const dvar_vector &x, const int &ii, const dvariable &pen)
Definition: model.cpp:998
Description not yet available.
Definition: admodel.h:1803
static void set_inactive_only_random_effects(void)
Definition: model.cpp:259
static adlist_ptr varsptr
Definition: admodel.h:838
virtual void set_value_inv(const dvector &x, const int &ii)
Definition: model.cpp:1008
unsigned int current_size
Definition: admodel.h:749