/
create.poped.database.R
1395 lines (1257 loc) · 74.3 KB
/
create.poped.database.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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#' Create a PopED database
#'
#' This function takes the input file (a previously created poped database) supplied by the user, or function arguments,
#' and creates a database that can then be used to
#' run all other PopED functions. The function supplies default values to elements of the
#' database that are not specified in the
#' input file or as function arguments. Default arguments are supplied in the Usage section
#' (easiest to use a text search to find values you are interested in).
#'
#' @inheritParams create_design_space
#' @param popedInput A PopED database file or an empty list \code{list()}. List elements should match the values seen in
#' the Usage section (the defaults to function arguments).
#' @param ff_file \itemize{
#' \item \bold{******START OF MODEL DEFINITION OPTIONS**********}
#' }
#' A string giving the function name or filename and path of the structural model.
#' The filename and the function name must be the same if giving a filename.
#' e.g. \code{"ff.PK.1.comp.oral.md.KE"}
#' @param ff_fun Function describing the structural model. e.g. \code{ff.PK.1.comp.oral.md.KE}.
#' @param fg_file A string giving the function name or filename and path of the
#' parameter model.
#' The filename and the function name must be the same if giving a filename.
#' e.g. \code{"parameter.model"}
#' @param fg_fun Function describing the parameter model. e.g. \code{parameter.model}.
#' @param fError_file A string giving the function name or filename and path of the
#' residual error model.
#' The filename and the function name must be the same if giving a filename.
#' e.g. \code{"feps.prop"}.
#' @param fError_fun Function describing the residual error model. e.g. \code{feps.prop}.
#'
#' @param optsw \itemize{
#' \item \bold{******WHAT TO OPTIMIZE**********}}
#' Row vector of optimization tasks (1=TRUE,0=FALSE) in the following order:
#' (Samples per subject, Sampling schedule, Discrete design variable, Continuous design variable, Number of id per group).
#' All elements set to zero => only calculate the FIM with current design
#'
#'
#' @param xt \itemize{
#' \item \bold{******START OF INITIAL DESIGN OPTIONS**********}}
#' Matrix defining the initial sampling schedule.
#' Each row is a group/individual.
#' If only one vector is supplied, e.g. \code{c(1,2,3,4)}, then all groups will
#' have the same initial design.
#' @param m Number of groups in the study. Each individual in a group will have the same design.
#' @param x A matrix defining the initial discrete values for the model
#' Each row is a group/individual.
#' @param nx Number of discrete design variables.
#' @param a Matrix defining the initial continuous covariate values.
#' n_rows=number of groups, n_cols=number of covariates.
#' If the number of rows is one and the number of groups > 1 then all groups are assigned the
#' same values.
# @param na The number of covariates in the model.
#' @param groupsize Vector defining the size of the different groups (num individuals in each group).
#' If only one number then the number will be the same in every group.
#' @param ni Vector defining the number of samples for each group.
#' @param model_switch Matrix defining which response a certain sampling time belongs to.
#'
#'
#' @param maxni \itemize{
#' \item \bold{******START OF DESIGN SPACE OPTIONS**********}}
#' Max number of samples per group/individual
#' @param minni Min number of samples per group/individual
#' @param maxgroupsize Vector defining the max size of the different groups (max number of individuals in each group)
#' @param mingroupsize Vector defining the min size of the different groups (min num individuals in each group) --
#' @param maxtotgroupsize The total maximal groupsize over all groups
#' @param mintotgroupsize The total minimal groupsize over all groups
#' @param maxxt Matrix or single value defining the maximum value for each xt sample. If a single value is
#' supplied then all xt values are given the same maximum value.
#' @param minxt Matrix or single value defining the minimum value for each xt sample. If a single value is
#' supplied then all xt values are given the same minimum value
#' @param discrete_x Cell array defining the discrete variables for each x value.
#' See examples in \code{\link{create_design_space}}.
#' @param discrete_xt Cell array \code{\link{cell}} defining the discrete variables allowed for each xt value.
#' Can also be a list of values \code{list(1:10)} (same values allowed for all xt), or a list of lists
#' \code{list(1:10, 2:23, 4:6)} (one for each value in xt). See examples in \code{\link{create_design_space}}.
#' @param discrete_a Cell array \code{\link{cell}} defining the discrete variables allowed for each a value.
#' Can also be a list of values \code{list(1:10)} (same values allowed for all a), or a list of lists
#' \code{list(1:10, 2:23, 4:6)} (one for each value in a). See examples in \code{\link{create_design_space}}.
#' @param maxa Vector defining the max value for each covariate. If a single value is supplied then
#' all a values are given the same max value
#' @param mina Vector defining the min value for each covariate. If a single value is supplied then
#' all a values are given the same max value
#' @param bUseGrouped_xt Use grouped time points (1=TRUE, 0=FALSE).
#' @param G_xt Matrix defining the grouping of sample points. Matching integers mean that the points are matched.
#' @param bUseGrouped_a Use grouped covariates (1=TRUE, 0=FALSE)
#' @param G_a Matrix defining the grouping of covariates. Matching integers mean that the points are matched.
#' @param bUseGrouped_x Use grouped discrete design variables (1=TRUE, 0=FALSE).
#' @param G_x Matrix defining the grouping of discrete design variables. Matching integers mean that the points are matched.
#' @param iFIMCalculationType \itemize{
#' \item \bold{******START OF FIM CALCULATION OPTIONS**********}}
#' Fisher Information Matrix type
#' \itemize{
#' \item 0=Full FIM
#' \item 1=Reduced FIM
#' \item 2=weighted models
#' \item 3=Loc models
#' \item 4=reduced FIM with derivative of SD of sigma as in PFIM
#' \item 5=FULL FIM parameterized with A,B,C matrices & derivative of variance
#' \item 6=Calculate one model switch at a time, good for large matrices
#' \item 7=Reduced FIM parameterized with A,B,C matrices & derivative of variance
#' }
#'
#' @param iApproximationMethod Approximation method for model, 0=FO, 1=FOCE, 2=FOCEI, 3=FOI
#' @param iFOCENumInd Num individuals in each step of FOCE
#' @param prior_fim The prior FIM (added to calculated FIM)
#' @param strAutoCorrelationFile Filename and path, or function name, for the Autocorrelation function,
#' empty string means no autocorrelation.
#' @param d_switch \itemize{
#' \item \bold{******START OF CRITERION SPECIFICATION OPTIONS**********}}
#' D-family design (1) or ED-family design (0) (with or without parameter uncertainty)
#' @param ofv_calc_type OFV calculation type for FIM
#' \itemize{
#' \item 1 = "D-optimality". Determinant of the FIM: det(FIM)
#' \item 2 = "A-optimality". Inverse of the sum of the expected parameter variances:
#' 1/trace_matrix(inv(FIM))
#' \item 4 = "lnD-optimality". Natural logarithm of the determinant of the FIM: log(det(FIM))
#' \item 6 = "Ds-optimality". Ratio of the Determinant of the FIM and the Determinant of the uninteresting
#' rows and columns of the FIM: det(FIM)/det(FIM_u)
#' \item 7 = Inverse of the sum of the expected parameter RSE: 1/sum(get_rse(FIM,poped.db,use_percent=FALSE))
#' }
#' @param ds_index Ds_index is a vector set to 1 if a parameter is uninteresting, otherwise 0.
#' size=(1,num unfixed parameters). First unfixed bpop, then unfixed d, then unfixed docc and last unfixed sigma.
#' Default is the fixed effects being important, everything else not important. Used in conjunction with
#' \code{ofv_calc_type=6}.
#' @param strEDPenaltyFile Penalty function name or path and filename, empty string means no penalty.
#' User defined criterion can be defined this way.
#' @param 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.
#' @param iEDCalculationType \itemize{
#' \item \bold{******START OF E-FAMILY CRITERION SPECIFICATION OPTIONS**********}}
#' ED Integral Calculation, 0=Monte-Carlo-Integration, 1=Laplace Approximation, 2=BFGS Laplace Approximation -- --
#' @param ED_samp_size Sample size for E-family sampling
#' @param bLHS How to sample from distributions in E-family calculations. 0=Random Sampling, 1=LatinHyperCube --
#' @param strUserDistributionFile Filename and path, or function name, for user defined distributions for E-family designs
#' @param nbpop \itemize{
#' \item \bold{******START OF Model parameters SPECIFICATION OPTIONS**********}}
#' Number of typical values
#' @param NumRanEff Number of IIV parameters. Typically can be computed from other values and not supplied.
#' @param NumDocc Number of IOV variance parameters. Typically can be computed from other values and not supplied.
#' @param NumOcc Number of occasions. Typically can be computed from other values and not supplied.
# @param ng The length of the g parameter vector. Typically can be computed from other values and not supplied.
#' @param bpop Matrix defining the fixed effects, per row (row number = parameter_number) we should have:
#' \itemize{
#' \item column 1 the type of the distribution for E-family designs (0 = Fixed, 1 = Normal, 2 = Uniform,
#' 3 = User Defined Distribution, 4 = lognormal and 5 = truncated normal)
#' \item column 2 defines the mean.
#' \item column 3 defines the variance of the distribution (or length of uniform distribution).
#' }
#' Can also just supply the parameter values as a vector \code{c()} if no uncertainty around the
#' parameter value is to be used. The parameter order of 'bpop' is defined in the 'fg_fun' or 'fg_file'. If you use named
#' arguments in 'bpop' then the order will be worked out automatically.
#' @param d Matrix defining the diagonals of the IIV (same logic as for the fixed effects
#' matrix bpop to define uncertainty). One can also just supply the parameter values as a \code{c()}.
#' The parameter order of 'd' is defined in the 'fg_fun' or 'fg_file'. If you use named
#' arguments in 'd' then the order will be worked out automatically.
#' @param covd Column major vector defining the covariances of the IIV variances.
#' That is, from your full IIV matrix \code{covd <- IIV[lower.tri(IIV)]}.
#' @param sigma Matrix defining the variances can covariances of the residual variability terms of the model.
#' can also just supply the diagonal parameter values (variances) as a \code{c()}.
#' @param docc Matrix defining the IOV, the IOV variances and the IOV distribution as for d and bpop.
#' @param covdocc Column major vector defining the covariance of the IOV, as in covd.
#' @param notfixed_bpop \itemize{
#' \item \bold{******START OF Model parameters fixed or not SPECIFICATION OPTIONS**********}}
#' Vector defining if a typical value is fixed or not (1=not fixed, 0=fixed).
#' The parameter order of 'notfixed_bpop' is defined in the 'fg_fun' or 'fg_file'. If you use named
#' arguments in 'notfixed_bpop' then the order will be worked out automatically.
#' @param notfixed_d Vector defining if a IIV is fixed or not (1=not fixed, 0=fixed).
#' The parameter order of 'notfixed_d' is defined in the 'fg_fun' or 'fg_file'. If you use named
#' arguments in 'notfixed_d' then the order will be worked out automatically.
#' @param notfixed_covd Vector defining if a covariance IIV is fixed or not (1=not fixed, 0=fixed)
#' @param notfixed_docc Vector defining if an IOV variance is fixed or not (1=not fixed, 0=fixed)
#' @param notfixed_covdocc Vector row major order for lower triangular matrix defining if a covariance IOV is fixed or not (1=not fixed, 0=fixed)
#' @param notfixed_sigma Vector defining if a residual error parameter is fixed or not (1=not fixed, 0=fixed)
#' @param notfixed_covsigma Vector defining if a covariance residual error parameter is fixed or not (1=not fixed, 0=fixed).
#' Default is fixed.
#'
#' @param bUseRandomSearch \itemize{
#' \item \bold{******START OF Optimization algorithm SPECIFICATION OPTIONS**********}}
#' Use random search (1=TRUE, 0=FALSE)
#' @param bUseStochasticGradient Use Stochastic Gradient search (1=TRUE, 0=FALSE)
#' @param bUseLineSearch Use Line search (1=TRUE, 0=FALSE)
#' @param bUseExchangeAlgorithm Use Exchange algorithm (1=TRUE, 0=FALSE)
#' @param bUseBFGSMinimizer Use BFGS Minimizer (1=TRUE, 0=FALSE)
#' @param EACriteria Exchange Algorithm Criteria, 1 = Modified, 2 = Fedorov
#' @param strRunFile Filename and path, or function name, for a run file that is used instead of the regular PopED call.
#' @param poped_version \itemize{
#' \item \bold{******START OF Labeling and file names SPECIFICATION OPTIONS**********}}
#' The current PopED version
#' @param modtit The model title
#' @param output_file Filename and path of the output file during search
#' @param output_function_file Filename suffix of the result function file
#' @param strIterationFileName Filename and path for storage of current optimal design
#' @param user_data \itemize{
#' \item \bold{******START OF Miscellaneous SPECIFICATION OPTIONS**********}}
#' User defined data structure that, for example could be used to send in data to the model
#' @param ourzero Value to interpret as zero in design
#' @param dSeed The seed number used for optimization and sampling -- integer or -1 which creates a random seed \code{as.integer(Sys.time())} or NULL.
#' @param line_opta Vector for line search on continuous design variables (1=TRUE,0=FALSE)
#' @param line_optx Vector for line search on discrete design variables (1=TRUE,0=FALSE)
#' @param bShowGraphs Use graph output during search
#' @param use_logfile If a log file should be used (0=FALSE, 1=TRUE)
#' @param m1_switch Method used to calculate M1
#' (0=Complex difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation)
#' @param m2_switch Method used to calculate M2
#' (0=Central difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation)
#' @param hle_switch Method used to calculate linearization of residual error
#' (0=Complex difference, 1=Central difference, 30=Automatic differentiation)
#' @param gradff_switch Method used to calculate the gradient of the model
#' (0=Complex difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation)
#' @param gradfg_switch Method used to calculate the gradient of the parameter vector g
#' (0=Complex difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation)
#' @param grad_all_switch Method used to calculate all the gradients
#' (0=Complex difference, 1=Central difference)
#' @param rsit_output Number of iterations in random search between screen output
#' @param sgit_output Number of iterations in stochastic gradient search between screen output
#' @param hm1 Step length of derivative of linearized model w.r.t. typical values
#' @param hlf Step length of derivative of model w.r.t. g
#' @param hlg Step length of derivative of g w.r.t. b
#' @param hm2 Step length of derivative of variance w.r.t. typical values
#' @param hgd Step length of derivative of OFV w.r.t. time
#' @param hle Step length of derivative of model w.r.t. sigma
#' @param AbsTol The absolute tolerance for the diff equation solver
#' @param RelTol The relative tolerance for the diff equation solver
#' @param iDiffSolverMethod The diff equation solver method, NULL as default.
#' @param bUseMemorySolver If the differential equation results should be stored in memory (1) or not (0)
#' @param rsit Number of Random search iterations
#' @param sgit Number of stochastic gradient iterations
#' @param intrsit Number of Random search iterations with discrete optimization.
#' @param intsgit Number of Stochastic Gradient search iterations with discrete optimization
#' @param maxrsnullit Iterations until adaptive narrowing in random search
#' @param convergence_eps Stochastic Gradient convergence value,
#' (difference in OFV for D-optimal, difference in gradient for ED-optimal)
#' @param rslxt Random search locality factor for sample times
#' @param rsla Random search locality factor for covariates
#' @param cfaxt Stochastic Gradient search first step factor for sample times
#' @param cfaa Stochastic Gradient search first step factor for covariates
#' @param bGreedyGroupOpt Use greedy algorithm for group assignment optimization
#' @param EAStepSize Exchange Algorithm StepSize
#' @param EANumPoints Exchange Algorithm NumPoints
#' @param EAConvergenceCriteria Exchange Algorithm Convergence Limit/Criteria
#' @param bEANoReplicates Avoid replicate samples when using Exchange Algorithm
#' @param BFGSConvergenceCriteriaMinStep BFGS Minimizer Convergence Criteria Minimum Step
#' @param BFGSProjectedGradientTol BFGS Minimizer Convergence Criteria Normalized Projected Gradient Tolerance
#' @param BFGSTolerancef BFGS Minimizer Line Search Tolerance f
#' @param BFGSToleranceg BFGS Minimizer Line Search Tolerance g
#' @param BFGSTolerancex BFGS Minimizer Line Search Tolerance x
#' @param ED_diff_it Number of iterations in ED-optimal design to calculate convergence criteria
#' @param ED_diff_percent ED-optimal design convergence criteria in percent
#' @param line_search_it Number of grid points in the line search
#' @param Doptim_iter Number of iterations of full Random search and full Stochastic Gradient if line search is not used
#' @param iCompileOption \bold{******START OF PARALLEL OPTIONS**********} Compile options for PopED
#' \itemize{
#' \item -1 = No compilation,
#' \item 0 or 3 = Full compilation,
#' \item 1 or 4 = Only using MCC (shared lib),
#' \item 2 or 5 = Only MPI,
#' \item Option 0,1,2 runs PopED and option 3,4,5 stops after compilation
#' }
#'
#' @param iUseParallelMethod Parallel method to use (0 = Matlab PCT, 1 = MPI)
#' @param MCC_Dep Additional dependencies used in MCC compilation (mat-files), if several space separated
#' @param strExecuteName Compilation output executable name
#' @param iNumProcesses Number of processes to use when running in parallel (e.g. 3 = 2 workers, 1 job manager)
#' @param iNumChunkDesignEvals Number of design evaluations that should be evaluated in each process before getting new work from job manager
# @param strMatFileInputPrefix The prefix of the input mat file to communicate with the executable
#' @param Mat_Out_Pre The prefix of the output mat file to communicate with the executable
#' @param strExtraRunOptions Extra options send to e$g. the MPI executable or a batch script, see execute_parallel$m for more information and options
#' @param dPollResultTime Polling time to check if the parallel execution is finished
#' @param strFunctionInputName The file containing the popedInput structure that should be used to evaluate the designs
#' @param bParallelRS If the random search is going to be executed in parallel
#' @param bParallelSG If the stochastic gradient search is going to be executed in parallel
#' @param bParallelMFEA If the modified exchange algorithm is going to be executed in parallel
#' @param bParallelLS If the line search is going to be executed in parallel
#'
#' @return A PopED database
#' @family poped_input
#'
#' @example tests/testthat/examples_fcn_doc/examples_create.poped.database.R
#'
#' @export
# @importFrom mvtnorm rmvnorm
create.poped.database <-
function(popedInput=list(),
## --------------------------
## ---- Model definition
## --------------------------
# -- Filname and path of the model file --
ff_file=NULL,
ff_fun = poped.choose(popedInput$model$ff_pointer,NULL),
# -- Filname and path of the g parameter file --
fg_file=NULL,
fg_fun=poped.choose(popedInput$model$fg_pointer,NULL),
# -- Filname and path of the error model file --
fError_file=NULL,
fError_fun=poped.choose(popedInput$model$ferror_pointer,NULL),
## --------------------------
## ---- What to optimize
## --------------------------
## -- Vector of optimization tasks (1=TRUE,0=FALSE)
## (Samples per subject, Sampling schedule, Discrete design variable, Continuous design variable, Number of id per group)
## -- All elements set to zero => only calculate the FIM with current design --
optsw=poped.choose(popedInput$settings$optsw,cbind(0,0,0,0,0)),
## --------------------------
## ---- Initial Design
## --------------------------
## -- Matrix defining the initial sampling schedule --
xt=poped.choose(popedInput$design[["xt"]],stop("'xt' needs to be defined")),
## -- Number of groups/individuals --
#m=poped.choose(popedInput[["m"]],size(xt,1)),
m=poped.choose(popedInput$design[["m"]],NULL),
## -- Matrix defining the initial discrete values --
#x=poped.choose(popedInput$design[["x"]],zeros(m,0)),
x=poped.choose(popedInput$design[["x"]],NULL),
## -- Number of discrete design variables --
#nx=poped.choose(popedInput$nx,size(x,2)),
nx=poped.choose(popedInput$design$nx,NULL),
## -- Vector defining the initial covariate values --
#a=poped.choose(popedInput$design[["a"]],zeros(m,0)),
a=poped.choose(popedInput$design[["a"]],NULL),
## number of continuous design variables that are not time (e.g. continuous covariates)
#na=poped.choose(popedInput$na,size(a,2)),
#na=poped.choose(popedInput$na,NULL),
## -- Vector defining the size of the different groups (num individuals in each group) --
groupsize=poped.choose(popedInput$design$groupsize,stop("'groupsize' needs to be defined")),
## -- Vector defining the number of samples for each group --
#ni=poped.choose(popedInput$design$ni,matrix(size(xt,2),m,1)),
ni=poped.choose(popedInput$design$ni,NULL),
## -- Vector defining which response a certain sampling time belongs to --
#model_switch=poped.choose(popedInput$design$model_switch,ones(size(xt,1),size(xt,2))),
model_switch=poped.choose(popedInput$design$model_switch,NULL),
## --------------------------
## ---- Design space
## --------------------------
## -- Max number of samples per group/individual --
maxni=poped.choose(popedInput$design_space$maxni,NULL),
## -- Min number of samples per group/individual --
minni=poped.choose(popedInput$design_space$minni,NULL),
maxtotni=poped.choose(popedInput$design_space$maxtotni,NULL),
mintotni=poped.choose(popedInput$design_space$mintotni,NULL),
## -- Vector defining the max size of the different groups (max num individuals in each group) --
maxgroupsize=poped.choose(popedInput$design_space$maxgroupsize,NULL),
## -- Vector defining the min size of the different groups (min num individuals in each group) --
#mingroupsize=poped.choose(popedInput$design$mingroupsize,ones(m,1)),
mingroupsize=poped.choose(popedInput$design_space$mingroupsize,NULL),
## -- The total maximal groupsize over all groups--
maxtotgroupsize=poped.choose(popedInput$design_space$maxtotgroupsize,NULL),
## -- The total minimal groupsize over all groups--
mintotgroupsize=poped.choose(popedInput$design_space$mintotgroupsize,NULL),
## -- Matrix defining the max value for each sample --
maxxt=poped.choose(popedInput$design_space$maxxt,NULL),
## -- Matrix defining the min value for each sample --
minxt=poped.choose(popedInput$design_space$minxt,NULL),
discrete_xt=poped.choose(popedInput$design_space$xt_space,NULL),
## -- Cell defining the discrete variables --
#discrete_x=poped.choose(popedInput$design$discrete_x,cell(m,nx)),
discrete_x=poped.choose(popedInput$design_space$discrete_x,NULL),
## -- Vector defining the max value for each covariate --
maxa=poped.choose(popedInput$design_space$maxa,NULL),
## -- Vector defining the min value for each covariate --
mina=poped.choose(popedInput$design_space$mina,NULL),
discrete_a=poped.choose(popedInput$design_space$a_space,NULL),
## -- Use grouped time points (1=TRUE, 0=FALSE) --
bUseGrouped_xt=poped.choose(popedInput$design_space$bUseGrouped_xt,FALSE),
## -- Matrix defining the grouping of sample points --
G_xt=poped.choose(popedInput$design_space$G_xt,NULL),
## -- Use grouped covariates (1=TRUE, 0=FALSE) --
bUseGrouped_a=poped.choose(popedInput$design_space$bUseGrouped_a,FALSE),
## -- Matrix defining the grouping of covariates --
G_a=poped.choose(popedInput$design_space$G_a,NULL),
## -- Use grouped discrete design variables (1=TRUE, 0=FALSE) --
bUseGrouped_x=poped.choose(popedInput$design_space$bUseGrouped_x,FALSE),
## -- Matrix defining the grouping of discrete design variables --
G_x=poped.choose(popedInput$design_space[["G_x"]],NULL),
## --------------------------
## ---- FIM calculation
## --------------------------
## -- Fisher Information Matrix type
## (0=Full FIM,
## 1=Reduced FIM,
## 2=weighted models,
## 3=Loc models,
## 4=reduced FIM with derivative of SD of sigma as pfim,
## 5=FULL FIM parameterized with A,B,C matrices & derivative of variance,
## 6=Calculate one model switch at a time, good for large matrices,
## 7=Reduced FIM parameterized with A,B,C matrices & derivative of variance) --
iFIMCalculationType=poped.choose(popedInput$settings$iFIMCalculationType,1),
## -- Approximation method for model, 0=FO, 1=FOCE, 2=FOCEI, 3=FOI --
iApproximationMethod=poped.choose(popedInput$settings$iApproximationMethod,0),
## -- Num individuals in each step of FOCE --
iFOCENumInd=poped.choose(popedInput$settings$iFOCENumInd,1000),
## -- The prior FIM (added to calculated FIM) --
prior_fim=poped.choose(popedInput$settings$prior_fim,matrix(0,0,1)),
## -- Filname and path for the Autocorrelation function, empty string means no autocorrelation --
strAutoCorrelationFile=poped.choose(popedInput$model$auto_pointer,''),
## --------------------------
## ---- Criterion specification
## --------------------------
## -- D-family design (1) or ED-family design (0) (with or without parameter uncertainty) --
d_switch=poped.choose(popedInput$settings$d_switch,1),
## -- OFV calculation type for FIM (1=Determinant of FIM,4=log determinant of FIM,6=determinant of interesting part of FIM (Ds)) --
ofv_calc_type=poped.choose(popedInput$settings$ofv_calc_type,4),
## -- Ds_index, set index to 1 if a parameter is uninteresting, otherwise 0.
## size=(1,num unfixed parameters). First unfixed bpop, then unfixed d, then unfixed docc and last unfixed sigma --
## default is the fixed effects being important
ds_index=popedInput$parameters$ds_index,
## -- Penalty function, empty string means no penalty. User defined criterion --
strEDPenaltyFile=poped.choose(popedInput$settings$strEDPenaltyFile,''),
ofv_fun = poped.choose(popedInput$settings$ofv_fun, NULL),
## --------------------------
## ---- E-family Criterion options
## --------------------------
## -- ED Integral Calculation, 0=Monte-Carlo-Integration, 1=Laplace Approximation, 2=BFGS Laplace Approximation -- --
iEDCalculationType=poped.choose(popedInput$settings$iEDCalculationType,0),
## -- Sample size for E-family sampling --
ED_samp_size=poped.choose(popedInput$settings$ED_samp_size,45),
## -- How to sample from distributions in E-family calculations. 0=Random Sampling, 1=LatinHyperCube --
bLHS=poped.choose(popedInput$settings$bLHS,1),
## -- Filname and path for user defined distributions for E-family designs --
strUserDistributionFile=poped.choose(popedInput$model$user_distribution_pointer,''),
## --------------------------
## ---- Model parameters
## --------------------------
## -- Number of typical values --
nbpop=popedInput$parameters$nbpop,
## -- Number of IIV parameters --
NumRanEff=popedInput$parameters$NumRanEff,
## -- Number of IOV variance parameters --
NumDocc=popedInput$parameters$NumDocc,
## -- Number of occassions --
NumOcc= popedInput$parameters$NumOcc,
## -- The length of the g parameter vector --
#ng=popedInput$parameters$ng,
## -- Matrix defining the fixed effects, per row (row number = parameter_number),
## the type of the distribution for E-family designs (0 = Fixed, 1 = Normal, 2 = Uniform,
## 3 = User Defined Distribution, 4 = lognormal and 5 = truncated normal).
## The second column defines the mean.
## The third column defines the variance of the distribution.
# can also just supply the parameter values as a c()
bpop=poped.choose(popedInput$parameters$bpop,stop('bpop must be defined')),
## -- Matrix defining the diagonals of the IIV (same logic as for the fixed effects) --
# can also just supply the parameter values as a c()
d=poped.choose(popedInput$parameters$d,NULL),
## -- vector defining the row major lower triangle of the covariances of the IIV variances --
# set to zero if not defined
covd=popedInput$parameters$covd,
## -- Matrix defining the variances of the residual variability terms --
## REQUIRED! No defaults given.
# can also just supply the diagonal values as a c()
sigma=popedInput$parameters$sigma,
## -- Matrix defining the IOV, the IOV variances and the IOV distribution --
docc=poped.choose(popedInput$parameters$docc,matrix(0,0,3)),
## -- Matrix defining the covariance of the IOV --
covdocc=poped.choose(popedInput$parameters$covdocc,zeros(1,length(docc[,2,drop=F])*(length(docc[,2,drop=F])-1)/2)),
## --------------------------
## ---- Model parameters fixed or not
## --------------------------
## -- Vector defining if a typical value is fixed or not (1=not fixed, 0=fixed) --
notfixed_bpop=popedInput$parameters$notfixed_bpop,
## -- Vector defining if a IIV is fixed or not (1=not fixed, 0=fixed) --
notfixed_d=popedInput$parameters$notfixed_d,
## -- Vector defining if a covariance IIV is fixed or not (1=not fixed, 0=fixed) --
notfixed_covd=popedInput$parameters$notfixed_covd,
## -- Vector defining if an IOV variance is fixed or not (1=not fixed, 0=fixed) --
notfixed_docc=popedInput$parameters$notfixed_docc,
## -- Vector row major order for lower triangular matrix defining if a covariance IOV is fixed or not (1=not fixed, 0=fixed) --
notfixed_covdocc=poped.choose(popedInput$parameters$notfixed_covdocc,zeros(1,length(covdocc))),
## -- Vector defining if a residual error parameter is fixed or not (1=not fixed, 0=fixed) --
notfixed_sigma=poped.choose(popedInput$parameters$notfixed_sigma,t(rep(1,size(sigma,2)))),
## -- Vector defining if a covariance residual error parameter is fixed or not (1=not fixed, 0=fixed) --
## default is fixed
notfixed_covsigma=poped.choose(popedInput$parameters$notfixed_covsigma,zeros(1,length(notfixed_sigma)*(length(notfixed_sigma)-1)/2)),
## --------------------------
## ---- Optimization algorithm choices
## --------------------------
## -- Use random search (1=TRUE, 0=FALSE) --
bUseRandomSearch=poped.choose(popedInput$settings$bUseRandomSearch,TRUE),
## -- Use Stochastic Gradient search (1=TRUE, 0=FALSE) --
bUseStochasticGradient=poped.choose(popedInput$settings$bUseStochasticGradient,TRUE),
## -- Use Line search (1=TRUE, 0=FALSE) --
bUseLineSearch=poped.choose(popedInput$settings$bUseLineSearch,TRUE),
## -- Use Exchange algorithm (1=TRUE, 0=FALSE) --
bUseExchangeAlgorithm=poped.choose(popedInput$settings$bUseExchangeAlgorithm,FALSE),
## -- Use BFGS Minimizer (1=TRUE, 0=FALSE) --
bUseBFGSMinimizer=poped.choose(popedInput$settings$bUseBFGSMinimizer,FALSE),
## -- Exchange Algorithm Criteria, 1 = Modified, 2 = Fedorov --
EACriteria=poped.choose(popedInput$settings$EACriteria,1),
## -- Filename and path for a run file that is used instead of the regular PopED call --
strRunFile=poped.choose(popedInput$settings$run_file_pointer,''),
## --------------------------
## ---- Labeling and file names
## --------------------------
## -- The current PopED version --
poped_version=poped.choose(popedInput$settings$poped_version, packageVersion("PopED")),
## -- The model title --
modtit=poped.choose(popedInput$settings$modtit,'PopED model'),
## -- Filname and path of the output file during search --
output_file=poped.choose(popedInput$settings$output_file,paste("PopED_output",'_summary',sep='')),
## -- Filname suffix of the result function file --
output_function_file=poped.choose(popedInput$settings$output_function_file,paste("PopED",'_output_',sep='')),
## -- Filename and path for storage of current optimal design --
strIterationFileName=poped.choose(popedInput$settings$strIterationFileName,paste("PopED",'_current.R',sep='')),
## --------------------------
## ---- Misc options
## --------------------------
## -- User defined data structure that, for example could be used to send in data to the model --
user_data=poped.choose(popedInput$settings$user_data,cell(0,0)),
## -- Value to interpret as zero in design --
ourzero=poped.choose(popedInput$settings$ourzero,1e-5),
#ourzero=poped.choose(popedInput$ourzero,0),
## -- The seed number used for optimization and sampling -- integer or -1 which creates a random seed
dSeed=poped.choose(popedInput$settings$dSeed,NULL),
## -- Vector for line search on continuous design variables (1=TRUE,0=FALSE) --
line_opta=poped.choose(popedInput$settings$line_opta,NULL),
## -- Vector for line search on discrete design variables (1=TRUE,0=FALSE) --
line_optx=poped.choose(popedInput$settings$line_optx,NULL), #matrix(0,0,1)
## -- Use graph output during search --
bShowGraphs=poped.choose(popedInput$settings$bShowGraphs,FALSE),
## -- If a log file should be used (0=FALSE, 1=TRUE) --
use_logfile=poped.choose(popedInput$settings$use_logfile,FALSE),
## -- Method used to calculate M1
## (0=Complex difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation) --
m1_switch=poped.choose(popedInput$settings$m1_switch,1),
## -- Method used to calculate M2
## (0=Central difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation) --
m2_switch=poped.choose(popedInput$settings$m2_switch,1),
## -- Method used to calculate linearization of residual error
## (0=Complex difference, 1=Central difference, 30=Automatic differentiation) --
hle_switch=poped.choose(popedInput$settings$hle_switch,1),
## -- Method used to calculate the gradient of the model
## (0=Complex difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation) --
gradff_switch=poped.choose(popedInput$settings$gradff_switch,1),
## -- Method used to calculate the gradient of the parameter vector g
## (0=Complex difference, 1=Central difference, 20=Analytic derivative, 30=Automatic differentiation) --
gradfg_switch=poped.choose(popedInput$settings$gradfg_switch,1),
## -- Method used to calculate all the gradients
## (0=Complex difference, 1=Central difference) --
grad_all_switch=poped.choose(popedInput$settings$grad_all_switch,1),
## -- Number of iterations in random search between screen output --
rsit_output=poped.choose(popedInput$settings$rsit_output,5),
## -- Number of iterations in stochastic gradient search between screen output --
sgit_output=poped.choose(popedInput$settings$sgit_output,1),
## -- Step length of derivative of linearized model w.r.t. typical values --
hm1=poped.choose(popedInput$settings[["hm1"]],0.00001),
## -- Step length of derivative of model w.r.t. g --
hlf=poped.choose(popedInput$settings[["hlf"]],0.00001),
## -- Step length of derivative of g w.r.t. b --
hlg=poped.choose(popedInput$settings[["hlg"]],0.00001),
## -- Step length of derivative of variance w.r.t. typical values --
hm2=poped.choose(popedInput$settings[["hm2"]],0.00001),
## -- Step length of derivative of OFV w.r.t. time --
hgd=poped.choose(popedInput$settings[["hgd"]],0.00001),
## -- Step length of derivative of model w.r.t. sigma --
hle=poped.choose(popedInput$settings[["hle"]],0.00001),
## -- The absolute tolerance for the diff equation solver --
AbsTol=poped.choose(popedInput$settings$AbsTol,0.000001),
## -- The relative tolerance for the diff equation solver --
RelTol=poped.choose(popedInput$settings$RelTol,0.000001),
## -- The diff equation solver method, 0, no other option --
iDiffSolverMethod=poped.choose(popedInput$settings$iDiffSolverMethod,NULL),
## -- If the differential equation results should be stored in memory (1) or not (0) --
bUseMemorySolver=poped.choose(popedInput$settings$bUseMemorySolver,FALSE),
## -- Number of Random search iterations --
rsit=poped.choose(popedInput$settings[["rsit"]],300),
## -- Number of Stochastic gradient search iterations --
sgit=poped.choose(popedInput$settings[["sgit"]],150),
## -- Number of Random search iterations with discrete optimization --
intrsit=poped.choose(popedInput$settings$intrsit,250),
## -- Number of Stochastic Gradient search iterations with discrete optimization --
intsgit=poped.choose(popedInput$settings$intsgit,50),
## -- Iterations until adaptive narrowing in random search --
maxrsnullit=poped.choose(popedInput$settings$maxrsnullit,50),
## -- Stoachstic Gradient convergence value,
## (difference in OFV for D-optimal, difference in gradient for ED-optimal) --
convergence_eps=poped.choose(popedInput$settings$convergence_eps,1e-08),
## -- Random search locality factor for sample times --
rslxt=poped.choose(popedInput$settings$rslxt,10),
## -- Random search locality factor for covariates --
rsla=poped.choose(popedInput$settings$rsla,10),
## -- Stochastic Gradient search first step factor for sample times --
cfaxt=poped.choose(popedInput$settings$cfaxt,0.001),
## -- Stochastic Gradient search first step factor for covariates --
cfaa=poped.choose(popedInput$settings$cfaa,0.001),
## -- Use greedy algorithm for group assignment optimization --
bGreedyGroupOpt=poped.choose(popedInput$settings$bGreedyGroupOpt,FALSE),
## -- Exchange Algorithm StepSize --
EAStepSize=poped.choose(popedInput$settings$EAStepSize,0.01),
## -- Exchange Algorithm NumPoints --
EANumPoints=poped.choose(popedInput$settings$EANumPoints,FALSE),
## -- Exchange Algorithm Convergence Limit/Criteria --
EAConvergenceCriteria=poped.choose(popedInput$settings$EAConvergenceCriteria,1e-20),
## -- Avoid replicate samples when using Exchange Algorithm --
bEANoReplicates=poped.choose(popedInput$settings$bEANoReplicates,FALSE),
## -- BFGS Minimizer Convergence Criteria Minimum Step --
BFGSConvergenceCriteriaMinStep=NULL,
#poped.choose(popedInput$settings$BFGSConvergenceCriteriaMinStep,1e-08),
## -- BFGS Minimizer Convergence Criteria Normalized Projected Gradient Tolerance --
BFGSProjectedGradientTol=poped.choose(popedInput$settings$BFGSProjectedGradientTol,0.0001),
## -- BFGS Minimizer Line Search Tolerance f --
BFGSTolerancef=poped.choose(popedInput$settings$BFGSTolerancef,0.001),
## -- BFGS Minimizer Line Search Tolerance g --
BFGSToleranceg=poped.choose(popedInput$settings$BFGSToleranceg,0.9),
## -- BFGS Minimizer Line Search Tolerance x --
BFGSTolerancex=poped.choose(popedInput$settings$BFGSTolerancex,0.1),
## -- Number of iterations in ED-optimal design to calculate convergence criteria --
ED_diff_it=poped.choose(popedInput$settings$ED_diff_it,30),
## -- ED-optimal design convergence criteria in percent --
ED_diff_percent=poped.choose(popedInput$settings$ED_diff_percent,10),
## -- Number of grid points in the line search --
line_search_it=poped.choose(popedInput$settings$ls_step_size,50),
## -- Number of iterations of full Random search and full Stochastic Gradient if line search is not used --
Doptim_iter=poped.choose(popedInput$settings$iNumSearchIterationsIfNotLineSearch,1),
## --------------------------
## -- Parallel options for PopED -- --
## --------------------------
# ## -- Compile option for PopED
# ## -1 = No compilation,
# ## 0 or 3 = Full compilation,
# ## 1 or 4 = Only using MCC (shared lib),
# ## 2 or 5 = Only MPI,
# ## Option 0,1,2 runs PopED and option 3,4,5 stops after compilation --
iCompileOption=poped.choose(popedInput$settings$parallel$iCompileOption,-1),
## -- Parallel method to use (0 = Matlab PCT, 1 = MPI) --
iUseParallelMethod=poped.choose(popedInput$settings$parallel$iUseParallelMethod,1),
## -- Additional dependencies used in MCC compilation (mat-files), if several space separated --
MCC_Dep = NULL,
#poped.choose(popedInput$settings$parallel$strAdditionalMCCCompilerDependencies, ''),
## -- Compilation output executable name --
strExecuteName=poped.choose(popedInput$settings$parallel$strExecuteName,'calc_fim.exe'),
## -- Number of processes to use when running in parallel (e.g. 3 = 2 workers, 1 job manager) --
iNumProcesses=poped.choose(popedInput$settings$parallel$iNumProcesses,2),
## -- Number of design evaluations that should be evaluated in each process before getting new work from job manager --
iNumChunkDesignEvals=poped.choose(popedInput$settings$parallel$iNumChunkDesignEvals,-2),
## -- The prefix of the input mat file to communicate with the executable --
#strMatFileInputPrefix = poped.choose(
# popedInput$settings$parallel$strMatFileInputPrefix,
# 'parallel_input'),
## -- The prefix of the output mat file to communicate with the executable --
Mat_Out_Pre=poped.choose(popedInput$settings$parallel$strMatFileOutputPrefix,'parallel_output'),
## -- Extra options send to e$g. the MPI executable or a batch script, see execute_parallel$m for more information and options --
strExtraRunOptions=poped.choose(popedInput$settings$parallel$strExtraRunOptions,''),
## -- Polling time to check if the parallel execution is finished --
dPollResultTime=poped.choose(popedInput$settings$parallel$dPollResultTime,0.1),
## -- The file containing the popedInput structure that should be used to evaluate the designs --
strFunctionInputName=poped.choose(popedInput$settings$parallel$strFunctionInputName,'function_input'),
## -- If the random search is going to be executed in parallel --
bParallelRS=poped.choose(popedInput$settings$parallel$bParallelRS,FALSE),
## -- If the stochastic gradient search is going to be executed in parallel --
bParallelSG=poped.choose(popedInput$settings$parallel$bParallelSG,FALSE),
## -- If the modified exchange algorithm is going to be executed in parallel --
bParallelMFEA=poped.choose(popedInput$settings$parallel$bParallelMFEA,FALSE),
## -- If the line search is going to be executed in parallel --
bParallelLS=poped.choose(popedInput$settings$parallel$bParallelLS,FALSE)
){
poped.db <- list()
# five main headings for database
# poped.db <- list(design=NULL,
# design_space=NULL,
# models=NULL,
# parameters=NULL,
# settings=NULL)
# # update popedInput with options supplied in function
# called_args <- match.call()
# default_args <- formals()
# for(i in names(called_args)[-1]){
# if(length(grep("^popedInput$",capture.output(default_args[[i]])))==1) {
# eval(parse(text=paste(capture.output(default_args[[i]]),"<-",called_args[[i]])))
# }
# }
#modifyList(settings, list()$settings)
## compare to a default input function.
# ## -- Filname and path of the model file --
# popedInput$ff_file='ff'
# ## -- Filname and path of the parameter file --
# popedInput$fg_file='sfg'
# ## -- Filname and path of the residual error model file --
# popedInput$fError_file='feps.add.prop'
# ## -- The model title --
# popedInput$modtit='Sigmoidal Emax model'
poped.db$settings <- list()
poped.db$settings$poped_version = poped_version
if(is.null(BFGSConvergenceCriteriaMinStep)){
BFGSConvergenceCriteriaMinStep <- poped.choose(popedInput$settings$BFGSConvergenceCriteriaMinStep,
1e-08)
}
if(is.null(MCC_Dep)){
MCC_Dep <- poped.choose(popedInput$settings$parallel$strAdditionalMCCCompilerDependencies, '')
}
poped.db$model <- list()
poped.db$model$user_distribution_pointer=''
#poped.db$user_distribution_pointer=''
if((!as.character(strUserDistributionFile)=='')){
if(exists(strUserDistributionFile)){
poped.db$model$user_distribution_pointer = strUserDistributionFile
} else {
source(strUserDistributionFile)
returnArgs <- fileparts(strUserDistributionFile)
strUserDistFilePath <- returnArgs[[1]]
strUserDistFilename <- returnArgs[[2]]
## if (~strcmp(strUserDistFilePath,''))
## cd(strUserDistFilePath);
## end
poped.db$model$user_distribution_pointer = strUserDistFilename
}
}
if(any(size(x)==0)){ ## should be removed
x <- NULL
G_x <- NULL
discrete_x <- NULL
}
if(any(size(a)==0)){ ## should be removed
a <- NULL
G_a <- NULL
mina <- NULL
maxa <- NULL
}
design <- create_design(xt=xt,
groupsize=groupsize,
m=m,
x=x,
a=a,
ni=ni,
model_switch=model_switch)
design_space <- create_design_space(design,
maxni=maxni,
minni=minni,
maxtotni=maxtotni,
mintotni=mintotni,
maxgroupsize=maxgroupsize,
mingroupsize=mingroupsize,
maxtotgroupsize=maxtotgroupsize,
mintotgroupsize=mintotgroupsize,
maxxt=maxxt,
minxt=minxt,
xt_space = discrete_xt,
maxa=maxa,
mina=mina,
a_space = discrete_a,
x_space = discrete_x,
use_grouped_xt=bUseGrouped_xt,
grouped_xt=G_xt,
use_grouped_a=bUseGrouped_a,
grouped_a=G_a,
use_grouped_x=bUseGrouped_x,
grouped_x=G_x,
our_zero=ourzero)
design <- design_space$design
design_space <- design_space$design_space
## all of this should be replaced with using the names used in create_design_space as function arguments
if(!is.null(design_space[["use_grouped_a"]])){
design_space$bUseGrouped_a <- design_space[["use_grouped_a"]]
design_space[["use_grouped_a"]] <- NULL
}
if(!is.null(design_space[["use_grouped_x"]])){
design_space$bUseGrouped_x <- design_space[["use_grouped_x"]]
design_space[["use_grouped_x"]] <- NULL
}
if(!is.null(design_space[["use_grouped_xt"]])){
design_space$bUseGrouped_xt <- design_space[["use_grouped_xt"]]
design_space[["use_grouped_xt"]] <- NULL
}
if(!is.null(design_space[["grouped_a"]])){
design_space$G_a <- design_space[["grouped_a"]]
design_space[["grouped_a"]] <- NULL
}
if(!is.null(design_space[["grouped_x"]])){
design_space$G_x <- design_space[["grouped_x"]]
design_space[["grouped_x"]] <- NULL
}
if(!is.null(design_space[["grouped_xt"]])){
design_space$G_xt <- design_space[["grouped_xt"]]
design_space[["grouped_xt"]] <- NULL
}
if(!is.null(design_space[["x_space"]])){
design_space$discrete_x <- design_space[["x_space"]]
design_space[["x_space"]] <- NULL
}
#design_space$maxni <- max(design_space$maxni)
#design_space$minni <- min(design_space$minni)
if(is.null(design[["x"]])){ ## should be removed
design$x <- zeros(design$m,0)
design_space$G_x <- design$x
design_space$bUseGrouped_x <- FALSE
design_space$discrete_x <- cell(design$m,0)
}
if(is.null(design[["a"]])){ ## should be removed
design$a <- zeros(design$m,0)
design_space$G_a <- design$a
design_space$bUseGrouped_a <- FALSE
design_space$mina <- design$a
design_space$maxa <- design$a
}
poped.db$design <- design
poped.db$design_space <- design_space
#poped.db$m = poped.db$design$m # should be removed only in design
#poped.db$nx = poped.choose(nx,size(design$x,2)) # should be removed, not needed or in design
#poped.db$na = poped.choose(na,size(design$a,2)) # should be removed, not needed or in design
poped.db$settings$bLHS = bLHS
#poped.db$discrete_x = design_space$discrete_x # should be removed only in design_space
#poped.db$maxni=max(design_space$maxni) # should be only in design_space and called maxmaxni if needed
#poped.db$minni=min(design_space$minni) # should be only in design_space and called minminni if needed
#poped.db$bUseGrouped_xt = design_space$bUseGrouped_xt # should be only in design_space
#poped.db$bUseGrouped_a = design_space$bUseGrouped_a # should be only in design_space
#poped.db$bUseGrouped_x = design_space$bUseGrouped_x # should be only in design_space
poped.db$settings$d_switch = d_switch
poped.db$settings$iApproximationMethod = iApproximationMethod
poped.db$settings$iFOCENumInd = iFOCENumInd
poped.db$settings$bUseRandomSearch = bUseRandomSearch
poped.db$settings$bUseStochasticGradient = bUseStochasticGradient
poped.db$settings$bUseLineSearch = bUseLineSearch
poped.db$settings$bUseExchangeAlgorithm = bUseExchangeAlgorithm
poped.db$settings$bUseBFGSMinimizer=bUseBFGSMinimizer
poped.db$settings$iEDCalculationType=iEDCalculationType
poped.db$settings$BFGSConvergenceCriteriaMinStep=BFGSConvergenceCriteriaMinStep
poped.db$settings$BFGSProjectedGradientTol=BFGSProjectedGradientTol
poped.db$settings$BFGSTolerancef=BFGSTolerancef
poped.db$settings$BFGSToleranceg=BFGSToleranceg
poped.db$settings$BFGSTolerancex=BFGSTolerancex
poped.db$parameters$covdocc=covdocc
poped.db$parameters$notfixed_covdocc=notfixed_covdocc
poped.db$parameters$notfixed_covsigma=notfixed_covsigma
poped.db$settings$parallel$iCompileOption = iCompileOption
poped.db$settings$parallel$strAdditionalMCCCompilerDependencies = MCC_Dep
poped.db$settings$parallel$iUseParallelMethod = iUseParallelMethod
poped.db$settings$parallel$strExecuteName = strExecuteName
poped.db$settings$parallel$iNumProcesses = iNumProcesses
poped.db$settings$parallel$iNumChunkDesignEvals = iNumChunkDesignEvals
#poped.db$settings$parallel$strMatFileInputPrefix = strMatFileInputPrefix
poped.db$settings$parallel$strMatFileOutputPrefix = Mat_Out_Pre
poped.db$settings$parallel$strExtraRunOptions = strExtraRunOptions
poped.db$settings$parallel$dPollResultTime = dPollResultTime
poped.db$settings$parallel$strFunctionInputName = strFunctionInputName
poped.db$settings$parallel$bParallelRS = bParallelRS
poped.db$settings$parallel$bParallelSG = bParallelSG
poped.db$settings$parallel$bParallelLS = bParallelLS
poped.db$settings$parallel$bParallelMFEA = bParallelMFEA
poped.db$settings$hm1=hm1
poped.db$settings$hlf=hlf
poped.db$settings$hlg=hlg
poped.db$settings$hm2=hm2
poped.db$settings$hgd=hgd
poped.db$settings$hle=hle
poped.db$settings$AbsTol = AbsTol
poped.db$settings$RelTol = RelTol
poped.db$settings$iDiffSolverMethod = iDiffSolverMethod
#Temp thing for memory solvers
poped.db$settings$bUseMemorySolver = bUseMemorySolver
poped.db$settings$solved_solutions = cell(0,0)
poped.db$settings$maxtime = max(max(poped.db$design_space$maxxt))+poped.db$settings$hgd
poped.db$settings$iFIMCalculationType = iFIMCalculationType
poped.db$settings$rsit=rsit
poped.db$settings$sgit=sgit
poped.db$settings$intrsit=intrsit
poped.db$settings$intsgit=intsgit
poped.db$settings$maxrsnullit=maxrsnullit
poped.db$settings$convergence_eps=convergence_eps
poped.db$settings$rslxt=rslxt
poped.db$settings$rsla=rsla
poped.db$settings$cfaxt=cfaxt
poped.db$settings$cfaa=cfaa
poped.db$settings$EACriteria = EACriteria
poped.db$settings$EAStepSize = EAStepSize
poped.db$settings$EANumPoints = EANumPoints
poped.db$settings$EAConvergenceCriteria = EAConvergenceCriteria
poped.db$settings$ED_samp_size=ED_samp_size
poped.db$settings$ED_diff_it = ED_diff_it
poped.db$settings$ED_diff_percent = ED_diff_percent
poped.db$settings$ls_step_size=line_search_it
poped.db$settings$ofv_calc_type = ofv_calc_type
poped.db$settings$iNumSearchIterationsIfNotLineSearch = Doptim_iter
poped.db$settings$ourzero=ourzero
poped.db$settings$rsit_output=rsit_output
poped.db$settings$sgit_output=sgit_output
if(is.function(fg_fun)){
poped.db$model$fg_pointer = fg_fun
} else if(is.character(fg_fun)){
if(exists(fg_fun)) poped.db$model$fg_pointer = fg_fun
} else if(exists(fg_file)){
poped.db$model$fg_pointer = fg_file
} else {
source(fg_file)
returnArgs <- fileparts(fg_file)
strfgModelFilePath <- returnArgs[[1]]
strfgModelFilename <- returnArgs[[2]]
## if (~strcmp(strfgModelFilePath,''))
## cd(strfgModelFilePath);
## end
poped.db$model$fg_pointer = strfgModelFilename
}
poped.db$settings$ed_penalty_pointer=zeros(1,0)
if((!as.character(strEDPenaltyFile)=='')){
if(exists(strEDPenaltyFile)){
poped.db$settings$ed_penalty_pointer = strEDPenaltyFile
} else {
source(popedInput$strEDPenaltyFile)
returnArgs <- fileparts(popedInput$strEDPenaltyFile)
strEDPenaltyFilePath <- returnArgs[[1]]
strEDPenaltyFilename <- returnArgs[[2]]
## if (~strcmp(strEDPenaltyFilePath,''))
## cd(strEDPenaltyFilePath);
## end
poped.db$settings$ed_penalty_pointer = strEDPenaltyFilename
}
}
# if(is.null(ofv_fun) || is.function(ofv_fun)){
# poped.db$settings$ofv_fun = ofv_fun
# } else {
# stop("ofv_fun must be a function or NULL")
# }
if(is.null(ofv_fun) || is.function(ofv_fun)){
poped.db$settings$ofv_fun <- 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))
poped.db$settings$ofv_fun <- 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")
}
}