CCS-Lab / hBayesDM

Hierarchical Bayesian modeling of RLDM tasks, using R & Python
https://ccs-lab.github.io/hBayesDM
GNU General Public License v3.0
223 stars 113 forks source link

Refactor Stan files into chunks #61

Open dlemfh opened 6 years ago

dlemfh commented 6 years ago

As Ben Goodrich mentioned a year back, it may be worth refactoring the Stan files into smaller chunks that can be shared across multiple Stan files.

I think the main thing is that you need to consolidate your 10 Stan programs into a smaller number of Stan programs that have branch logic. The rstanarm package technically only has 6 .stan files, although you can estimate many more types of models.

It works like this: https://github.com/stan-dev/rstanarm/blob/master/src/stan_files/count.stan image Where you use the #include notation to include a .stan file, and while it behaves as an inline replacement, compilation is only done once even if this code chunk is used multiple times, thus increasing the efficiency in the compilation process.

Although, for our package, it is true that models of different tasks do not have many overlapping lines of code to go through a major refactoring.

Thus, good places to start would be:

JaeyeongYang commented 6 years ago

I highly agree on the point that repetitions on the codebase make the whole package large and slow on the compilation time. But instead of using one single file for a model, making it a combination of separate code files might lead new developers a little hard to understand the overall processes. So, before we start to make it into separate chunks, I think we should determine which chunks can be organized into one submodule-like group.

In the example of rstanarm, the developers organized them following the code blocks (e.g., functions, data, tdata or transformed data, and so on). Following that kind of approach can be one good way to go.

dlemfh commented 6 years ago