Description Usage Arguments Details References See Also Examples
Optimize a design defined in a PopED database using the objective function described in the database (or in the arguments to this function). The function works for both discrete and continuous optimization variables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | poped_optim(
poped.db,
opt_xt = poped.db$settings$optsw[2],
opt_a = poped.db$settings$optsw[4],
opt_x = poped.db$settings$optsw[3],
opt_samps = poped.db$settings$optsw[1],
opt_inds = poped.db$settings$optsw[5],
method = c("ARS", "BFGS", "LS"),
control = list(),
trace = TRUE,
fim.calc.type = poped.db$settings$iFIMCalculationType,
ofv_calc_type = poped.db$settings$ofv_calc_type,
approx_type = poped.db$settings$iApproximationMethod,
d_switch = poped.db$settings$d_switch,
ED_samp_size = poped.db$settings$ED_samp_size,
bLHS = poped.db$settings$bLHS,
use_laplace = poped.db$settings$iEDCalculationType,
out_file = "",
parallel = F,
parallel_type = NULL,
num_cores = NULL,
mrgsolve_model = NULL,
loop_methods = ifelse(length(method) > 1, TRUE, FALSE),
iter_max = 10,
stop_crit_eff = 1.001,
stop_crit_diff = NULL,
stop_crit_rel = NULL,
ofv_fun = poped.db$settings$ofv_fun,
maximize = T,
allow_replicates = TRUE,
allow_replicates_xt = TRUE,
allow_replicates_a = TRUE,
...
)
|
poped.db |
A PopED database. |
opt_xt |
Should the sample times be optimized? |
opt_a |
Should the continuous design variables be optimized? |
opt_x |
Should the discrete design variables be optimized? |
opt_samps |
Are the number of sample times per group being optimized? |
opt_inds |
Are the number of individuals per group being optimized? |
method |
A vector of optimization methods to use in a sequential
fashion. Options are |
control |
Contains control arguments for each method specified. |
trace |
Should the algorithm output results intermittently. |
fim.calc.type |
The method used for calculating the FIM. Potential values:
|
ofv_calc_type |
OFV calculation type for FIM
|
approx_type |
Approximation method for model, 0=FO, 1=FOCE, 2=FOCEI, 3=FOI. |
d_switch |
D-family design (1) or ED-family design (0) (with or without parameter uncertainty) |
ED_samp_size |
Sample size for E-family sampling |
bLHS |
How to sample from distributions in E-family calculations. 0=Random Sampling, 1=LatinHyperCube – |
use_laplace |
Should the Laplace method be used in calculating the expectation of the OFV? |
out_file |
Save output from the optimization to a file. |
parallel |
Should we use parallel computations? |
parallel_type |
Which type of parallelization should be used?
Can be "snow" or "multicore". "snow" works on Linux-like systems & Windows. "multicore" works only on
Linux-like systems. By default this is chosen for you depending on your operating system.
See |
num_cores |
The number of cores to use in the parallelization. By default is set to the number
output from
|
mrgsolve_model |
If the computations require a mrgsolve model and you
are using the "snow" method then you need to specify the name of the model
object created by |
loop_methods |
Should the optimization methods be looped for
|
iter_max |
If line search is used then the algorithm tests if line
search (always run at the end of the optimization iteration) changes the
design in any way. If not, the algorithm stops. If yes, then a new
iteration is run unless |
stop_crit_eff |
If |
stop_crit_diff |
If |
stop_crit_rel |
If |
ofv_fun |
User defined function used to compute the objective function. The function must have a poped database object as its first argument and have "..." in its argument list. Can be referenced as a function or as a file name where the function defined in the file has the same name as the file. e.g. "cost.txt" has a function named "cost" in it. |
maximize |
Should the objective function be maximized or minimized? |
allow_replicates |
Should the algorithm allow optimized design components to have the same value? If FALSE then
all discrete optimizations will not allow replicates within variable types
(equivalent to |
allow_replicates_xt |
Should the algorithm allow optimized |
allow_replicates_a |
Should the algorithm allow optimized |
... |
arguments passed to other functions. |
This function takes information from the PopED database supplied as an argument. The PopED database supplies information about the the model, parameters, design and methods to use. Some of the arguments coming from the PopED database can be overwritten; if they are supplied then they are used instead of the arguments from the PopED database.
If more than one optimization method is
specified then the methods are run in series. If loop_methods=TRUE
then the series of optimization methods will be run for iter_max
iterations, or until the efficiency of the design after the current series
(compared to the start of the series) is less than stop_crit_eff
.
M. Foracchia, A.C. Hooker, P. Vicini and A. Ruggeri, "PopED, a software fir optimal experimental design in population kinetics", Computer Methods and Programs in Biomedicine, 74, 2004.
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.
Other Optimize:
Doptim()
,
LEDoptim()
,
RS_opt()
,
a_line_search()
,
bfgsb_min()
,
calc_autofocus()
,
calc_ofv_and_grad()
,
mfea()
,
optim_ARS()
,
optim_LS()
,
poped_optim_1()
,
poped_optim_2()
,
poped_optim_3()
,
poped_optimize()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | library(PopED)
############# START #################
## Create PopED database
## (warfarin model for optimization)
#####################################
## Warfarin example from software comparison in:
## Nyberg et al., "Methods and software tools for design evaluation
## for population pharmacokinetics-pharmacodynamics studies",
## Br. J. Clin. Pharm., 2014.
## Optimization using an additive + proportional reidual error
## to avoid sample times at very low concentrations (time 0 or very late samples).
## find the parameters that are needed to define from the structural model
ff.PK.1.comp.oral.sd.CL
## -- parameter definition function
## -- names match parameters in function ff
sfg <- function(x,a,bpop,b,bocc){
parameters=c(CL=bpop[1]*exp(b[1]),
V=bpop[2]*exp(b[2]),
KA=bpop[3]*exp(b[3]),
Favail=bpop[4],
DOSE=a[1])
return(parameters)
}
## -- Define initial design and design space
poped.db <- create.poped.database(ff_fun=ff.PK.1.comp.oral.sd.CL,
fg_fun=sfg,
fError_fun=feps.add.prop,
bpop=c(CL=0.15, V=8, KA=1.0, Favail=1),
notfixed_bpop=c(1,1,1,0),
d=c(CL=0.07, V=0.02, KA=0.6),
sigma=c(prop=0.01,add=0.25),
groupsize=32,
xt=c( 0.5,1,2,6,24,36,72,120),
minxt=0.01,
maxxt=120,
a=c(DOSE=70),
mina=c(DOSE=0.01),
maxa=c(DOSE=100))
############# END ###################
## Create PopED database
## (warfarin model for optimization)
#####################################
##############
# D-family Optimization
##############
# below are a number of ways to optimize the problem
# ARS+BFGS+LS optimization of dose
# optimization with just a few iterations
# only to check that things are working
out_1 <- poped_optim(poped.db,opt_a =TRUE,
control = list(ARS=list(iter=2),
BFGS=list(maxit=2),
LS=list(line_length=2)),
iter_max = 1)
# cost function
# PRED at 120 hours
crit_fcn <- function(poped.db,...){
pred_df <- model_prediction(poped.db)
return(pred_df[pred_df$Time==120,"PRED"])
}
# maximize cost function
out_2 <- poped_optim(poped.db,opt_a =TRUE,
ofv_fun=crit_fcn,
control = list(ARS=list(iter=2),
BFGS=list(maxit=2),
LS=list(line_length=2)),
iter_max = 2)
# minimize the cost function
out_3 <- poped_optim(poped.db,opt_a =TRUE,
ofv_fun=crit_fcn,
control = list(ARS=list(iter=2),
BFGS=list(maxit=2),
LS=list(line_length=2)),
iter_max = 2,
maximize = FALSE,
evaluate_fim = FALSE)
## Not run:
# RS+BFGS+LS optimization of sample times
# (longer run time than above but more likely to reach a maximum)
output <- poped_optim(poped.db,opt_xt=T,parallel = TRUE)
get_rse(output$FIM,output$poped.db)
plot_model_prediction(output$poped.db)
# optimization with only integer times allowed
poped.db.2 <- poped.db
poped.db.2$design_space$xt_space <- matrix(list(seq(1,120)),1,8)
output_2 <- poped_optim(poped.db.2,opt_xt=T,parallel = TRUE)
get_rse(output_2$FIM,output_2$poped.db)
plot_model_prediction(output_2$poped.db)
# Examine efficiency of sampling windows
plot_efficiency_of_windows(output_2$poped.db,xt_windows=0.5)
plot_efficiency_of_windows(output_2$poped.db,xt_windows=1)
# Adaptive Random Search (ARS, just a few samples here)
rs.output <- poped_optim(poped.db,opt_xt=T,method = "ARS",
control = list(ARS=list(iter=5)))
get_rse(rs.output$FIM,rs.output$poped.db)
# line search, DOSE and sample time optimization
ls.output <- poped_optim(poped.db,opt_xt=T,opt_a=T,method = "LS",
control = list(LS=list(line_length=5)))
# Adaptive random search,
# DOSE and sample time optimization
ars.output <- poped_optim(poped.db,opt_xt=T,opt_a=T,method = "ARS",
control = list(ARS=list(iter=5)))
# BFGS gradient search from the stats::optim() function,
# DOSE and sample time optimization
bfgs.output <- poped_optim(poped.db,opt_xt=T,opt_a=T,method = "BFGS",
control = list(BFGS=list(maxit=5)))
# genetic algorithm from the GA::ga() function,
# DOSE and sample time optimization
ga.output <- poped_optim(poped.db,opt_xt=T,opt_a=F,method = "GA",parallel=T)
# cost function with GA
# maximize
out_2 <- poped_optim(poped.db,opt_a =TRUE,
ofv_fun=crit_fcn,
parallel = T,
method=c("GA"))
# cost function with GA
# minimize
out_2 <- poped_optim(poped.db,opt_a =TRUE,
ofv_fun=crit_fcn,
parallel = T,
method=c("GA"),
iter_max = 1,
maximize = F,
evaluate_fim = F)
# optimize distribution of individuals in 3 groups
poped_db_2 <- create.poped.database(ff_fun=ff.PK.1.comp.oral.sd.CL,
fg_fun=sfg,
fError_fun=feps.add.prop,
bpop=c(CL=0.15, V=8, KA=1.0, Favail=1),
notfixed_bpop=c(1,1,1,0),
d=c(CL=0.07, V=0.02, KA=0.6),
sigma=c(prop=0.01,add=0.25),
groupsize=32,
m=3,
xt=list(c( 0.5,1,2,6,8),c(36,72,120),
c(10,12,14,16,18,20,22,24)),
minxt=0.01,
maxxt=120,
a=c(DOSE=70),
mina=c(DOSE=0.01),
maxa=c(DOSE=100))
opt_xt_inds <-
poped_optim(poped_db_2,
opt_a =TRUE,
opt_inds = TRUE,
control = list(ARS=list(iter=2),
BFGS=list(maxit=2),
LS=list(line_length=2)),
iter_max = 1)
##############
# E-family Optimization
##############
# 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=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),
groupsize=32,
xt=c( 0.5,1,2,6,24,36,72,120),
minxt=0,
maxxt=120,
a=70,
mina=0,
maxa=100)
# E_ln(D) optimization using Random search (just a few samples here)
output <- poped_optim(poped.db,opt_xt=TRUE,opt_a=TRUE,d_switch=0,
method = c("ARS","LS"),
control = list(ARS=list(iter=2),
LS=list(line_length=2)),
iter_max = 1)
get_rse(output$FIM,output$poped.db)
# ED with laplace approximation,
# optimization using Random search (just a few iterations here)
ars.output <- poped_optim(poped.db,opt_xt=T,opt_a=T,method = "ARS",
d_switch=0,use_laplace=TRUE,#laplace.fim=TRUE,
parallel=T,
control = list(ARS=list(iter=5)))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.