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

Implement AutoGuideList.quantiles() #2896

Merged
merged 6 commits into from
Jul 6, 2021
Merged
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
13 changes: 13 additions & 0 deletions pyro/infer/autoguide/guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ def median(self, *args, **kwargs):
result.update(part.median(*args, **kwargs))
return result

def quantiles(self, quantiles, *args, **kwargs):
"""
Returns the posterior quantile values of each latent variable.

:param list quantiles: A list of requested quantiles between 0 and 1.
:returns: A dict mapping sample site name to quantiles tensor.
:rtype: dict
"""
result = {}
for part in self:
result.update(part.quantiles(quantiles, *args, **kwargs))
return result


class AutoCallable(AutoGuide):
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/infer/test_autoguide.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ def model():
assert_equal(attr_get(guide_deser), attr_get(guide).data)


def AutoGuideList_x(model):
guide = AutoGuideList(model)
guide.append(AutoNormal(poutine.block(model, expose=["x"])))
guide.append(AutoLowRankMultivariateNormal(poutine.block(model, hide=["x"])))
return guide


@pytest.mark.parametrize(
"auto_class",
[
Expand All @@ -430,6 +437,7 @@ def model():
AutoNormal,
AutoLowRankMultivariateNormal,
AutoLaplaceApproximation,
AutoGuideList_x,
],
)
@pytest.mark.parametrize("Elbo", [Trace_ELBO, TraceGraph_ELBO, TraceEnum_ELBO])
Expand Down