Changeset 18137
- Timestamp:
- 06/11/14 08:19:01 (11 years ago)
- Location:
- issm/trunk-jpl/src/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/c/cores/control_core.cpp
r18134 r18137 183 183 IssmDouble* Jlist = NULL; 184 184 femmodel->CostFunctionx(&J,&Jlist,NULL); 185 //_printf0_("f(x) = "<<setw(12)<<setprecision(7)<<*pf<<" | "); 186 187 /*Retrieve objective functions independently*/ 188 //for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]); 189 //_printf0_("\n"); 185 _printf0_("f(x) = "<<setw(12)<<setprecision(7)<<J<<" | "); 186 for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]); 187 _printf0_("\n"); 190 188 191 189 /*Free ressources:*/ … … 289 287 /*Compute misfit for this velocity field.*/ 290 288 femmodel->CostFunctionx(&J,&Jlist,NULL); 291 //_printf0_("f(x) = "<<setw(12)<<setprecision(7)<<*pf<<" | ");292 //for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]);293 //_printf0_("\n");289 _printf0_("f(x) = "<<setw(12)<<setprecision(7)<<J<<" | "); 290 for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]); 291 _printf0_("\n"); 294 292 295 293 /*Clean-up and return*/ -
issm/trunk-jpl/src/c/shared/Numerics/BrentSearch.cpp
r18128 r18137 48 48 IssmDouble* X = xNew<IssmDouble>(nsize); 49 49 50 /*Header of printf*/ 51 _printf0_("\n"); 52 _printf0_(" x | Cost function f(x) | List of contributions\n"); 53 50 54 /*start iterations*/ 51 55 for(int n=0;n<nsteps;n++){ 56 57 /*Print iteration number*/ 58 _printf0_("====================== step "<< n+1 << "/" << nsteps <<" ===============================\n"); 52 59 53 60 /*Reset some variables*/ … … 59 66 60 67 /*Get current Gradient at xmin=0*/ 61 if(VerboseControl()) _printf0_("\n" << " step " << n+1 << "/" << nsteps << "\n");68 _printf0_(" x = "<<setw(9)<<xmin<<" | "); 62 69 fxmin = (*g)(&G,X0,usr); if(xIsNan<IssmDouble>(fxmin)) _error_("Function evaluation returned NaN"); 63 if(VerboseControl()) _printf0_("\n");64 if(VerboseControl()) _printf0_(" Iteration x f(x) Tolerance Procedure\n");65 if(VerboseControl()) _printf0_("\n");66 if(VerboseControl()) _printf0_(" N/A "<<setw(12)<<xmin<<" "<<setw(12)<<fxmin<<" N/A boundary\n");67 70 68 71 /*Get f(xmax)*/ 72 _printf0_(" x = "<<setw(9)<<xmax<<" | "); 69 73 for(int i=0;i<nsize;i++) X[i]=X0[i]+xmax*G[i]; 70 74 fxmax = (*f)(X,usr); if (xIsNan<IssmDouble>(fxmax)) _error_("Function evaluation returned NaN"); 71 if(VerboseControl()) _printf0_(" N/A "<<setw(12)<<xmax<<" "<<setw(12)<<fxmax<<" N/A boundary\n");75 //if(VerboseControl()) _printf0_(" N/A "<<setw(12)<<xmax<<" "<<setw(12)<<fxmax<<" N/A boundary\n"); 72 76 73 77 /*test if jump option activated and xmin==0*/ … … 92 96 93 97 /*2: call the function to be evaluated*/ 98 _printf0_(" x = "<<setw(9)<<x<<" | "); 94 99 for(int i=0;i<nsize;i++) X[i]=X0[i]+x*G[i]; 95 100 fxbest = (*f)(X,usr); if(xIsNan<IssmDouble>(fxbest)) _error_("Function evaluation returned NaN"); … … 106 111 107 112 /*4: print result*/ 108 if(VerboseControl())109 _printf0_(" "<<setw(5)<<iter<<" "<<setw(12)<<xbest<<" "<<setw(12)<<fxbest<<" "<<setw(12)<<pow(pow(xbest-xm,2),0.5)<<" initial\n");113 //if(VerboseControl()) 114 //_printf0_(" "<<setw(5)<<iter<<" "<<setw(12)<<xbest<<" "<<setw(12)<<fxbest<<" "<<setw(12)<<pow(pow(xbest-xm,2),0.5)<<" initial\n"); 110 115 if (!xIsNan<IssmDouble>(cm_jump[n]) && (xmin==0) && ((fxbest/fxmin)<cm_jump[n])){ 111 if(VerboseControl()) _printf0_(" optimization terminated: current x satisfies criteria 'cm_jump'=" << cm_jump[n] << "\n");116 //if(VerboseControl()) _printf0_(" optimization terminated: current x satisfies criteria 'cm_jump'=" << cm_jump[n] << "\n"); 112 117 loop=false; 113 118 } … … 176 181 177 182 //evaluate function on x 183 _printf0_(" x = "<<setw(9)<<x<<" | "); 178 184 for(int i=0;i<nsize;i++) X[i]=X0[i]+x*G[i]; 179 185 fx = (*f)(X,usr); if(xIsNan<IssmDouble>(fx)) _error_("Function evaluation returned NaN"); … … 202 208 tol1=seps*pow(pow(xbest,2),0.5)+tolerance/3.0; 203 209 tol2=2.0*tol1; 204 if(VerboseControl())205 _printf0_(" "<<setw(5)<<iter<<" "<<setw(12)<<x<<" "<<setw(12)<<fx<<" "<<setw(12)<<pow(pow(xbest-xm,2),0.5)<<206 " "<<(goldenflag?"golden":"parabolic")<<"\n");210 //if(VerboseControl()) 211 // _printf0_(" "<<setw(5)<<iter<<" "<<setw(12)<<x<<" "<<setw(12)<<fx<<" "<<setw(12)<<pow(pow(xbest-xm,2),0.5)<< 212 // " "<<(goldenflag?"golden":"parabolic")<<"\n"); 207 213 208 214 /*Stop the optimization?*/ 209 215 if (sqrt(pow(xbest-xm,2)) < (tol2-0.5*(xmax-xmin))){ 210 if(VerboseControl()) _printf0_(" optimization terminated: current x satisfies criteria 'tolx'=" << tolerance << "\n");216 //if(VerboseControl()) _printf0_(" optimization terminated: current x satisfies criteria 'tolx'=" << tolerance << "\n"); 211 217 loop=false; 212 218 } 213 219 else if (iter>=maxiter[n]){ 214 if(VerboseControl()) _printf0_(" exiting: Maximum number of iterations has been exceeded ('maxiter'=" << maxiter[n] << ")\n");220 //if(VerboseControl()) _printf0_(" exiting: Maximum number of iterations has been exceeded ('maxiter'=" << maxiter[n] << ")\n"); 215 221 loop=false; 216 222 } 217 223 else if (!xIsNan<IssmDouble>(cm_jump[n]) && (xmin==0) && ((fxbest/fxmin)<cm_jump[n])){ 218 if(VerboseControl()) _printf0_(" optimization terminated: current x satisfies criteria 'cm_jump'=" << cm_jump[n] << "\n");224 //if(VerboseControl()) _printf0_(" optimization terminated: current x satisfies criteria 'cm_jump'=" << cm_jump[n] << "\n"); 219 225 loop=false; 220 226 }
Note:
See TracChangeset
for help on using the changeset viewer.