From 86a2a1a508400d56599b97d8deef94871d032b66 Mon Sep 17 00:00:00 2001 From: kellijohnson-NOAA Date: Sat, 31 Aug 2024 15:59:11 -0700 Subject: [PATCH] fix(proportion_female): Removes faulty est input proportion_female appeared to be estimable and/or specified by the user but it was still hard coded to 0.5 for every age. This commit reverts back part of PR #543 where the hard-coded value (not by age) was made 0.5 by age with a user interface. Part of #638 --- .../include/interface/rcpp/rcpp_interface.hpp | 2 -- .../rcpp/rcpp_objects/rcpp_population.hpp | 9 --------- .../population/population.hpp | 19 +++++++++---------- tests/gtest/test_population_B_and_SB.cpp | 4 ++-- .../test_population_Unfished_Initial.cpp | 2 +- ...dynamics_population_initialize_prepare.cpp | 8 -------- tests/gtest/test_population_test_fixture.hpp | 18 ------------------ .../testthat/test-rcpp-population-interface.R | 4 ---- 8 files changed, 12 insertions(+), 54 deletions(-) diff --git a/inst/include/interface/rcpp/rcpp_interface.hpp b/inst/include/interface/rcpp/rcpp_interface.hpp index 25b19e232..4d48416eb 100644 --- a/inst/include/interface/rcpp/rcpp_interface.hpp +++ b/inst/include/interface/rcpp/rcpp_interface.hpp @@ -431,9 +431,7 @@ RCPP_MODULE(fims) { .field("nyears", &PopulationInterface::nyears) .field("log_M", &PopulationInterface::log_M) .field("log_init_naa", &PopulationInterface::log_init_naa) - .field("proportion_female", &PopulationInterface::proportion_female) .field("ages", &PopulationInterface::ages) - .field("estimate_prop_female", &PopulationInterface::estimate_prop_female) .method("evaluate", &PopulationInterface::evaluate) .method("SetMaturity", &PopulationInterface::SetMaturity) .method("SetGrowth", &PopulationInterface::SetGrowth) diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp index 07885098d..cbb62efc4 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp @@ -64,9 +64,6 @@ class PopulationInterface : public PopulationInterfaceBase { ParameterVector log_init_naa; /**ages[i] = this->ages[i]; } - for (int i = 0; i < proportion_female.size(); i++) { - population->proportion_female[i] = this->proportion_female[i]; - if (estimate_prop_female) { - info->RegisterParameter(population->proportion_female[i]); - } - } population->numbers_at_age.resize((nyears + 1) * nages); info->variable_map[this->numbers_at_age.id_m] = &(population)->numbers_at_age; diff --git a/inst/include/population_dynamics/population/population.hpp b/inst/include/population_dynamics/population/population.hpp index 9d9694154..67d6e1f8f 100644 --- a/inst/include/population_dynamics/population/population.hpp +++ b/inst/include/population_dynamics/population/population.hpp @@ -40,13 +40,14 @@ struct Population : public fims_model_object::FIMSObject { size_t nages; /*!< total number of ages in the population*/ size_t nfleets; /*!< total number of fleets in the fishery*/ + // constants + const Type proportion_female = 0.5; /*!< Sex proportion fixed at 50/50*/ + // parameters are estimated; after initialize in create_model, push_back to // parameter list - in information.hpp (same for initial F in fleet) fims::Vector log_init_naa; /*!< estimated parameter: log numbers at age*/ fims::Vector log_M; /*!< estimated parameter: log Natural Mortality*/ - fims::Vector - proportion_female; /*!< estimated parameter: proportion female by age */ // Transformed values fims::Vector M; /*!< transformed parameter: Natural Mortality*/ @@ -131,7 +132,6 @@ struct Population : public fims_model_object::FIMSObject { mortality_F.resize(nyears * nages); mortality_Z.resize(nyears * nages); proportion_mature_at_age.resize((nyears + 1) * nages); - proportion_female.resize(nages); weight_at_age.resize(nages); unfished_numbers_at_age.resize((nyears + 1) * nages); biomass.resize((nyears + 1)); @@ -169,7 +169,6 @@ struct Population : public fims_model_object::FIMSObject { std::fill(proportion_mature_at_age.begin(), proportion_mature_at_age.end(), 0.0); std::fill(mortality_Z.begin(), mortality_Z.end(), 0.0); - std::fill(proportion_female.begin(), proportion_female.end(), 0.5); // Transformation Section for (size_t age = 0; age < this->nages; age++) { @@ -315,9 +314,9 @@ struct Population : public fims_model_object::FIMSObject { */ void CalculateSpawningBiomass(size_t i_age_year, size_t year, size_t age) { this->spawning_biomass[year] += - this->proportion_female[age] * this->numbers_at_age[i_age_year] * + this->proportion_female * this->numbers_at_age[i_age_year] * this->proportion_mature_at_age[i_age_year] * this->weight_at_age[age]; - POPULATION_LOG << " proportion female " << this->proportion_female[age] + POPULATION_LOG << " proportion female " << this->proportion_female << " " << " mature age " << age << " is " << this->proportion_mature_at_age[i_age_year] << " " @@ -340,7 +339,7 @@ struct Population : public fims_model_object::FIMSObject { void CalculateUnfishedSpawningBiomass(size_t i_age_year, size_t year, size_t age) { this->unfished_spawning_biomass[year] += - this->proportion_female[age] * + this->proportion_female * this->unfished_numbers_at_age[i_age_year] * this->proportion_mature_at_age[i_age_year] * this->weight_at_age[age]; } @@ -353,12 +352,12 @@ struct Population : public fims_model_object::FIMSObject { Type CalculateSBPR0() { std::vector numbers_spr(this->nages, 1.0); Type phi_0 = 0.0; - phi_0 += numbers_spr[0] * this->proportion_female[0] * + phi_0 += numbers_spr[0] * this->proportion_female * this->proportion_mature_at_age[0] * this->growth->evaluate(ages[0]); for (size_t a = 1; a < (this->nages - 1); a++) { numbers_spr[a] = numbers_spr[a - 1] * fims_math::exp(-this->M[a]); - phi_0 += numbers_spr[a] * this->proportion_female[a] * + phi_0 += numbers_spr[a] * this->proportion_female * this->proportion_mature_at_age[a] * this->growth->evaluate(ages[a]); } @@ -367,7 +366,7 @@ struct Population : public fims_model_object::FIMSObject { (numbers_spr[nages - 2] * fims_math::exp(-this->M[nages - 2])) / (1 - fims_math::exp(-this->M[this->nages - 1])); phi_0 += numbers_spr[this->nages - 1] * - this->proportion_female[this->nages - 1] * + this->proportion_female * this->proportion_mature_at_age[this->nages - 1] * this->growth->evaluate(ages[this->nages - 1]); return phi_0; diff --git a/tests/gtest/test_population_B_and_SB.cpp b/tests/gtest/test_population_B_and_SB.cpp index 0ce4fe698..8be185381 100644 --- a/tests/gtest/test_population_B_and_SB.cpp +++ b/tests/gtest/test_population_B_and_SB.cpp @@ -13,7 +13,7 @@ namespace std::vector test_SB(nyears + 1, 0); std::vector test_B(nyears + 1, 0); - test_SB[year] += population.numbers_at_age[i_age_year] * population.proportion_female[age] * population.proportion_mature_at_age[i_age_year] * + test_SB[year] += population.numbers_at_age[i_age_year] * 0.5 * population.proportion_mature_at_age[i_age_year] * population.growth->evaluate(population.ages[age]); test_B[year] += population.numbers_at_age[i_age_year] * population.growth->evaluate(population.ages[age]); @@ -40,7 +40,7 @@ namespace std::vector test_SSB(nyears + 1, 0); - test_SSB[nyears] += population.numbers_at_age[i_age_year] * population.proportion_female[age] * + test_SSB[nyears] += population.numbers_at_age[i_age_year] * 0.5 * population.proportion_mature_at_age[i_age_year] * population.growth->evaluate(population.ages[age]); diff --git a/tests/gtest/test_population_Unfished_Initial.cpp b/tests/gtest/test_population_Unfished_Initial.cpp index b2d725330..983beb218 100644 --- a/tests/gtest/test_population_Unfished_Initial.cpp +++ b/tests/gtest/test_population_Unfished_Initial.cpp @@ -115,7 +115,7 @@ namespace population.CalculateUnfishedSpawningBiomass(i_age_year, year, age); test_unfished_spawning_biomass[year] += population.proportion_mature_at_age[i_age_year] * - population.proportion_female[age] * + 0.5 * test_unfished_numbers_at_age[i_age_year] * population.growth->evaluate(population.ages[age]); diff --git a/tests/gtest/test_population_dynamics_population_initialize_prepare.cpp b/tests/gtest/test_population_dynamics_population_initialize_prepare.cpp index f87e3edd5..6752f4677 100644 --- a/tests/gtest/test_population_dynamics_population_initialize_prepare.cpp +++ b/tests/gtest/test_population_dynamics_population_initialize_prepare.cpp @@ -32,7 +32,6 @@ namespace EXPECT_EQ(population.unfished_spawning_biomass.size(), (nyears + 1)); EXPECT_EQ(population.spawning_biomass.size(), nyears + 1); EXPECT_EQ(population.log_init_naa.size(), nages); - EXPECT_EQ(population.proportion_female.size(), nages); EXPECT_EQ(population.log_M.size(), nyears * nages); EXPECT_EQ(population.M.size(), nyears * nages); } @@ -85,13 +84,6 @@ namespace } EXPECT_EQ(population.M.size(), nyears * nages); - // Test population.proportion_female - fims::Vector p_female(nages, 0.5); - for(int i = 0; i < nages; i++) - { - EXPECT_EQ(population.proportion_female[i], p_female[i]); - } - // Test population.fleet->Fmort // fmort and logfmort are vectors of length year fims::Vector Fmort(nfleets * nyears, 0); diff --git a/tests/gtest/test_population_test_fixture.hpp b/tests/gtest/test_population_test_fixture.hpp index 89a34c30d..76f0c03b9 100644 --- a/tests/gtest/test_population_test_fixture.hpp +++ b/tests/gtest/test_population_test_fixture.hpp @@ -116,15 +116,6 @@ class PopulationEvaluateTestFixture : public testing::Test { population.log_init_naa[i] = log_naa_distribution(generator); } - // prop_female - double prop_female_min = 0.1; - double prop_female_max = 0.9; - std::uniform_real_distribution prop_female_distribution( - prop_female_min, prop_female_max); - for (int i = 0; i < nages; i++) { - population.proportion_female[i] = prop_female_distribution(generator); - } - // log_M double log_M_min = fims_math::log(0.1); double log_M_max = fims_math::log(0.3); @@ -277,15 +268,6 @@ class PopulationPrepareTestFixture : public testing::Test { population.log_init_naa[i] = log_naa_distribution(generator); } - // prop_female - double prop_female_min = 0.1; - double prop_female_max = 0.9; - std::uniform_real_distribution prop_female_distribution( - prop_female_min, prop_female_max); - for (int i = 0; i < nages; i++) { - population.proportion_female[i] = prop_female_distribution(generator); - } - // log_M double log_M_min = fims_math::log(0.1); double log_M_max = fims_math::log(0.3); diff --git a/tests/testthat/test-rcpp-population-interface.R b/tests/testthat/test-rcpp-population-interface.R index ce671328b..099292052 100644 --- a/tests/testthat/test-rcpp-population-interface.R +++ b/tests/testthat/test-rcpp-population-interface.R @@ -11,8 +11,6 @@ test_that("Population input settings work as expected", { population$nfleets <- 2 population$nseasons <- 1 population$nyears <- nyears - population$proportion_female <- rep(0.5, nages) - population$estimate_prop_female <- FALSE expect_equal(population$get_id(), 1) for(i in 1:(nyears * nages)){ @@ -23,8 +21,6 @@ test_that("Population input settings work as expected", { expect_equal(population$log_init_naa[i]$value, 0) expect_true(population$log_init_naa[i]$estimated) } - expect_false(population$estimate_prop_female) - expect_equal(population$proportion_female, rep(0.5, nages)) clear() })