bambinos / bambi

BAyesian Model-Building Interface (Bambi) in Python.
https://bambinos.github.io/bambi/
MIT License
1.08k stars 124 forks source link

Extract underlying PYMC code #539

Open zwelitunyiswa opened 2 years ago

zwelitunyiswa commented 2 years ago

@tomicapretto There is a function in BRMS called make_stancode() that generates the STAN code from a BRMS model. Are we able to extract that somehow from model.build() result? Would it be hard to add this functionality?

I think that would that this would be useful for 2 reasons:

  1. It would allow users to build a base model in Bambi and then tweak it in PMYC for more power
  2. It would allow users to better understand the mechanics of models for educational purposes. I find that sometimes prefer to build models block by block in PYMC but I really struggle with mixed-effects models which I understand much better in Wilkinson Notation but struggle with in PYMC (shape struggles). I also struggle in PYMC to set predictors etc. Being able to set up a template in Bambi, and playing around with the result would be invaluable.

As always, I appreciate your kind attention.

tomicapretto commented 2 years ago

I'm familiar with the make_stancode() function in brms. There it has a much more critical importance because that's the actual code that's passed to the Stan compiler.

In our case, PyMC models are written using Python code and Python structures. Thus we don't need to write a clean version of the PyMC model and then somehow use that to build the model. Thus, we don't have a function similar to make_stancode(). I think it won't be easy to create a function that would write clean PyMC code just because how Bambi builds PyMC models... I'll keep thinking about this, but I can't promise that we'll have an implementation soon.

zwelitunyiswa commented 2 years ago

That makes sense. Thought I would ask. Thanks, mate.