Changeset 18137


Ignore:
Timestamp:
06/11/14 08:19:01 (11 years ago)
Author:
Mathieu Morlighem
Message:

CHG: better display of Brent search inversion

Location:
issm/trunk-jpl/src/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/cores/control_core.cpp

    r18134 r18137  
    183183        IssmDouble* Jlist = NULL;
    184184        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");
    190188
    191189        /*Free ressources:*/
     
    289287        /*Compute misfit for this velocity field.*/
    290288        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");
    294292
    295293        /*Clean-up and return*/
  • issm/trunk-jpl/src/c/shared/Numerics/BrentSearch.cpp

    r18128 r18137  
    4848        IssmDouble* X = xNew<IssmDouble>(nsize);
    4949
     50        /*Header of printf*/
     51        _printf0_("\n");
     52        _printf0_("       x       |  Cost function f(x)  |  List of contributions\n");
     53
    5054        /*start iterations*/
    5155        for(int n=0;n<nsteps;n++){
     56
     57                /*Print iteration number*/
     58                _printf0_("====================== step "<< n+1 << "/" << nsteps <<" ===============================\n");
    5259
    5360                /*Reset some variables*/
     
    5966
    6067                /*Get current Gradient at xmin=0*/
    61                 if(VerboseControl()) _printf0_("\n" << "   step " << n+1 << "/" << nsteps << "\n");
     68                _printf0_(" x = "<<setw(9)<<xmin<<" | ");
    6269                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");
    6770               
    6871                /*Get f(xmax)*/
     72                _printf0_(" x = "<<setw(9)<<xmax<<" | ");
    6973                for(int i=0;i<nsize;i++) X[i]=X0[i]+xmax*G[i];
    7074                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");
    7276
    7377                /*test if jump option activated and xmin==0*/
     
    9296
    9397                /*2: call the function to be evaluated*/
     98                _printf0_(" x = "<<setw(9)<<x<<" | ");
    9499                for(int i=0;i<nsize;i++) X[i]=X0[i]+x*G[i];
    95100                fxbest = (*f)(X,usr); if(xIsNan<IssmDouble>(fxbest)) _error_("Function evaluation returned NaN");
     
    106111
    107112                /*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");
    110115                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");
    112117                        loop=false;
    113118                }
     
    176181
    177182                        //evaluate function on x
     183                        _printf0_(" x = "<<setw(9)<<x<<" | ");
    178184                        for(int i=0;i<nsize;i++) X[i]=X0[i]+x*G[i];
    179185                        fx = (*f)(X,usr); if(xIsNan<IssmDouble>(fx)) _error_("Function evaluation returned NaN");
     
    202208                        tol1=seps*pow(pow(xbest,2),0.5)+tolerance/3.0;
    203209                        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");
    207213
    208214                        /*Stop the optimization?*/
    209215                        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");
    211217                                loop=false;
    212218                        }
    213219                        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");
    215221                                loop=false;
    216222                        }
    217223                        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");
    219225                                loop=false;
    220226                        }
Note: See TracChangeset for help on using the changeset viewer.