Changeset 18571


Ignore:
Timestamp:
10/03/14 14:06:00 (10 years ago)
Author:
Mathieu Morlighem
Message:

CHG: added gradient norm

File:
1 edited

Legend:

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

    r18128 r18571  
    8181        if(VerboseControl())_printf0_("   Computing initial solution\n");
    8282        _printf0_("\n");
    83         _printf0_("Cost function f(x)   | List of contributions\n");
    84         _printf0_("_____________________________________________\n");
     83        _printf0_("Cost function f(x)   | Gradient norm |g(x)| | List of contributions\n");
     84        _printf0_("____________________________________________________________________\n");
    8585        indic = 0; //no adjoint required
    8686        simul(&indic,&n,X,&f,G,izs,rzs,(void*)femmodel);
     
    162162        _printf0_("f(x) = "<<setw(12)<<setprecision(7)<<*pf<<"  |  ");
    163163
    164         /*Retrieve objective functions independently*/
    165         for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]);
    166         _printf0_("\n");
    167         xDelete<IssmDouble>(Jlist);
     164
    168165
    169166        if(indic==0){
    170167                /*dry run, no gradient required*/
     168
     169                /*Retrieve objective functions independently*/
     170                _printf0_("            N/A |\n");
     171                for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]);
     172                _printf0_("\n");
     173
     174                xDelete<IssmDouble>(Jlist);
    171175                xDelete<IssmDouble>(XU);
    172176                xDelete<IssmDouble>(XL);
     
    185189
    186190        /*Constrain Gradient*/
     191        IssmDouble  Gnorm = 0.;
    187192        for(long i=0;i<*n;i++){
    188193                if(X[i]>=XU[i]) G[i]=0.;
    189194                if(X[i]<=XL[i]) G[i]=0.;
    190         }
     195                Gnorm += G[i]*G[i];
     196        }
     197        Gnorm = sqrt(Gnorm);
     198
     199        /*Print info*/
     200        _printf0_("       "<<setw(12)<<setprecision(7)<<Gnorm<<" |");
     201        for(int i=0;i<num_responses;i++) _printf0_(" "<<setw(12)<<setprecision(7)<<Jlist[i]);
     202        _printf0_("\n");
    191203
    192204        /*Clean-up and return*/
     205                xDelete<IssmDouble>(Jlist);
    193206        xDelete<IssmDouble>(XU);
    194207        xDelete<IssmDouble>(XL);
Note: See TracChangeset for help on using the changeset viewer.