Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #if defined(USE_LAPLACE)
00008 #include <df1b2fun.h>
00009 #include <adrndeff.h>
00010 #include <admodel.h>
00011
00012 void function_minimizer::function_evaluation_block_pvm_slave_random_effects
00013 (int nvar,int _crit,
00014 independent_variables& x,const dvector& _g,const double& _f)
00015 {
00016 double & f= (double&)_f;
00017
00018
00019
00020 tracing_message(traceflag,"C2");
00021
00022 fmm fmc(nvar);
00023 int on1;
00024 if ( (on1=option_match(ad_comm::argc,ad_comm::argv,"-nox"))>-1)
00025 {
00026 fmc.noprintx=1;
00027 }
00028 fmc.maxfn= maxfn;
00029 int nopt=0;
00030 if ( (on1=option_match(ad_comm::argc,ad_comm::argv,"-dd",nopt))>-1)
00031 {
00032 if (!nopt)
00033 {
00034 cerr << "Usage -iprint option needs integer -- ignored" << endl;
00035 fmc.iprint=iprint;
00036 }
00037 else
00038 {
00039 int jj=atoi(ad_comm::argv[on1+1]);
00040 fmc.dcheck_flag=jj;
00041 }
00042 }
00043 nopt=0;
00044 if ( (on1=option_match(ad_comm::argc,ad_comm::argv,"-iprint",nopt))>-1)
00045 {
00046 if (!nopt)
00047 {
00048 cerr << "Usage -iprint option needs integer -- ignored" << endl;
00049 fmc.iprint=iprint;
00050 }
00051 else
00052 {
00053 int jj=atoi(ad_comm::argv[on1+1]);
00054 fmc.iprint=jj;
00055 }
00056 }
00057 else
00058 {
00059 fmc.iprint= iprint;
00060 }
00061 fmc.crit = crit;
00062 fmc.imax = imax;
00063 fmc.dfn= dfn;
00064 fmc.scroll_flag= scroll_flag;
00065 fmc.min_improve=min_improve;
00066 tracing_message(traceflag,"D2");
00067 gradient_structure::set_YES_DERIVATIVES();
00068
00069 if (_crit)
00070 {
00071 fmc.crit = _crit;
00072 }
00073 if (!(!convergence_criteria))
00074 {
00075 int ind=min(convergence_criteria.indexmax(),
00076 initial_params::current_phase);
00077 fmc.crit=convergence_criteria(ind);
00078 }
00079 if (!(!maximum_function_evaluations))
00080 {
00081 int ind=min(maximum_function_evaluations.indexmax(),
00082 initial_params::current_phase);
00083 fmc.maxfn= (int) maximum_function_evaluations(ind);
00084 }
00085
00086
00087
00088 int unvar=1;
00089 if (random_effects_flag)
00090 {
00091 initial_params::set_active_only_random_effects();
00092
00093 unvar=initial_params::nvarcalc();
00094 initial_params::restore_start_phase();
00095 initial_params::set_inactive_random_effects();
00096 int nvar1=initial_params::nvarcalc();
00097 if (nvar1 != nvar)
00098 {
00099 cerr << "failed sanity check in "
00100 "void function_minimizer::quasi_newton_block" << endl;
00101 ad_exit(1);
00102 }
00103 }
00104
00105 if (!random_effects_flag || !unvar)
00106 {
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 }
00128 else
00129 {
00130
00131
00132
00133
00134
00135 initial_params::set_active_only_random_effects();
00136
00137 int unvar=initial_params::nvarcalc();
00138
00139
00140 if (lapprox)
00141 {
00142 delete lapprox;
00143 lapprox=0;
00144 df1b2variable::pool->deallocate();
00145
00146 for (int i=0;i<df1b2variable::adpool_counter;i++)
00147 {
00148 delete df1b2variable::adpool_vector[i];
00149 df1b2variable::adpool_vector[i]=0;
00150 df1b2variable::nvar_vector[i]=0;
00151 df1b2variable::adpool_counter=0;
00152 }
00153 }
00154 lapprox=new laplace_approximation_calculator(nvar,unvar,1,nvar+unvar,
00155 this);
00156 initial_df1b2params::current_phase=initial_params::current_phase;
00157
00158 initial_df1b2params::save_varsptr();
00159 allocate();
00160 initial_df1b2params::restore_varsptr();
00161
00162 df1b2_gradlist::set_no_derivatives();
00163 int nvar=initial_params::nvarcalc_all();
00164 dvector y(1,nvar);
00165 initial_params::xinit_all(y);
00166 initial_df1b2params::reset_all(y);
00167
00168
00169 int ireturn=0;
00170 while (ireturn>=0)
00171 {
00172
00173 ireturn=get_int_from_master();
00174 if (ireturn>0)
00175 {
00176
00177 (*lapprox)(x,f,this);
00178 }
00179 }
00180
00181
00182 initial_params::set_inactive_only_random_effects();
00183
00184
00185 }
00186
00187
00188
00189
00190 gradient_structure::set_NO_DERIVATIVES();
00191 ffbest=fmc.fbest;
00192 iexit=fmc.iexit;
00193 ifn=fmc.ifn;
00194 ihflag=fmc.ihflag;
00195 ihang=fmc.ihang;
00196 maxfn_flag=fmc.maxfn_flag;
00197 quit_flag=fmc.quit_flag;
00198 objective_function_value::gmax=fabs(fmc.gmax);
00199 }
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 #endif //#if defined(USE_LAPLACE)