From 8b94131388071980e62c17190eb4229e89975a0c Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 4 Dec 2013 10:25:14 +0100 Subject: Make it possible to use different ode solvers --- GNUmakefile | 22 +++++++++++++++++++--- R/mkinfit.R | 8 +++++--- R/mkinpredict.R | 10 ++++++---- man/mkinfit.Rd | 6 ++++++ man/mkinpredict.Rd | 17 +++++++++++------ 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 255b97f..cf5c845 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -19,9 +19,13 @@ help: @echo " build Create the package" @echo " build-no-vignettes Create the package without rebuilding vignettes" @echo " check Invoke build and then check the package" + @echo " check-no-vignettes Invoke build without rebuilding vignettes, and then check" @echo " install Invoke build and then install the result" + @echo " install Invoke build without rebuilding vignettes and then install the result" @echo " test Install a new copy of the package and run it " @echo " through the testsuite" + @echo " test-no-vignettes Invoke build without rebuilding vignettes, and then run it" + @echo " through the testsuite" @echo "" @echo "Packaging Tasks" @echo "---------------" @@ -44,15 +48,27 @@ build-no-vignettes: cd ..;\ "$(RBIN)/R" CMD build $(PKGSRC) --no-build-vignettes -install%: build% +install: build cd ..;\ "$(RBIN)/R" CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz -check%: build% +install-no-vignettes: build-no-vignettes + cd ..;\ + "$(RBIN)/R" CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz + +check: build + cd ..;\ + "$(RBIN)/R" CMD check --as-cran --no-tests $(PKGNAME)_$(PKGVERS).tar.gz + +check-no-vignettes: build-no-vignettes cd ..;\ "$(RBIN)/R" CMD check --as-cran --no-tests $(PKGNAME)_$(PKGVERS).tar.gz -test%: install% +test: install + cd tests;\ + "$(RBIN)/Rscript" doRUnit.R + +test-no-vignettes: install-no-vignettes cd tests;\ "$(RBIN)/Rscript" doRUnit.R diff --git a/R/mkinfit.R b/R/mkinfit.R index 3e47479..749d748 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -1,5 +1,3 @@ -# $Id$ - # Copyright (C) 2010-2013 Johannes Ranke # Contact: jranke@uni-bremen.de # The summary function is an adapted and extended version of summary.modFit @@ -28,6 +26,7 @@ mkinfit <- function(mkinmod, observed, fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], solution_type = "auto", + method.ode = "lsoda", method.modFit = "Marq", control.modFit = list(), plot = FALSE, quiet = FALSE, @@ -161,6 +160,7 @@ mkinfit <- function(mkinmod, observed, # Solve the system with current transformed parameter values out <- mkinpredict(mkinmod, parms, odeini, outtimes, solution_type = solution_type, + method.ode = method.ode, atol = atol, rtol = rtol, ...) assign("out_predicted", out, inherits=TRUE) @@ -177,7 +177,9 @@ mkinfit <- function(mkinmod, observed, outtimes_plot = seq(min(observed$time), max(observed$time), length.out=100) out_plot <- mkinpredict(mkinmod, parms, odeini, outtimes_plot, - solution_type = solution_type, atol = atol, rtol = rtol, ...) + solution_type = solution_type, + method.ode = method.ode, + atol = atol, rtol = rtol, ...) plot(0, type="n", xlim = range(observed$time), ylim = range(observed$value, na.rm=TRUE), diff --git a/R/mkinpredict.R b/R/mkinpredict.R index 7ce26ca..07c1a81 100644 --- a/R/mkinpredict.R +++ b/R/mkinpredict.R @@ -1,6 +1,4 @@ -# $Id$ - -# Copyright (C) 2010-2012 Johannes Ranke +# Copyright (C) 2010-2013 Johannes Ranke # Contact: jranke@uni-bremen.de # This file is part of the R package mkin @@ -18,7 +16,10 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see -mkinpredict <- function(mkinmod, odeparms, odeini, outtimes, solution_type = "deSolve", map_output = TRUE, atol = 1e-8, rtol = 1e-10, ...) { +mkinpredict <- function(mkinmod, odeparms, odeini, + outtimes, solution_type = "deSolve", + method.ode = "lsoda", atol = 1e-8, rtol = 1e-10, + map_output = TRUE, ...) { # Get the names of the state variables in the model mod_vars <- names(mkinmod$diffs) @@ -96,6 +97,7 @@ mkinpredict <- function(mkinmod, odeparms, odeini, outtimes, solution_type = "de times = outtimes, func = mkindiff, parms = odeparms, + method = method.ode, atol = atol, rtol = rtol, ... diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index 51e26ed..0c5d76a 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -20,6 +20,7 @@ mkinfit(mkinmod, observed, state.ini = c(100, rep(0, length(mkinmod$diffs) - 1)), fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], solution_type = "auto", + method.ode = "lsoda", method.modFit = "Marq", control.modFit = list(), plot = FALSE, quiet = FALSE, err = NULL, weight = "none", @@ -85,6 +86,11 @@ mkinfit(mkinmod, observed, dependence of degradation rates and metabolites). This argument is passed on to the helper function \code{\link{mkinpredict}}. } + \item{method.ode}{ + The solution method passed via \code{\link{mkinpredict}} to + \code{\link{ode}} in case the solution type is "deSolve". The default + "lsoda" is performant, but sometimes fails to converge. + } \item{method.modFit}{ The optimisation method passed to \code{\link{modFit}}. The default "Marq" is the Levenberg Marquardt algorithm \code{\link{nls.lm}} from the package diff --git a/man/mkinpredict.Rd b/man/mkinpredict.Rd index afb57e0..97db90e 100644 --- a/man/mkinpredict.Rd +++ b/man/mkinpredict.Rd @@ -10,7 +10,7 @@ } \usage{ mkinpredict(mkinmod, odeparms, odeini, outtimes, solution_type = "deSolve", - map_output = TRUE, atol = 1e-08, rtol = 1e-10, ...) + method.ode = "lsoda", atol = 1e-08, rtol = 1e-10, map_output = TRUE, ...) } \arguments{ \item{mkinmod}{ @@ -33,12 +33,13 @@ The method that should be used for producing the predictions. This should generally be "analytical" if there is only one observed variable, and usually "deSolve" in the case of several observed variables. The third - possibility "eigen" is faster but produces results that the author believes - to be less accurate. + possibility "eigen" is faster but not applicable to some models e.g. + using FOMC for the parent compound. } - \item{map_output}{ - Boolean to specify if the output should list values for the observed - variables (default) or for all state variables (if set to FALSE). + \item{method.ode}{ + The solution method passed via \code{\link{mkinpredict}} to + \code{\link{ode}} in case the solution type is "deSolve". The default + "lsoda" is performant, but sometimes fails to converge. } \item{atol}{ Absolute error tolerance, passed to \code{\link{ode}}. Default is 1e-8, @@ -48,6 +49,10 @@ Absolute error tolerance, passed to \code{\link{ode}}. Default is 1e-10, much lower than in \code{\link{lsoda}}. } + \item{map_output}{ + Boolean to specify if the output should list values for the observed + variables (default) or for all state variables (if set to FALSE). + } \item{\dots}{ Further arguments passed to the ode solver in case such a solver is used. } -- cgit v1.2.1