-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
[FR] Use row-wise mult when adding random effects #825
Comments
It's only circumstantial evidence but throwing the above model change into cmdstanr seems to make the model a lot faster I wonder if we could do something like cmdstan performance test but with a handful of brms models |
I think this is too much fiddling, would require a bit too much of a rewrite, but the gist below has a semi complicated model with a matrix version of the random effect accumulation that's pretty general. It only assumes the random effects input vectors are all the same size. The only major bummer is that mu += transpose(columns_dot_product(transpose(r_1_mu[J_1, ]), transpose(Z_1))); https://gist.github.com/SteveBronder/796836a9ab72b5726b1fa8a17ce951b3 If you have any other ideas or things that would make things easier for brms models in stan math lmk! |
Thank you so much steve for diving into this! I had the same feeling that we should be able to make this more efficient. See #772 and the 're-multiple-indexing' branch. I am not sure if I tried the raw multi-indexing stuff, that is just avoding the loop but keeping everything else the same, but the more concise version (or at least the on I tried) actually seems to be slower. A second problem is that, due to brms' ID syntax, r_1 may need to be split into multiple parts distributed across distributional parameters or response variables. This needs to be taken into account as well when performing the indexing. |
Ty!
Can you share the mod you are checking? .* being slower might be due to some weird things upstream I can check out
Ah in that case yes probs better to keep as is! |
I will provide more information in the other thread about what exactly I have tried and with what model later on. Thank you for helping me with this! |
Right now for a simple random effects model brms generates something like
Then the generated C++ is
Would using J_1 directly with multi-indexing give the same result? ala
Because the C++ code looks a bit nicer. I can run some lil tests but the below should vectorize a bit better
If we put Z_* into a matrix instead of separate vectors and I added a
colwise_sum
method in stan math we could do something likeThe text was updated successfully, but these errors were encountered: