BiologicalRecordsCentre / sparta

Species Presence/Absence R Trends Analyses
http://biologicalrecordscentre.github.io/sparta/index.html
MIT License
21 stars 24 forks source link

Scoping out major surgery to `occDetFunc` #249

Open drnickisaac opened 1 year ago

drnickisaac commented 1 year ago

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.

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 commented 1 year ago

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

drnickisaac commented 1 year ago

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

03rcooke commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.