[Developers] phase
Johnoel Ancheta
johnoel at hawaii.edu
Wed Aug 11 15:14:58 PDT 2010
Coded in the phase output. Please review before I commit the changes.
Here is an example output.
Initial statistics: 10 variables; iteration 0; function evaluation 0;
phase 2
Function value 2.2430580e+03; maximum gradient component mag -3.9566e+01
Var Value Gradient |Var Value Gradient |Var Value
Gradient
1 -1.16054 3.77930e+01 | 2 -0.86316 2.96040e+01 | 3 -0.77564
2.28586e+01
4 -0.46619 1.82310e+01 | 5 -0.27110 5.00940e+00 | 6 -0.12734
-2.74813e+00
7 0.27721 -1.06853e+01 | 8 0.39379 -2.48485e+01 | 9 0.66532
-3.54306e+01
10 1.05507 -3.95660e+01 |
Below is the diff of changes using Dave's suggestions.
$ svn diff src
Index: src/nh99/model.cpp
===================================================================
--- src/nh99/model.cpp (revision 723)
+++ src/nh99/model.cpp (working copy)
@@ -63,6 +63,7 @@
# endif
}
+extern int* pointer_to_phase;
initial_params::initial_params(void)
{
# if defined(USE_SHARE_FLAGS)
@@ -74,6 +75,7 @@
initial_value_flag=0;
active_flag=0;
scalefactor=0;
+ pointer_to_phase=&initial_params::current_phase;
}
void initial_params::set_initial_value(double x)
Index: src/linad99/newfmin.cpp
===================================================================
--- src/linad99/newfmin.cpp (revision 723)
+++ src/linad99/newfmin.cpp (working copy)
@@ -80,6 +80,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
+
+int* pointer_to_phase = 0;
+
double dafsqrt( double x );
void tracing_message(int traceflag,const char *s);
void tracing_message(int traceflag,const char *s,int *pn);
@@ -359,9 +362,14 @@
label7003:
if (iprint>0)
{
- if (ad_printf) (*ad_printf)("%d variables; iteration %ld;
function evaluation %ld\n",
- n, itn, ifn);
- if (ad_printf) (*ad_printf)("Function value %15.7le; maximum
gradient component mag %12.4le\n",
+ if (ad_printf)
+ {
+ (*ad_printf)("%d variables; iteration %ld; function
evaluation %ld", n, itn, ifn);
+ if (pointer_to_phase)
+ {
+ (*ad_printf)("; phase %d", *pointer_to_phase);
+ }
+ (*ad_printf)("\nFunction value %15.7le; maximum gradient
component mag %12.4le\n",
#if defined(USE_DDOUBLE)
#undef double
double(f), double(gmax));
@@ -369,6 +377,7 @@
#else
f, gmax);
#endif
+ }
}
label7002:
if(iprint>0)
On 8/9/10 8:04 AM, John Sibert wrote:
> That would do it, and the if (ad_printf && pointer_to_phase) take care
> of the AUDODIF applications where phase in not defined.
>
> On 08/08/2010 11:48 PM, dave fournier wrote:
>> John Sibert wrote:
>>
>> But that is just the same difficulty in a different form.
>> the right way I think is to put a global pointer in
>> newfmin.cpp
>>
>> int * pointer_to_phase=0;
>>
>> and then in the initial_params startup assign
>>
>> pointer_to_phase=&initial_params::current_phase;
>>
>> and then
>>
>> if (ad_printf && pointer_to_phase) (*ad_printf)("Current Phase
>> %d ",
>> *pointer_to_phase );
>>
>>
>>
>>> Or you could add an additional argument to fmmdisp(...), eg,
>>>
>>> void fmmdisp(_CONST dvector& x,_CONST dvector& g,
>>> const int& nvar, int scroll_flag,int noprintx, const
>>> int phase=-1)
>>>
>>> Giving phase a default value would not break calls to fmmdisp in
>>> other context, The problem would be that the code which calls
>>> fmmdisp would need to have access to the initial_params structure or
>>> the get_current_phase() function.
>>>
>>>
>>> On 08/08/2010 08:37 PM, dave fournier wrote:
>>>> There are a few issues involved here.
>>>>
>>>> First here is how it migbht be done. the current phase is contained
>>>> as a static member of the class initial_params. Lets say we are
>>>> working
>>>> with the quasi newton function minimizer in the file newfmin.cpp.
>>>>
>>>> first we need to add
>>>>
>>>> #include <admodel.h>
>>>>
>>>> near the top of the file.
>>>>
>>>> then at the right place(s) add something like
>>>>
>>>> if (ad_printf) (*ad_printf)("Current Phase %d ",
>>>> initial_params::current_phase );
>>>>
>>>> However this will break all code that just uses the autodif stuff
>>>> I think as the symbol initial_params::current_phase will be undefined.
>>>> Maybe someone has a better idea.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Developers mailing list
>>>> Developers at admb-project.org
>>>> http://lists.admb-project.org/mailman/listinfo/developers
>>>>
>>>
>>
>>
>
More information about the Developers
mailing list