-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add .random method to MvGaussianRandomWalk (Issue #4337) #4388
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4388 +/- ##
==========================================
+ Coverage 88.13% 88.17% +0.04%
==========================================
Files 88 88
Lines 14550 14563 +13
==========================================
+ Hits 12823 12841 +18
+ Misses 1727 1722 -5
|
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.
Looks like a great start @awray3 . I addressed a few things below.
Let's iterate over it and get it ready for merge.
Do you get failing tests in existing test cases? |
No, just for new tests created when I include a new test called |
How should |
Yes. The You can add tests very similar to how MvNormal random method is tested with np arrays here - If this works, then we can add a test where a parameter can be a random variable. |
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.
That's a great progress @awray3 . Minor nitpicks below -
Also, the test cases pass with numpy arrays 🎉 . Last step would be to add a test where mu
and any one of chol
, cov
or tau
are random variables. Similar to how MvNormal is tested.
There is a conflicting file. Can you rebase to current master to start the GitHub Actions? |
No problem, I just pushed after rebasing. Currently working out an error from
|
Oh. This is very much similar to bug described in #4010 . |
Let's think of the case, dist_shape = (10, 3) and mu_shape = (10, 3) Let's consider an arbitrary tensor with shape (10, 3) following MvGaussianRandomWalk. Its first row (or first time step) comes from init distribution. And that initial distribution is Flat one in our case. The remaining 9 steps will come from adding (9, 3) multivariate samples as noise to the initial row. I think the error is because we initialize MvNormal with shape (10, 3) and ask for logp from MvNormal with (9, 3) shaped tensor. And there is a mismatch. |
A good solution for me will be to open an issue for logp miscalculations. Write the failing test cases here and mark them as xfail. Another thing I notice, is that after the rebase, this PR contains all the changes from #4368 . But #4368 is now merged into master. Can you lookup what went wrong in the rebase? |
Yes, I can look up the issue. I'm new to a lot of the git workflow, so I might have messed something up 😅 |
Okay, I royally messed something up (probably by not rebasing as often I should have), but I think I resolved my rebase issue. |
Actually, I'm still not sure I fixed my rebase issue, and it's causing a headache! I need to step away and come back with fresh eyes. |
Oh. This is getting mixed with commits. Can you give this a try? git checkout 79e47b19 # Let's go to a cleaner commit
git checkout -b add_random_2
git push -f origin add_random Another option can be resetting back and force push git reset --hard 3200a84a
git push -f origin add_random |
That definitely worked. I appreciate the lending of git expertise! I definitely have more tricks to learn. 🙂 |
@Sayam753 Feel free to merge when you think this is ready. |
Hooray! First pull request to be merged! 🥳 I also want to implement random methods for Also, I notice that |
I had not paid attention to the reason behind starting the random draws from zero. But looking at the #3985 (comment) , I am thinking this way -
That's a good point. For the next PR, I have these ideas -
|
Last step would be wrapping the docstring examples in |
Implements the random method for MvGaussianRandomWalk, partially fixing #4337.
Improves the implementation by using MvNormal.random as suggested by @Sayam753. Also updated its docstring to add more examples.
This commit rewrites the random method to pass the entire shape into MvNormal. MvGaussianRandomWalk also now supports an integer shape that must match the dimensionality of mu. In this case it is assumed that there are no time steps, and a random sample from the multivariate normal distribution will be returned.
Remove equality since the shape parameter cannot have more than 2 dimensions. Co-authored-by: Sayam Kumar <[email protected]>
Co-authored-by: Sayam Kumar <[email protected]>
Adds a more explicit conditional on the time_axis statement. Co-authored-by: Sayam Kumar <[email protected]>
Added tests for both chol and cov to be random variables.
Moves the brittle comment in MvRandom._random's docstring to the actual location in the code for clarity.
These all sound like great ideas. I also like the idea of polishing the random walks before moving on. |
Thanks @awray3 and congrats on your first Pull Request 🎉 |
This PR addresses Issue #4337. So far I have implemented the .random method for
MvGaussianRandomWalk
and updated a few of the docstrings in this file. The implementation is similar toGaussianRandomWalk.random
.Currently I am having issues with adding this method to
test_distributions_random.py
; I get many failing tests and I am not sure if the base test class is appropriate with its current settings for this time series.