-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 error in docstring example for MatrixNormal #7599
Conversation
|
pymc/distributions/multivariate.py
Outdated
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,compute_corr=False, | ||
sd_dist=sd_dist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit more succinct?
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,compute_corr=False, | |
sd_dist=sd_dist) | |
colchol_packed, _, _ = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2, sd_dist=sd_dist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ricardoV94 Yeah also if we are using this approach then there is No need for expand_packed_triangular(line:1832) since it's already expanded. Also I will rename "cholchol_packed" to "cholchol"
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2, | ||
sd_dist=sd_dist) | ||
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,compute_corr=False, | ||
sd_dist=sd_dist) | ||
colchol = pm.expand_packed_triangular(3, colchol_packed) | ||
|
||
# Setup left covariance matrix | ||
scale = pm.LogNormal('scale', mu=np.log(true_scale), sigma=0.5) | ||
rowcov = pt.diag([scale**(2*i) for i in range(m)]) | ||
|
||
vals = pm.MatrixNormal('vals', mu=mu, colchol=colchol, rowcov=rowcov, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suggestion can't be applied directyl, but this seems more clean
vals = pm.MatrixNormal('vals', mu=mu, colchol=colchol, rowcov=rowcov, | |
vals = pm.MatrixNormal('vals', mu=mu, colchol=colchol, rowcov=rowcov, observed=data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missid this. I would put in same line, looks odd split
@roesta07 you can ignore that pre-commit fail, it's indeed not related to your PR |
pymc/distributions/multivariate.py
Outdated
@@ -1827,16 +1827,16 @@ class MatrixNormal(Continuous): | |||
with pm.Model() as model: | |||
# Setup right cholesky matrix | |||
sd_dist = pm.HalfCauchy.dist(beta=2.5, shape=3) | |||
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2, | |||
sd_dist=sd_dist) | |||
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,compute_corr=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,compute_corr=False, | |
colchol, _, _ = pm.LKJCholeskyCov('colchol', n=3, eta=2, |
pymc/distributions/multivariate.py
Outdated
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,compute_corr=False, | ||
sd_dist=sd_dist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ricardoV94 Yeah also if we are using this approach then there is No need for expand_packed_triangular(line:1832) since it's already expanded. Also I will rename "cholchol_packed" to "cholchol"
pymc/distributions/multivariate.py
Outdated
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2, | ||
sd_dist=sd_dist) | ||
colchol_packed = pm.LKJCholeskyCov('colcholpacked', n=3, eta=2,compute_corr=False, | ||
sd_dist=sd_dist) | ||
colchol = pm.expand_packed_triangular(3, colchol_packed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colchol = pm.expand_packed_triangular(3, colchol_packed) |
Hi @ricardoV94, I have fixed the docs string as a fresh commit.
|
@roesta07 Ideally the code snippet would be completely correct that you could copy past and run in the terminal, so it would be better to put it in a model context |
Co-authored-by: Ricardo Vieira <[email protected]>
fa74e40
to
7e47f7a
Compare
@ricardoV94 I have added the model context at the top along with the previous changes. |
pymc/distributions/multivariate.py
Outdated
@@ -1792,7 +1792,7 @@ class MatrixNormal(Continuous): | |||
-------- | |||
Define a matrixvariate normal variable for given row and column covariance | |||
matrices:: | |||
|
|||
with pm.Model() as model: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add a .. code:: python
with white line above and below to render nicely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also include imports so example is fully specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- added imports on top.
- added codeblocks
.. code:: python
with appropriate whitespaces
Check these recent changes
Thanks @roesta07 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7599 +/- ##
==========================================
- Coverage 92.84% 92.83% -0.02%
==========================================
Files 106 106
Lines 17745 17748 +3
==========================================
+ Hits 16476 16477 +1
- Misses 1269 1271 +2
|
Co-authored-by: Rojan Shrestha <[email protected]> Co-authored-by: Ricardo Vieira <[email protected]>
…rrent version
Description
The compute_corr parameter in pm.LKJCholeskyCov is set to True by default, which causes the issue in latest pymc versions.
Also discussed here: https://discourse.pymc.io/t/matrixnormal-example-in-documentation-throws-an-error/16171
Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pymc--7599.org.readthedocs.build/en/7599/