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

Keep 0 dimensional parameters as 0 dimensional instead of 1 dimensional #575

Merged
merged 11 commits into from
Oct 22, 2022

Conversation

tomicapretto
Copy link
Collaborator

Until now, we've been treating 0-dimensional parameters (a slope parameter for a 1d numerical predictor) as 1-dimensional. It was not creating any visible issues until we have #572.

This PR creates 0-dimensional parameters in PyMC when they're 0-dimensional so we avoid unnecessary dimensions in the resulting InferenceData object.

Following the example in the issue, now it works.

import bambi as bmb
import pandas as pd

df = pd.DataFrame({'x': [1,2,3], 'y': [2, 3, 4], 'z': [2, 2, 4]})

test_model = bmb.Model('y ~ 1 + x', df)
test_model.build()
test_model.graph()

image

test_approx = test_model.fit(inference_method='vi')
test_tr = test_approx.sample(draws=1000)
test_model.predict(idata=test_tr, data=pd.DataFrame({'x': [4, 5], 'y': [1,1]}))

Also with two predictors

test_model = bmb.Model('y ~ 1 + x + z', df)
test_model.build()
test_model.graph()

image

test_approx = test_model.fit(inference_method='vi')
test_tr = test_approx.sample(draws=1000)
test_model.predict(idata=test_tr, data=pd.DataFrame({'x': [4, 5], 'y': [1, 1], 'z': [3, 3]}))

@codecov-commenter
Copy link

codecov-commenter commented Oct 16, 2022

Codecov Report

Merging #575 (bc1462c) into main (32525a8) will increase coverage by 1.12%.
The diff coverage is 92.23%.

@@            Coverage Diff             @@
##             main     #575      +/-   ##
==========================================
+ Coverage   86.02%   87.15%   +1.12%     
==========================================
  Files          32       29       -3     
  Lines        2691     2413     -278     
==========================================
- Hits         2315     2103     -212     
+ Misses        376      310      -66     
Impacted Files Coverage Δ
bambi/backend/pymc.py 82.18% <ø> (ø)
bambi/families/univariate.py 87.20% <75.75%> (+0.61%) ⬆️
bambi/backend/terms.py 96.29% <100.00%> (+0.04%) ⬆️
bambi/families/link.py 65.71% <100.00%> (ø)
bambi/families/multivariate.py 97.67% <100.00%> (+0.23%) ⬆️
bambi/models.py 85.63% <100.00%> (+0.37%) ⬆️
bambi/utils.py
bambi/terms.py
bambi/__init__.py

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tomicapretto
Copy link
Collaborator Author

It's much easier to review this one. We can merge this right after we merge #573

@tomicapretto tomicapretto merged commit 9a29a27 into bambinos:main Oct 22, 2022
@tomicapretto tomicapretto deleted the pymc_shapes branch October 22, 2022 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants