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 Stan files into chunks #61

Open
dlemfh opened this issue Oct 31, 2018 · 2 comments
Open

Refactor Stan files into chunks #61

dlemfh opened this issue Oct 31, 2018 · 2 comments

Comments

@dlemfh
Copy link
Contributor

dlemfh commented Oct 31, 2018

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:

  • Code in the data block for handling the general_infos (e.g. N, T, Tsubj)
  • gng task models (where the next model incorporates the previous one's parameters)
  • dd task models
  • prl task models (where, for instance, ficticious_rp incorporates ficticious and rp)
  • Code for the regressors (which seem to overlap within same-task models - gng, prl)
  • Code in the generated quantities block (which seem to contain replicas of the same lines of code that have appeared earlier in the file)
@JaeyeongYang
Copy link
Contributor

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
Copy link
Contributor Author

dlemfh commented Oct 31, 2018

  • The custom functions in choiceRT_lba & choiceRT_lba_single
  • Code part for declaring y_pred and initializing all elements to -1.

@JaeyeongYang JaeyeongYang added this to the v1.0 milestone Nov 1, 2018
@JaeyeongYang JaeyeongYang removed this from the v1.0 milestone Aug 20, 2019
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

2 participants