Skip to content

Commit

Permalink
Allow some inadmissible draws in tuning (grf-labs#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikcs authored Nov 17, 2021
1 parent 1cb0f9e commit 5503f78
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions r-package/grf/R/tune_forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ tune_forest <- function(data,
error <- small.forest$debiased.error
mean(error, na.rm = TRUE)
})
# Some estimates may be all NaN because of arbitrary inadmissible parameter draws,
# such as a very low sample.fraction on data with few clusters.
keep <- !is.na(small.forest.errors)

if (anyNA(small.forest.errors)) {
if (sum(keep) < 10) {
warning(paste0(
"Could not tune forest because some small forest error estimates were NA.\n",
"Consider increasing tuning argument tune.num.trees."))
"Could not tune forest because nearly all small forest error estimates were NA.\n",
"Consider increasing tuning arguments tune.num.trees or tune.num.draws."))
out <- get_tuning_output(params = c(tune.parameters.defaults), status = "failure")
return(out)
} else {
small.forest.errors = small.forest.errors[keep]
fit.draws = fit.draws[keep, , drop = FALSE]
}

if (sd(small.forest.errors) == 0 || sd(small.forest.errors) / mean(small.forest.errors) < 1e-10) {
Expand Down

0 comments on commit 5503f78

Please sign in to comment.