@@ -25,60 +25,65 @@ evalTargetFun.OptState = function(opt.state, xs, extras) {
25
25
# short names and so on
26
26
nevals = length(xs )
27
27
ny = control $ n.objectives
28
+ imputeY = control $ impute.y.fun
28
29
29
30
# trafo X points
30
31
xs.trafo = lapply(xs , trafoValue , par = par.set )
31
32
32
- # handle noisy instances
33
- if (isTRUE(control $ noisy.instances > 1L )) {
34
- nevals = nevals * control $ noisy.instances
35
- xs = rep(xs , each = control $ noisy.instances )
36
- extras = rep(extras , each = control $ noisy.instances )
37
- if (! control $ noisy.self.replicating ) {
38
- xs.trafo = rep(xs.trafo , each = control $ noisy.instances )
39
- if (! is.na(control $ noisy.instance.param )) {
40
- inst.param = lapply(seq_len(control $ noisy.instances ), function (x ) setNames(list (x ), control $ noisy.instance.param ))
41
- xs.trafo = Map(c , xs.trafo , inst.param )
42
- }
43
- }
44
- }
45
-
46
-
47
- num.format = control $ output.num.format
48
- num.format.string = paste(" %s = " , num.format , sep = " " )
49
- dobs = ensureVector(asInteger(getOptStateLoop(opt.state )), n = nevals , cl = " integer" )
50
- imputeY = control $ impute.y.fun
51
-
52
-
53
33
# function to measure of fun call
54
- wrapFun = function (x ) {
55
- st = proc.time()
56
- y = do.call(getOptProblemFun(opt.problem ), insert(list (x = x ), getOptProblemMoreArgs(opt.problem )))
57
- user.extras = list ()
34
+ wrapFun = function (x ) {
35
+ st = proc.time()
36
+ y = do.call(getOptProblemFun(opt.problem ), insert(list (x = x ), getOptProblemMoreArgs(opt.problem )))
37
+ user.extras = list ()
58
38
# here we extract additional stuff which the user wants to log in the opt path
59
- if (hasAttributes(y , " extras" )) {
60
- user.extras = attr(y , " extras" )
61
- y = setAttribute(y , " extras" , NULL )
62
- }
63
- if (! is.null(control $ noisy.instance.param ) && ! is.na(control $ noisy.instance.param ) && ! control $ noisy.self.replicating ) {
64
- user.extras = c(user.extras , x [control $ noisy.instance.param ])
65
- }
66
- st = proc.time() - st
67
- list (y = y , time = st [3 ], user.extras = user.extras )
39
+ if (hasAttributes(y , " extras" )) {
40
+ user.extras = attr(y , " extras" )
41
+ y = setAttribute(y , " extras" , NULL )
42
+ }
43
+ if (! is.null(control $ noisy.instance.param ) && ! is.na(control $ noisy.instance.param ) && ! control $ noisy.self.replicating ) {
44
+ user.extras = c(user.extras , x [control $ noisy.instance.param ])
68
45
}
46
+ st = proc.time() - st
47
+ list (y = y , time = st [3 ], user.extras = user.extras )
48
+ }
69
49
70
50
# do we have a valid y object?
71
51
isYValid = function (y ) {
72
- ! is.error(y ) && testNumeric(y , len = ny , any.missing = FALSE , finite = TRUE )
52
+ if (! isTRUE(control $ noisy.self.replicating )) {
53
+ len = NULL
54
+ } else {
55
+ len = ny
56
+ }
57
+ ! is.error(y ) && testNumeric(y , len = len , any.missing = FALSE , finite = TRUE )
73
58
}
74
59
75
60
# return error objects if we impute
76
- res = parallelMap(wrapFun , xs.trafo , level = " mlrMBO.feval" ,
77
- impute.error = if (is.null(imputeY )) NULL else identity )
61
+ res = parallelMap(wrapFun , xs.trafo , level = " mlrMBO.feval" , impute.error = if (is.null(imputeY )) NULL else identity )
62
+
63
+ # handle noisy instances
64
+ if (isTRUE(control $ noisy.self.replicating )) {
65
+ nevals.each = lengths(extractSubList(res , " y" , simplify = FALSE ))
66
+ nevals = sum(nevals.each )
67
+
68
+ # replications for opt path stuff
69
+ repVec = function (x , fun = replicate ) {
70
+ unlist(Map(fun , nevals.each , x , simplify = FALSE ), recursive = FALSE )
71
+ }
72
+ xs = repVec(xs )
73
+ xs.trafo = repVec(xs.trafo )
74
+
75
+ # set extras to NA that are only important for the first point
76
+ setNAfun = function (n , xs , ... ) {
77
+ res = replicate(n = n , expr = xs , ... )
78
+ res [- 1 ] = lapply(res [- 1 ], function (x ) {
79
+ x [c(" train.time" , " error.model" , " propose.time" )] = NA
80
+ x
81
+ })
82
+ res
83
+ }
84
+ extras = repVec(extras , setNAfun )
78
85
79
- # handle noisy instances of self.replicating functions
80
- if (isTRUE(control $ noisy.instances > 1L ) && control $ noisy.self.replicating ) {
81
- xs.trafo = rep(xs.trafo , each = control $ noisy.instances )
86
+ # handle result list
82
87
res = lapply(res , function (r ) {
83
88
if (is.error(r )) {
84
89
rep(list (r ), control $ noisy.instances )
@@ -91,6 +96,9 @@ evalTargetFun.OptState = function(opt.state, xs, extras) {
91
96
res = unlist(res , recursive = FALSE )
92
97
}
93
98
99
+ num.format.string = paste(" %s = " , control $ output.num.format , sep = " " )
100
+ dobs = ensureVector(asInteger(getOptStateLoop(opt.state )), n = nevals , cl = " integer" )
101
+
94
102
# loop evals and to some post-processing
95
103
for (i in seq_len(nevals )) {
96
104
r = res [[i ]]; x = xs [[i ]]; x.trafo = xs.trafo [[i ]]; dob = dobs [i ]
0 commit comments