Thomas Petzoldt schrieb:
Martin Maechler wrote:
"TP" == Thomas Petzoldt <[EMAIL PROTECTED]>
on Sun, 16 Mar 2008 13:50:55 +0100 writes:
TP> Hello, I wonder why the control parameter REPORT is not
TP> supported by method SANN. Looking into optim.c I found
TP> an internal constant:
TP> #define STEPS 100
TP> ... and decreasing this to 10 helped me fine-tuning the
TP> annealing parameters in an actual problem.
TP> Is there any reason why not passing nREPORT to samin and
TP> setting something like:
TP> STEPS = nREPORT / tmax
Sorry to reply late (but then, rather than never ..).
You ask for reasons... I see/guess :
- the SANN method also was contributed from "outside"
(as ?optim mentions); and the original authors may not have
seen a use for such more flexible monitoring.
- the R core members are probably not using 'samin' very often
- If there is a need you can write the function you are
optimizing in a way that it prints info.
- Nobody has contributed a well-tested patch against R-devel to
both code and documentation
which would implement your proposal ___ BACK COMPATIBLY __
(i.e. the default for SANN should remain to print every 100th;
and this differs from the default for BFGS where the default
'REPORT' leads to output every 10th eval).
Regards,
Martin
Well, I see. The reasons are obviously more or less historical and not
fundamental. I can, of course, contribute an idea for a modifications of
samin and do_optim in optim.c. However, to convert my personal hack into
a "well-tested patch" a few additional considerations have to be
undertaken, especially about back-compatibility:
1) the patch requires to pass the additional argument nREPORT to
function "samin".
- Is this still back-compatible? Is it likely that other functions (e.g.
in packages call samin directly?
- if yes (i.e. direct call is likely), what is the preferred way to
ensure compatibility? Rename samin to samin2 and add a new
"compatibility function" function samin that calls samin2?
- the reporting interval of samin is STEPS * tmax where
- tmax is as documented "number of function evaluations at each
temperature" (10) and
- STEPS is a hard-coded constant: #define STEPS 10
- this means that reporting is every 10 per temperature.
2) if one starts patching SANN, then one migth also think about
"Nelder-Mead" and "CG" with totally different reporting, but smaller
(!) reporting schedule.
In contrast to this, SANN that is used for difficult systems *and* that
(see optim.Rd) "depends critically on the settings of the control
parameters" has a rather long reporting interval.
Thomas P.
o.k. here is it. The patch works by re-using trace for SANN -- as
suggested by Martin Maechler off-list after my first suggestion. The new
patch avoids an extended parameter list of samin and therefore the
necessity to modify the API.
The patched files and a few test examples are also on
http://hhbio.wasser.tu-dresden.de/projects/temp/optim/
Thank you for consideration
Thomas P.
Index: src/main/optim.c
===================================================================
--- src/main/optim.c (revision 45155)
+++ src/main/optim.c (working copy)
@@ -268,6 +268,7 @@
else if (strcmp(tn, "SANN") == 0) {
tmax = asInteger(getListElement(options, "tmax"));
temp = asReal(getListElement(options, "temp"));
+ if (trace) trace = asInteger(getListElement(options, "REPORT"));
if (tmax == NA_INTEGER) error(_("'tmax' is not an integer"));
if (!isNull(gr)) {
if (!isFunction(gr)) error(_("'gr' is not a function"));
@@ -1082,7 +1083,6 @@
#define E1 1.7182818 /* exp(1.0)-1.0 */
-#define STEPS 100
void samin(int n, double *pb, double *yb, optimfn fminfn, int maxit,
int tmax, double ti, int trace, void *ex)
@@ -1100,6 +1100,9 @@
int k, its, itdoc;
double t, y, dy, ytry, scale;
double *p, *dp, *ptry;
+
+ if (trace <= 0)
+ error(_("REPORT must be > 0 (method = \"SANN\")"));
if(n == 0) { /* don't even attempt to optimize */
*yb = fminfn(n, pb, ex);
@@ -1138,7 +1141,7 @@
}
its++; k++;
}
- if ((trace) && ((itdoc % STEPS) == 0))
+ if ((trace) && ((itdoc % trace) == 0))
Rprintf("iter %8d value %f\n", its - 1, *yb);
itdoc++;
}
@@ -1151,4 +1154,3 @@
}
#undef E1
-#undef STEPS
Index: src/library/stats/man/optim.Rd
===================================================================
--- src/library/stats/man/optim.Rd (revision 45026)
+++ src/library/stats/man/optim.Rd (working copy)
@@ -133,9 +133,11 @@
for the \code{"Nelder-Mead"} method. \code{alpha} is the reflection
factor (default 1.0), \code{beta} the contraction factor (0.5) and
\code{gamma} the expansion factor (2.0).}
- \item{\code{REPORT}}{The frequency of reports for the \code{"BFGS"}
- and \code{"L-BFGS-B"} methods if \code{control$trace} is positive.
- Defaults to every 10 iterations.}
+ \item{\code{REPORT}}{The frequency of reports for the \code{"BFGS"},
+ \code{"L-BFGS-B"} and \code{"SANN"} methods if \code{control$trace}
+ is positive. Defaults to every 10 iterations for
+ \code{"BFGS"} and \code{"L-BFGS-B"} resp. 10 temperatures
+ for \code{"SANN"}.}
\item{\code{type}}{for the conjugate-gradients method. Takes value
\code{1} for the Fletcher--Reeves update, \code{2} for
Polak--Ribiere and \code{3} for Beale--Sorenson.}
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel