Refitting with n.init can lead to poor models when new.loglik >> out$logl. I suggest a few changes. Accept a new model under the conditions:
n.i == 1
gradient contains only numeric values (i.e., no NaNs or NAs, occurs rarely)
gradient is sufficiently similar (difference of norm(oldgr)/length(oldgr) and norm(newgr)/length(newgr) smaller than 1 and if new.loglik > out$logl
otherwise, accept if norm(newgr)/length(newgr)<norm(oldgr)/length(oldgr)
note: adding new.loglik > out$logl additionally does not work when new.loglik>>out$logl erroneously, which can occur frequently with the quadratic model. new.loglik <0 can occur too, but is considerably harder to catch (as I have seen cases fitted with VA where that seems to lead to a valid model).
(and other conditions, i.e., finite value for likelihood, no error for optimizer, as usual)
I have also introduced the control argument n.init.max, which stops iterations for n.init if reached, and it is reached if no better fit is found after the specified number of iterations. By default this is set to n.init + 10. Every time a better fit is found, the count restarts.
Refitting with n.init can lead to poor models when
new.loglik >> out$logl
. I suggest a few changes. Accept a new model under the conditions:n.i == 1
norm(oldgr)/length(oldgr)
andnorm(newgr)/length(newgr)
smaller than 1 and ifnew.loglik > out$logl
norm(newgr)/length(newgr)<norm(oldgr)/length(oldgr)
new.loglik > out$logl
additionally does not work whennew.loglik>>out$logl
erroneously, which can occur frequently with the quadratic model.new.loglik <0
can occur too, but is considerably harder to catch (as I have seen cases fitted with VA where that seems to lead to a valid model).I have also introduced the control argument
n.init.max
, which stops iterations for n.init if reached, and it is reached if no better fit is found after the specified number of iterations. By default this is set ton.init + 10
. Every time a better fit is found, the count restarts.