Skip to content

Commit

Permalink
reorder code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bai-Li-NOAA committed Aug 1, 2024
1 parent 03caaa5 commit 163d559
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
32 changes: 16 additions & 16 deletions content/R/pk_prepare_dat.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,19 @@ res <- rbind(res, landings, index, catchage, indexage)
## rm(landings, index, catchage, indexage)

age_frame <- FIMS::FIMSFrame(res)
# fishery_catch <- FIMS::m_landings(age_frame)
# fishery_agecomp <- FIMS::m_agecomp(age_frame, "fleet1")
# survey_index2 <- FIMS::m_index(age_frame, "survey2")
# survey_agecomp2 <- FIMS::m_agecomp(age_frame, "survey2")
# survey_index3 <- FIMS::m_index(age_frame, "survey3")
# survey_agecomp3 <- FIMS::m_agecomp(age_frame, "survey3")
# survey_index6 <- FIMS::m_index(age_frame, "survey6")
# survey_agecomp6 <- FIMS::m_agecomp(age_frame, "survey6")
# # need to think about how to deal with multiple fleets - only using 1 fleeet for now
# fish_index <- methods::new(Index, nyears)
# fish_age_comp <- methods::new(AgeComp, nyears, nages)
# fish_index$index_data <- fishery_catch
# fish_age_comp$age_comp_data <-
# fishery_agecomp * catchage$uncertainty#rep(Ncaa, each=nages)
#
# FIMS::m_index(age_frame, 'survey2')
fishery_catch <- FIMS::m_landings(age_frame)
fishery_agecomp <- FIMS::m_agecomp(age_frame, "fleet1")
survey_index2 <- FIMS::m_index(age_frame, "survey2")
survey_agecomp2 <- FIMS::m_agecomp(age_frame, "survey2")
survey_index3 <- FIMS::m_index(age_frame, "survey3")
survey_agecomp3 <- FIMS::m_agecomp(age_frame, "survey3")
survey_index6 <- FIMS::m_index(age_frame, "survey6")
survey_agecomp6 <- FIMS::m_agecomp(age_frame, "survey6")
# need to think about how to deal with multiple fleets - only using 1 fleeet for now
fish_index <- methods::new(Index, nyears)
fish_age_comp <- methods::new(AgeComp, nyears, nages)
fish_index$index_data <- fishery_catch
fish_age_comp$age_comp_data <-
fishery_agecomp * catchage$uncertainty#rep(Ncaa, each=nages)

FIMS::m_index(age_frame, 'survey2')
22 changes: 10 additions & 12 deletions content/run_pollock_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,28 @@ estimate_q6 <- TRUE
estimate_F <- TRUE
estimate_recdevs <- TRUE



## Organize input lists by process
clear()
clear_logs()
# source("R/pk_prepare_FIMS_inputs.R")
source(file.path(getwd(), "content", "R", "pk_prepare_FIMS_inputs.R"))
# source("R/pk_prepare_FIMS_inputs_by_process.R")
source(file.path(getwd(), "content", "R", "pk_prepare_FIMS_inputs_by_process.R"))
## make FIMS model
success <- CreateTMBModel()
parameters <- list(p = get_fixed())
obj1 <- MakeADFun(data = list(), parameters, DLL = "FIMS", silent = TRUE)
rep1 <- obj1$report()
obj2 <- MakeADFun(data = list(), parameters, DLL = "FIMS", silent = TRUE)
## report values for the two models
rep2 <- obj2$report()


## Organize input lists by process
clear()
clear_logs()
# source("R/pk_prepare_FIMS_inputs_by_process.R")
source(file.path(getwd(), "content", "R", "pk_prepare_FIMS_inputs_by_process.R"))
# source("R/pk_prepare_FIMS_inputs.R")
source(file.path(getwd(), "content", "R", "pk_prepare_FIMS_inputs.R"))
## make FIMS model
success <- CreateTMBModel()
parameters <- list(p = get_fixed())
obj2 <- MakeADFun(data = list(), parameters, DLL = "FIMS", silent = TRUE)
## report values for the two models
rep2 <- obj2$report()
obj1 <- MakeADFun(data = list(), parameters, DLL = "FIMS", silent = TRUE)
rep1 <- obj1$report()

## Test that the two models are identical
all.equal(rep1,rep2)
Expand Down
27 changes: 26 additions & 1 deletion content/run_pollock_tests_by_fleet.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ nages <- 10
ages <- 1:nages
source(file.path(getwd(), "content", "R", "pk_prepare_dat.R"))


# test R functions: approach 1 --------------------------------------------
clear()
clear_logs()
Expand Down Expand Up @@ -224,12 +223,38 @@ obj3 <- TMB::MakeADFun(data = list(), parameters, DLL = "FIMS", silent = TRUE)
## report values for the two models
rep3 <- obj3$report()


clear()
clear_logs()
# source("R/pk_prepare_FIMS_inputs.R")
estimate_fish_selex <- TRUE
estimate_survey_selex <- TRUE
estimate_q2 <- TRUE
estimate_q3 <- TRUE
estimate_q6 <- TRUE
estimate_F <- TRUE
estimate_recdevs <- TRUE
source(file.path(getwd(), "content", "R", "pk_prepare_FIMS_inputs.R"))
## make FIMS model
success <- CreateTMBModel()
parameters <- list(p = get_fixed())
obj1 <- TMB::MakeADFun(data = list(), parameters, DLL = "FIMS", silent = TRUE)
rep1 <- obj1$report()

## Parameters are in a different order but seem to match
opt1 <- with(obj1, nlminb(par, fn, gr))
opt3 <- with(obj3, nlminb(par, fn, gr))
clear()
clear_logs()


## Test that the two models are identical
all.equal(rep1,rep3)
all.equal(obj1$report(opt1$par), obj3$report(opt3$par))
sum(obj1$par)-sum(obj3$par)

print(cbind(sort(opt1$par)- sort(opt3$par)))

# test R functions: approach 2 --------------------------------------------
# selectivity_double_logistic <- set_selectivity(
# form = "DoubleLogisticSelectivity",
Expand Down

0 comments on commit 163d559

Please sign in to comment.