Using VI & minibatches with Bambi (original) (raw)

April 20, 2023, 10:44am 1

@tcapretto

I have a dataset that looks like this:

Screenshot 2023-04-20 at 6.34.21 AM

I build the model with this formula:

Screenshot 2023-04-20 at 6.34.14 AM

And I call a fit using Variational Inference using this:

fit = model.fit(inference_method=‘vi’, n_init=100_000, obj_optimizer=pm.adagrad_window(learning_rate=1e-2)).sample(1_000)

Everything works fine (tested it on a much smaller row count) but is slow at 164k observations. I want to use the pm.minibatch function but struggling with how to get it to work.

I thought of doing the model.build() then >>>> with model.build() as xxx: then setting pm.MutableData but getting stuck.

Any ideas would be appreciated but wanted to pin this here and if I figure out a solution share it.

Hi!

A couple of comments

zweli April 20, 2023, 12:09pm 3

Whoops, I meant ‘cumruns ~ 1 + (1|striker) + (1|striker:ballnumber)’ - wich nests the balls faced. This is some cricket (the sport) data that I am playing with to test growth modeling and vi, so I can use it with intensive longitudinal data. I wanted to look at the trajectories of batters of the South African team over a couple of seasons as a test case.

You can check out the notebook and data here:

Looks really nice! I love you use both polars and plotnine, we need more of that in the Python world!

If this is not proprietary, are you interested in contributing this example or a simplified version to our docs? :smiley:

zweli April 20, 2023, 4:55pm 5

Yes! It’s time I contributed. I will ask for help as it’s my first time. But this cricket example can show longitudinal modeling + VI, which will be fun. Thanks for asking.