Skip to content

Commit

Permalink
refactor: styler and remove OS check
Browse files Browse the repository at this point in the history
  • Loading branch information
Chantel Wetzel committed Aug 29, 2022
1 parent f16e1a7 commit 33a9077
Show file tree
Hide file tree
Showing 9 changed files with 776 additions and 690 deletions.
51 changes: 25 additions & 26 deletions R/get_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,80 +13,79 @@
#'
#' @examples
#' get_settings(list("Njitter" = 10))
#'
#'
#' settings <- list()

#'
get_settings <- function(settings = NULL, verbose = FALSE) {

if (is.vector(settings)) settings <- as.list(settings)

Settings_all = list(
base_name = "model",
Settings_all <- list(
base_name = "model",
para_offset = FALSE,
run = c("jitter", "profile", "retro"),
profile_details = NULL,
version = "3.30",
exe = "ss",
verbose = FALSE,

# Jitter Settings
# Jitter Settings
extras = "-nohess",
Njitter = 100,
show_in_console = TRUE,
printlikes = FALSE,
jitter_fraction = 0.05,
jitter_init_values_src = NULL,

# Retrospective Settings
oldsubdir = "",
newsubdir = 'retro',
newsubdir = "retro",
retro_yrs = -1:-5,
overwrite = TRUE,
show_in_console = FALSE,

# Profile Settings
remove_files = TRUE,
newctlfile = "control_modified.ss",
linenum = NULL,
string = NULL,
newctlfile = "control_modified.ss",
linenum = NULL,
string = NULL,
profilevec = NULL,
usepar = FALSE,
globalpar = FALSE,
parlinenum = NULL,
usepar = FALSE,
globalpar = FALSE,
parlinenum = NULL,
parstring = NULL,
saveoutput = TRUE,
overwrite = TRUE,
whichruns = NULL,
whichruns = NULL,
prior_check = FALSE,
read_like = TRUE,
init_values_src = 0
init_values_src = 0
)

Settings_all$profile_details = get_settings_profile()
Settings_all$profile_details <- get_settings_profile()

need <- !names(Settings_all) %in% names(settings)
if (verbose) {
message("Adding the following objects to settings:\n",
paste(names(Settings_all[need]), collapse = "\n"), "\n",
appendLF = TRUE)
appendLF = TRUE
)
}
Settings_all <- c(settings, Settings_all[need])

# Check some items
if (!is.null( Settings_all$profile_details) ) {
if (length(Settings_all$profile_details[is.na(Settings_all$profile_details)]) > 0){
if (!is.null(Settings_all$profile_details)) {
if (length(Settings_all$profile_details[is.na(Settings_all$profile_details)]) > 0) {
stop("Missing entry in the get_settings_profile data frame.")
}
if (!is.numeric(Settings_all$profile_details$low) &
!is.numeric(Settings_all$profile_details$high) &
!is.numeric(Settings_all$profile_details$step_size)){
!is.numeric(Settings_all$profile_details$high) &
!is.numeric(Settings_all$profile_details$step_size)) {
stop("There is a non-numeric value in the low, high, or step size fiedl of the get_settings_profile data frame.")
}
if (sum(!Settings_all$profile_details$param_space %in% c("real", "relative", "multiplier")) > 0){
if (sum(!Settings_all$profile_details$param_space %in% c("real", "relative", "multiplier")) > 0) {
stop("The param_space column should be either real or relative in the get_settings_profile data frame.")
}

}

return(Settings_all)
}
}
102 changes: 51 additions & 51 deletions R/get_settings_profile.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#' Get Default Settings For Profiles
#'
#'
#' Create a matrix of default values for profiling over
#' the typical parameters given results will be presented to the
#' Pacific Fisheries Management Council.
#'
#'
#' The column titled 'param_space' indicated where the range of of the profile parameter
#' should be interpretted as relative to the base model estimate vs. across a pre-specified range.
#' An example is for R0 where the default setting below indicates that the param_space is relative
#' where the low bound for the profile is set = base model log(R0) - 2 and high = base model log(R0) + 2.
#' The default range for M is set as a multiplier to explore a range of (M - 0.40 * M) - (M + 0.40 * M)
#' The default range for M is set as a multiplier to explore a range of (M - 0.40 * M) - (M + 0.40 * M)
#' at a step size of 0.005. This range may be too large (or small) with a step size too large (or too small)
#' and should be considered if the default settings are appropriate for your specific model. The default setting
#' for steepness is in 'real' space which means that the low and high is in the same parameter space as the
#' parameter. A user can select any of the options for specifying a parameter range for any parameter.
#'
#' for steepness is in 'real' space which means that the low and high is in the same parameter space as the
#' parameter. A user can select any of the options for specifying a parameter range for any parameter.
#'
#' @param parameters vector of SS parameter names to conduct a profile for
#' @param low a vector of low paramater bounds for the profile
#' @param high a vector of upper parameter bounds for the profile
Expand All @@ -22,9 +22,9 @@
#' real indicates bounds in the parameter space, relative indicates how far to go from the base parameter, and
#' multiplier indicates that low and high bounds are set at x\% above and below the base parameter.
#' @param use_prior_like options: Option to include or exclude the prior likelihoods in the likelihood
#' profiles. A value of 0 corresponds to the Stock Sythesis were this would exclude
#' and a value of 1 would include the prior likelihood contribution. Parameters with priors used for estimation
#' (e.g., natural mortality, steepness) are often profiled across and including or excluding the prior likelihood
#' profiles. A value of 0 corresponds to the Stock Sythesis were this would exclude
#' and a value of 1 would include the prior likelihood contribution. Parameters with priors used for estimation
#' (e.g., natural mortality, steepness) are often profiled across and including or excluding the prior likelihood
#' contribution may be wanted in specific instances. The default setting excludes the prior likelihood contributions.
#'
#' @return A matrix of low, high, and step size values for the default parameters
Expand All @@ -34,53 +34,53 @@
#'
#' @author Chantel Wetzel & Kelli Johnson
#' @export
#'
#'
#' @examples
#' \dontrun{
#'
#'
#' # Define each parameter in real space
#' get_settings_profile( parameters = c("NatM_p_1_Fem_GP_1", "SR_BH_steep", "SR_LN(R0)"),
# low = c(0.02, 0.25, 8),
# high = c(0.07, 1.0, 11),
# step_size = c(0.005, 0.05, 0.25),
# param_space = c('real', 'real', 'real'),
#' use_prior_like = c(1, 1, 0))
#'
#' get_settings_profile(
#' parameters = c("NatM_p_1_Fem_GP_1", "SR_BH_steep", "SR_LN(R0)"),
#' # low = c(0.02, 0.25, 8),
#' # high = c(0.07, 1.0, 11),
#' # step_size = c(0.005, 0.05, 0.25),
#' # param_space = c('real', 'real', 'real'),
#' use_prior_like = c(1, 1, 0)
#' )
#'
#' # Example 2: Run a profile for natural mortality one with the prior likelihood and one without
#' get_settings_profile( parameters = c("NatM_p_1_Fem_GP_1","NatM_p_1_Fem_GP_1"),
#' low = c(0.40, 0.40),
#' high = c(0.40, 0.40),
#' step_size = c(0.005, 0.005),
#' param_space = c('multiplier', 'multiplier'),
#' use_prior_like = c(0, 1))
#'}
#' get_settings_profile(
#' parameters = c("NatM_p_1_Fem_GP_1", "NatM_p_1_Fem_GP_1"),
#' low = c(0.40, 0.40),
#' high = c(0.40, 0.40),
#' step_size = c(0.005, 0.005),
#' param_space = c("multiplier", "multiplier"),
#' use_prior_like = c(0, 1)
#' )
#' }
#'
get_settings_profile <- function( parameters = c("NatM_p_1_Fem_GP_1", "SR_BH_steep", "SR_LN(R0)"),
low = c(0.40, 0.25, -2),
high = c(0.40, 1.0, 2),
step_size = c(0.01, 0.05, 0.25),
param_space = c('multiplier', 'real', 'relative'),
use_prior_like = c(0, 0, 0))
{

if (length(parameters) != length(low) |
length(parameters) != length(high) |
length(parameters) != length(step_size) |
length(parameters) != length(param_space) |
length(parameters) != length(use_prior_like) ){
stop("Error: input vectors do match in length.")
}
get_settings_profile <- function(parameters = c("NatM_p_1_Fem_GP_1", "SR_BH_steep", "SR_LN(R0)"),
low = c(0.40, 0.25, -2),
high = c(0.40, 1.0, 2),
step_size = c(0.01, 0.05, 0.25),
param_space = c("multiplier", "real", "relative"),
use_prior_like = c(0, 0, 0)) {
if (length(parameters) != length(low) |
length(parameters) != length(high) |
length(parameters) != length(step_size) |
length(parameters) != length(param_space) |
length(parameters) != length(use_prior_like)) {
stop("Error: input vectors do match in length.")
}

out = data.frame( parameters = parameters,
low = low,
high = high,
step_size = step_size,
param_space = param_space,
use_prior_like = use_prior_like)
out <- data.frame(
parameters = parameters,
low = low,
high = high,
step_size = step_size,
param_space = param_space,
use_prior_like = use_prior_like
)

return(out)
return(out)
}




Loading

0 comments on commit 33a9077

Please sign in to comment.