From e5c5b292a6f316c8bff601e9270deefd9452adbd Mon Sep 17 00:00:00 2001 From: Iago Mosqueira Date: Mon, 9 Dec 2024 09:52:58 +0100 Subject: [PATCH] Added segregDa, testing --- DESCRIPTION | 4 ++-- R/fwd.R | 7 ++++--- inst/include/fwdSR.h | 3 +++ src/fwdSR.cpp | 17 +++++++++++++++++ src/operating_model.cpp | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae391de..9440fbd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,7 @@ Description: Projection of future population and fishery dynamics is carried (fleet) that will result in the required abundances, catches or fishing mortalities. X-schema.org-keywords: forecast, fisheries, flr, R -Version: 0.7.1.9221 +Version: 0.7.1.9223 Authors@R: c( person(given = 'Iago', family = 'Mosqueira', role = c('aut', 'cre'), email = 'iago.mosqueira@wur.nl'), @@ -26,7 +26,7 @@ Imports: LinkingTo: Rcpp SystemRequirements: C++11 Byarch: false -Additional_repositories: http://flr-project.org/R +Additional_repositories: https://flr.r-universe.dev Suggests: testthat, knitr, diff --git a/R/fwd.R b/R/fwd.R index 6851c36..1004df4 100644 --- a/R/fwd.R +++ b/R/fwd.R @@ -50,7 +50,7 @@ setMethod("fwd", signature(object="FLBiols", fishery="FLFisheries", control="fwdControl"), function(object, fishery, control, effort_max=rep(100, length(fishery)), deviances=residuals, residuals=lapply(lapply(object, spwn), - "[<-", value=1)) { + "[<-", value=1), verbose=FALSE) { # CHECK valid fwdControl if(!validObject(control)) @@ -301,8 +301,9 @@ setMethod("fwd", signature(object="FLBiols", fishery="FLFisheries", ids <- which(out$solver_codes != 1, arr.ind=TRUE) - warning(paste("Unsolved targets at control rows: ", - paste(unique(ids[,"row"]), collapse=", "))) + if(verbose) + warning(paste("Unsolved targets at control rows: ", + paste(unique(ids[,"row"]), collapse=", "))) } # STRUCTURE of out diff --git a/inst/include/fwdSR.h b/inst/include/fwdSR.h index c629187..63960d2 100644 --- a/inst/include/fwdSR.h +++ b/inst/include/fwdSR.h @@ -88,6 +88,9 @@ T cushing(const T srp, const std::vector params); template T segreg(const T srp, const std::vector params); +template +T segregDa(const T srp, const std::vector params); + template T survsrr(const T srp, const std::vector params); diff --git a/src/fwdSR.cpp b/src/fwdSR.cpp index e299199..7f4a5e3 100644 --- a/src/fwdSR.cpp +++ b/src/fwdSR.cpp @@ -34,6 +34,8 @@ void fwdSR_base::init_model_map(){ map_model_name_to_function["cushing"] = &cushing; map_model_name_to_function["Cushing"] = &cushing; map_model_name_to_function["Segreg"] = &segreg; + map_model_name_to_function["segregDa"] = &segregDa; + map_model_name_to_function["SegregDa"] = &segregDa; map_model_name_to_function["segreg"] = &segreg; map_model_name_to_function["survSRR"] = &survsrr; map_model_name_to_function["survsrr"] = &survsrr; @@ -499,6 +501,21 @@ T segreg(const T srp, const std::vector params){ return rec; } +template +T segregDa(const T srp, const std::vector params){ + T rec; + // rec = if(ssb < b) a * ssb else a * b + if(pow(srp, params[2]) <= params[1]) { + rec = params[0] * pow(srp, params[2]); + } + else { + rec = params[0] * params[1]; + } + return rec; +} + + + template T survsrr(const T ssf, const std::vector params){ T rec; diff --git a/src/operating_model.cpp b/src/operating_model.cpp index ad2cc25..d84e894 100644 --- a/src/operating_model.cpp +++ b/src/operating_model.cpp @@ -500,7 +500,7 @@ std::vector operatingModel::calc_rec(const unsigned int biol_no, const * Calculate the instantaneous fishing mortality * This method is the workhorse fishing mortality method that is called by other fishing mortality methods that do make checks. * F = effort * selectivity * catchability. - * F = effort * selectivity * alpha * biomass ^ -beta + * F = effort %*% selectivity * alpha * biomass ^ -beta * Selectivity and biomass are disaggregated across all the FLQ dimensions (biomass has length 1 in the quant dimension), i.e. they will have seasons and units. * Effort always has length 1 in the unit and quant dimension and is disaggregated across other dimensions. * The catchability parameters can be disaggreated across dimensions 2 to 6. If not, they are recycled.