diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds index e1614ce..20670a5 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds index 6fd8ccb..abdc8c2 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds index 593a877..9e3929e 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds index a45660d..80afd5a 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds index 0f069d2..ae7a463 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds index 20fe29f..f93a945 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds index 0f028e8..a1bc572 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds index 4915993..9b67535 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds index 6a6fac8..c96b832 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds index a45660d..3fc7716 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds index 0f069d2..5e0ffed 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds index 20fe29f..cc48679 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds index c7f9f27..95f6e48 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds index 5ec0f4e..4e9181f 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds index ecef84e..b74ee91 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds index a5487fd..162ad46 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds index b6389f0..ef352f7 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds index afca81e..8564e0b 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds index f2bf400..788b166 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds index 0b11d79..6c86be3 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds index a825c7d..5fc06be 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds index 478ebfc..f87b6f0 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds index 8924de6..290abdd 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds index db66b72..ac4f1c4 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds index f2e296d..de01621 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds index 9fa6f6f..46e004e 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds index 9335c47..60f0f18 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds index 478ebfc..72b91be 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds index 8924de6..e335373 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds index db66b72..9a6c007 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds index d14f3a5..a849199 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds index e0e9876..e3b8f40 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds index 6cf3e76..5f72ca4 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds index a5ad8f0..7ec5608 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds index 951923a..388351d 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds index c5c5225..7944c8f 100644 Binary files a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/test-constants.R b/tests/testthat/test-constants.R index c688285..7d0cbdb 100644 --- a/tests/testthat/test-constants.R +++ b/tests/testthat/test-constants.R @@ -5,8 +5,7 @@ CREATE_BASELINE_FILES <- FALSE NUMBER_OF_STEPS <- 5 # should be an odd multiple of nrows=600 (i.e., 5,15,30) FACTOR_VALUE <- 5 -SEED_VALUE <- 1 -SEED_OFFSET <- 2000 +SEED_VALUE <- 7 TOLERANCE_VALUE <- 1e-5 RUN_QUIET <- TRUE YLIMIT_DIFFERENCE_PLOTS <- 0.05 diff --git a/tests/testthat/test-rpath.R b/tests/testthat/test-rpath.R index cae56c5..dfc187a 100644 --- a/tests/testthat/test-rpath.R +++ b/tests/testthat/test-rpath.R @@ -20,6 +20,9 @@ print(paste0("OUTPUT_DATA_DIR: ", OUTPUT_DATA_DIR)) #RSK print(paste0("INPUT_DATA_DIR_BASELINE: ", INPUT_DATA_DIR_BASELINE)) #RSK print(paste0("INPUT_DATA_DIR_CURRENT: ", INPUT_DATA_DIR_CURRENT)) #RSK +# Set the seed here so that all runs will be deterministic. +set.seed(SEED_VALUE) + # Create the current and output directories if they don't already exist. if (! dir.exists(INPUT_DATA_DIR_CURRENT)) { dir.create(INPUT_DATA_DIR_CURRENT,recursive=TRUE) @@ -612,7 +615,6 @@ testthat::test_that("Rpath Unit Tests", { # in the tests.yml file but don't fail when run via R-CMD-Check.yml. # # This line doesn't fail in git actions (it's just not the exact logic I need) - # set.seed(modNum*typeNum*SEED_OFFSET) # REcosystem_scenario_jitter$forcing$ForcedBio <- jitter(REcosystem_scenario_jitter$forcing$ForcedBio,factor=FACTOR_VALUE) # # Another way to jitter @@ -626,7 +628,7 @@ testthat::test_that("Rpath Unit Tests", { # speciesBiomass <- REcosystem_scenario_jitter$start_state$Biomass[aSpecies] # totSpeciesBiomass <- totSpeciesBiomass + speciesBiomass # for (month in 1:numMonths) { - # randVal <- randomNumber(modNum*typeNum*SEED_OFFSET+speciesNum*numMonths+month) + # randVal <- ... # jitteredValue <- speciesBiomass * (1.0 + randVal) # totRandVal <- totRandVal + randVal # jitterVector <- append(jitterVector,jitteredValue) @@ -742,7 +744,7 @@ testthat::test_that("Rpath Unit Tests", { numMonths <- nrow(REcosystem_scenario$fishing$ForcedEffort) REcosystem_scenario_jitter <- REcosystem_scenario fishingOriginalData <- list(REcosystem_scenario$fishing$ForcedEffort, REcosystem_scenario$fishing$ForcedFRate, REcosystem_scenario$fishing$ForcedCatch) - typeData <- list(FORCED_EFFORT,FORCED_FRATE,FORCED_CATCH) + typeData <- list(FORCED_EFFORT, FORCED_FRATE, FORCED_CATCH) for (i in 1:length(fishingOriginalData)) { theTypeData <- typeData[[i]] modNum <- modNum + 1 diff --git a/tests/testthat/test-utils-jitter.R b/tests/testthat/test-utils-jitter.R index 6194d5d..09fcbfd 100644 --- a/tests/testthat/test-utils-jitter.R +++ b/tests/testthat/test-utils-jitter.R @@ -6,15 +6,13 @@ source("test-constants.R") #' #' @param matrix : data matrix to be jittered #' @param factor : the R jitter factor (the larger the number the greater the jitter amount) -#' @param seedOffset : offset to the seed value, useful for getting "groups" of seed values #' @param xlabel : x axis label for plot #' @param ylabel : y axis label for plot #' @param title : main title for plot #' #' @return Returns the jittered matrix #' -addJitter <- function(matrix,seedOffset,xlabel,ylabel,title) { - set.seed(seedOffset) # *SEED_VALUE) +addJitter <- function(matrix,xlabel,ylabel,title) { # From jitter() doc: If amount == 0, jitter returns factor * z/50, where # z = max(x0) - min(x), aka the range. So if factor=5 and amount=0, jitter() # returns a random value within a tenth of the range. @@ -28,26 +26,26 @@ addJitter <- function(matrix,seedOffset,xlabel,ylabel,title) { #' Create a jittered vector #' -#' Used for jittering a matrix column. Can't use replicate because need to pass a different seed for every value for reproducibility. +#' Used for jittering a matrix column. #' +#' @param typeData : the type of data to be jittered #' @param value : value to add jitter to #' @param numElements : number of elements in vector -#' @param seedOffset : offset to the main seed value #' @param xlabel : x axis label for plot #' @param ylabel : y axis label for plot #' @param title : main title for plot +#' @param title : the type of random number (positive only or any) #' #' @return Returns the column-jittered matrix #' -createJitterVectorFromValue <- function(typeData,value,numElements,seedOffset,xlabel,ylabel,title,randomNumberType) { +createJitterVectorFromValue <- function(typeData,value,numElements,xlabel,ylabel,title,randomNumberType) { jitterVector <- c() migrationScaleFactor <- 1 if (typeData == FORCED_MIGRATION) { migrationScaleFactor = FORCED_MIGRATION_SCALE_FACTOR_JITTER # = 1000 } for (i in 1:numElements) { - # jitteredValue <- addJitter(value,seedOffset+i,'','','') - randVal <- randomNumber(seedOffset+i,migrationScaleFactor*JITTER_AMOUNT_PCT,randomNumberType) # JITTER_AMOUNT_PCT = 0.01 + randVal <- randomNumber(migrationScaleFactor*JITTER_AMOUNT_PCT,randomNumberType) jitteredValue <- value * (1.0 + randVal) jitterVector <- append(jitterVector,jitteredValue) } diff --git a/tests/testthat/test-utils-plot.R b/tests/testthat/test-utils-plot.R index ee5b244..6f90540 100644 --- a/tests/testthat/test-utils-plot.R +++ b/tests/testthat/test-utils-plot.R @@ -19,7 +19,7 @@ source("test-constants.R") plotResultsSuperimposed <- function(BaseData,CurrData,baseAlg,currAlg,tableName,forcedData,forcedType,species) { plots <- list() group <- species - yLabel <- "Biomass (mt/km²)" + yLabel <- "Biomass (mt/km\U00B2)" currDf <- data.frame() baseDf <- data.frame() @@ -80,7 +80,7 @@ plotResultsSuperimposed <- function(BaseData,CurrData,baseAlg,currAlg,tableName, plotResultsDifference <- function(BaseData,CurrData,baseAlg,currAlg,tableName,forcedData,forcedType,species) { plots <- list() group <- species - yLabel <- "Biomass (mt/km²)" + yLabel <- "Biomass (mt/km\U00B2)" diffDf <- data.frame() for (member in group) { diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index c56d17f..319ed30 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -2,15 +2,15 @@ source("test-constants.R") #' Random number generator #' -#' This function returns a seeded random number from a uniform distribution between +#' This function returns a random number from a uniform distribution between #' a min and max value. #' -#' @param seed : the random "seed" value to make the function deterministic +#' @param pctToJitter : the percent to jitter (value=0.5 means 50%) +#' @param positiveOnly : boolean that signifies random number returned is limited to non-negative numbers #' #' @return Returns the random value #' -randomNumber <- function(seed,pctToJitter,positiveOnly) { - set.seed(seed) +randomNumber <- function(pctToJitter,positiveOnly) { minJitter <- -pctToJitter maxJitter <- pctToJitter if (positiveOnly) { @@ -112,7 +112,7 @@ modifyFishingMatrix <- function(modNum,species,fleets,typeData,forcingData,model const2 <- 1 upperLimit <- 0.5 usePBValue <- FALSE - scaleFactorPB <- 0.01 # Needed this to add enough randomness to the plots, else they'd be fairly smooth + scaleFactorPB <- 0.0001 # Needed this to add enough randomness to the plots, else they'd be fairly smooth if (typeData == "Forced Effort") { speciesOrFleets <- fleets } else if (typeData == "Forced FRate" || typeData == "Forced Catch") { @@ -132,14 +132,11 @@ modifyFishingMatrix <- function(modNum,species,fleets,typeData,forcingData,model for (i in 1:length(speciesOrFleets)) { item <- speciesOrFleets[i] vectorData <- ForcedMatrix[,item] - # matrixDataWithJitter <- addJitter(matrixData,modNum*SEED_OFFSET*SEED_VALUE+i,"Months","Effort",paste0(typeData," with Random Noise - ",item)) newVectorWithJitter <- c() for (value in vectorData) { j <- j + 1 # Not sure why I need the [1] index here, this should always be just a single value but sometimes it's a list - # Forced Effort: jitteredValue <- (randomNumber(i+j,0.5))[1] - # Forced FRate: pb[species index]*randomNumber(i+j,0.5))[1] - jitteredValue <- (const1+const2*randomNumber(i+j,upperLimit,randomNumberType))[1] + jitteredValue <- (const1+const2*randomNumber(upperLimit,randomNumberType))[1] newVectorWithJitter = append(newVectorWithJitter,jitteredValue) } ForcedMatrix[,item] <- newVectorWithJitter @@ -170,21 +167,20 @@ modifyForcingMatrix <- function (modNum,species,modifyType,typeData,forcingData, speciesBiomass <- scenario$start_state$Biomass[aSpecies] startValue <- speciesBiomass if (typeData == FORCED_MIGRATION) { - # rval <- (randomNumber(i,FORCED_MIGRATION_BIOMASS_PCT)+FORCED_MIGRATION_BIOMASS_PCT)/2.0 - rval <- randomNumber(i,FORCED_MIGRATION_BIOMASS_PCT,randomNumberType) + # rval <- (randomNumber(FORCED_MIGRATION_BIOMASS_PCT)+FORCED_MIGRATION_BIOMASS_PCT)/2.0 + rval <- randomNumber(FORCED_MIGRATION_BIOMASS_PCT,randomNumberType) startValue <- rval # print(paste0("species: ",aSpecies,", biomass: ",speciesBiomass,", randomNum: ",rval,", startValue: ",startValue)) } - # print(paste0(modNum," ",i," ",SEED_OFFSET," ",aSpecies)) if (modifyType == JITTERED) { # print(paste0("start value: ",i,", ",startValue)) - ForcedMatrix[,aSpecies] <- createJitterVectorFromValue(typeData, startValue, numMonths, modNum*i*SEED_OFFSET, - "Months","Biomass (mt/km²)", + ForcedMatrix[,aSpecies] <- createJitterVectorFromValue(typeData, startValue, numMonths, + "Months","Biomass (mt/km\U00B2)", paste0(typeData,' with ',modifyType,' Noise - ',aSpecies), POSITIVE_AND_NEGATIVE) } else { stepType <- ((i-1)%%3)+1 # Only current step types are 1, 2, or 3 - ForcedMatrix[,aSpecies] <- stepifyBiomass(typeData, startValue, numMonths, stepType, "Months","Biomass (mt/km²)", + ForcedMatrix[,aSpecies] <- stepifyBiomass(typeData, startValue, numMonths, stepType, "Months","Biomass (mt/km\U00B2)", paste0(typeData,' with ',modifyType,' Noise - ',aSpecies), scaleFactors[i]) } }