Skip to content

Commit

Permalink
changes to make package build work
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhooker committed May 27, 2014
1 parent c173eb0 commit 815635d
Show file tree
Hide file tree
Showing 28 changed files with 215 additions and 456 deletions.
6 changes: 1 addition & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ Title: Population (and individual) optimal Experimental Design
Version: 0.1.1
Date: 2014-05-27
Depends: ggplot2
Imports: MASS, mvtnorm
Imports: MASS, mvtnorm, nlme
Suggests: testthat, Hmisc
Author: Andrew C. Hooker, Sebastian Ueckert (MATLAB version),
Marco Foracchia (O-Matrix version) and Joakim Nyberg (MATLAB version)
with contributions from Eric Stroemberg (MATLAB version).
Maintainer: Andrew C. Hooker <[email protected]>
Authors@R: c(person("Andrew C.","Hooker",
email="[email protected]",
role=c("aut","cre","trl","cph")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import(ggplot2)
importFrom(MASS, write.matrix)
importFrom(mvtnorm, rmvnorm)
importFrom(nlme, fdHess)
exportPattern("^[[:alpha:]]+")
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PopED 0.1.1

* New functionality to compute the ED OFV using the Laplace approximation.
This can be orders of magnitude faster than the standard MC integration approach.
See '?ed_laplace_ofv' and '?evaluate.e.ofv.fim'

* Added a general function to compute the FIM and OFV(FIM) for all avaialbale methods in PopED.
See '?calc_ofv_and_fim'.
Expand Down
4 changes: 3 additions & 1 deletion R/LEDoptim.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#' @inheritParams RS_opt_gen
#' @inheritParams create.poped.database
#' @inheritParams Doptim
#' @inheritParams calc_ofv_and_fim
#' @param fim_init The initial value of the FIM. If set to zero then it is computed.
#' @param ofv_init The inital OFV. If set to zero then it is computed.
#' @param trflag Should the optimization be output to the screen and to a file?
#' @param use_RS should the fucntion use a random search algorithm?
#'
#' @family Optimize
#'
Expand Down Expand Up @@ -203,7 +205,7 @@ LEDoptim <- function(poped.db,
fprintf('Starting BGFS minimization with OFV of %g \n', best_dmf)
returnArgs <- bfgsb_min('ed_laplace_ofv',
list(model_switch,aa,axt,poped.db$groupsize,ni,
xtopt,xopt,aopt,bpop,d,poped.db$sigma,docc_full,poped.db,
xtopt,xopt,aopt,bpopdescr,ddescr,poped.db$sigma,poped.db$param.pt.val$docc,poped.db,
return_gradient=T,
optxt=optxt, opta=optx, x=x),
x_k,lb,ub,options)
Expand Down
7 changes: 7 additions & 0 deletions R/RS_opt_gen.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
#' @inheritParams evaluate.fim
#' @inheritParams Doptim
#' @inheritParams create.poped.database
#' @inheritParams calc_ofv_and_fim
#' @param cfaxt First step factor for sample times
#' @param opt_xt Should the sample times be optimized?
#' @param opt_a Should the continuous design variables be optimized?
#' @param opt_x Should the discrete design variables be optimized?
#' @param approx_type Approximation method for model, 0=FO, 1=FOCE, 2=FOCEI, 3=FOI.
#' @param iter The number of iterations entered into the \code{blockheader_2} function.
#' @param header_flag Should the header text be printed out?
#' @param footer_flag Should the footer text be printed out?
#' @param out_file Which file should the output be directed to? A string, a file handle using
#' \code{\link{file}} or \code{""} will output to the screen.
#' @param compute_inv should the inverse of the FIM be used to compute expected RSE values? Often not needed
#' except for diagnostic purposes.
#' @param ... arguments passed to \code{\link{evaluate.fim}} and \code{\link{ofv_fim}}.
#'
#'
Expand Down
1 change: 1 addition & 0 deletions R/blockfinal.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @inheritParams create.poped.database
#' @inheritParams blockexp
#' @inheritParams blockheader
#' @inheritParams RS_opt_gen
#' @param fmf_init Initial FIM.
#' @param dmf_init Initial OFV.
#' @param param_cvs_init The inital design parameter RSE values.
Expand Down
2 changes: 2 additions & 0 deletions R/blockheader.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#' @inheritParams blockexp
#' @inheritParams Doptim
#' @inheritParams create.poped.database
#' @inheritParams RS_opt_gen
#' @param name The name used for the output file. Combined with \code{name_header} and \code{iter}.
#' If \code{""} then output is to the screen.
#' @param iter The last number in the name printed to the output file, combined with \code{name}.
#' @param name_header The initial portion of the file name.
#' @param file_path The path to where the file should be created.
#' @param header_flag Should the header text be printed out?
#' @param ... Additional arguments passed to further functions.
#'
#' @family Helper
Expand Down
2 changes: 2 additions & 0 deletions R/calc_ofv_and_fim.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @inheritParams evaluate.fim
#' @inheritParams Doptim
#' @inheritParams create.poped.database
#' @param ofv The current ofv. If other than zero then this values is simply returned unchanged.
#' @param fim The current FIM. If other than zero then this values is simply returned unchanged.
#' @param use_laplace Should the Laplace method be used in calculating the expectation of the OFV?
#' @param laplace.fim Should an E(FIM) be calculated when computing the Laplace approximated E(OFV). Typically
#' the FIM does not need to be computed and, if desired, this calculation
Expand Down
7 changes: 5 additions & 2 deletions R/ed_laplace_ofv.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#' @param optxt If sampling times are optimized
#' @param opta If continuous design variables are optimized
#' @param aopto the continuous design variables
#'
#' @param method If 0 then use an optimization routine translated from poped code written in MATLAB to
#' optimize the parameters in the Laplace approximation. If 1 then use \code{\link{optim}} to compute both
#' k and the hessian of k (see Dodds et al, JPP, 2005 for more information). If 2 then use \code{\link{fdHess}}
#' to compute the hessian.
#' @param return_gradient Should the gradient be returned.
#'
#' @return The FIM and the hessian of the FIM.
Expand Down Expand Up @@ -224,7 +227,7 @@ ed_laplace_ofv <- function(model_switch,groupsize,ni,xtopto,xopto,aopto,

## Different hessian and gradient calculation
if(method==2){
k_vals <- nlme::fdHess(output$par,
k_vals <- fdHess(output$par,
function(x) calc_k(x,model_switch,groupsize,ni,xtopto,xopto,
aopto,bpopdescr,ddescr,covd,sigma,docc,poped.db,Engine,
return_gradient=F)[["k"]])
Expand Down
3 changes: 3 additions & 0 deletions R/log_prior_pdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#' @inheritParams evaluate.fim
#' @inheritParams create.poped.database
#' @inheritParams Doptim
#' @param alpha A parameter vector.
#' @param return_hessian Should the hessian be returned?
#'
#' @example tests/testthat/examples_fcn_doc/warfarin_optimize.R
#' @example tests/testthat/examples_fcn_doc/examples_log_prior_pdf.R

log_prior_pdf <- function(alpha, bpopdescr, ddescr,return_gradient=F,return_hessian=F){
Expand Down
1 change: 1 addition & 0 deletions R/poped_optimize.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @inheritParams Doptim
#' @inheritParams create.poped.database
#' @inheritParams Dtrace
#' @inheritParams calc_ofv_and_fim
#' @param ... arguments passed to other functions. See \code{\link{Doptim}}.
#'
#'
Expand Down
116 changes: 51 additions & 65 deletions man/LEDoptim.Rd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
% Generated by roxygen2 (4.0.1): do not edit by hand
\name{LEDoptim}
\alias{LEDoptim}
\title{Laplace approximated ED-optimization function}
\title{Optimization function for D-family, E-family and Laplace approximated ED designs}
\usage{
LEDoptim(poped.db, model_switch = NULL, ni = NULL, xt = NULL, x = NULL,
a = NULL, bpopdescr = NULL, ddescr = NULL, maxxt = NULL,
Expand All @@ -19,9 +19,7 @@ LEDoptim(poped.db, model_switch = NULL, ni = NULL, xt = NULL, x = NULL,

\item{trflag}{Should the optimization be output to the screen and to a file?}

\item{ls_step_size}{Number of grid points in the line search}

\item{iter_tot}{Number of iterations of full Random search and full Stochastic Gradient if line search is not used.}
\item{use_RS}{should the fucntion use a random search algorithm?}

\item{opt_xt}{Should the sample times be optimized?}

Expand All @@ -31,6 +29,13 @@ LEDoptim(poped.db, model_switch = NULL, ni = NULL, xt = NULL, x = NULL,

\item{...}{arguments passed to \code{\link{evaluate.fim}} and \code{\link{ofv_fim}}.}

\item{header_flag}{Should the header text be printed out?}

\item{footer_flag}{Should the footer text be printed out?}

\item{out_file}{Which file should the output be directed to? A string, a file handle using
\code{\link{file}} or \code{""} will output to the screen.}

\item{model_switch}{Matrix defining which response a certain sampling time belongs to.}

\item{ni}{Vector defining the number of samples for each group.}
Expand Down Expand Up @@ -77,9 +82,15 @@ D-family design (1) or ED-familty design (0) (with or without parameter uncertai
}}

\item{ddescr}{Matrix defining the diagnonals of the IIV (same logic as for the \code{bpopdescr}).}

\item{use_laplace}{Should the Laplace method be used in calculating the expectation of the OFV?}

\item{laplace.fim}{Should an E(FIM) be calculated when computing the Laplace approximated E(OFV). Typically
the FIM does not need to be computed and, if desired, this calculation
is done usng the standard MC integration technique, so can be slow.}
}
\description{
Optimize the Laplace approximated ED-objective function.
Optimize the objective fucntion for D-family, E-family and Laplace approximated ED designs.
Right now there is only one optimization algorithm used in this
function
\enumerate{
Expand Down Expand Up @@ -114,11 +125,19 @@ sfg <- function(x,a,bpop,b,bocc){
return(parameters)
}

# Adding 10\% log-normal Uncertainty to fixed effects (not Favail)
bpop_vals <- c(CL=0.15, V=8, KA=1.0, Favail=1)
bpop_vals_ed_ln <- cbind(ones(length(bpop_vals),1)*4, # log-normal distribution
bpop_vals,
ones(length(bpop_vals),1)*(bpop_vals*0.1)^2) # 10\% of bpop value
bpop_vals_ed_ln["Favail",] <- c(0,1,0)
bpop_vals_ed_ln

## -- Define initial design and design space
poped.db <- create.poped.database(ff_file="ff.PK.1.comp.oral.sd.CL",
fg_file="sfg",
fError_file="feps.add.prop",
bpop=c(CL=0.15, V=8, KA=1.0, Favail=1),
bpop=bpop_vals_ed_ln,
notfixed_bpop=c(1,1,1,0),
d=c(CL=0.07, V=0.02, KA=0.6),
sigma=c(0.01,0.25),
Expand All @@ -129,78 +148,45 @@ poped.db <- create.poped.database(ff_file="ff.PK.1.comp.oral.sd.CL",
a=70,
mina=0,
maxa=100)
# warfarin optimize model
# warfain ed model

\dontrun{

##############
# typically one will use poped_optimize
# This then calls Doptim for continuous optimization problems
##############
LEDoptim(poped.db)

LEDoptim(poped.db,opt_xt=T,rsit=10)

# RS+SG+LS optimization of sample times
# optimization with just a few iterations
# only to check that things are working
output <- poped_optimize(poped.db,opt_xt=T,
rsit=5,sgit=5,ls_step_size=5)
LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE)

LEDoptim(poped.db,opt_xt=T,rsit=10,laplace.fim=TRUE)

# RS+SG+LS optimization of sample times
# (longer run time than above but more likely to reach a maximum)
output <- poped_optimize(poped.db,opt_xt=T)
get_rse(output$fmf,output$poped.db)
plot_model_prediction(output$poped.db)
LEDoptim(poped.db,opt_xt=T,rsit=10,use_laplace=FALSE)

## testing header and footer
LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
out_file="foobar.txt")

# Random search (just a few samples here)
rs.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,rsit=20,
bUseRandomSearch= 1,
bUseStochasticGradient = 0,
bUseBFGSMinimizer = 0,
bUseLineSearch = 0)
ff <- LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
trflag=FALSE)

# line search, DOSE and sample time optimization
ls.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,
bUseRandomSearch= 0,
bUseStochasticGradient = 0,
bUseBFGSMinimizer = 0,
bUseLineSearch = 1,
ls_step_size=10)
LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
header_flag=FALSE)

# Stochastic gradient search, DOSE and sample time optimization
sg.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,
bUseRandomSearch= 0,
bUseStochasticGradient = 1,
bUseBFGSMinimizer = 0,
bUseLineSearch = 0,
sgit=20)
LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
out_file="")

# BFGS search, DOSE and sample time optimization
bfgs.output <- poped_optimize(poped.db,opt_xt=1,opt_a=1,
bUseRandomSearch= 0,
bUseStochasticGradient = 0,
bUseBFGSMinimizer = 1,
bUseLineSearch = 0)

##############
# If you really want to you can use Doptim dirtectly
##############
dsl <- downsizing_general_design(poped.db)
poped.db$optsw[2] <- 1 # sample time optimization
output <- Doptim(poped.db,dsl$ni, dsl$xt, dsl$model_switch, dsl$x, dsl$a,
dsl$bpop, dsl$d, dsl$maxxt, dsl$minxt,dsl$maxa,dsl$mina)
LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
footer_flag=FALSE)

}

LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
footer_flag=FALSE, header_flag=FALSE)

LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
footer_flag=FALSE, header_flag=FALSE,out_file="foobar.txt")

LEDoptim(poped.db,opt_xt=T,rsit=10,d_switch=TRUE,
footer_flag=FALSE, header_flag=FALSE,out_file="")

}
\references{
\enumerate{
\item M. Foracchia, A.C. Hooker, P. Vicini and A. Ruggeri, "PopED, a software for optimal
experimental design in population kinetics", Computer Methods and Programs in Biomedicine, 74, 2004.
\item J. Nyberg, S. Ueckert, E.A. Stroemberg, S. Hennig, M.O. Karlsson and A.C. Hooker, "PopED: An extended,
parallelized, nonlinear mixed effects models optimal design tool",
Computer Methods and Programs in Biomedicine, 108, 2012.
}
}
\seealso{
Expand Down
1 change: 0 additions & 1 deletion man/PopED-internal.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
\alias{numel}
\alias{new_ferror_file}
\alias{min_function}
\alias{log_prior_pdf}
\alias{linspace}
\alias{line_search_uc}
\alias{line_search}
Expand Down
16 changes: 16 additions & 0 deletions man/RS_opt_gen.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ RS_opt_gen(poped.db, ni = NULL, xt = NULL, model_switch = NULL,

\item{iter}{The number of iterations entered into the \code{blockheader_2} function.}

\item{header_flag}{Should the header text be printed out?}

\item{footer_flag}{Should the footer text be printed out?}

\item{out_file}{Which file should the output be directed to? A string, a file handle using
\code{\link{file}} or \code{""} will output to the screen.}

\item{compute_inv}{should the inverse of the FIM be used to compute expected RSE values? Often not needed
except for diagnostic purposes.}

\item{...}{arguments passed to \code{\link{evaluate.fim}} and \code{\link{ofv_fim}}.}

\item{poped.db}{A PopED database.}
Expand Down Expand Up @@ -94,6 +104,12 @@ all a values are given the same max value}
\item{d_switch}{\itemize{
\item \bold{******START OF CRITERION SPECIFICATION OPTIONS**********}}
D-family design (1) or ED-familty design (0) (with or without parameter uncertainty)}

\item{use_laplace}{Should the Laplace method be used in calculating the expectation of the OFV?}

\item{laplace.fim}{Should an E(FIM) be calculated when computing the Laplace approximated E(OFV). Typically
the FIM does not need to be computed and, if desired, this calculation
is done usng the standard MC integration technique, so can be slow.}
}
\description{
Optimize the objective function using an adaptive random search algorithm.
Expand Down
10 changes: 9 additions & 1 deletion man/blockfinal.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ can also just supply the parameter values as a \code{c()}.}
can also just supply the diagnonal parameter values (variances) as a \code{c()}.}

\item{fn}{The file handle to write to.}

\item{compute_inv}{should the inverse of the FIM be used to compute expected RSE values? Often not needed
except for diagnostic purposes.}

\item{out_file}{Which file should the output be directed to? A string, a file handle using
\code{\link{file}} or \code{""} will output to the screen.}

\item{footer_flag}{Should the footer text be printed out?}
}
\description{
Create some output to the screen and a text file that summarizes the problem you solved.
Expand Down Expand Up @@ -109,7 +117,7 @@ poped.db <- create.poped.database(ff_file="ff.PK.1.comp.oral.sd.CL",


FIM <- evaluate.fim(poped.db)
<- det(FIM)
dmf <- det(FIM)


blockfinal(fn="",fmf=FIM,
Expand Down
Loading

0 comments on commit 815635d

Please sign in to comment.