-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Feature/matrix input to mvn [WIP] #2540
Conversation
For the |
Do you mean transforming |
I was initially, but now I realise that doesn't make much sense in this context, where the y/mu dimensions need to match sigma's. What i was thinking would only really make sense for passing matrices to the univariate distributions |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
Thanks Adam! I made an example of what I think would be nice here you can check out in the diff below What we want to do is utilize the matrix inputs for more efficient code than the standard mvn. So in the below instead of having to call https://github.com/stan-dev/math/compare/review/mvn-matrix?expand=1 |
Closing this for now since it's still in draft. @adamhaber, please reopen if it's active. |
Sorry... I didn't realize it wasn't a draft. Reopening. |
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.
Thanks for the PR!
Please add a unit test for different sizes. I believe it should throw an std::illegal_argument
exception so that sampling stops.
using lp_type = return_type_t<T_y, T_loc, T_covar>; | ||
|
||
const size_t N = y.rows(); | ||
lp_type lp(0.0); |
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.
Could you take away the using lp_type...
statement on 111 and declare lp
as that type? It's easier to read when that's together.
lp_type lp(0.0); | ||
|
||
for (size_t n = 0; n < N; ++n) { | ||
auto current_y = y.row(n); |
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.
Is this code safe? What happens if y
and mu
have different lengths? Won't this just read off the end?
I'd like to see this fixed before it gets into the code base. Perhaps use a check_matching_sizes
or something similar?
EXPECT_FLOAT_EQ(-23.47816, stan::math::multi_normal_lpdf(y, mu, Sigma)); | ||
EXPECT_NO_THROW(stan::math::multi_normal_rng(mu, Sigma, rng)); | ||
} | ||
|
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.
Please add a test where y
and mu
have different number of rows. This will trigger a failure and we should know what that is through a unit test.
Sorry, it is a draft! I'm closing it until it's ready to be reopened. |
Summary
Allow multivariate normal distribution to take in matrices for
y
andmu
arguments (see #2532)Tests
Added a simple initial test for
lpdf
andrng
, will add others (matching the tests for the non-matrix mvn?) if the current implementation makes sense.Side Effects
None.
Release notes
Allow multivariate normal distribution to take in matrices for
y
andmu
arguments.Checklist
Math issue Allow multivariate distributions to take in matrices #2532
Copyright holder: Adam Haber
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested