You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@mahout.apache.org by Dan Filimon <da...@gmail.com> on 2012/11/14 09:32:36 UTC

MultiNormal distribution radius

Hi,

I'm familiar with the basic univariate normal distribution but am
having trouble understanding how the Mahout multivariate normal
distribution works.

Specifically, what does the radius of the distribution stand for?
What I'm imagining (at lest for 3 dimensions) is that all points would
fit into a sphere centered in the mean with the given radius and that
they would be normally distributed inside.

This however doesn't seem to be the case (unless my tests are broken).

What am I missing?
Thanks!

Re: MultiNormal distribution radius

Posted by Ted Dunning <te...@gmail.com>.
Yes.  Evil naming.

I will patch shortly.

On Wed, Nov 14, 2012 at 2:33 AM, Sean Owen <sr...@gmail.com> wrote:

> Ted I am also confused by the naming in this class. What I'd imagine is the
> vector of means is called "offset". The variances come in to the picture
> via a matrix called "mean". (That's not the covariance matrix right? might
> expect that from an API perspective but I don't think that's how it is
> used.) And the parameter for the case where all variances are the same is
> "radius".
>

Re: MultiNormal distribution radius

Posted by Sean Owen <sr...@gmail.com>.
Got it. For the diagonal covariance case that explains why it's just the
square root of the matrix, which are of course the std deviations.

You don't necessarily have to implement a constructor that takes in the
covariance matrix. The ones that take the Cholesky decomposition could just
be made private as they are not otherwise used yet. Heck you don't even
need a matrix multiplication if not dealing with the off-diagonal elements.


On Wed, Nov 14, 2012 at 5:58 PM, Ted Dunning <te...@gmail.com> wrote:

> On Wed, Nov 14, 2012 at 9:48 AM, Sean Owen <sr...@gmail.com> wrote:
>
> > I'm talking about the case here where covariances are 0. The marginals in
> > each dimension are independent and are normally distributed. Right?
> >
>
> Yes.  With no covariance, all of the axes are independent.
>
>
> > What is that matrix connecting the univariate normals to multivariate
> BTW?
> >
>
>
> http://en.wikipedia.org/wiki/Multivariate_normal_distribution#Drawing_values_from_the_distribution
>
>
> > I don't know what it is theoretically. It's not the covariance matrix,
> > which might be a reader's first guess on looking at the constructor.
> >
>
> Should I fix the constructor to accept covariance?  The SVD or Cholesky
> decomposition required is pretty quick.
>

Re: MultiNormal distribution radius

Posted by Ted Dunning <te...@gmail.com>.
On Wed, Nov 14, 2012 at 9:48 AM, Sean Owen <sr...@gmail.com> wrote:

> I'm talking about the case here where covariances are 0. The marginals in
> each dimension are independent and are normally distributed. Right?
>

Yes.  With no covariance, all of the axes are independent.


> What is that matrix connecting the univariate normals to multivariate BTW?
>

http://en.wikipedia.org/wiki/Multivariate_normal_distribution#Drawing_values_from_the_distribution


> I don't know what it is theoretically. It's not the covariance matrix,
> which might be a reader's first guess on looking at the constructor.
>

Should I fix the constructor to accept covariance?  The SVD or Cholesky
decomposition required is pretty quick.

Re: MultiNormal distribution radius

Posted by Sean Owen <sr...@gmail.com>.
I'm talking about the case here where covariances are 0. The marginals in
each dimension are independent and are normally distributed. Right?

What is that matrix connecting the univariate normals to multivariate BTW?
I don't know what it is theoretically. It's not the covariance matrix,
which might be a reader's first guess on looking at the constructor.

Yes that is right about sampling, you can't sample the radius uniformly!
Very important detail to overlook.





On Wed, Nov 14, 2012 at 5:38 PM, Ted Dunning <te...@gmail.com> wrote:

> On Wed, Nov 14, 2012 at 3:53 AM, Sean Owen <sr...@gmail.com> wrote:
>
> > The wikipedia article is a fine intro. If your covariances are 0, there's
> > not much to know at all. The multivariate normal is just several
> univariate
> > normals, independent in each dimension.
> >
>
> Not quite.  The multivariate normal is several univariate normals
> multiplied by a matrix.
>
>
> > If you want a uniform distribution over a unit sphere, that's different,
> > but you're actually also on the right track. You don't need to sample and
> > discard, just pick your point as above and normalize to a length randomly
> > chosen in (0,radius]. 90% sure that's correct off the top of my head.
> >
>
> In high dimensions, this doesn't work because you get vastly too much mass
> near the origin.  You need to sample the radius from a distribution biased
> toward larger values.  The idea is that each shell of radius r and
> thickness dr needs to have probability according to the volume of the shell
> which is proportional to r^(d-1).  If every shell has equal mass, then the
> inner shells are much too dense.  The desired cumulative distribution is
> proportional to r^d so you can sample r by using the inverse method
>
>     u ~ Uniform(0,1)
>     r = Math.pow(u, 1/d)
>
> See https://dl.dropbox.com/u/36863361/spherical-sampling.png for a picture
> of 2-d sampling which is the first interesting case.  For higher
> dimensional cases, to get a comparable picture, you need to take a slice of
> data near a 2-d plane since simply projecting to the x-y plane will give
> very biased results.
>

Re: MultiNormal distribution radius

Posted by Ted Dunning <te...@gmail.com>.
On Wed, Nov 14, 2012 at 3:53 AM, Sean Owen <sr...@gmail.com> wrote:

> The wikipedia article is a fine intro. If your covariances are 0, there's
> not much to know at all. The multivariate normal is just several univariate
> normals, independent in each dimension.
>

Not quite.  The multivariate normal is several univariate normals
multiplied by a matrix.


> If you want a uniform distribution over a unit sphere, that's different,
> but you're actually also on the right track. You don't need to sample and
> discard, just pick your point as above and normalize to a length randomly
> chosen in (0,radius]. 90% sure that's correct off the top of my head.
>

In high dimensions, this doesn't work because you get vastly too much mass
near the origin.  You need to sample the radius from a distribution biased
toward larger values.  The idea is that each shell of radius r and
thickness dr needs to have probability according to the volume of the shell
which is proportional to r^(d-1).  If every shell has equal mass, then the
inner shells are much too dense.  The desired cumulative distribution is
proportional to r^d so you can sample r by using the inverse method

    u ~ Uniform(0,1)
    r = Math.pow(u, 1/d)

See https://dl.dropbox.com/u/36863361/spherical-sampling.png for a picture
of 2-d sampling which is the first interesting case.  For higher
dimensional cases, to get a comparable picture, you need to take a slice of
data near a 2-d plane since simply projecting to the x-y plane will give
very biased results.

Re: MultiNormal distribution radius

Posted by Sean Owen <sr...@gmail.com>.
The wikipedia article is a fine intro. If your covariances are 0, there's
not much to know at all. The multivariate normal is just several univariate
normals, independent in each dimension.

If you want a uniform distribution over a unit sphere, that's different,
but you're actually also on the right track. You don't need to sample and
discard, just pick your point as above and normalize to a length randomly
chosen in (0,radius]. 90% sure that's correct off the top of my head.

Heh, so, know any nice introductory articles (preferably with lots of
> pictures) about the multivariate distribution?
> Thanks! :)
>

Re: MultiNormal distribution radius

Posted by Dan Filimon <da...@gmail.com>.
On Wed, Nov 14, 2012 at 1:22 PM, Sean Owen <sr...@gmail.com> wrote:
>> Right, I probably want a modified version in my case where I normalize
>> the distances somehow.
>>
>
> You can divide the result by any scalar you want and it will still have
> non-zero probability of being farther than any given distance d from the
> mean. Of course, it gets very very unlikely as the distance increases.

That's true. I'll just drop points that are too far away.

>
>> So "radius" in this case is the variance of the ith component of the
>> vector, since the covariance matrix is diagonal?
>>
>>
> I don't think that's a covariance matrix in general given how it is
> applied. The argument in question is used as a standard deviation rather
> than (co)variance from what I can see.

Heh, so, know any nice introductory articles (preferably with lots of
pictures) about the multivariate distribution?
Thanks! :)

Re: MultiNormal distribution radius

Posted by Ted Dunning <te...@gmail.com>.
On Wed, Nov 14, 2012 at 3:22 AM, Sean Owen <sr...@gmail.com> wrote:

> > Right, I probably want a modified version in my case where I normalize
> > the distances somehow.
> >
>
> You can divide the result by any scalar you want and it will still have
> non-zero probability of being farther than any given distance d from the
> mean. Of course, it gets very very unlikely as the distance increases.
>

Cosine normalization gives symmetric results on a sphere.

You can also use a rejection method to drop all points outside the sphere.


> > So "radius" in this case is the variance of the ith component of the
> > vector, since the covariance matrix is diagonal?
> >
> >
> I don't think that's a covariance matrix in general given how it is
> applied. The argument in question is used as a standard deviation rather
> than (co)variance from what I can see.
>

Standard deviation is just the 1-d version of covariance.  If you want a
spherically symmetric multi-variate normal, then a diagonal covariance does
the trick.

Re: MultiNormal distribution radius

Posted by Sean Owen <sr...@gmail.com>.
> Right, I probably want a modified version in my case where I normalize
> the distances somehow.
>

You can divide the result by any scalar you want and it will still have
non-zero probability of being farther than any given distance d from the
mean. Of course, it gets very very unlikely as the distance increases.


> So "radius" in this case is the variance of the ith component of the
> vector, since the covariance matrix is diagonal?
>
>
I don't think that's a covariance matrix in general given how it is
applied. The argument in question is used as a standard deviation rather
than (co)variance from what I can see.

Re: MultiNormal distribution radius

Posted by Dan Filimon <da...@gmail.com>.
On Wed, Nov 14, 2012 at 12:33 PM, Sean Owen <sr...@gmail.com> wrote:
> In the univariate case, there is no max/min possible value. We just have
> the variance to say how unlikely a value is that is far from the
> distribution mean, though any value is possible. Same in multivariate, so I
> don't think you could say the distribution fits strictly inside a sphere.

Right, I probably want a modified version in my case where I normalize
the distances somehow.

> The distribution will only be symmetrical and not 'elongated' if the
> variances are the same, which is the case I think you're talking about.
>
> Ted I am also confused by the naming in this class. What I'd imagine is the
> vector of means is called "offset". The variances come in to the picture
> via a matrix called "mean". (That's not the covariance matrix right? might
> expect that from an API perspective but I don't think that's how it is
> used.) And the parameter for the case where all variances are the same is
> "radius".

So "radius" in this case is the variance of the ith component of the
vector, since the covariance matrix is diagonal?

>
> On Wed, Nov 14, 2012 at 8:32 AM, Dan Filimon <da...@gmail.com>wrote:
>
>> Hi,
>>
>> I'm familiar with the basic univariate normal distribution but am
>> having trouble understanding how the Mahout multivariate normal
>> distribution works.
>>
>> Specifically, what does the radius of the distribution stand for?
>> What I'm imagining (at lest for 3 dimensions) is that all points would
>> fit into a sphere centered in the mean with the given radius and that
>> they would be normally distributed inside.
>>
>> This however doesn't seem to be the case (unless my tests are broken).
>>
>> What am I missing?
>> Thanks!
>>

Re: MultiNormal distribution radius

Posted by Sean Owen <sr...@gmail.com>.
In the univariate case, there is no max/min possible value. We just have
the variance to say how unlikely a value is that is far from the
distribution mean, though any value is possible. Same in multivariate, so I
don't think you could say the distribution fits strictly inside a sphere.

The distribution will only be symmetrical and not 'elongated' if the
variances are the same, which is the case I think you're talking about.

Ted I am also confused by the naming in this class. What I'd imagine is the
vector of means is called "offset". The variances come in to the picture
via a matrix called "mean". (That's not the covariance matrix right? might
expect that from an API perspective but I don't think that's how it is
used.) And the parameter for the case where all variances are the same is
"radius".


On Wed, Nov 14, 2012 at 8:32 AM, Dan Filimon <da...@gmail.com>wrote:

> Hi,
>
> I'm familiar with the basic univariate normal distribution but am
> having trouble understanding how the Mahout multivariate normal
> distribution works.
>
> Specifically, what does the radius of the distribution stand for?
> What I'm imagining (at lest for 3 dimensions) is that all points would
> fit into a sphere centered in the mean with the given radius and that
> they would be normally distributed inside.
>
> This however doesn't seem to be the case (unless my tests are broken).
>
> What am I missing?
> Thanks!
>