[Lme4-commits] r1737 - pkg/lme4/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed May 16 05:10:05 CEST 2012
Author: dmbates
Date: 2012-05-16 05:10:05 +0200 (Wed, 16 May 2012)
New Revision: 1737
Modified:
pkg/lme4/src/external.cpp
Log:
Impose a limit on the number of iterations in pwrssUpdate. Add verbose output.
Modified: pkg/lme4/src/external.cpp
===================================================================
--- pkg/lme4/src/external.cpp 2012-05-16 03:09:06 UTC (rev 1736)
+++ pkg/lme4/src/external.cpp 2012-05-16 03:10:05 UTC (rev 1737)
@@ -265,25 +265,29 @@
static void pwrssUpdate(glmResp *rp, merPredD *pp, bool uOnly, double tol, int verbose) {
double oldpdev=std::numeric_limits<double>::max();
- while (true) {
+ bool cvgd = false, verb = verbose > 2;
+ for (int i = 0; i < 30; i++) {
Vec olddelu(pp->delu()), olddelb(pp->delb());
double pdev=internal_glmerWrkIter(pp, rp, uOnly);
- if (std::abs((oldpdev - pdev) / pdev) < tol) break;
+ if (verb) Rcpp::Rcout << i << ": " << pdev << std::endl;
+ if (std::abs((oldpdev - pdev) / pdev) < tol) {cvgd = true; break;}
if (pdev > oldpdev) { // try step halving
- if (verbose > 2)
- Rcpp::Rcout << "Trying step halving: oldpdev = " << oldpdev
- << ", pdev = " << pdev << std::endl;
- for (int k=0; k < 10 && pdev > oldpdev; k++) {
+ if (verb) Rcpp::Rcout << "Step halving: oldpdev = "
+ << oldpdev << ", pdev = " << pdev
+ << std::endl;
+ for (int k = 0; k < 10 && pdev > oldpdev; k++) {
pp->setDelu((olddelu + pp->delu())/2.);
if (!uOnly) pp->setDelb((olddelb + pp->delb())/2.);
pdev = internal_glmerWrkIter(pp, rp, uOnly);
- if (verbose > 2)
- Rcpp::Rcout << "k = " << k << ", pdev = " << pdev << std::endl;
+ if (verb) Rcpp::Rcout << "k = " << k << ", pdev = "
+ << pdev << std::endl;
}
if (pdev > oldpdev) throw runtime_error("PIRLS step failed");
}
oldpdev = pdev;
}
+ if (!cvgd)
+ throw runtime_error("pwrssUpdate did not converge in 30 iterations");
}
SEXP glmerLaplace(SEXP pp_, SEXP rp_, SEXP nAGQ_, SEXP tol_, SEXP verbose_) {
More information about the Lme4-commits
mailing list