ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
newmodm5.cpp
Go to the documentation of this file.
1 
8 #include <admodel.h>
9 #include <df1b2fun.h>
10 #include <adrndeff.h>
11 
12 #ifdef ISZERO
13  #undef ISZERO
14 #endif
15 #define ISZERO(d) ((d)==0.0)
16 
17 void function_minimizer::prof_minimize_re(int iprof, double sigma,
18  double new_value, const double& _fprof,const int underflow_flag,
19  double global_min, const double& _penalties, const double& _final_weight)
20  {
21  double& penalties=(double&) _penalties;
22  double& fprof=(double&) _fprof;
23  double& final_weight=(double&) _final_weight;
24  if (!underflow_flag)
25  {
26  int max_profile_phases=3;
27  int profile_phase=1;
29  while (profile_phase <= max_profile_phases)
30  {
31  {
32 // ****************************************************************
33 // ****************************************************************
34 // ****************************************************************
35 // ****************************************************************
37  //cout << nvar << endl;
38  /*int unvar=*/initial_params::nvarcalc(); // get the number of active
41  int nvar=initial_params::nvarcalc(); // get the number of active
42 
43 // ****************************************************************
44 // ****************************************************************
45 // ****************************************************************
46 // ****************************************************************
47 
48 
49  dvector g(1,nvar);
50  independent_variables x(1,nvar);
51  initial_params::xinit(x); // get the initial values into the
52  // x vector
53  fmm fmc(nvar);
54  fmc.maxfn= maxfn;
55  fmc.iprint= iprint;
56  fmc.crit = crit;
57  fmc.imax = imax;
58  fmc.dfn= dfn;
61  double f=0.0;
63  // set convergence criterion for this phase
64  if (!(!convergence_criteria))
65  {
68  fmc.crit=convergence_criteria(ind);
69  }
71  {
74  fmc.maxfn=int(maximum_function_evaluations(ind));
75  }
76  int itnsave=0;
77  //double weight=pow(50.0,profile_phase)/(sigma*sigma);
78  double weight = pow(120.0,profile_phase);
79  if (!ISZERO(sigma))
80  {
81  weight /= (sigma*sigma);
82  }
83  final_weight=weight;
84 
85 // ****************************************************************
86 // ****************************************************************
87 // ****************************************************************
88 // ****************************************************************
89  {
90  // calculate the number of random effects unvar
91  // this turns on random effects variables and turns off
92  // everything else
93  //cout << nvar << endl;
95  //cout << nvar << endl;
96  int unvar=initial_params::nvarcalc(); // get the number of active
97  //df1b2_gradlist::set_no_derivatives();
98 
100  {
101  delete funnel_init_var::py;
103  }
104  if (lapprox)
105  {
106  delete lapprox;
107  lapprox=0;
109 
110  for (int i=1;i<df1b2variable::adpool_counter;i++)
111  {
115  }
116  df1b2variable::adpool_counter=0;
117  }
118  lapprox=new laplace_approximation_calculator(nvar,unvar,1,nvar+unvar,
119  this);
120  if (!lapprox)
121  {
122  cerr << "Error allocating memory for lapprox" << endl;
123  ad_exit(1);
124  }
126 
128  allocate();
130 
133  dvector y(1,nvar);
136 
138  //vmon_begin();
139  // see what kind of hessian we are dealing with
140  int on=0;
141  int nopt=0;
142  // DF Nov 27 11
144  nvar=initial_params::nvarcalc(); // get the number of active
145 
147  {
149  {
150  if ( (on=option_match(ad_comm::argc,ad_comm::argv,"-newht",nopt))>-1)
151  {
153  }
154  else
155  {
157  }
158  }
159  cout << "Hesstype = " << lapprox->hesstype << endl;
160  }
161 
162  /*
163  cout << "NEED to remove !!!! " << endl;
164  initial_df1b2params::separable_flag=0;
165  lapprox->hesstype=1;
166  */
167 
168  // linear mixed effects optimization
170  {
172  }
173 
174  if (negdirections==0)
175  {
176  dvector g1(1,nvar);
177  while (fmc.ireturn>=0)
178  {
179  fmc.fmin(f,x,g);
180  double diff =
181  new_value-value(likeprof_params::likeprofptr[iprof]->variable());
182  if (fmc.itn>itnsave && diff < pow(.1,iprof)*sigma)
183  {
184  fmc.ifn=fmc.imax;
185  }
186  if (fmc.ireturn>0)
187  {
188  g=(*lapprox)(x,f,this);
189  }
190  dvariable vf=0.0;
193  //**********************************************************
194  //**********************************************************
195  //**********************************************************
196  if (lapprox)
197  {
198  if (lapprox->hesstype==2)
199  {
200  //lapprox->num_separable_calls=0;
202  }
203  }
204  //**********************************************************
205  //**********************************************************
206  //**********************************************************
207  //**********************************************************
208  userfunction();
210  vf+=weight*square(new_value-tv);
211  f+=value(vf);
212  gradcalc(nvar,g1);
213  g+=g1;
214  }
215  }
217  }
218 
219 
220 
221 
222 // ****************************************************************
223 // ****************************************************************
224 // ****************************************************************
225 // ****************************************************************
226 
227 
228 
230  iexit=fmc.iexit;
231  ihflag=fmc.ihflag;
232  ihang=fmc.ihang;
234  quit_flag=fmc.quit_flag;
237  //**********************************************************
238  //**********************************************************
239  //**********************************************************
240  if (lapprox)
241  {
242  if (lapprox->hesstype==2)
243  {
244  //lapprox->num_separable_calls=0;
246  }
247  }
248  //**********************************************************
249  //**********************************************************
250  //**********************************************************
251  //**********************************************************
252  userfunction();
253  double tv=value(likeprof_params::likeprofptr[iprof]->variable());
255  penalties=weight*(new_value-tv)*(new_value-tv);
256  fprof+=penalties;
257  if (quit_flag=='Q') break;
258  if (!quit_flag || quit_flag == 'N')
259  {
260  profile_phase++;
261  }
262  }
263  }
264  }
265  else
266  {
267  fprof=global_min+20.0;
268  }
269  }
static likeprof_params * likeprofptr[500]
Definition: admodel.h:2257
static adpool * pool
Definition: df1b2fun.h:273
laplace_approximation_calculator * lapprox
Definition: admodel.h:1862
static dvar_vector * variance_components_vector
Definition: adrndeff.h:204
static void reset_all(const dvector &)
Description not yet available.
Definition: df1b2f18.cpp:17
double dfn
Definition: fvar.hpp:3187
static adpool * adpool_vector[]
Definition: df1b2fun.h:282
double crit
Definition: fvar.hpp:3184
static void set_no_derivatives(void)
Definition: df1b2fun.h:760
Description not yet available.
Definition: adrndeff.h:182
static void set_NO_DERIVATIVES(void)
Disable accumulation of derivative information.
Definition: gradstrc.cpp:641
Description not yet available.
#define x
Vector of double precision numbers.
Definition: dvector.h:50
int maxfn_flag
Definition: fvar.hpp:3194
static void xinit_all(const dvector &x)
Description not yet available.
Definition: nvarcall.cpp:31
long maxfn
Definition: fvar.hpp:3182
static int separable_flag
Definition: df1b2fun.h:1351
static unsigned int nvar_vector[]
Definition: df1b2fun.h:288
static char ** argv
Definition: fvar.hpp:8866
void get_hessian_components_banded_lme(function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lme.cpp:20
exitptr ad_exit
Definition: gradstrc.cpp:53
static dvariable reset(const dvar_vector &x)
Definition: model.cpp:345
void fmin(const double &f, const dvector &x, const dvector &g)
Function fmin contains Quasi-Newton function minimizer with inexact line search using Wolfe condition...
Definition: newfmin.cpp:254
ADMB variable vector.
Definition: fvar.hpp:2172
static void restore_start_phase(void)
Definition: model.cpp:275
void check_hessian_type(const dvector &_x, function_minimizer *)
Description not yet available.
Definition: df1b2lp8.cpp:360
void check_hessian_type2(function_minimizer *pfmin)
Description not yet available.
Definition: df1b2lp10.cpp:98
virtual dvariable variable(void)=0
void gradcalc(int nvar, const dvector &g)
Definition: sgradclc.cpp:77
static void save_varsptr(void)
Description not yet available.
Definition: df1b2fun.cpp:70
static int nvarcalc()
Definition: model.cpp:152
void deallocate(void)
Description not yet available.
Definition: adpool.cpp:319
long imax
Definition: fvar.hpp:3186
static int current_phase
Definition: df1b2fun.h:1350
prnstream & endl(prnstream &)
Description not yet available.
Definition: fvar.hpp:1937
static int current_phase
Definition: admodel.h:842
long ihang
Definition: fvar.hpp:3192
static void set_active_only_random_effects(void)
Definition: model.cpp:251
int scroll_flag
Definition: fvar.hpp:3193
static dvector maximum_function_evaluations
Definition: admodel.h:1917
static int max_number_phases
Definition: admodel.h:841
#define min(a, b)
Definition: cbivnorm.cpp:188
static int argc
Definition: fvar.hpp:8863
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
static objective_function_value * pobjfun
Definition: admodel.h:2394
Description not yet available.
long ifn
Definition: fvar.hpp:3188
static void xinit(const dvector &x)
Definition: model.cpp:226
Functions and variables for function minimizer.
Definition: fvar.hpp:3290
static int nvarcalc_all(void)
Description not yet available.
Definition: nvarcall.cpp:17
static void set_inactive_random_effects(void)
Definition: model.cpp:288
int quit_flag
Definition: fvar.hpp:3195
void prof_minimize_re(int iprof, double sigma, double new_value, const double &fprof, const int underflow_flag, double global_min, const double &penalties, const double &final_weight)
Definition: newmodm5.cpp:17
int option_match(int argc, char *argv[], const char *string)
Checks if the program has been invoked with a particular command line argument (&quot;string&quot;).
Definition: optmatch.cpp:25
dmatrix * negdirections
Definition: admodel.h:1858
long ihflag
Definition: fvar.hpp:3191
double min_improve
Definition: fvar.hpp:3196
Description not yet available.
static void set_YES_DERIVATIVES(void)
Enable accumulation of derivative information.
Definition: gradstrc.cpp:650
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
double min_improve
Definition: admodel.h:1900
virtual void userfunction(void)=0
long iprint
Definition: fvar.hpp:3183
static init_df1b2vector * py
Definition: df1b2fnl.h:68
static int adpool_counter
Definition: df1b2fun.h:279
virtual void allocate()
Definition: admodel.h:1903
long int itn
Definition: fvar.hpp:3301
static void restore_varsptr(void)
Description not yet available.
Definition: df1b2fun.cpp:90
static dvector convergence_criteria
Definition: admodel.h:1915
int ireturn
Definition: fvar.hpp:3197
long iexit
Definition: fvar.hpp:3189
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
#define ISZERO(d)
Definition: newmodm5.cpp:15
static void set_inactive_only_random_effects(void)
Definition: model.cpp:259
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17