Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor recruitment deviations to log space #514

Merged
merged 10 commits into from
Nov 15, 2023

Conversation

Andrea-Havron-NOAA
Copy link
Collaborator

What is the feature?

  • change recruitment deviations from parameter to log-space

How have you implemented the solution?

  • renamed recruit_deviations to log_recruit_devs
  • modified functions to account for the devs being in log-space

Does the PR impact any other area of the project?

How to test this change

  • test-fims-estimation.R
  • test-recruitment-interface.R

Developer pre-PR checklist

  • Ran devtools::check() locally and the package compiled and all R tests passed. If there are failing tests, run devtools::test(filter = "file_name") (where "test-file_name.R" is the file containing the failing tests) to troubleshoot tests. -->

Co-authored-by: iantaylor-NOAA <ian.taylor@noaa.gov>
Co-authored-by: KyleShertzer-NOAA <kyle.shertzer@noaa.gov>
@Andrea-Havron-NOAA
Copy link
Collaborator Author

changing recruitment deviations to logspace resulted in failing tests in test-fims-estimation. I have compared output from tests to output run from test-fims-estimation on main. All estimated values and negative log-likelihood values are identiical. I suspect tests are failing because gradients are larger with the refactor.

@Andrea-Havron-NOAA
Copy link
Collaborator Author

fixed gradient tests by removing the first log_recruit_dev from calculations as this value was not informing likelihoods. Additionally moved initial logr0 off true value.

The log_recruit_dev vector is now of length nyears-1. If this is how we want to constrain this vector moving forward, I will fix the remaining R and C++ tests

@msupernaw
Copy link
Contributor

msupernaw commented Nov 6, 2023 via email

@Andrea-Havron-NOAA
Copy link
Collaborator Author

@msupernaw, what I said above wasn't exactly correct. log_recruit_dev[0] is being evaluated in the recruitment likelihood, but nothing from population is informing the parameter. log_recruit_dev[0] is being pulled towards 0 as that is the mean of the rec_nll. I think this issue is related to the fact that there isn't a constraint on the log_rec_dev vector. We will be investigating the best way to constrain the log_recruit_devs in M2 (issue #364) and can look into this issue further then. Typically, this vector should be a length of nyears-1, to account for the lose of a degree of freedom in the constraint.

@Andrea-Havron-NOAA
Copy link
Collaborator Author

We decided to add a new index i_dev so it is a bit more clear that this is different from year-1. We also added documentation throughout explaining that the log_recruit_dev did not include the initial term.

@Andrea-Havron-NOAA
Copy link
Collaborator Author

I have merged main into this branch so do not update using rebase

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (e5c4588) 74.58% compared to head (ceb75b3) 76.10%.

❗ Current head ceb75b3 differs from pull request most recent head 7eb8f86. Consider uploading reports for the commit 7eb8f86 to get more accurate results

Files Patch % Lines
...dynamics/recruitment/functors/recruitment_base.hpp 33.33% 6 Missing ⚠️
...e/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #514      +/-   ##
==========================================
+ Coverage   74.58%   76.10%   +1.52%     
==========================================
  Files          38       37       -1     
  Lines        2034     1791     -243     
  Branches      136        0     -136     
==========================================
- Hits         1517     1363     -154     
+ Misses        476      428      -48     
+ Partials       41        0      -41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Andrea-Havron-NOAA Andrea-Havron-NOAA marked this pull request as ready for review November 10, 2023 00:48
@Andrea-Havron-NOAA Andrea-Havron-NOAA requested review from a team, KyleShertzer-NOAA, timjmiller and ChristineStawitz-NOAA and removed request for a team and KyleShertzer-NOAA November 10, 2023 00:48
Copy link
Contributor

@ChristineStawitz-NOAA ChristineStawitz-NOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this substantial change - at some point during M2 we should revisit the +1 and -1 throughout the indexing since I'm concerned these could lead to user index errors.

@ChristineStawitz-NOAA ChristineStawitz-NOAA merged commit 36fe2ad into main Nov 15, 2023
13 checks passed
@ChristineStawitz-NOAA ChristineStawitz-NOAA deleted the new-402-refactor-recdevs branch November 15, 2023 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants