ParBayesianOptimization icon indicating copy to clipboard operation
ParBayesianOptimization copied to clipboard

add na.rm=TRUE to min/max in zeroOneScale

Open kevingoneill opened this issue 4 years ago • 1 comments

Thanks for developing this, it's a cool package! I came across a small bug where if the user-provided FUN returns list(Score=NA) during fitting, I get the following error:

Error in if (r == 0) stop("Results from FUN have 0 variance, cannot build GP.") : 
  missing value where TRUE/FALSE needed

This isn't very helpful, but it tells me that there's a missing value somewhere. Looking through your source code, I found that the error is happening in the function zeroOneScale in the file SmallFuncs.R, which is being used to scale the Scores over each evaluated point. This is reasonable enough, but you lose any of the progress that you've made until this point so it can be hard for a user to debug. Thankfully there's an obvious simple fix. I found that if you add na.rm=TRUE in the calls to min and max within this function, you get a more reasonable error:

Returning results so far. Error encountered while training GP: <non-finite value supplied by optim>

This seems preferable because it (a) tells the user directly that the score function is giving NA/NaN values, and (b) it gives the user access to the returned value, allowing you to determine which parameter values are causing trouble for FUN.

kevingoneill avatar May 21 '21 17:05 kevingoneill

Yup, in the case that NA is explicitly returned from the scoring function, an error is not recorded. The scaling function is only run on scores which returned successfully, which the NA did... I think the best solution would be to actually report an error from the scoring function in this case.

samFarrellDay avatar May 25 '21 19:05 samFarrellDay