biodiverse / ubms

Fit models to data from unmarked animals using Stan. Uses a similar interface to the R package 'unmarked', while providing the advantages of Bayesian inference and allowing estimation of random effects.
https://hmecology.github.io/ubms/
GNU General Public License v3.0
35 stars 8 forks source link

Comment model code #72

Open VLucet opened 11 months ago

VLucet commented 11 months ago

I really like that this package is bundling so many models in such an accessible way! Thank for your for efforts in that direction.

Eventually, users will want to build upon the included models (I do!). The packaged stan code seems to be written to be able to accommodate all the models at once, making it difficult to extract the code specific to a given model, understand said code, and build upon it.

I understand that modifying the code so that only code relevant to the chosen model is included at runtime would require a lot of efforts. As a first step, would it be possible to comment the stan code so that it is easier to understand? It would add great value to those who like me, have found using ubms a much needed shortcut from coding models directly from the literature.

kenkellner commented 11 months ago

It would be helpful to know if your goal is mainly to contribute to ubms, or to fit similar (customized) models separately in Stan. If the latter, I think only the code in this folder (i.e., the actual likelihood code) will be useful. I agree the lack of comments on these functions is an issue I need to fix.

Splitting the Stan code into separate files by model type is not something I'm likely to do in the future. All the Stan code is pre-compiled on package install (or when the binary package is created). The length of time this takes is proportional to the number of separate model files to compile, and it already takes a very long time. Hence the unintuitive "mega-model" structure.

I do see the need for a tool that can generate model code useful as a "starting point" for further modification. I'm working on something for this although it will use nimble rather than Stan.

VLucet commented 11 months ago

Thanks for your reply. It would be for fitting similar customized models. To be more precise, I'm interested in considering things like group size and misclassification to distance sampling models for camera trap data.

A few comments would go a long way to help adapt these models, which are otherwise not easily found written in stan code anywhere else (unless I am mistaken), making this package quite unique and valuable. I understand the reason being the "mega-model" approach.

VLucet commented 11 months ago

I hope this request did not come across badly, I apologize if it did. I understand there isn't much that can be done easily. I'll do my best to decode the stan files, and look forward these new development in nimble.

kenkellner commented 11 months ago

Not at all, you're not the first person to ask about this and the comments really ought to be improved. I'm just not sure when I will get to it. Keeping this open so I remember.