MBB-team / VBA-toolbox

The VBA toolbox
GNU General Public License v3.0
129 stars 67 forks source link

Conversion of Noise Distribution #77

Open manueich opened 5 years ago

manueich commented 5 years ago

The two functions added allow the conversion between a gamma distributed precision and the distribution over the associated standard deviation in both directions for the more intuitive interpretation/definition of posterior/prior distributions of the noise parameters. The attached document provides the mathematical details. Notes.pdf

lionel-rigoux commented 5 years ago

Thank you for your contribution! This looks like very promising and a welcome addition to the toolbox (the current VBA_guess_hyperpriors is a bit rough...). Jean and I will review your code and notes and we'll come back to you if we have questions. Also, in the case we would integrate your code, would you be willing to write a litte paragraph/page for our wiki to explain how to use your function (for the less experienced users)?

manueich commented 5 years ago

Thanks for your feedback. I put it up after Jean suggested it in recent forum post I made. I would be happy to write something for the wiki, should it be accepted. Something I should mention is that the conversion from mu and sig to a and b is based on a numerical optimization scheme, which does not work for all possible combinations of mu and sig. For example if mu is very large in comparison to sig, e.g. mu=10000 and sig=0.01, the optimization fails. However these cases should be quite unrealistic in practice. The function automatically checks if the optimization worked within a certain error margin and alerts the user if it failed.

Looking forward to hearing from you.

manueich commented 5 years ago

Dear Jean and Lionel, I was wondering whether you had a chance to review my submission. I have been developing this method in the context of my PhD project and it has fed into a few papers (one of them is listed in VBA's website list of publications under Eichenlaub M. and more are likely to follow), so I would be really interested in your opinion on this. It is not a big deal, but I said I think this is useful to anyone who wants a more intuitive interpretation of the noise parameter distributions. Best wishes, Manuel

manueich commented 4 years ago

Hi, I was wondering if there is any chance that this will get reviewed at some point. Manuel

lionel-rigoux commented 4 years ago

Hi Manuel,

Sorry for the long silence, it's been a busy year and the toolbox was quite down the priority list unfortunately.

I'll add some comments to your pull request right away.

The only thing I think is missing is a demo (like demo_static or demo_multisession) with a very simple model that shows the difference between using the default method and the one you suggest. The goal is double: 1) provide the other users with a minimal working example that could serve as a tutorial, 2) have a formal way to check that your method indeed works (either by running it manually, but also through VBA_test). Would you have time to implement this?

Could you also send me a little text for the wiki?

manueich commented 4 years ago

Hello Lionel, thank you very much for your reply and comments. Before we go any further, I think I need to clarify something.

Reading your comments, I think you might have slightly misunderstood what the functions are implementing. It seems to me that you think the function does the following: Given a gamma distributed precision p, defined by a and b, the function VBA_Convert_ab (or VBA_Gam2Norm as you suggested) approximates the distribution over the standard deviation s=1/sqrt(p) with a normal distribution, defined with mu and sigma.

This is not exactly the case as I don't use a normal distribution at all. What I suggest is not an approximation, it is the exact thing. Given the transformation s=1/sqrt(p), it is possible to directly formulate the PDF over s, called IRGamma defined by a and b from the "original" gamma distribution. Subsequently, mean and standard deviation, which I call mu and sig, of this new PDF (IRGamma) can be directly calculated using a and b. This is what the function VBA_Convert_ab does.

The second function (VBA_Create_Noise _Prior) essentially reverses this by calculating a and b given mu and sig. Here I use a numerical approximation simply because a direct analytical derivation of a and b is not possible (as far as I can tell and I have tried a few things).

The document I attached in my very first post, provides the details of this. Nevertheless I attached a very short document explaining this as well.

Short.pdf

If my reasoning is correct and you still think this is a valuable contribution to the toolbox, I am happy to make the changes you asked for and write a demo and something for the wiki. I am also happy to test the function against the existing functions if you give me a bit more details on which to use. I already had a look at the VBA_guessHyperpriors function, but am not quite sure how it works, maybe you could give me an example.

Manuel

lionel-rigoux commented 4 years ago

Hi Manu,

Of course you're not relying on a Gaussian approximation, I don't know why I was confused.

You demo shows well how your function can help the estimation. I'm also glad to see that mine was not too bad either (compared to the default).

I think that I will go one step further and create a more generic function allowing to define the hyperpriors using different summary statistics, like mean and variance of the std (using your function), confidence interval about the explained variance (like in guessHyperpriors), and so on. To do so, I will create a new branch in which I will accept your pull request. Once the feature is done it will be merged in the dev then master branch. I hope this is fine with you. If you want to help, you could eg. see if deriving a and b from a confidence interval about the noise std is possible.

I just have one request left: you pushed your functions twice, once in the root folder, and once in the utils folder. I am not sure those two are the same... Please delete the outdated one so I am sure to integrate the right one.

manueich commented 4 years ago

Hi Lionel,

thank you very much. I am happy to hear that you think my contributions are useful. I think the idea of creating a more generic function combining different approaches is great and I look forward to using it.

I apologise for the confusion with the uploads. The two relevant and up to date functions are now only in the utils folder and I have moved the demo into demos/0_basics folder.

Please let me know if I can help with anything else.

Best wishes, Manuel

manueich commented 3 years ago

Hi,

just to give an update on this. I published a preprint on this method (https://arxiv.org/abs/2101.06289) and you will find an updated version of the code in the repository (https://github.com/manueich/Noise_Gamma), in case you decide to include it.

Manuel