Multivariate Normal Distribution

Hi there Could somebody give me a clear example about how to construct a MVND using the syntaxis given by the Distribution Pkg. I know that with Distributions.jl it is possible to generate a MVND just as it is possible to do an univariate one. The thing is that since I knew using Julia I would like to have some advice on how to generate a MVND. Grettings for the retro

See ?MvNormal, it is documented. Eg

MvNormal(mu, sigma)

where mu is a vector and sigma is a PSD matrix. There are other constructors, see the docstrings.

1 Like

The name MvNormal seems difficult to discover.

1 Like

I am not sure I understand why you think this, it is right there in the docs:

https://juliastats.github.io/Distributions.jl/latest/multivariate/#Distributions.MvNormal

I know the information is there, its just that I dont know exactly how to build the vectors of mean and covariance given by the syntaxis I just need an example on how the construction is using some numbers I do understand the theory of the bivariate distribution but I,m stuck cause I dont know how to build the syntaxis structure like Julia says.

Sorry for the inconvinient

Grettings

Eg

using Distributions, LinearAlgebra
MvNormal(ones(3), Diagonal(ones(3)))

but you may benefit from just reading through the manual first:

https://docs.julialang.org/en/v1/

Thank you very much for the approach and sure I will read the manual indeed

See some examples in Section 3.7 here: https://people.smp.uq.edu.au/YoniNazarathy/julia-stats/StatisticsWithJulia.pdf

3 Likes
  • A Google search for “Julia multivariate normal” did not take me to that page; and
  • you can’t guess the name using tab completion at the REPL.
    Indeed, I find it hard to remember the name MvNormal even after seeing it a few times. Maybe MultivariateNormal would be better?
4 Likes

It was already established that the relevant package is Distributions.

While being able to guess things in the REPL via completion is indeed nice, I don’t think it is reasonable to expect to rely on that for everything. Quite a bit if effort goes into writing good docs for Julia and some (but of course, not all) packages, so looking that up should be the first thing to do.

I am puzzled why people don’t read package docs or the Julia manual. Do they not expect them to exist, are they just difficult to find, or they don’t think it would be useful?

Why just not Normal(Array{T,1},Array{T,2}) ?

1 Like

You should not be so puzzled over questions like this. People do read docs but the documentation is not always so good.

If you want to achieve something, you browse the documentation until you find a solution. Nobody reads the whole doc before they start coding. Just the other day I discovered diagind. Until now I had just computed the indices manually.

There should be more code examples that people can just copy and start modifying. This is why I like https://en.cppreference.com/ or https://mathworks.com/help/index.html.

Another point is peoples expectations. You know C++ is low level and Matlab is high level. But what is Julia? Some parts are abstracted to obscurity while some are unnecessary low. The level of abstraction is very uneven.

As an example, I give you Plots.jl. It just works, until it doesn’t and the documentation does not tell you what to do. If you want to create a color palette, should you try high abstraction or low abstraction?

1 Like

Possibly — which is a great opportunity to improve on it by making a PR.

You may not, I usually do. The “whole” documentation is not that long for most packages, and can be read through within 10–30 minutes. For larger “meta” packages like DiffEq or Plots, it is usually easy to find the relevant section and just read that.

Also just to add I don’t think the Distributions.jl docs can be accused of being “not so good” in this particular case - there’s a page for multivariate distributions that is linked in the index right on the landing page, so it should be reasonably easy to find relevant info on multivariate distributions:

https://juliastats.github.io/Distributions.jl/stable/multivariate/

2 Likes

Wife : It’s a floor wax, I’m telling you!
Husband : It’s a dessert topping, you cow!
Spokesman : [ enters quickly ] Hey, hey, hey, calm down, you two. New Shimmer is both a floor wax and a dessert topping!

Seriously, isn’t being both low level and high level a necessary part of how Julia solves the two language problem? The fact that I can use very specific integer representation and be very expressive in an array comprehension with broadcasting inside and peek at the resulting assembly code all in one place is just amazing. Maybe in another generation (i.e. 20 years or so) we’ll get something more expressive than Julia and as fast without requiring as much low level knowledge to get the speed, but for now I think this is intrinsic to Julia.

P.S. My apologies to the international and/or young audience who won’t know the floor wax / dessert topping quote - it’s from an '80s episode of Saturday Night Live. It just felt relevant to me.

1 Like

Thank you for this question! And of course I agree with your point that the documentation of the packages should be read.

Also I don’t want to say that I am inexperienced in explaining facts and therefore here is my, maybe a bit hard sounding statement, that very often the Julia and package documentation is difficult to understand. In the beginning I often googled or watched YouTube videos to understand the documentary. It shouldn’t be like that …

I come from the R-world and in most cases the user will find one or more well described and executable examples. I wish something like this for the Julia world as well. I wrote something similar in the last Julia survey. And I have the hope that something will change… :wink:

Those are my two cents…

When you find some documentation difficult to understand, you are in the unique position the be an agent of this change. Ideally, once one figures out the answer to a question, it should be followed by a PR to the docs (they are very easy to make — you can do it on Github, editing the code directly), or at least an issue.

Just complaining about the quality of documentation in general and hoping this will change is unlikely to improve anything. The problem is that writing good introductory docs requires the unique perspective of having been puzzled by something recently which could be explained better. Package authors rarely have that perspective, since they are very familiar with the code. So they need your help.

Imagine the parallel universe where the effort expended on kvetching about the docs of Distributions.jl in this topic went into a PR.

1 Like

Yes, it’s all true! Just wondering and complaining does not help! I will accept the ball and play! :grinning: