-
Notifications
You must be signed in to change notification settings - Fork 85
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 MultivariateNormalDiag distribution. #208
base: master
Are you sure you want to change the base?
Conversation
This is an extremely common special case of the MultivariateNormal distributon due to its efficient sampling and log-probability computations.
1a81244
to
e23531f
Compare
I see thorough work here, I really appreciate the thorough tests, but I'm unsure about accepting this pr. If, for any reason As I see it, I believe that your feature set can wrap
please let me know if this would not be correct or if I'm missing something important. But I see both those items being a result of being independently and identically distributed (i.i.d). Perhaps there's an ergonomic solution to cover i.i.d variables from distribution Note: An ergonomic way to support different distributions from uncorrelated variables does not yet seem worthwhile to me, but I would listen to input here as well. |
That seems highly unlikely to happen, given the widespread usage of Usually the libraries reduce the duplication by abstracting away the square root of the covariance matrix (be it a cholesky factor or the diagonal scale) (e.g. MultivariateNormalLinearOperator from TensorFlow Probability and the Covariance from scipy. A wrapper distribution over independent distributions is a pretty common component of statistics toolkits (e.g. Independent from TensorFlow Probability, ProductDistribution from |
Your first point alone,
in tandem - which I'd really not considered - with a significant specialization relative to independent variables is enough motivator to dispel my concern. I like the ideas you mention about how to allow for specialization of multidimensional distributions. Seems like a good idea for another PR. EDIT |
Took another look at this, I also think that uncorrelated multivariate normal variables are common enough to be useful, but would it make sense to have a distinct API from existing MVN? It allows a user to opt in/out for optimizations, is this intended? I'm looking at the scipy implementation that you referenced, and it's close to what I'm thinking. What methods would a Covariance trait have that allow specifying different behavior for the pdf and sampling depending on the representation? |
Something like this would be a good start trait Covariance
{
type V;
type M;
/// sqrt(cov) @ vec
fn forward(&self, vec: &V) -> V;
/// inv(sqrt(cov)) @ vec
fn inverse(&self, vec: &V) -> V;
/// diag_part(cov)
fn diag(&self) -> V;
/// dense(cov)
fn dense(&self) -> M;
/// abs(det(cov))
fn abs_determinant(&self) -> f64;
/// ln(abs(det(cov)))
fn ln_abs_determinant(&self) -> f64;
} That'll let you implement efficient sampling/log probability and also compute the variance vector and (dense) covariance matrix. Like for the current MVN implementation, the return values of many of them can be pre-computed upon construction. For inverse/forward methods, TensorFlow calls them |
This looks really good! Would you be willing to implement it to support diagonal and correlations for mvn? |
This is an extremely common special case of the MultivariateNormal distribution due to its efficient sampling and log-probability computations.