Skip to content

Commit

Permalink
Fixed outcleandf for add_level
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinErickson committed Nov 3, 2020
1 parent 3509e0b commit d193c54
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
22 changes: 21 additions & 1 deletion R/ffexp.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ ffexp <- R6::R6Class(

self$number_runs <- nrow(self$rungrid)
self$completed_runs <- rep(FALSE, self$number_runs)
self$outlist <- rep(list(NULL), self$number_runs)
self$parallel <- parallel
# self$parallel_cores <- parallel_cores
if (self$parallel || !self$parallel) {
Expand Down Expand Up @@ -851,6 +852,8 @@ ffexp <- R6::R6Class(
}
)
},
#' @description Calculate the effects of each variable as if this
#' was an experiment using a linear model.
calculate_effects2 = function() {
nvar <- ncol(self$rungrid)
outputcols <- (nvar+1):(ncol(self$outrawdf)-3)
Expand Down Expand Up @@ -1186,8 +1189,18 @@ ffexp <- R6::R6Class(
# Or could use rungrid and replace new_values with biggest number
# existing_indexes <- which(
# new_exp$rungrid[,arg_name] < max(new_exp$rungrid[,arg_name]))
# Loop over runs that were already part of experiment, completed or not.
# Copy over data, leaving space for new runs.
existing_indexes <- which(
new_exp$rungrid[,arg_name] %in% existing_level_indexes)
# browser()
# Need to add rows to outcleandf, and copy over existing outcleandf
nrowsperindex <- nrow(self$outcleandf) / self$number_runs
new_exp$outcleandf <- new_exp$outcleandf[nrow(new_exp$outcleandf) +
1:(new_exp$number_runs*nrowsperindex), ]
rownames(new_exp$outcleandf) <- 1:nrow(new_exp$outcleandf)
new_exp$outrawdf <- new_exp$outrawdf[nrow(new_exp$outrawdf) + 1:(new_exp$number_runs*nrowsperindex), ]
rownames(new_exp$outrawdf) <- 1:nrow(new_exp$outrawdf)
for(old_index in existing_indexes) {
old_rg_row <- self$rungrid[old_index,]
new_index <- which(apply(new_exp$rungrid,1,
Expand All @@ -1197,15 +1210,22 @@ ffexp <- R6::R6Class(
# new_index <- 1
new_exp$completed_runs[new_index] <- self$completed_runs[old_index]
new_exp$outlist[[new_index]] <- self$outlist[[old_index]]
new_exp$outcleandf[1:nrowsperindex + nrowsperindex*(new_index-1), ] <-
self$outcleandf[1:nrowsperindex + nrowsperindex*(old_index-1), ]
new_exp$outrawdf[1:nrowsperindex + nrowsperindex*(new_index-1), ] <-
self$outrawdf[1:nrowsperindex + nrowsperindex*(old_index-1), ]
}; rm(old_rg_row, new_index, old_index)
# Loop over new runs, prepare them.
for (new_index in setdiff(1:new_exp$number_runs, existing_indexes)) {
stopifnot(!new_exp$completed_runs[new_index])
# Needed in order to run add_level twice in a row without having run it
new_exp$outlist[[new_index]] <- list(NULL)
}
# browser("outcleandf")
# new_exp$outcleandf
# Notify user that it wasn't changed in place
if (!suppressMessage) {
message("Returning new object with added variable")
message("Returning new object with added variable, object was not changed in place.")
}
return(new_exp)
},
Expand Down
1 change: 1 addition & 0 deletions R/hype.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ if (F) {
#' )
#' h1$run_all()
#' h1$add_EI(n = 1)
#' h1$run_all()
#' #system.time(h1$run_EI_for_time(sec=3, batch_size = 1))
#' #system.time(h1$run_EI_for_time(sec=3, batch_size = 3))
#' h1$plotorder()
Expand Down
12 changes: 12 additions & 0 deletions man/ffexp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/hype.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions scratch/ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ If yes, maybe don't.
* recover temp gives error, print which one

* Delete results of a trial (flip completed, remove from outlist and outdfs)

* Rename ffexp?

* Run fractional experiments?

* ffexp plot effects?

* calculate effects that calculates slopes instead of for each level.

* add_level fix outcleandf

* print something after run_all

* run_all print running then clear with \r

* list outputs, get some for outcleandf
7 changes: 5 additions & 2 deletions tests/testthat/test_ffexp.R
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,22 @@ test_that("Test add_variable", {
expect_error({rm(f1, g1); gc()}, NA)
})

# Add level ----
test_that("Test add_level", {
f1 <- ffexp$new(n=c(100, 1000, 10000),
nulleff=c(0,1),
eval_func=function(n, nulleff) {
samp <- rnorm(n)
data.frame(mean=mean(samp), se=sd(samp)/sqrt(n))}
)
f1$run_all(verbose=0)
f1$run_all(to_run = c(1,4), verbose=0)
# f1$run_all(verbose=0)
expect_error(f1$add_level("notavar", 2))
g1 <- f1$add_level("nulleff", 2)
expect_equal(9, length(g1$completed_runs))
expect_equal(sum(f1$completed_runs), sum(g1$completed_runs))
expect_equal(length(g1$completed_runs), 3 + length(f1$completed_runs))
expect_equal(nrow(g1$outcleandf), 9)

# Add two new levels
g1$run_all(verbose=0)
Expand All @@ -331,7 +334,7 @@ test_that("Test add_level", {
expect_equal(length(h1$completed_runs), 9 + length(f1$completed_runs))

# Delete at end
expect_error({rm(f1, g1); gc()}, NA)
expect_error({rm(f1, g1, h1); gc()}, NA)
})

test_that("Test add_level with data frame", {
Expand Down

0 comments on commit d193c54

Please sign in to comment.