diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2018-02-02 12:38:55 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2018-02-02 12:38:55 +0100 |
commit | a8ab5f5f1139d97f8636c22cb39e4a31b71bc889 (patch) | |
tree | 52abe3ef6db4c5bd1975e3cff6e3a92136260237 /R/mkinfit.R | |
parent | 4de47be0bc4e6b923a6db15b9abc461046a99eac (diff) |
mkinfit: Work around a bug in the current FME version
that prevented the convergence message to be returned in the case of non-convergence.
Diffstat (limited to 'R/mkinfit.R')
-rw-r--r-- | R/mkinfit.R | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/R/mkinfit.R b/R/mkinfit.R index ab7b5ad2..c471b01c 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -36,7 +36,7 @@ mkinfit <- function(mkinmod, observed, transform_rates = TRUE,
transform_fractions = TRUE,
plot = FALSE, quiet = FALSE,
- err = NULL,
+ err = NULL,
weight = c("none", "std", "mean", "tc"),
tc = c(sigma_low = 0.5, rsd_high = 0.07),
scaleVar = FALSE,
@@ -439,7 +439,7 @@ mkinfit <- function(mkinmod, observed, if (reweight.method == "tc") {
sr_old <- tc_fitted
observed[err] <- predict(tc_fit)
-
+
}
fit <- modFit(cost, fit$par, method = method.modFit,
control = control.modFit, lower = lower, upper = upper, ...)
@@ -483,13 +483,22 @@ mkinfit <- function(mkinmod, observed, if(!quiet) cat("Optimisation by method", method.modFit, "successfully terminated.\n")
}
}
- if (method.modFit %in% c("Port", "SANN", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B")) {
+ if (method.modFit == "Port") {
+ if (fit$convergence != 0) {
+ fit$warning = paste0("Optimisation by method ", method.modFit,
+ " did not converge:\n",
+ if(is.character(fit$counts)) fit$counts # FME bug
+ else fit$message)
+ warning(fit$warning)
+ } else {
+ if(!quiet) cat("Optimisation by method", method.modFit, "successfully terminated.\n")
+ }
+ }
+ if (method.modFit %in% c("SANN", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B")) {
if (fit$convergence != 0) {
fit$warning = paste0("Optimisation by method ", method.modFit,
" did not converge.\n",
- "Convergence code is ", fit$convergence,
- ifelse(is.null(fit$message), "",
- paste0("\nMessage is ", fit$message)))
+ "Convergence code returned by optim() is", fit$convergence)
warning(fit$warning)
} else {
if(!quiet) cat("Optimisation by method", method.modFit, "successfully terminated.\n")
|