Add MultivariateNormalDiag distribution.#208
Add MultivariateNormalDiag distribution.#208SiegeLord wants to merge 2 commits intostatrs-dev:masterfrom
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.