mroughan / LinePicking

Numerical code for geometric probability problems, in particular density functions for the "line picking" problem.
0 stars 1 forks source link

moments for the n-sphere are now in the PDF #31

Closed mroughan closed 12 years ago

mroughan commented 12 years ago

Please add these to the n-sphere calculations. I'm still working on higher moments for the nsphere-geodesic.

lamestllama commented 12 years ago

Matt

Do you want to add a moments set of functions in instead of mean and var ? so where we have higher moments we can return them ?

ERic

On 10/09/2012, at 11:25 AM, Matthew Roughan wrote:

Please add these to the n-sphere calculations. I'm still working on higher moments for the nsphere-geodesic.

— Reply to this email directly or view it on GitHub.

mroughan commented 12 years ago

No, I think we just need mean and var, otherwise we trap ourselves into producing moments for all of them, which would be a pain, and mostly unneeded.

BTW, I now have a guess at the form of the 2nd moment for the n-sphere-geodesic. Will continue to work on justifying it, but if you implement it at least we can test it out.

lamestllama commented 12 years ago

We already had the mean for the n-sphere so atm all you want added is the variance for the n-sphere ?

and you assigned that to me whilst on leave ?

and put it in writing on git ?

lamestllama commented 12 years ago

The n-sphere moments are not believable. Equation 96 says

$E[ X^k ] = \frac{(2R)^{k-1} \Gamma\left[ n \right] \Gamma\left[ (k+n)/2 \right]}{\Gamma\left[\frac{n}{2}\right] \Gamma\left[ n+k/2 \right] }$

Now for the first moment (the mean) we have $2R^(k-1)$ with $k = 1$ so $R$ has no effect on the mean ?

I have implemented it regardless.

mroughan commented 12 years ago

You missed the obvious mistake. Its fixed now -- try the new version.

Also the results for the n-sphere geodesics are in the PDF, and the derivations {\em seem} correct. Worth testing once you implement.

lamestllama commented 12 years ago

Once you spot one mistake in any math no point in looking for more unless you intend to fix it

lamestllama commented 12 years ago

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

mroughan commented 12 years ago

Not sure where this is coming from. If you had that solution, why not write it up?

On 10/09/12 20:41, Eric Parsonage wrote:

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8420373.

lamestllama commented 12 years ago

On 11/09/2012, at 1:54 AM, Matthew Roughan wrote:

Not sure where this is coming from. If you had that solution, why not write it up?

Not sure it is correct. I stuck bits and bobs into mathematica so the intermediate steps are a mystery.

but looking at what you have it is certainly related. And evaluating the first 6 they come to the same.

The trigamma function i.e. psi^(1) can be written as an infinite sum of terms 1 / (z + k)^2 which seems to be a part of what you have. In my case the infinite sums cancel out after a while and must come to the same value as your finite sums.

In fact the wiki page shows \psi_1(z + 1) = \psi_1(z) - \frac{1}{z^2} which looks very close you your recurrence relation.

On 10/09/12 20:41, Eric Parsonage wrote:

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8420373.

— Reply to this email directly or view it on GitHub.

mroughan commented 12 years ago

I'm not sure it matters much. We have two simply evaluated forms of solutions.

The trigamma doesn't teach us anything I can think of.

If you are still keen to solve it, then the usual approach is to find generating functions, e.g., something like \sum_i z^i m_i

Cheers, Matt

On 11/09/12 02:08, Eric Parsonage wrote:

On 11/09/2012, at 1:54 AM, Matthew Roughan wrote:

Not sure where this is coming from. If you had that solution, why not write it up?

Not sure it is correct. I stuck bits and bobs into mathematica so the intermediate steps are a mystery.

but looking at what you have it is certainly related. And evaluating the first 6 they come to the same.

The trigamma function i.e. psi^(1) can be written as an infinite sum of terms 1 / (z + k)^2 which seems to be a part of what you have. In my case the infinite sums cancel out after a while and must come to the same value as your finite sums.

In fact the wiki page shows \psi_1(z + 1) = \psi_1(z) - \frac{1}{z^2} which looks very close you your recurrence relation.

On 10/09/12 20:41, Eric Parsonage wrote:

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8420373.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8429165.

lamestllama commented 12 years ago

The only difference is for very large both the solutions you present time scales with n the the but the evaluation of the trigamma becomes fixed above n = 6 or 7.

It all depends on how big n is going to be.

lamestllama commented 12 years ago

I forgot to say I did try the generating function approach. both using the laplace transform of the pdf and the other method using the CDF.

in the end i just got mathematica to evaluate

E[X^2] - E[X]^2 like you did

and do a full simplify.

The thing that dropped out was the trigamma thing.

I couldn't see how it got that at all.

On 11/09/2012, at 8:34 AM, Matthew Roughan wrote:

I'm not sure it matters much. We have two simply evaluated forms of solutions.

The trigamma doesn't teach us anything I can think of.

If you are still keen to solve it, then the usual approach is to find generating functions, e.g., something like \sum_i z^i m_i

Cheers, Matt

On 11/09/12 02:08, Eric Parsonage wrote:

On 11/09/2012, at 1:54 AM, Matthew Roughan wrote:

Not sure where this is coming from. If you had that solution, why not write it up?

Not sure it is correct. I stuck bits and bobs into mathematica so the intermediate steps are a mystery.

but looking at what you have it is certainly related. And evaluating the first 6 they come to the same.

The trigamma function i.e. psi^(1) can be written as an infinite sum of terms 1 / (z + k)^2 which seems to be a part of what you have. In my case the infinite sums cancel out after a while and must come to the same value as your finite sums.

In fact the wiki page shows \psi_1(z + 1) = \psi_1(z) - \frac{1}{z^2} which looks very close you your recurrence relation.

On 10/09/12 20:41, Eric Parsonage wrote:

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8420373.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8429165.

— Reply to this email directly or view it on GitHub.

mroughan commented 12 years ago

Looks pretty easy to see how you could derive the recurrence relation in terms of trigammas, just from the defn, and its special values. http://en.wikipedia.org/wiki/Trigamma_function

Fast computation for large n shouldn't be really needed, but I guess if its easy we may as well have it.

Matt

On 11/09/12 09:50, Eric Parsonage wrote:

The only difference is for very large both the solutions you present time scales with n the the but the evaluation of the trigamma becomes fixed above n = 6 or 7.

It all depends on how big n is going to be.

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8443077.

mroughan commented 12 years ago

That's the problem with mathematica et al, they don't give you much insight into solutions, but its helps a lot if you know where you are heading.

I did it the old-fashioned, hard way, but you inevitably work backwards and forwards from what you think you want to get, back to what you can derive, and so on. So knowing the solution up front would have been helpful.

Cheers, Matt

On 11/09/12 10:18, Eric Parsonage wrote:

I forgot to say I did try the generating function approach. both using the laplace transform of the pdf and the other method using the CDF.

in the end i just got mathematica to evaluate

E[X^2] - E[X]^2 like you did

and do a full simplify.

The thing that dropped out was the trigamma thing.

I couldn't see how it got that at all.

On 11/09/2012, at 8:34 AM, Matthew Roughan wrote:

I'm not sure it matters much. We have two simply evaluated forms of solutions.

The trigamma doesn't teach us anything I can think of.

If you are still keen to solve it, then the usual approach is to find generating functions, e.g., something like \sum_i z^i m_i

Cheers, Matt

On 11/09/12 02:08, Eric Parsonage wrote:

On 11/09/2012, at 1:54 AM, Matthew Roughan wrote:

Not sure where this is coming from. If you had that solution, why not write it up?

Not sure it is correct. I stuck bits and bobs into mathematica so the intermediate steps are a mystery.

but looking at what you have it is certainly related. And evaluating the first 6 they come to the same.

The trigamma function i.e. psi^(1) can be written as an infinite sum of terms 1 / (z + k)^2 which seems to be a part of what you have. In my case the infinite sums cancel out after a while and must come to the same value as your finite sums.

In fact the wiki page shows \psi_1(z + 1) = \psi_1(z) - \frac{1}{z^2} which looks very close you your recurrence relation.

On 10/09/12 20:41, Eric Parsonage wrote:

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8420373.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8429165.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8443554.

mroughan commented 12 years ago

Fast algorithm seems to be here. Its under LGPL -- not sure of implications if we wanted to include it -- you know more about licenses, but its so simple that it would be hard to rewrite it and get something that looks really different.

http://people.sc.fsu.edu/~jburkardt/c_src/asa121/asa121.html http://people.sc.fsu.edu/~jburkardt/c_src/asa121/asa121.c

Let me know if you want to include, or how to proceed. BTW, the same page has an incomplete beta function http://people.sc.fsu.edu/~jburkardt/c_src/asa063/asa063.html

Maybe its faster than mine? I don't know how much time we want to mess around with these little numerical tweaks though.

Cheers, Matt

On 11/09/12 10:18, Eric Parsonage wrote:

I forgot to say I did try the generating function approach. both using the laplace transform of the pdf and the other method using the CDF.

in the end i just got mathematica to evaluate

E[X^2] - E[X]^2 like you did

and do a full simplify.

The thing that dropped out was the trigamma thing.

I couldn't see how it got that at all.

On 11/09/2012, at 8:34 AM, Matthew Roughan wrote:

I'm not sure it matters much. We have two simply evaluated forms of solutions.

The trigamma doesn't teach us anything I can think of.

If you are still keen to solve it, then the usual approach is to find generating functions, e.g., something like \sum_i z^i m_i

Cheers, Matt

On 11/09/12 02:08, Eric Parsonage wrote:

On 11/09/2012, at 1:54 AM, Matthew Roughan wrote:

Not sure where this is coming from. If you had that solution, why not write it up?

Not sure it is correct. I stuck bits and bobs into mathematica so the intermediate steps are a mystery.

but looking at what you have it is certainly related. And evaluating the first 6 they come to the same.

The trigamma function i.e. psi^(1) can be written as an infinite sum of terms 1 / (z + k)^2 which seems to be a part of what you have. In my case the infinite sums cancel out after a while and must come to the same value as your finite sums.

In fact the wiki page shows \psi_1(z + 1) = \psi_1(z) - \frac{1}{z^2} which looks very close you your recurrence relation.

On 10/09/12 20:41, Eric Parsonage wrote:

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8420373.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8429165.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8443554.

lamestllama commented 12 years ago

Matt

that was the algorithm I based my timings on

Eric

On 11/09/2012, at 10:39 AM, Matthew Roughan wrote:

Fast algorithm seems to be here. Its under LGPL -- not sure of implications if we wanted to include it -- you know more about licenses, but its so simple that it would be hard to rewrite it and get something that looks really different.

http://people.sc.fsu.edu/~jburkardt/c_src/asa121/asa121.html http://people.sc.fsu.edu/~jburkardt/c_src/asa121/asa121.c

Let me know if you want to include, or how to proceed. BTW, the same page has an incomplete beta function http://people.sc.fsu.edu/~jburkardt/c_src/asa063/asa063.html

Maybe its faster than mine? I don't know how much time we want to mess around with these little numerical tweaks though.

Cheers, Matt

On 11/09/12 10:18, Eric Parsonage wrote:

I forgot to say I did try the generating function approach. both using the laplace transform of the pdf and the other method using the CDF.

in the end i just got mathematica to evaluate

E[X^2] - E[X]^2 like you did

and do a full simplify.

The thing that dropped out was the trigamma thing.

I couldn't see how it got that at all.

On 11/09/2012, at 8:34 AM, Matthew Roughan wrote:

I'm not sure it matters much. We have two simply evaluated forms of solutions.

The trigamma doesn't teach us anything I can think of.

If you are still keen to solve it, then the usual approach is to find generating functions, e.g., something like \sum_i z^i m_i

Cheers, Matt

On 11/09/12 02:08, Eric Parsonage wrote:

On 11/09/2012, at 1:54 AM, Matthew Roughan wrote:

Not sure where this is coming from. If you had that solution, why not write it up?

Not sure it is correct. I stuck bits and bobs into mathematica so the intermediate steps are a mystery.

but looking at what you have it is certainly related. And evaluating the first 6 they come to the same.

The trigamma function i.e. psi^(1) can be written as an infinite sum of terms 1 / (z + k)^2 which seems to be a part of what you have. In my case the infinite sums cancel out after a while and must come to the same value as your finite sums.

In fact the wiki page shows \psi_1(z + 1) = \psi_1(z) - \frac{1}{z^2} which looks very close you your recurrence relation.

On 10/09/12 20:41, Eric Parsonage wrote:

I have been waiting two days for you to confirm that the variance is where \psi is the polygamma function.

All you need to do is solve your recurrence relation

\begin{equation} Var\big[ X_{n,R} \big] = \frac{1}{4} R^2 \left(4 \psi ^{(1)}(n+1)+(-1)^{2 n} \left(\psi ^{(1)}\left(\frac{n+1}{2}\right)-\psi ^{(1)}\left(\frac{n+2}{2}\right)\right)\right) \end{equation}

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8420373.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub

https://github.com/mroughan/LinePicking/issues/31#issuecomment-8429165.

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/mroughan/LinePicking/issues/31#issuecomment-8443554.

— Reply to this email directly or view it on GitHub.