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

Check if is an attribute before trying to access it #851

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions bambi/priors/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ def scale_response(self):
# Here we would add cases for other families if we wanted
if isinstance(self.model.family, (Gaussian, StudentT)):
sigma = self.model.components["sigma"]
if isinstance(sigma, ConstantComponent) and sigma.prior.auto_scale:
if (
isinstance(sigma, ConstantComponent)
and hasattr(sigma.prior, "auto_scale") # not available when `.prior` is a scalar
and sigma.prior.auto_scale
):
sigma.prior = Prior("HalfStudentT", nu=4, sigma=self.response_std)
elif isinstance(self.model.family, VonMises):
kappa = self.model.components["kappa"]
if isinstance(kappa, ConstantComponent) and kappa.prior.auto_scale:
if (
isinstance(kappa, ConstantComponent)
and hasattr(kappa.prior, "auto_scale") # not available when `.prior` is a scalar
and kappa.prior.auto_scale
):
kappa.prior = Prior("HalfStudentT", nu=4, sigma=self.response_std)

def scale_intercept(self, term):
Expand Down
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ dev = [

jax = [
"bayeux-ml>=0.1.13",
"jax<=0.4.33",
"jaxlib<=0.4.33",
]

[project.urls]
Expand All @@ -50,14 +52,14 @@ changelog = "https://github.com/bambinos/bambi/blob/main/docs/CHANGELOG.md"

[tool.setuptools]
packages = [
"bambi",
"bambi.backend",
"bambi.data",
"bambi.defaults",
"bambi",
"bambi.backend",
"bambi.data",
"bambi.defaults",
"bambi.families",
"bambi.interpret",
"bambi.priors",
"bambi.terms",
"bambi.interpret",
"bambi.priors",
"bambi.terms",
]

[tool.black]
Expand Down
Loading