On Mon, 6 Jul 2009, Riccardo (Jack) Lucchetti wrote:
BFGS converges alright. I'll see what I can do.
Ok, I think I've got it. The reason why line 548 in gretl_bgfs.c reads
crit_ok = !na(f) && (f >= fmax + d);
instead of
crit_ok = !na(f) && (f >= fmax);
is that, in normal circumstances, we want to avoid jumping from one place
to another if the jump doesn't yield a *significant* improvement in the
objective function. Here d is the threshold, which, in turn, is computed
as
d = sumgrad * steplen * acctol;
acctol is a hand-tweaked small number, steplen is between 0 and 1, so what
really makes the difference here is sumgrad.
The sumgrad variable contains the result of a quadratic form g'Hg, where g
is the gradient and H is the BFGS curvature matrix. Now, at the first
iteration this is conventionally set at I, while it could be any other pd
matrix. So if for some problem the identity matrix happens to be a poor
choice for H, then d becomes unreasonably big and you never have the
chance of satisfying the criterion. This is not a problem after the first
iteration, since H should contain "sensible" numbers, but the initial
value for H becomes a problem.
The following one-liner sets d=0 for the first iteration only:
--- lib/src/gretl_bfgs.c.~1.7.~ 2009-07-06 11:07:30.000000000 +0200
+++ lib/src/gretl_bfgs.c 2009-07-06 12:06:48.000000000 +0200
@@ -543,7 +543,7 @@
}
if (ndelta > 0) {
f = cfunc(b, data);
- d = sumgrad * steplen * acctol;
+ d = (iter>1) ? sumgrad * steplen * acctol : 0;
fcount++;
crit_ok = !na(f) && (f >= fmax + d);
#if BFGS_DEBUG
which lets your example script run fine. Could you please try it with your
"real" stuff?
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti