Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bambinos/bambi into governance
Browse files Browse the repository at this point in the history
  • Loading branch information
tomicapretto committed Sep 27, 2023
2 parents f4d4442 + d1724e8 commit c1668dd
Show file tree
Hide file tree
Showing 66 changed files with 21,795 additions and 773 deletions.
55 changes: 0 additions & 55 deletions .github/workflows/publish-docs-release.yml

This file was deleted.

55 changes: 25 additions & 30 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ on:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
- closed

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Set up Pandoc
uses: r-lib/actions/setup-pandoc@v2

- name: Checkout source
uses: actions/checkout@v2
with:
Expand All @@ -25,37 +27,30 @@ jobs:
with:
python-version: "3.10"

- name: Install Bambi and all its dependencies
- name: Install quartodoc and griffe
run: |
conda install -c conda-forge python-graphviz
conda install pip
pip install .
pip install .[dev]
pip install .[jax]
python -m pip install --upgrade pip
python -m pip install quartodoc==0.6.1
- name: Checkout gh-pages
uses: actions/checkout@v2
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
ref: gh-pages
path: docs/_build/html

- name: Test build docs
if: github.ref != 'refs/heads/main' && ! startsWith(github.ref, 'refs/tags')
run: BUILDDIR=_build/html/main make -C docs/ local
version: 1.2.280 # since this is my local version, we could change it

- name: Build docs
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')
shell: bash
run: |
sphinx-build docs docs/_build/html
touch docs/_build/html/.nojekyll
- name: Publish docs to gh-pages
# Only once from main or a tag
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: peaceiris/actions-gh-pages@bbdfb200618d235585ad98e965f4aafc39b4c501 # v3.7.3
python -m quartodoc build --config docs/_quarto.yml
quarto render docs
touch docs/_site/.nojekyll
- name: Publish to GitHub
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags') # Only from main or a tag
uses: quarto-dev/quarto-actions/publish@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/html
keep_files: true
target: gh-pages
render: false
path: docs/_site

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11"]

name: Set up Python ${{ matrix.python-version }}
steps:
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
shell: bash -l {0}
run: |
echo "Running black..."
black bambi --check
black bambi --check --diff --color
echo "Checking code style with pylint..."
pylint bambi
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ tags
.cache
docs/_build
.vscode/
pytest.ini
pytest.ini
/.quarto/
10 changes: 1 addition & 9 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ disable=missing-docstring,
too-many-locals,
too-many-branches,
too-many-statements,
no-self-use,
too-few-public-methods,
bad-continuation,
cyclic-import # There was a false positive when working on #607


Expand Down Expand Up @@ -132,12 +130,6 @@ max-line-length=100
# Maximum number of lines in a module
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
Expand Down Expand Up @@ -259,7 +251,7 @@ good-names=b,
ok,
sd,
tr,
eta,
eta,
Run,
_log,
_,
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md → CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

### Maintenance and fixes

* Bump `quartodoc` version to 0.6.1 (#720)

### Documentation

### Deprecation

* Drop official suport for Python 3.8 (#720)


## 0.12.0

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Bambi is a high-level Bayesian model-building interface written in Python. It's

## Installation

Bambi requires a working Python interpreter (3.8+). We recommend installing Python and key numerical libraries using the [Anaconda Distribution](https://www.anaconda.com/products/individual#Downloads), which has one-click installers available on all major platforms.
Bambi requires a working Python interpreter (3.9+). We recommend installing Python and key numerical libraries using the [Anaconda Distribution](https://www.anaconda.com/products/individual#Downloads), which has one-click installers available on all major platforms.

Assuming a standard Python environment is installed on your machine (including pip), Bambi itself can be installed in one line using pip:

Expand Down
28 changes: 24 additions & 4 deletions bambi/interpret/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def predictions(
use_hdi: bool = True,
prob=None,
transforms=None,
sample_new_groups=False,
) -> pd.DataFrame:
"""Compute Conditional Adjusted Predictions
Expand Down Expand Up @@ -443,6 +444,9 @@ def predictions(
transforms : dict, optional
Transformations that are applied to each of the variables being plotted. The keys are the
name of the variables, and the values are functions to be applied. Defaults to ``None``.
sample_new_groups : bool, optional
If the model contains group-level effects, and data is passed for unseen groups, whether
to sample from the new groups. Defaults to ``False``.
Returns
-------
Expand Down Expand Up @@ -496,11 +500,15 @@ def predictions(
response_transform = transforms.get(response_name, identity)

if pps:
idata = model.predict(idata, data=cap_data, inplace=False, kind="pps")
idata = model.predict(
idata, data=cap_data, sample_new_groups=sample_new_groups, inplace=False, kind="pps"
)
y_hat = response_transform(idata.posterior_predictive[response.name])
y_hat_mean = y_hat.mean(("chain", "draw"))
else:
idata = model.predict(idata, data=cap_data, inplace=False)
idata = model.predict(
idata, data=cap_data, sample_new_groups=sample_new_groups, inplace=False
)
y_hat = response_transform(idata.posterior[response.name_target])
y_hat_mean = y_hat.mean(("chain", "draw"))

Expand Down Expand Up @@ -534,6 +542,7 @@ def comparisons(
use_hdi: bool = True,
prob: Union[float, None] = None,
transforms: Union[dict, None] = None,
sample_new_groups: bool = False,
) -> pd.DataFrame:
"""Compute Conditional Adjusted Comparisons
Expand Down Expand Up @@ -562,6 +571,9 @@ def comparisons(
transforms : dict, optional
Transformations that are applied to each of the variables being plotted. The keys are the
name of the variables, and the values are functions to be applied. Defaults to ``None``.
sample_new_groups : bool, optional
If the model contains group-level effects, and data is passed for unseen groups, whether
to sample from the new groups. Defaults to ``False``.
Returns
-------
Expand Down Expand Up @@ -631,7 +643,9 @@ def comparisons(
comparisons_data = create_differences_data(
conditional_info, contrast_info, conditional_info.user_passed, kind="comparisons"
)
idata = model.predict(idata, data=comparisons_data, inplace=False)
idata = model.predict(
idata, data=comparisons_data, sample_new_groups=sample_new_groups, inplace=False
)

predictive_difference = PredictiveDifferences(
model,
Expand Down Expand Up @@ -663,6 +677,7 @@ def slopes(
use_hdi: bool = True,
prob: Union[float, None] = None,
transforms: Union[dict, None] = None,
sample_new_groups: bool = False,
) -> pd.DataFrame:
"""Compute Conditional Adjusted Slopes
Expand Down Expand Up @@ -702,6 +717,9 @@ def slopes(
transforms : dict, optional
Transformations that are applied to each of the variables being plotted. The keys are the
name of the variables, and the values are functions to be applied. Defaults to ``None``.
sample_new_groups : bool, optional
If the model contains group-level effects, and data is passed for unseen groups, whether
to sample from the new groups. Defaults to ``False``.
Returns
-------
Expand Down Expand Up @@ -776,7 +794,9 @@ def slopes(
slopes_data = create_differences_data(
conditional_info, wrt_info, conditional_info.user_passed, effect_type
)
idata = model.predict(idata, data=slopes_data, inplace=False)
idata = model.predict(
idata, data=slopes_data, sample_new_groups=sample_new_groups, inplace=False
)

predictive_difference = PredictiveDifferences(
model, slopes_data, wrt_info, conditional_info, response, use_hdi, effect_type
Expand Down
15 changes: 15 additions & 0 deletions bambi/interpret/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def plot_predictions(
idata: az.InferenceData,
covariates: Union[str, list],
target: str = "mean",
sample_new_groups: bool = False,
pps: bool = False,
use_hdi: bool = True,
prob=None,
Expand All @@ -110,6 +111,9 @@ def plot_predictions(
Which model parameter to plot. Defaults to 'mean'. Passing a parameter into target only
works when pps is False as the target may not be available in the posterior predictive
distribution.
sample_new_groups : bool, optional
If the model contains group-level effects, and data is passed for unseen groups, whether
to sample from the new groups. Defaults to ``False``.
pps: bool, optional
Whether to plot the posterior predictive samples. Defaults to ``False``.
use_hdi : bool, optional
Expand Down Expand Up @@ -174,6 +178,7 @@ def plot_predictions(
use_hdi=use_hdi,
prob=prob,
transforms=transforms,
sample_new_groups=sample_new_groups,
)

response_name = get_aliased_name(model.response_component.response_term)
Expand Down Expand Up @@ -219,6 +224,7 @@ def plot_comparisons(
conditional: Union[str, dict, list, None] = None,
average_by: Union[str, list] = None,
comparison_type: str = "diff",
sample_new_groups: bool = False,
use_hdi: bool = True,
prob=None,
legend: bool = True,
Expand All @@ -245,6 +251,9 @@ def plot_comparisons(
over the other covariates in the model. Defaults to ``None``.
comparison_type : str, optional
The type of comparison to plot. Defaults to 'diff'.
sample_new_groups : bool, optional
If the model contains group-level effects, and data is passed for unseen groups, whether
to sample from the new groups. Defaults to ``False``.
use_hdi : bool, optional
Whether to compute the highest density interval (defaults to True) or the quantiles.
prob : float, optional
Expand Down Expand Up @@ -332,6 +341,7 @@ def plot_comparisons(
use_hdi=use_hdi,
prob=prob,
transforms=transforms,
sample_new_groups=sample_new_groups,
)

return _plot_differences(
Expand All @@ -355,6 +365,7 @@ def plot_slopes(
average_by: Union[str, list] = None,
eps: float = 1e-4,
slope: str = "dydx",
sample_new_groups: bool = False,
use_hdi: bool = True,
prob=None,
transforms=None,
Expand Down Expand Up @@ -395,6 +406,9 @@ def plot_slopes(
change in the response.
'dyex' represents a percent change in 'wrt' is associated with a unit increase
in the response.
sample_new_groups : bool, optional
If the model contains group-level effects, and data is passed for unseen groups, whether
to sample from the new groups. Defaults to ``False``.
use_hdi : bool, optional
Whether to compute the highest density interval (defaults to True) or the quantiles.
prob : float, optional
Expand Down Expand Up @@ -486,6 +500,7 @@ def plot_slopes(
use_hdi=use_hdi,
prob=prob,
transforms=transforms,
sample_new_groups=sample_new_groups,
)

return _plot_differences(
Expand Down
Loading

0 comments on commit c1668dd

Please sign in to comment.