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

Scoping out major surgery to occDetFunc #249

Open
drnickisaac opened this issue Oct 14, 2022 · 5 comments
Open

Scoping out major surgery to occDetFunc #249

drnickisaac opened this issue Oct 14, 2022 · 5 comments

Comments

@drnickisaac
Copy link
Contributor

To gain the full benefit of Nimble, we could change the structure of sparta such that the model is compiled only once, then applied to each species in turn. This could really cut down on runtime.

To start scoping out the challenge, I made a list of all the points in occDetFunc where the identity of the species actually matters.

  • line 198: checks that species name is in the dataset.
  • lines 215-234: dataMetrics, apply Rules of Thumb and merging the species data onto occDetData. Based on this, there is a decision whether to proceed , which is implemented at line 242. If the species doesn't have enough data, subsequent steps are omitted.
  • line 366: defining zst
  • line 454: defining bugs_data

Changing occDetFunc so that it works with multiple species would be quite challenging.

Much of the code between lines 234 and 366 is associated with setting up of the vectors defining Regions and regional aggregates. Perhaps these could be placed into a separate function. Probably this is a general solution to make the challenge clearer: package up individual sections of the code and put them elsewhere. Then the critical dependencies will become clearer.

@drnickisaac drnickisaac self-assigned this Oct 14, 2022
@drnickisaac
Copy link
Contributor Author

drnickisaac commented Oct 14, 2022

Thinking about this some more, I'm wondering whether in fact it may be more straightforward that we thought. Some suggestions:

  • taxa_name could optionally be a vector, but this option prohibited if method="jags"
  • At line 198, the multispecies version would simply strip out species that are not in the dataset. Return a warning. Only stop if length(taxa_name) = 0
  • lines 215-234: Apply the ROT to all species in taxa_name and take forward only those that pass.
  • Test at proceed would be overridden if method="nimble"
  • line 366: Move definition of zst to much later
  • line 454: omit y from definition of bugs_data (until later)

@drnickisaac
Copy link
Contributor Author

If we go down this route, we would also have to figure out how to do this in parallel.

@03rcooke
Copy link
Contributor

This all sounds reasonable. An alternative however would be a function that wraps around occDetFunc and runs it for each species. Then this new function could have a compileOnce = TRUE argument. The function would then step through occDetFunc for the first species (the first species that doesn't drop out) and return the compiled model. This compiled model could then be fed in to occDetFunc for all species within the new function.

@drnickisaac
Copy link
Contributor Author

I've started implementing this on my version of the Nimble branch.
There are several hundred lines of code that generate the bugs_data object: I've put these into a new function called prepOccData()
I've separately wrapped the code that generates BUGS code (including the Nimble version) into a function getBUGScode() that permits writing to the screen.

@drnickisaac
Copy link
Contributor Author

This should make it easier to work with editing the Nimble version.

Once that is done, we'll want to edit the code in order to make it compatible with multiple species.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants