-
Notifications
You must be signed in to change notification settings - Fork 285
Bayesian Workflow with SEMs #807
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Nathaniel <[email protected]>
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Signed-off-by: Nathaniel <[email protected]>
Signed-off-by: Nathaniel <[email protected]>
Signed-off-by: Nathaniel <[email protected]>
Signed-off-by: Nathaniel <[email protected]>
I would ditch the Rhat plots -- all the action is in a tiny region just above 1.0, so most of the plot is irrelevant. |
Signed-off-by: Nathaniel <[email protected]>
Signed-off-by: Nathaniel <[email protected]>
Signed-off-by: Nathaniel <[email protected]>
@ricardoV94 , not looking for a review, just wondering about the shape handling in the MvNormal after pymc 5.17. If you see above i have a hierarchical SEM model which uses an indexing trick to pass group specific covariance structures to the likelihood. While this works in 5.17 see above it breaks in 5.30... is that a bug, or intended behaviour. Do you know how i could replicate the results with 5.30+? |
View / edit / reply to this conversation on ReviewNB ricardoV94 commented on 2025-09-30T10:28:00Z Line #9. corr_values = [ Nit this is a terrible way to have the values in the notebook for a reader. Just tell black to ignore and let multiple values per line |
@NathanielF I didn't see any block failing in the notebook, can you give me a small snippet of code that is failing for you? You showed numpy code above |
The notebook code works but its running on pymc 5.17, you can see in the watermark... if i change or update the version. I tried to 5.30 it breaks on cell which creates the hierarchical modelling and gives the trace back you see above. I can run the notebook tonight on 5.30 and push it to show you But it should break on the cell that defines the hierarchical model. Just under the section heading "hierarchical model on structural components"... |
I see, let me take a quick look |
Thank you! |
What do you mean by pymc 5.30, last release is 5.25 |
Unrelated but please don't do this You can use a |
No worries, problem goes away then? Suggestion use the newer syntax for set_subtensor: Lambda = pt.set_subtensor(Lambda[0:3, 0], lambdas_1)
# Equivalent
Lambda = Lambda[0:3, 0].set(lambdas_1) |
Yes! I think problem goes away! Woop! |
You can also use pt.linalg.block_diag(np.ones((3, 1)), np.ones((3, 1))*2, np.ones((3, 1))*3, np.ones((3, 1))).eval()
array([[1., 0., 0., 0.],
[1., 0., 0., 0.],
[1., 0., 0., 0.],
[0., 2., 0., 0.],
[0., 2., 0., 0.],
[0., 2., 0., 0.],
[0., 0., 3., 0.],
[0., 0., 3., 0.],
[0., 0., 3., 0.],
[0., 0., 0., 1.],
[0., 0., 0., 1.],
[0., 0., 0., 1.]]) It will be more clever about the dot product with eta, since it can just dot the original matrices. CC @jessegrabowski we should have a rewrite that canonicalizes nested set_subtensor of this kind to block_diag? |
That looks like it should be much neater |
View / edit / reply to this conversation on ReviewNB ricardoV94 commented on 2025-09-30T11:33:26Z Line #9. Lambda = pt.zeros((12, 4)) Any reason you didn't use NathanielF commented on 2025-09-30T11:44:00Z None really, I think i was thinking pedagogically explaining how to abstract the pattern away into a function makes it cleaner we build more complex models.... but haven't finalised the write up around it. |
None really, I think i was thinking pedagogically explaining how to abstract the pattern away into a function makes it cleaner we build more complex models.... but haven't finalised the write up around it. View entire conversation on ReviewNB |
100% |
Marking this one as ready for review now. I won't do any more modelling work on it. I will revisit the write up and add a conclusion, but i think it might be good to get some feedback on the general structure and whether i hit the right notes about bayesian workflow/SEMs cc @fonnesbeck Also, @ricardoV94 i tried the pt.linalg method... and ran into a bug
I think i can resolve it if instead of creating a new index dynamically i just sample a set of 3 x 1 matrices originally, but then it seems like that I need a redundant dummy dimension in the coords? This seems a little inelegant. |
Bayesian Workflow with SEMs
Related to proposal here
#806
Helpful links
📚 Documentation preview 📚: https://pymc-examples--807.org.readthedocs.build/en/807/