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

Fix size issue when using broadcastable dimensions in multivariate RandomVariables #1056

Conversation

ricardoV94
Copy link
Contributor

@ricardoV94 ricardoV94 commented Jul 17, 2022

Closes #1055

The original issue seems to have been misunderstood. This PR allows size to broadcast multivariate distribution parameters in exactly the same way that it broadcasts univariate distribution parameters. It does not allow size to be shorter or inconsistent with the original parameter shapes, which seems to be the reason why the more restrictive checks were introduced originally. The following cases are now both possible:

import numpy as np
import aesara.tensor as at

# Already allowed before
at.random.normal(np.ones((3, 1, 3)), size=(3, 10, 3)).eval().shape  # (3, 10, 3)

# Allowed now
at.random.dirichlet(np.ones((3, 1, 3)), size=(3, 10)).eval().shape  # (3, 10, 3)

@ricardoV94 ricardoV94 force-pushed the size_broadcasts_multivariate_params branch from b73120d to c3a34ea Compare July 17, 2022 15:01
@codecov
Copy link

codecov bot commented Jul 17, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.25%. Comparing base (be222f0) to head (c3a34ea).
Report is 503 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1056      +/-   ##
==========================================
- Coverage   79.25%   79.25%   -0.01%     
==========================================
  Files         152      152              
  Lines       47882    47875       -7     
  Branches    10909    10906       -3     
==========================================
- Hits        37949    37942       -7     
  Misses       7436     7436              
  Partials     2497     2497              
Files Coverage Δ
aesara/tensor/random/basic.py 98.90% <100.00%> (-0.02%) ⬇️

Copy link
Member

@brandonwillard brandonwillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original issue seems to have been misunderstood. This PR allows size to broadcast multivariate distribution parameters in exactly the same way that it broadcasts univariate distribution parameters. It does not allow size to be shorter or inconsistent with the original parameter shapes, which seems to be the reason why the more restrictive checks were introduced originally. The following cases are now both possible:

No, the original issue was not misunderstood. See #1044 (reply in thread). I'm now assuming you mean the first issue you created that was converted into a discussion, and not the issue(s) addressed by #446.

I've clarified the issue in #1058 and separated it from our general interpretation of size (i.e. #412). That interpretation shouldn't be an issue; instead, there only seems to be a bug in our current implementation.

@brandonwillard brandonwillard changed the title Allow size to broadcast multivariate distribution parameters Fix size broadcasting issue in multivariate RandomVariables Jul 17, 2022
@brandonwillard brandonwillard changed the title Fix size broadcasting issue in multivariate RandomVariables Fix size issue when using broadcastable dimensions in multivariate RandomVariables Jul 17, 2022
@brandonwillard brandonwillard added the bug Something isn't working label Jul 17, 2022
@brandonwillard brandonwillard self-requested a review July 17, 2022 23:36
@brandonwillard brandonwillard merged commit 8794f48 into aesara-devs:main Jul 17, 2022
@ricardoV94
Copy link
Contributor Author

Oh, I forgot to fix the Categorical distribution as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants