-
Notifications
You must be signed in to change notification settings - Fork 21
/
poped_optim_3.R
642 lines (554 loc) · 27.6 KB
/
poped_optim_3.R
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
#' Optimization main module for PopED
#'
#' Optimize the objective function. The function works for both discrete and
#' continuous optimization variables. If more than one optimization method is
#' specified then the methods are run in series. If \code{loop_methods=TRUE}
#' then the series of optimization methods will be run for \code{iter_max}
#' iterations, or until the efficiency of the design after the current series
#' (compared to the start of the series) is less than \code{stop_crit_eff}.
#'
#' 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.
#'
#' @inheritParams RS_opt
#' @inheritParams Doptim
#' @inheritParams create.poped.database
#' @inheritParams Dtrace
#' @inheritParams calc_ofv_and_fim
#' @inheritParams optim_LS
#' @param ... arguments passed to other functions.
#' @param control Contains control arguments specified for each method separately.
#' @param method A vector of optimization methods to use in a sequential
#' fashion. Options are \code{c("ARS","BFGS","LS","GA")}. \code{c("ARS")} is
#' for Adaptive Random Search \code{\link{optim_ARS}}. \code{c("LS")} is for
#' Line Search \code{\link{optim_LS}}. \code{c("BFGS")} is for Method
#' "L-BFGS-B" from \code{\link[stats]{optim}}. \code{c("GA")} is for the
#' genetic algorithm from \code{\link[GA]{ga}}. If \code{opt_inds=TRUE} then
#' this optimization is always added to the end of the sequential optimization.
#' @param out_file Save output from the optimization to a file.
#' @param loop_methods Should the optimization methods be looped for
#' \code{iter_max} iterations, or until the efficiency of the design after the
#' current series (compared to the start of the series) is less than, or equal to,
#' \code{stop_crit_eff}?
#' @param stop_crit_eff If \code{loop_methods==TRUE}, the looping will stop if the
#' efficiency of the design after the current series (compared to the start of
#' the series) is less than, or equal to, \code{stop_crit_eff} (if \code{maximize==FALSE} then 1/stop_crit_eff is the cut
#' off and the efficiency must be greater than or equal to this value to stop the looping).
#' @param stop_crit_diff If \code{loop_methods==TRUE}, the looping will stop if the
#' difference in criterion value of the design after the current series (compared to the start of
#' the series) is less than, or equal to, \code{stop_crit_diff} (if \code{maximize==FALSE} then -stop_crit_diff is the cut
#' off and the difference in criterion value must be greater than or equal to this value to stop the looping).
#' @param stop_crit_rel If \code{loop_methods==TRUE}, the looping will stop if the
#' relative difference in criterion value of the design after the current series (compared to the start of
#' the series) is less than, or equal to, \code{stop_crit_rel} (if \code{maximize==FALSE} then -stop_crit_rel is the cut
#' off and the relative difference in criterion value must be greater than or equal to this value to stop the looping).
#' @param maximize Should the objective function be maximized or minimized?
#'
#'
#'
#' @references \enumerate{ \item 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. \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. }
#'
#' @family Optimize
#'
#' @keywords internal
# @example tests/testthat/examples_fcn_doc/warfarin_optimize.R
# @example tests/testthat/examples_fcn_doc/examples_poped_optim.R
# @export
poped_optim_3 <- function(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,
ds_index=poped.db$parameters$ds_index,
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,
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,
...){
#------------ update poped.db with options supplied in function
called_args <- match.call()
default_args <- formals()
for(i in names(called_args)[-1]){
if(length(grep("^poped\\.db\\$",capture.output(default_args[[i]])))==1) {
#eval(parse(text=paste(capture.output(default_args[[i]]),"<-",called_args[[i]])))
eval(parse(text=paste(capture.output(default_args[[i]]),"<-",i)))
}
}
#------------- initialization
fmf = 0 #The best FIM so far
dmf = 0 #The best ofv of FIM so far
#output <-calc_ofv_and_fim(poped.db,...)
#--------------------- Header information
## only for header information
if(is.null(ofv_fun) || is.function(ofv_fun)){
ofv_fun_user <- ofv_fun
} else {
# source explicit file
# here I assume that function in file has same name as filename minus .txt and pathnames
if(file.exists(as.character(ofv_fun))){
source(as.character(ofv_fun))
ofv_fun_user <- eval(parse(text=fileparts(ofv_fun)[["filename"]]))
} else {
stop("ofv_fun is not a function or NULL, and no file with that name was found")
}
}
if(!is.null(ofv_fun)){
poped.db$settings$ofv_calc_type = 0
ofv_calc_type = 0
}
output <-calc_ofv_and_fim(poped.db,d_switch=d_switch,
ED_samp_size=ED_samp_size,
bLHS=bLHS,
use_laplace=use_laplace,
ofv_calc_type=ofv_calc_type,
fim.calc.type=fim.calc.type,
ofv_fun = ofv_fun_user,
...)
fmf <- output$fim
dmf <- output$ofv
fmf_init <- fmf
dmf_init <- dmf
poped.db_init <- poped.db
if(is.nan(dmf_init)) stop("Objective function of initial design is NaN")
fn=blockheader(poped.db,name="optim",e_flag=!d_switch,
fmf=fmf_init,dmf=dmf_init,
out_file=out_file,
trflag=trace,
...)
# handle optimization of n distribution
if(opt_inds){
if(poped.db$design$m==1){
message("There is only one group, so proportions of individuals in each group cannot be optimized\n")
opt_inds <- FALSE
} else{
method <- c(method,"opt_n_dist")
if(missing(loop_methods) & (length(method)>1)) loop_methods <- TRUE
opt_inds <- FALSE
}
}
#------------ optimize
if(!(fn=="")) sink(fn, append=TRUE, split=TRUE)
iter <- 0
stop_crit <- FALSE
output$ofv <- dmf_init
while(stop_crit==FALSE && iter < iter_max){
ofv_init <- output$ofv
iter=iter+1
method_loop <- method
if(loop_methods){
cat("************* Iteration",iter," for all optimization methods***********************\n\n")
}
while(length(method_loop)>0){
cur_meth <- method_loop[1]
method_loop <- method_loop[-1]
if(!(cur_meth %in% c("ARS","LS","GA","BFGS","opt_n_dist")))
stop("Current method ", cur_meth, " not defined")
if(cur_meth=="ARS"){
cat("*******************************************\n")
cat("Running Adaptive Random Search Optimization\n")
cat("*******************************************\n")
# Get parameters and space
ps_tbl <- get_par_and_space_optim(poped.db,
opt_xt=opt_xt,
opt_a=opt_a,
opt_x=opt_x,
opt_samps=opt_samps,
opt_inds=opt_inds,
transform_parameters=F)
# handle control arguments
con <- list(trace = trace,
parallel=parallel,
parallel_type=parallel_type,
num_cores = num_cores)
con[names(control$ARS)] <- control$ARS
# handle replicates
if(!allow_replicates)
con$replicates_index=ps_tbl$type
if(!allow_replicates_xt | !allow_replicates_a)
con$replicates_index <- seq(1,length(ps_tbl$par))
if(!allow_replicates_xt)
con$replicates_index[ps_tbl$type=="xt"]="xt"
if(!allow_replicates_a)
con$replicates_index[ps_tbl$type=="a"]="a"
tmp_ofv_fun <- function(par,...){
ofv_optim(par,ps_tbl,poped.db,
d_switch=d_switch,
ED_samp_size=ED_samp_size,
bLHS=bLHS,
use_laplace=use_laplace,
ofv_calc_type=ofv_calc_type,
fim.calc.type=fim.calc.type,
ofv_fun = ofv_fun_user,
...)}
output <-
do.call(optim_ARS,
c(list(par=ps_tbl$par,
fn=tmp_ofv_fun,
lower=ps_tbl$lower,
upper=ps_tbl$upper,
allowed_values = ps_tbl$allowed_values,
maximize=maximize),
con,
list(...)))
poped.db <- add_to_poped_db(poped.db, ps_tbl, par = output$par)
}
if(cur_meth=="LS"){
cat("*******************************************\n")
cat("Running Line Search Optimization\n")
cat("*******************************************\n")
# Get parameters and space
ps_tbl <- get_par_and_space_optim(poped.db,
opt_xt=opt_xt,
opt_a=opt_a,
opt_x=opt_x,
opt_samps=opt_samps,
opt_inds=opt_inds,
transform_parameters=F)
# handle control arguments
con <- list(trace = trace,
parallel=parallel,
parallel_type=parallel_type,
num_cores = num_cores)
con[names(control$LS)] <- control$LS
# handle replicates
if(!allow_replicates)
con$replicates_index=ps_tbl$type
if(!allow_replicates_xt | !allow_replicates_a)
con$replicates_index <- seq(1,length(ps_tbl$par))
if(!allow_replicates_xt)
con$replicates_index[ps_tbl$type=="xt"]="xt"
if(!allow_replicates_a)
con$replicates_index[ps_tbl$type=="a"]="a"
tmp_ofv_fun <- function(par,...){ofv_optim(par,ps_tbl,poped.db,
d_switch=d_switch,
ED_samp_size=ED_samp_size,
bLHS=bLHS,
use_laplace=use_laplace,
ofv_calc_type=ofv_calc_type,
fim.calc.type=fim.calc.type,
ofv_fun = ofv_fun_user,
...)}
output <-
do.call(optim_LS,
c(list(par=ps_tbl$par,
fn=tmp_ofv_fun,
lower=ps_tbl$lower,
upper=ps_tbl$upper,
allowed_values = ps_tbl$allowed_values,
maximize=maximize
),
con,
list(...)))
poped.db <- add_to_poped_db(poped.db, ps_tbl, par = output$par)
}
if(cur_meth=="BFGS"){
cat("*******************************************\n")
cat("Running BFGS Optimization\n")
cat("*******************************************\n")
# Get parameters and space
ps_tbl <- get_par_and_space_optim(poped.db,
opt_xt=opt_xt,
opt_a=opt_a,
opt_x=opt_x,
opt_samps=opt_samps,
opt_inds=opt_inds,
transform_parameters=T,
cont_cat = "cont",
warn_when_none=F)
if(nrow(ps_tbl)==0){
cat("\nNo continuous variables to optimize, BFGS Optimization skipped\n\n")
next
}
if(!allow_replicates_xt | !allow_replicates_a | !allow_replicates){
msg <- stringr::str_glue(
'One or more of allow_replicates, allow_replicates_a, allow_replicates_xt are set to FALSE ',
'with design parameters that will be optimized accross a continuous space. ',
'These options will be ignored for this optimization method and the ',
'continuous optimization parameters.'
)
message(msg)
}
if(trace) trace_optim=3
if(is.numeric(trace)) trace_optim = trace
#if(trace==2) trace_optim = 4
#if(trace==3) trace_optim = 5
#if(trace==4) trace_optim = 6
# handle control arguments
con <- list(trace=trace_optim)
nmsC <- names(con)
con[(namc <- names(control$BFGS))] <- control$BFGS
fnscale=-1
if(!maximize) fnscale=1
if(is.null(con[["fnscale"]])) con$fnscale <- fnscale
#if (length(noNms <- namc[!namc %in% nmsC])) warning("unknown names in control: ", paste(noNms, collapse = ", "))
tmp_ofv_fun <- function(par,...){ofv_optim(par,ps_tbl,poped.db,
d_switch=d_switch,
ED_samp_size=ED_samp_size,
bLHS=bLHS,
use_laplace=use_laplace,
ofv_calc_type=ofv_calc_type,
fim.calc.type=fim.calc.type,
ofv_fun = ofv_fun_user,
...)}
output <- optim(par=ps_tbl$par,
fn=tmp_ofv_fun,
gr=NULL,
...,
#par_full=par_full,
# only_cont=T,
method = "BFGS",
control=con)
output$ofv <- output$value
poped.db <- add_to_poped_db(poped.db, ps_tbl, par=output$par)
fprintf('\n')
if(fn!="") fprintf(fn,'\n')
}
if(cur_meth=="GA"){
cat("*******************************************\n")
cat("Running Genetic Algorithm (GA) Optimization\n")
cat("*******************************************\n")
if (!requireNamespace("GA", quietly = TRUE)) {
stop("GA package needed for this function to work. Please install it.",
call. = FALSE)
}
# Get parameters and space
ps_tbl <- get_par_and_space_optim(poped.db,
opt_xt=opt_xt,
opt_a=opt_a,
opt_x=opt_x,
opt_samps=opt_samps,
opt_inds=opt_inds,
transform_parameters=F,
cont_cat = "cont",
warn_when_none=F)
if(nrow(ps_tbl)==0){
cat("\nNo continuous variables to optimize, GA Optimization skipped\n\n")
next
}
if(!allow_replicates_xt | !allow_replicates_a | !allow_replicates){
msg <- stringr::str_glue(
'One or more of allow_replicates, allow_replicates_a, allow_replicates_xt are set to FALSE ',
'with design parameters that will be optimized accross a continuous space. ',
'These options will be ignored for this optimization method and the ',
'continuous optimization parameters.'
)
message(msg)
}
# handle control arguments
parallel_ga <- parallel
if(!is.null(num_cores)) parallel_ga <- num_cores
if(!is.null(parallel_type)) parallel_ga <- parallel_type
con <- list(parallel=parallel_ga)
#dot_vals <- dots(...)
#if(is.null(dot_vals[["monitor"]])){
#if(packageVersion("GA")>="3.0.2" && packageVersion("GA")<"3.1.1") con$monitor <- GA::gaMonitor2
#if(packageVersion("GA")>="3.1.1") con$monitor <- GA::gaMonitor
#}
nmsC <- names(con)
con[(namc <- names(control$GA))] <- control$GA
#if (length(noNms <- namc[!namc %in% nmsC])) warning("unknown names in control: ", paste(noNms, collapse = ", "))
tmp_ofv_fun <- function(par,...){ofv_optim(par,ps_tbl,poped.db,
d_switch=d_switch,
ED_samp_size=ED_samp_size,
bLHS=bLHS,
use_laplace=use_laplace,
ofv_calc_type=ofv_calc_type,
fim.calc.type=fim.calc.type,
ofv_fun = ofv_fun_user,
...)}
if(!maximize) tmp_ofv_fun <- function(par,...){-ofv_optim(par,ps_tbl,poped.db,
d_switch=d_switch,
ED_samp_size=ED_samp_size,
bLHS=bLHS,
use_laplace=use_laplace,
ofv_calc_type=ofv_calc_type,
fim.calc.type=fim.calc.type,
ofv_fun = ofv_fun_user,
...)}
if(packageVersion("GA")<"3.1.1")
output_ga <- do.call(GA::ga,c(list(type = "real-valued",
fitness = tmp_ofv_fun,
#par_full=par_full,
# only_cont=T,
min=ps_tbl$lower,
max=ps_tbl$upper,
suggestions=ps_tbl$par),
#allowed_values = allowed_values),
con,
list(...)))
if(packageVersion("GA")>="3.1.1")
output_ga <- do.call(GA::ga,c(list(type = "real-valued",
fitness = tmp_ofv_fun,
#par_full=par_full,
# only_cont=T,
lower=ps_tbl$lower,
upper=ps_tbl$upper,
suggestions=ps_tbl$par),
#allowed_values = allowed_values),
con,
list(...)))
output$ofv <- output_ga@fitnessValue
if(!maximize) output$ofv <- -output$ofv
output$par <- output_ga@solution
poped.db <- add_to_poped_db(poped.db, ps_tbl, par=output$par)
fprintf('\n')
if(fn!="") fprintf(fn,'\n')
}
if(cur_meth=="opt_n_dist"){
cat("*******************************************\n")
cat("Running distribution of individuals optimization\n")
cat("*******************************************\n")
# Get parameters and space
# ps_tbl <- get_par_and_space_optim(poped.db,
# opt_xt=opt_xt,
# opt_a=opt_a,
# opt_x=opt_x,
# opt_samps=opt_samps,
# opt_inds=opt_inds,
# transform_parameters=F,
# cont_cat = "cont",
# warn_when_none=F)
#
# handle control arguments
con <- control$opt_n_dist
output_opt_n_dist <- do.call(optimize_groupsize,
c(list(poped.db=poped.db),
con,
list(...)))
poped.db <- create.poped.database(poped.db,
groupsize = output_opt_n_dist$opt_n_per_group,
mingroupsize = output_opt_n_dist$opt_n_per_group,
maxgroupsize = output_opt_n_dist$opt_n_per_group)
fprintf('\n')
if(fn!="") fprintf(fn,'\n')
}
}
if(!loop_methods){
stop_crit <- TRUE
} else {
cat("*******************************************\n")
cat("Stopping criteria testing\n")
cat("(Compare between start of iteration and end of iteration)\n")
cat("*******************************************\n")
# relative difference
rel_diff <- (output$ofv - ofv_init)/abs(ofv_init)
abs_diff <- (output$ofv - ofv_init)
fprintf("Difference in OFV: %.3g\n",abs_diff)
fprintf("Relative difference in OFV: %.3g%%\n",rel_diff*100)
# efficiency
eff <- efficiency(ofv_init, output$ofv, poped.db,...)
fprintf("Efficiency: \n (%s) = %.5g\n",attr(eff,"description"),eff)
#cat("Efficiency: \n ", attr(eff,"description"), sprintf("%.5g",eff), "\n")
#if(eff<=stop_crit_eff) stop_crit <- TRUE
#cat("eff: ",sprintf("%.3g",(output$ofv - ofv_init)/p), "\n")
#cat("eff: ",sprintf("%.3g",(exp(output$ofv)/exp(ofv_init))^(1/p)), "\n")
compare <-function(crit,crit_stop,maximize,inv=FALSE,neg=FALSE,text=""){
if(is.null(crit_stop)){
#cat(" Stopping criteria not defined\n")
return(FALSE)
}
cat("\n",text,"\n")
if(is.nan(crit)){
fprintf(" Stopping criteria using 'NaN' as a comparitor cannot be used\n")
return(FALSE)
}
comparitor <- "<="
if(!maximize) comparitor <- ">="
if(inv) crit_stop <- 1/crit_stop
if(neg) crit_stop <- -crit_stop
fprintf(" Is (%0.5g %s %0.5g)? ",crit,comparitor,crit_stop)
res <- do.call(comparitor,list(crit,crit_stop))
if(res) cat(" Yes.\n Stopping criteria achieved.\n")
if(!res) cat(" No.\n Stopping criteria NOT achieved.\n")
return(res)
#if(maximize) cat("Efficiency stopping criteria (lower limit) = ",crit_stop, "\n")
#if(!maximize) cat("Efficiency stopping criteria (upper limit) = ",1/crit_stop, "\n")
#if(maximize) return(crit <= crit_stop)
#if(!maximize) return(crit >= 1/crit_stop)
}
if(all(is.null(c(stop_crit_eff,stop_crit_rel,stop_crit_diff)))){
cat("No stopping criteria defined")
} else {
stop_eff <- compare(eff,stop_crit_eff,maximize,inv=!maximize,
text="Efficiency stopping criteria:")
stop_abs <- compare(abs_diff,stop_crit_diff,maximize,neg=!maximize,
text="OFV difference stopping criteria:")
stop_rel <- compare(rel_diff,stop_crit_rel,maximize,neg=!maximize,
text="Relative OFV difference stopping criteria:")
if(stop_eff || stop_rel || stop_abs) stop_crit <- TRUE
if(stop_crit){
cat("\nStopping criteria achieved.\n")
} else {
cat("\nStopping criteria NOT achieved.\n")
}
cat("\n")
}
}
} # end of total loop
if(!(fn=="")) sink()
FIM <-calc_ofv_and_fim(poped.db,
ofv=output$ofv,
fim=0,
d_switch=d_switch,
ED_samp_size=ED_samp_size,
bLHS=bLHS,
use_laplace=use_laplace,
ofv_calc_type=ofv_calc_type,
fim.calc.type=fim.calc.type,
ofv_fun = ofv_fun_user,
...)[["fim"]]
if(use_laplace) poped.db$settings$ofv_calc_type <- 1
time_value <-
blockfinal(fn=fn,fmf=FIM,
dmf=output$ofv,
groupsize=poped.db$design$groupsize,
ni=poped.db$design$ni,
xt=poped.db$design$xt,
x=poped.db$design$x,
a=poped.db$design$a,
model_switch=poped.db$design$model_switch,
poped.db$parameters$param.pt.val$bpop,
poped.db$parameters$param.pt.val$d,
poped.db$parameters$docc,
poped.db$parameters$param.pt.val$sigma,
poped.db,
fmf_init=fmf_init,
dmf_init=dmf_init,
...)
# }
#}
results <- list( ofv= output$ofv, FIM=FIM, initial=list(ofv=dmf_init, FIM=fmf_init, poped.db=poped.db_init),
run_time=time_value, poped.db = poped.db )
class(results) <- "poped_optim"
return(invisible(results))
}